rm unused log
This commit is contained in:
		| @ -1,26 +0,0 @@ | ||||
| const Database = require('better-sqlite3'); | ||||
| const path = require('path'); | ||||
| const os = require('os'); | ||||
|  | ||||
| const dbPath = path.join(os.homedir(), 'seabox_fanyi_application', 'database', 'seabox.db'); | ||||
| console.log('数据库路径:', dbPath); | ||||
|  | ||||
| try { | ||||
|   const db = new Database(dbPath); | ||||
|    | ||||
|   console.log('\n=== 局部代理配置 ==='); | ||||
|   const proxyConfigs = db.prepare('SELECT * FROM proxy_config').all(); | ||||
|   proxyConfigs.forEach(config => { | ||||
|     console.log(`ID: ${config.id}, partitionId: ${config.partitionId}, proxyIp: ${config.proxyIp}, proxyPort: ${config.proxyPort}, proxyStatus: ${config.proxyStatus}`); | ||||
|   }); | ||||
|    | ||||
|   console.log('\n=== 全局代理配置 ==='); | ||||
|   const globalConfigs = db.prepare('SELECT * FROM global_proxy_config').all(); | ||||
|   globalConfigs.forEach(config => { | ||||
|     console.log(`ID: ${config.id}, proxyIp: ${config.proxyIp}, proxyPort: ${config.proxyPort}, proxyStatus: ${config.proxyStatus}`); | ||||
|   }); | ||||
|    | ||||
|   db.close(); | ||||
| } catch (error) { | ||||
|   console.error('数据库查询失败:', error.message); | ||||
| } | ||||
| @ -1,190 +0,0 @@ | ||||
| // 局部代理配置调试脚本 | ||||
| // 帮助检查和设置局部代理配置 | ||||
|  | ||||
| const { app } = require('electron'); | ||||
|  | ||||
| // 您的局部代理配置 | ||||
| const LOCAL_PROXY_CONFIG = { | ||||
|   proxyStatus: "true",           // 启用代理 | ||||
|   proxyType: "socks5",          // 代理类型 | ||||
|   proxyIp: "143.20.228.192",    // 代理IP | ||||
|   proxyPort: "3306",            // 代理端口 | ||||
|   userVerifyStatus: "true",     // 启用认证 | ||||
|   username: "mNrz1aEg",         // 用户名 | ||||
|   password: "3xV3dBYB"          // 密码 | ||||
| }; | ||||
|  | ||||
| // 检查所有代理配置 | ||||
| async function checkAllProxyConfigs() { | ||||
|   console.log('🔍 检查所有代理配置...\n'); | ||||
|    | ||||
|   try { | ||||
|     // 1. 检查全局代理配置 | ||||
|     const globalConfig = await app.sdb.selectOne("global_proxy_config"); | ||||
|     console.log('📋 全局代理配置:'); | ||||
|     if (globalConfig) { | ||||
|       console.log(`   状态: ${globalConfig.proxyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`); | ||||
|       console.log(`   IP: ${globalConfig.proxyIp || "未设置"}`); | ||||
|       console.log(`   端口: ${globalConfig.proxyPort || "未设置"}`); | ||||
|     } else { | ||||
|       console.log('   ❌ 未找到全局代理配置'); | ||||
|     } | ||||
|      | ||||
|     // 2. 检查所有局部代理配置 | ||||
|     const allProxyConfigs = await app.sdb.selectAll("proxy_config"); | ||||
|     console.log('\n📋 所有局部代理配置:'); | ||||
|     if (allProxyConfigs && allProxyConfigs.length > 0) { | ||||
|       allProxyConfigs.forEach((config, index) => { | ||||
|         console.log(`   配置 ${index + 1}:`); | ||||
|         console.log(`     ID: ${config.id}`); | ||||
|         console.log(`     partitionId: ${config.partitionId || "未设置"}`); | ||||
|         console.log(`     状态: ${config.proxyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`); | ||||
|         console.log(`     类型: ${config.proxyType || "未设置"}`); | ||||
|         console.log(`     IP: ${config.proxyIp || "未设置"}`); | ||||
|         console.log(`     端口: ${config.proxyPort || "未设置"}`); | ||||
|         console.log(`     认证: ${config.userVerifyStatus === "true" ? "✅ 启用" : "❌ 禁用"}`); | ||||
|         console.log(`     用户名: ${config.username || "未设置"}`); | ||||
|         console.log(''); | ||||
|       }); | ||||
|     } else { | ||||
|       console.log('   ❌ 未找到任何局部代理配置'); | ||||
|     } | ||||
|      | ||||
|     // 3. 检查会话列表 | ||||
|     const sessions = await app.sdb.selectAll("session_list"); | ||||
|     console.log('📋 当前会话列表:'); | ||||
|     if (sessions && sessions.length > 0) { | ||||
|       sessions.forEach((session, index) => { | ||||
|         console.log(`   会话 ${index + 1}:`); | ||||
|         console.log(`     partitionId: ${session.partitionId}`); | ||||
|         console.log(`     platform: ${session.platform}`); | ||||
|         console.log(`     windowStatus: ${session.windowStatus}`); | ||||
|         console.log(''); | ||||
|       }); | ||||
|     } else { | ||||
|       console.log('   ❌ 未找到任何会话'); | ||||
|     } | ||||
|      | ||||
|   } catch (error) { | ||||
|     console.error('❌ 检查代理配置失败:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
| // 为指定的partitionId设置局部代理配置 | ||||
| async function setupLocalProxy(partitionId) { | ||||
|   console.log(`🔧 为 ${partitionId} 设置局部代理配置...\n`); | ||||
|    | ||||
|   try { | ||||
|     // 检查是否已存在配置 | ||||
|     const existingConfig = await app.sdb.selectOne("proxy_config", { partitionId }); | ||||
|      | ||||
|     const configData = { | ||||
|       partitionId, | ||||
|       ...LOCAL_PROXY_CONFIG | ||||
|     }; | ||||
|      | ||||
|     if (existingConfig) { | ||||
|       console.log('📝 更新现有的局部代理配置...'); | ||||
|       await app.sdb.update("proxy_config", configData, { id: existingConfig.id }); | ||||
|       console.log('✅ 局部代理配置更新成功!'); | ||||
|     } else { | ||||
|       console.log('📝 创建新的局部代理配置...'); | ||||
|       await app.sdb.insert("proxy_config", configData); | ||||
|       console.log('✅ 局部代理配置创建成功!'); | ||||
|     } | ||||
|      | ||||
|     console.log('\n📋 配置详情:'); | ||||
|     console.log(`   partitionId: ${partitionId}`); | ||||
|     console.log(`   状态: ${LOCAL_PROXY_CONFIG.proxyStatus === "true" ? "启用" : "禁用"}`); | ||||
|     console.log(`   类型: ${LOCAL_PROXY_CONFIG.proxyType.toUpperCase()}`); | ||||
|     console.log(`   地址: ${LOCAL_PROXY_CONFIG.proxyIp}:${LOCAL_PROXY_CONFIG.proxyPort}`); | ||||
|     console.log(`   认证: ${LOCAL_PROXY_CONFIG.userVerifyStatus === "true" ? "启用" : "禁用"}`); | ||||
|     console.log(`   用户: ${LOCAL_PROXY_CONFIG.username}`); | ||||
|     console.log(`   密码: ${'*'.repeat(LOCAL_PROXY_CONFIG.password.length)}`); | ||||
|      | ||||
|   } catch (error) { | ||||
|     console.error('❌ 设置局部代理配置失败:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
| // 清除指定partitionId的局部代理配置 | ||||
| async function clearLocalProxy(partitionId) { | ||||
|   console.log(`🧹 清除 ${partitionId} 的局部代理配置...\n`); | ||||
|    | ||||
|   try { | ||||
|     const existingConfig = await app.sdb.selectOne("proxy_config", { partitionId }); | ||||
|      | ||||
|     if (existingConfig) { | ||||
|       await app.sdb.update("proxy_config", { | ||||
|         proxyStatus: "false", | ||||
|         proxyType: "http", | ||||
|         proxyIp: "", | ||||
|         proxyPort: "", | ||||
|         userVerifyStatus: "false", | ||||
|         username: "", | ||||
|         password: "" | ||||
|       }, { id: existingConfig.id }); | ||||
|        | ||||
|       console.log('✅ 局部代理配置已清除'); | ||||
|     } else { | ||||
|       console.log('⚠️  未找到该partitionId的代理配置'); | ||||
|     } | ||||
|      | ||||
|   } catch (error) { | ||||
|     console.error('❌ 清除局部代理配置失败:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
| // 确保全局代理配置为空 | ||||
| async function ensureGlobalProxyDisabled() { | ||||
|   console.log('🔧 确保全局代理配置为空...\n'); | ||||
|    | ||||
|   try { | ||||
|     const globalConfig = await app.sdb.selectOne("global_proxy_config"); | ||||
|      | ||||
|     if (globalConfig) { | ||||
|       await app.sdb.update("global_proxy_config", { | ||||
|         proxyStatus: "false", | ||||
|         proxyType: "http", | ||||
|         proxyIp: "", | ||||
|         proxyPort: "", | ||||
|         userVerifyStatus: "false", | ||||
|         username: "", | ||||
|         password: "" | ||||
|       }); | ||||
|       console.log('✅ 全局代理配置已禁用'); | ||||
|     } else { | ||||
|       console.log('⚠️  未找到全局代理配置'); | ||||
|     } | ||||
|      | ||||
|   } catch (error) { | ||||
|     console.error('❌ 禁用全局代理配置失败:', error); | ||||
|   } | ||||
| } | ||||
|  | ||||
| // 导出函数 | ||||
| module.exports = { | ||||
|   checkAllProxyConfigs, | ||||
|   setupLocalProxy, | ||||
|   clearLocalProxy, | ||||
|   ensureGlobalProxyDisabled, | ||||
|   LOCAL_PROXY_CONFIG | ||||
| }; | ||||
|  | ||||
| // 如果直接运行此文件 | ||||
| if (require.main === module) { | ||||
|   console.log('⚠️  这个脚本需要在Electron应用启动后调用'); | ||||
|   console.log('💡 请在应用的控制台中运行以下命令:'); | ||||
|   console.log(''); | ||||
|   console.log('   // 检查所有配置'); | ||||
|   console.log('   const debug = require("./debug_local_proxy.js");'); | ||||
|   console.log('   debug.checkAllProxyConfigs();'); | ||||
|   console.log(''); | ||||
|   console.log('   // 确保全局代理禁用'); | ||||
|   console.log('   debug.ensureGlobalProxyDisabled();'); | ||||
|   console.log(''); | ||||
|   console.log('   // 为特定会话设置局部代理(替换为实际的partitionId)'); | ||||
|   console.log('   debug.setupLocalProxy("您的partitionId");'); | ||||
|   console.log(''); | ||||
|   console.log('🔍 或者先运行 checkAllProxyConfigs() 查看当前所有配置'); | ||||
| } | ||||
| @ -1,7 +1,7 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const path = require("path"); | ||||
| const { getBaseDir, getElectronDir } = require("ee-core/ps"); | ||||
| const { getBaseDir } = require("ee-core/ps"); | ||||
|  | ||||
| /** | ||||
|  * 默认配置 | ||||
| @ -21,7 +21,7 @@ module.exports = () => { | ||||
|         // webSecurity: false, | ||||
|         contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge) | ||||
|         nodeIntegration: true, | ||||
|         preload: path.join(getElectronDir(), 'preload', 'bridge.js'), // 添加preload脚本 | ||||
|         // preload: path.join(getElectronDir(),  'bridge.js'), | ||||
|       }, | ||||
|       titleBarStyle: "hidden", | ||||
|       frame: true, | ||||
| @ -30,7 +30,7 @@ module.exports = () => { | ||||
|     }, | ||||
|     logger: { | ||||
|       rotator: "day", | ||||
|       level: "INFO", | ||||
|       level: "WARN", // 从 INFO 改为 WARN,减少日志输出 | ||||
|       outputJSON: false, | ||||
|       appLogName: "ee.log", | ||||
|       coreLogName: "ee-core.log", | ||||
|  | ||||
| @ -15,10 +15,6 @@ class SystemController { | ||||
|         return await systemService.getBaseInfo(args,event); | ||||
|     } | ||||
|  | ||||
|     async getUserDataPath(args, event) { | ||||
|         return await systemService.getUserDataPath(args, event); | ||||
|     } | ||||
|  | ||||
|     async login(args,event) { | ||||
|         return await systemService.login(args,event); | ||||
|     } | ||||
|  | ||||
| @ -14,26 +14,6 @@ try { | ||||
|         return ipcRenderer.invoke(channel, data); | ||||
|       }, | ||||
|  | ||||
|       // 添加send方法 | ||||
|       send: (channel, data) => { | ||||
|         return ipcRenderer.send(channel, data); | ||||
|       }, | ||||
|  | ||||
|       // 添加on方法用于监听事件 | ||||
|       on: (channel, listener) => { | ||||
|         return ipcRenderer.on(channel, listener); | ||||
|       }, | ||||
|  | ||||
|       // 添加removeListener方法 | ||||
|       removeListener: (channel, listener) => { | ||||
|         return ipcRenderer.removeListener(channel, listener); | ||||
|       }, | ||||
|  | ||||
|       // 添加removeAllListeners方法 | ||||
|       removeAllListeners: (channel) => { | ||||
|         return ipcRenderer.removeAllListeners(channel); | ||||
|       }, | ||||
|  | ||||
|       // 原有的方法 | ||||
|       onDownloadProgress: (callback) => { | ||||
|         const listener = (_, progress) => callback(progress); | ||||
| @ -45,11 +25,6 @@ try { | ||||
|         ipcRenderer.on("update-downloaded", listener); | ||||
|         return () => ipcRenderer.removeListener("update-downloaded", listener); | ||||
|       }, | ||||
|       onUpdateAvailable: (callback) => { | ||||
|         const listener = () => callback(); | ||||
|         ipcRenderer.on("update-available", listener); | ||||
|         return () => ipcRenderer.removeListener("update-available", listener); | ||||
|       }, | ||||
|     }); | ||||
|  | ||||
|     console.log('✅ electronAPI 已通过 contextBridge 暴露'); | ||||
| @ -63,18 +38,6 @@ try { | ||||
|       invoke: (channel, data) => { | ||||
|         return ipcRenderer.invoke(channel, data); | ||||
|       }, | ||||
|       send: (channel, data) => { | ||||
|         return ipcRenderer.send(channel, data); | ||||
|       }, | ||||
|       on: (channel, listener) => { | ||||
|         return ipcRenderer.on(channel, listener); | ||||
|       }, | ||||
|       removeListener: (channel, listener) => { | ||||
|         return ipcRenderer.removeListener(channel, listener); | ||||
|       }, | ||||
|       removeAllListeners: (channel) => { | ||||
|         return ipcRenderer.removeAllListeners(channel); | ||||
|       }, | ||||
|       onDownloadProgress: (callback) => { | ||||
|         const listener = (_, progress) => callback(progress); | ||||
|         ipcRenderer.on("download-progress", listener); | ||||
| @ -85,11 +48,6 @@ try { | ||||
|         ipcRenderer.on("update-downloaded", listener); | ||||
|         return () => ipcRenderer.removeListener("update-downloaded", listener); | ||||
|       }, | ||||
|       onUpdateAvailable: (callback) => { | ||||
|         const listener = () => callback(); | ||||
|         ipcRenderer.on("update-available", listener); | ||||
|         return () => ipcRenderer.removeListener("update-available", listener); | ||||
|       }, | ||||
|     }; | ||||
|  | ||||
|     console.log('✅ electronAPI 已直接挂载到 window'); | ||||
| @ -105,24 +63,7 @@ try { | ||||
|       window.electronAPI = { | ||||
|         invoke: (channel, data) => { | ||||
|           return ipcRenderer.invoke(channel, data); | ||||
|         }, | ||||
|         send: (channel, data) => { | ||||
|           return ipcRenderer.send(channel, data); | ||||
|         }, | ||||
|         on: (channel, listener) => { | ||||
|           return ipcRenderer.on(channel, listener); | ||||
|         }, | ||||
|         removeListener: (channel, listener) => { | ||||
|           return ipcRenderer.removeListener(channel, listener); | ||||
|         }, | ||||
|         removeAllListeners: (channel) => { | ||||
|           return ipcRenderer.removeAllListeners(channel); | ||||
|         }, | ||||
|         onUpdateAvailable: (callback) => { | ||||
|           const listener = () => callback(); | ||||
|           ipcRenderer.on("update-available", listener); | ||||
|           return () => ipcRenderer.removeListener("update-available", listener); | ||||
|         }, | ||||
|         } | ||||
|       }; | ||||
|  | ||||
|       console.log('✅ electronAPI fallback 创建成功'); | ||||
|  | ||||
| @ -389,12 +389,6 @@ const ipcMainListener = () => { | ||||
|     return { status: true, data: app.wsBaseUrl }; | ||||
|   }); | ||||
|  | ||||
|   // 添加getUserDataPath处理器 | ||||
|   ipcMain.handle("getUserDataPath", async (event, args) => { | ||||
|     const { systemService } = require("../service/system"); | ||||
|     return await systemService.getUserDataPath(args, event); | ||||
|   }); | ||||
|  | ||||
|  | ||||
|   // 语言检测(转发到后端) | ||||
|   ipcMain.handle("detect-language", async (event, args) => { | ||||
|  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -24,39 +24,6 @@ class SystemService { | ||||
|     return systemInfo; | ||||
|   } | ||||
|  | ||||
|   async getUserDataPath(args, event) { | ||||
|     const path = require('path'); | ||||
|     const fs = require('fs'); | ||||
|  | ||||
|     const userDataPath = app.getPath('userData'); | ||||
|     const localStoragePath = path.join(userDataPath, 'Local Storage'); | ||||
|  | ||||
|     let localStorageExists = false; | ||||
|     let localStorageFiles = []; | ||||
|  | ||||
|     try { | ||||
|       const stats = fs.statSync(localStoragePath); | ||||
|       localStorageExists = stats.isDirectory(); | ||||
|       if (localStorageExists) { | ||||
|         localStorageFiles = fs.readdirSync(localStoragePath); | ||||
|       } | ||||
|     } catch (error) { | ||||
|       // localStorage目录不存在 | ||||
|     } | ||||
|  | ||||
|     return { | ||||
|       status: true, | ||||
|       data: { | ||||
|         userDataPath, | ||||
|         localStoragePath, | ||||
|         localStorageExists, | ||||
|         localStorageFiles, | ||||
|         cwd: process.cwd(), | ||||
|         appPath: app.getAppPath() | ||||
|       } | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   //   * 错误码说明: | ||||
|   // *  {401} 参数缺失 - 请求缺少必要参数或参数格式错误 | ||||
|   // *  {402} 账户不存在 - 提供的凭证未关联任何注册账户 | ||||
|  | ||||
| @ -163,15 +163,16 @@ class WindowService { | ||||
|           logger.info(`[${sessionPartitionId}] 等待代理设置生效...`); | ||||
|           await new Promise(resolve => setTimeout(resolve, 1000)); | ||||
|  | ||||
|           // 添加网络请求监听以诊断问题(仅记录重要请求,避免日志暴涨) | ||||
|           // 添加网络请求监听以诊断问题(仅记录关键请求,避免日志暴涨) | ||||
|           view.webContents.session.webRequest.onBeforeRequest((details, callback) => { | ||||
|             // 只记录WebSocket和API请求,忽略静态资源 | ||||
|             // 只记录WebSocket连接和关键API请求,避免日志暴涨 | ||||
|             if (details.url.startsWith('wss://') || details.url.startsWith('ws://')) { | ||||
|               logger.info(`[${sessionPartitionId}] WebSocket请求: ${details.method} ${details.url}`); | ||||
|             } else if (details.url.includes('/api/') || details.url.includes('ajax') || details.url.includes('graphql')) { | ||||
|               logger.info(`[${sessionPartitionId}] API请求: ${details.method} ${details.url}`); | ||||
|             } else if (details.url.includes('/api/') || details.url.includes('login') || details.url.includes('auth')) { | ||||
|               // 只记录关键API请求 | ||||
|               logger.info(`[${sessionPartitionId}] 关键API请求: ${details.method} ${details.url}`); | ||||
|             } | ||||
|             // 不再记录所有网络请求,避免日志暴涨 | ||||
|             // 移除了对所有网络请求的日志记录,避免日志文件暴涨 | ||||
|             callback({}); | ||||
|           }); | ||||
|  | ||||
| @ -440,20 +441,18 @@ class WindowService { | ||||
|         if (sessionObj) { | ||||
|           logger.info(`[${partitionId}] 刷新会话:重新加载代理配置`); | ||||
|  | ||||
|           // 清除会话缓存和旧的代理设置(保留登录状态) | ||||
|           // 清除会话缓存和旧的代理设置 | ||||
|           logger.info(`[${partitionId}] 清除会话缓存和旧代理设置`); | ||||
|           try { | ||||
|             // 只清除网络缓存,不清除存储数据以保持登录状态 | ||||
|             // 清除网络缓存 | ||||
|             await view.webContents.session.clearCache(); | ||||
|  | ||||
|             // ❌ 注释掉清除存储数据,避免清除登录状态 | ||||
|             // await view.webContents.session.clearStorageData({ | ||||
|             //   storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'] | ||||
|             // }); | ||||
|  | ||||
|             // 清除存储数据(但保留cookies和localStorage) | ||||
|             await view.webContents.session.clearStorageData({ | ||||
|               storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'] | ||||
|             }); | ||||
|             // 重置代理为系统代理,确保清除旧配置 | ||||
|             await view.webContents.session.setProxy({ mode: 'system' }); | ||||
|             logger.info(`[${partitionId}] 会话缓存清除完成(保留登录状态)`); | ||||
|             logger.info(`[${partitionId}] 会话缓存清除完成`); | ||||
|           } catch (clearError) { | ||||
|             logger.warn(`[${partitionId}] 清除缓存时出现警告:`, clearError.message); | ||||
|           } | ||||
| @ -1351,7 +1350,7 @@ class WindowService { | ||||
|         callback(0); // 0 = 验证成功 | ||||
|       }); | ||||
|  | ||||
|       // 2. 优化网络请求超时设置(不记录日志,避免暴涨) | ||||
|       // 2. 优化网络请求超时设置 | ||||
|       session.webRequest.onBeforeRequest((details, callback) => { | ||||
|         // 增加超时时间,减少连接中断 | ||||
|         callback({}); | ||||
| @ -1417,9 +1416,15 @@ class WindowService { | ||||
|         } | ||||
|       } else if (details.error === 'net::ERR_CONNECTION_CLOSED' || | ||||
|                  details.error === 'net::ERR_SSL_PROTOCOL_ERROR') { | ||||
|         logger.warn(`[${partitionId}] 网络连接错误: ${details.url} - ${details.error}`); | ||||
|       } else { | ||||
|         logger.error(`[${partitionId}] 网络请求失败: ${details.url} - ${details.error}`); | ||||
|         // 只记录关键连接错误,避免日志暴涨 | ||||
|         if (details.url.includes('/api/') || details.url.includes('login') || details.url.includes('auth')) { | ||||
|           logger.warn(`[${partitionId}] 关键API连接错误: ${details.url} - ${details.error}`); | ||||
|         } | ||||
|       } else if (details.error !== 'net::ERR_ABORTED' && details.error !== 'net::ERR_BLOCKED_BY_CLIENT') { | ||||
|         // 只记录非用户取消的关键错误,避免日志暴涨 | ||||
|         if (details.url.includes('/api/') || details.url.includes('login') || details.url.includes('auth')) { | ||||
|           logger.error(`[${partitionId}] 关键API请求失败: ${details.url} - ${details.error}`); | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|  | ||||
| @ -1881,11 +1886,9 @@ class WindowService { | ||||
|             return; | ||||
|           } | ||||
|  | ||||
|           // 阻止所有其他网络请求(减少日志输出) | ||||
|           if (details.url.includes('/api/') || details.url.startsWith('wss://') || details.url.startsWith('ws://')) { | ||||
|             logger.error(`[${partitionId}] 🔥 阻止重要请求: ${details.url}`); | ||||
|             logger.error(`[${partitionId}] 🔥 原因: 全局代理配置无效,严格模式不允许网络访问`); | ||||
|           } | ||||
|           // 阻止所有其他网络请求 | ||||
|           logger.error(`[${partitionId}] 🔥 阻止网络请求: ${details.url}`); | ||||
|           logger.error(`[${partitionId}] 🔥 原因: 全局代理配置无效,严格模式不允许网络访问`); | ||||
|           callback({ cancel: true }); | ||||
|         }); | ||||
|  | ||||
|  | ||||
| @ -88,31 +88,22 @@ onMounted(async () => { | ||||
|     menuStore.setTranslationRoute(finalRoutes) | ||||
|   } | ||||
|  | ||||
|   // 只有在用户已登录时才建立WebSocket连接 | ||||
|   if (menuStore.userInfo && menuStore.userInfo.userId) { | ||||
|     try { | ||||
|       const result = await ipc.invoke(ipcApiRoute.getWsBaseUrl, {}); | ||||
|       const ws = new WebSocket(result.data + '/ws/notice'); | ||||
|       ws.onopen = () => { | ||||
|         console.log('WebSocket连接成功'); | ||||
|       }; | ||||
|       ws.onmessage = (event) => { | ||||
|         const data = JSON.parse(event.data); | ||||
|         if (data.type === 'password_changed' && data.user_id === menuStore.userInfo.userId) { | ||||
|           ElMessage.error('密码已被修改,请重新登录') | ||||
|           localStorage.removeItem('session') | ||||
|           router.push('/login') | ||||
|         } | ||||
|       }; | ||||
|       ws.onerror = (error) => { | ||||
|         console.error('WebSocket连接错误:', error); | ||||
|       }; | ||||
|     } catch (error) { | ||||
|       console.warn('WebSocket连接失败:', error); | ||||
|   const result = await ipc.invoke(ipcApiRoute.getWsBaseUrl, {}); | ||||
|   const ws = new WebSocket(result.data + '/ws/notice'); | ||||
|   ws.onopen = () => { | ||||
|     console.log('Connected to server'); | ||||
|   }; | ||||
|   ws.onmessage = (event) => { | ||||
|     const data = JSON.parse(event.data); | ||||
|     if (data.type === 'password_changed' && data.user_id === menuStore.userInfo.userId) { | ||||
|       ElMessage.error('密码已被修改,请重新登录') | ||||
|       localStorage.removeItem('session') | ||||
|       router.push('/login') | ||||
|     } | ||||
|   } else { | ||||
|     console.log('用户未登录,跳过WebSocket连接,userInfo:', menuStore.userInfo); | ||||
|   } | ||||
|   }; | ||||
|   ws.onerror = (error) => { | ||||
|     console.error('WebSocket error:', error); | ||||
|   }; | ||||
| }) | ||||
| import { useDark } from '@vueuse/core' | ||||
| const isDark = useDark() | ||||
|  | ||||
| @ -1,11 +1,9 @@ | ||||
| // 优先使用 electronAPI(通过 contextBridge 暴露),然后回退到直接访问 | ||||
| const electronAPI = window.electronAPI; | ||||
| const Renderer = (window.require && window.require('electron')) || window.electron || {}; | ||||
|  | ||||
| /** | ||||
|  * ipc | ||||
|  * 官方api说明:https://www.electronjs.org/zh/docs/latest/api/ipc-renderer | ||||
|  * | ||||
|  *  | ||||
|  * 属性/方法 | ||||
|  * ipc.invoke(channel, param) - 发送异步消息(invoke/handle 模型) | ||||
|  * ipc.sendSync(channel, param) - 发送同步消息(send/on 模型) | ||||
| @ -20,24 +18,16 @@ const Renderer = (window.require && window.require('electron')) || window.electr | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * ipc - 优先使用 electronAPI,回退到直接访问 | ||||
|  * ipc | ||||
|  */ | ||||
| const ipc = electronAPI || Renderer.ipcRenderer || undefined; | ||||
| const ipc = Renderer.ipcRenderer || undefined; | ||||
|  | ||||
| /** | ||||
|  * 是否为EE环境 | ||||
|  */ | ||||
| const isEE = ipc ? true : false; | ||||
|  | ||||
| // 调试信息 | ||||
| console.log('🔍 IPC 初始化状态:', { | ||||
|   hasElectronAPI: !!electronAPI, | ||||
|   hasRenderer: !!Renderer.ipcRenderer, | ||||
|   finalIpc: !!ipc, | ||||
|   isEE | ||||
| }); | ||||
|  | ||||
| export { | ||||
|   Renderer, ipc, isEE, electronAPI | ||||
|   Renderer, ipc, isEE | ||||
| }; | ||||
|  | ||||
|  | ||||
| @ -50,46 +50,15 @@ onMounted(async () => { | ||||
|  | ||||
|   //检测是否有更新 | ||||
|   window.electronAPI?.onUpdateAvailable(() => { | ||||
|     console.log('🔄 检测到更新,禁用自动登录') | ||||
|     canAutoLogin.value = false | ||||
|   }) | ||||
|  | ||||
|   const savedSession = localStorage.getItem('session') | ||||
|   console.log('🔍 检查自动登录状态:', { | ||||
|     savedSession: !!savedSession, | ||||
|     canAutoLogin: canAutoLogin.value, | ||||
|     sessionData: savedSession ? JSON.parse(savedSession) : null | ||||
|   }) | ||||
|  | ||||
|   // 调试localStorage状态 | ||||
|   console.log('🔍 localStorage调试信息:', { | ||||
|     localStorage: typeof localStorage, | ||||
|     localStorageLength: localStorage.length, | ||||
|     allKeys: Object.keys(localStorage), | ||||
|     userDataPath: window.electronAPI ? 'Electron环境' : '浏览器环境' | ||||
|   }) | ||||
|  | ||||
|   // 获取Electron用户数据路径信息 | ||||
|   if (window.electronAPI) { | ||||
|     try { | ||||
|       const pathInfo = await ipc.invoke('getUserDataPath', {}) | ||||
|       console.log('🔍 Electron用户数据路径信息:', pathInfo) | ||||
|     } catch (error) { | ||||
|       console.error('❌ 获取用户数据路径失败:', error) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (savedSession && canAutoLogin.value) { | ||||
|     console.log('✅ 执行自动登录') | ||||
|   if (savedSession && canAutoLogin) { | ||||
|     const session = JSON.parse(savedSession) | ||||
|     menuStore.setUserInfo(session) | ||||
|     keepAuth.value = true | ||||
|     await router.push('/index') | ||||
|   } else { | ||||
|     console.log('❌ 不满足自动登录条件:', { | ||||
|       hasSavedSession: !!savedSession, | ||||
|       canAutoLogin: canAutoLogin.value | ||||
|     }) | ||||
|   } | ||||
| }) | ||||
|  | ||||
| @ -186,30 +155,10 @@ const handleLogin = async () => { | ||||
|         offset: 40, | ||||
|       }) | ||||
|  | ||||
|       console.log('🔍 登录成功,检查keepAuth状态:', { | ||||
|         keepAuth: keepAuth.value, | ||||
|         sessionData: res.data | ||||
|       }) | ||||
|  | ||||
|       if (keepAuth.value) { | ||||
|         try { | ||||
|           localStorage.setItem('session', JSON.stringify(res.data)) | ||||
|           console.log('✅ 已保存session到localStorage') | ||||
|  | ||||
|           // 立即验证是否保存成功 | ||||
|           const savedSession = localStorage.getItem('session') | ||||
|           console.log('🔍 验证保存结果:', { | ||||
|             saved: !!savedSession, | ||||
|             data: savedSession ? JSON.parse(savedSession) : null, | ||||
|             allKeys: Object.keys(localStorage), | ||||
|             localStorageLength: localStorage.length | ||||
|           }) | ||||
|         } catch (error) { | ||||
|           console.error('❌ 保存session失败:', error) | ||||
|         } | ||||
|         localStorage.setItem('session', JSON.stringify(res.data)) | ||||
|       } else { | ||||
|         localStorage.removeItem('session') | ||||
|         console.log('❌ 未勾选记住登录状态,清除session') | ||||
|       } | ||||
|       logger.info("login sssssssssssssssss",res.data) | ||||
|       menuStore.setUserInfo(res.data) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 unknown
					unknown