This commit is contained in:
2025-12-26 18:30:14 +08:00
parent abe131fedc
commit ee950e00a1
5 changed files with 59 additions and 39 deletions

View File

@@ -69,7 +69,6 @@
"electron-log": "^5.4.0", "electron-log": "^5.4.0",
"electron-store": "^8.0.0", "electron-store": "^8.0.0",
"electron-updater": "^6.3.9", "electron-updater": "^6.3.9",
"jquery": "^3.7.1",
"ws": "^8.18.2", "ws": "^8.18.2",
"xe-utils": "^3.7.4" "xe-utils": "^3.7.4"
}, },

View File

@@ -21,6 +21,11 @@ import WebSocketClient from './utils/WebSocketClient';
let wsClient=null let wsClient=null
const isDebugger=getStoreValue("isDebugger");
if (isDebugger==null||isDebugger==''){
setStoreValue("isDebugger",0)
}
// 延迟创建WebSocket连接等待应用完全启动后再连接 // 延迟创建WebSocket连接等待应用完全启动后再连接
function createWebSocketClient() { function createWebSocketClient() {
try { try {

View File

@@ -124,7 +124,19 @@ export function createTray() {
click: () => { click: () => {
createConfigWindow() createConfigWindow()
} }
} },
{
label: '打开日志目录',
click: () => {
try {
const configDir = app.getPath('userData')
logger.info('打开配置文件目录:', configDir)
shell.openPath(configDir)
} catch (error) {
logger.error('打开配置文件目录失败:', error)
}
}
},
] ]
}, },
{ type: 'separator' }, { type: 'separator' },
@@ -144,8 +156,6 @@ export function createTray() {
} }
} }
} }
}, },
{ type: 'separator' }, { type: 'separator' },

View File

@@ -134,7 +134,18 @@ export async function createWindow() {
// 创建菜单 // 创建菜单
createMenu(mainWindow, difyfullScreenWindow) createMenu(mainWindow, difyfullScreenWindow)
let code = `localStorage.setItem("IsHsAiApp","IsHsAiApp");localStorage.setItem("HsAppCode",${import.meta.env.VITE_HsAppCode});`
const isDebugger=getStoreValue("isDebugger");
const localStorageStatements = [
`localStorage.setItem("IsHsAiApp","IsHsAiApp");`,
`localStorage.setItem("HsAppCode",${import.meta.env.VITE_HsAppCode});`,
`localStorage.setItem("isDebugger",${isDebugger});`
].join('\n');
let code = `${localStorageStatements};`;
const isAdmin = getStoreValue("isAdmin") const isAdmin = getStoreValue("isAdmin")
@@ -156,12 +167,17 @@ export async function createWindow() {
// 监听快捷键 F12 来打开/关闭 DevTools // 监听快捷键 F12 来打开/关闭 DevTools
mainWindow.webContents.on('before-input-event', (event, input) => { mainWindow.webContents.on('before-input-event', (event, input) => {
if (input.key === 'F12') {
mainWindow.webContents.toggleDevTools() const isDebugger=getStoreValue("isDebugger");
} else if (input.key === 'F5') { if (isDebugger==1){
logger.info('主窗口 F5 快捷键触发') if (input.key === 'F12') {
mainWindow.reload() mainWindow.webContents.toggleDevTools()
} else if (input.key === 'F5') {
logger.info('全屏窗口 F5 快捷键触发')
mainWindow.reload()
}
} }
}) })
@@ -340,8 +356,15 @@ function registerShortcuts(window=null) {
logger.info(`F5快捷键注册${success ? '成功' : '失败'}`) logger.info(`F5快捷键注册${success ? '成功' : '失败'}`)
const isRegistered_F12 = globalShortcut.isRegistered('F12');
logger.info(`Is F12 registered: ${isRegistered_F12}`);
const isDebugger=getStoreValue("isDebugger");
if (isDebugger==1){
const isRegistered_F12 = globalShortcut.isRegistered('F12');
logger.info(`Is F12 registered: ${isRegistered_F12}`);
}
// 桌面端快要退出的时候,注销快捷键 // 桌面端快要退出的时候,注销快捷键
app.on('will-quit', () => { app.on('will-quit', () => {
@@ -455,12 +478,16 @@ export async function createNewWindow(url, access_token, refresh_token,sandbox=f
// 监听快捷键 F12 来打开/关闭 DevTools // 监听快捷键 F12 来打开/关闭 DevTools
difyfullScreenWindow.webContents.on('before-input-event', (event, input) => { difyfullScreenWindow.webContents.on('before-input-event', (event, input) => {
if (input.key === 'F12') { const isDebugger=getStoreValue("isDebugger");
difyfullScreenWindow.webContents.toggleDevTools() if (isDebugger==1){
} else if (input.key === 'F5') { if (input.key === 'F12') {
logger.info('全屏窗口 F5 快捷键触发') difyfullScreenWindow.webContents.toggleDevTools()
difyfullScreenWindow.reload() } else if (input.key === 'F5') {
logger.info('全屏窗口 F5 快捷键触发')
difyfullScreenWindow.reload()
}
} }
}) })
difyfullScreenWindow.webContents.setWindowOpenHandler((details) => { difyfullScreenWindow.webContents.setWindowOpenHandler((details) => {

View File

@@ -18,26 +18,5 @@ if (process.contextIsolated) {
window.electron = electronAPI window.electron = electronAPI
window.api = api window.api = api
// ✅ 重点修复:覆盖 require('jquery') 让它返回 jQuery
try {
// 保存原始 require 避免循环
const originalRequire = require;
// 重写 require 函数,让 'jquery' 请求返回 jQuery
require = (request) => {
if (request === 'jquery') {
// 确保 jQuery 已加载
if (!window.jQuery) {
window.jQuery = originalRequire('jquery');
window.$ = window.jQuery;
}
return window.jQuery;
}
return originalRequire(request);
};
// 初始化 jQuery触发上面的逻辑
window.jQuery = require('jquery');
window.$ = window.jQuery;
} catch (e) {
console.error('Failed to load jQuery:', e);
}
} }