(_context: IpcContext)
| 17 | * 注册网络设置相关的 IPC 处理器 |
| 18 | */ |
| 19 | export function registerNetworkHandlers(_context: IpcContext): void { |
| 20 | console.log('[IpcMain] Registering network handlers...') |
| 21 | |
| 22 | /** |
| 23 | * 获取代理配置 |
| 24 | */ |
| 25 | ipcMain.handle('network:getProxyConfig', (): ProxyConfig => { |
| 26 | return loadProxyConfig() |
| 27 | }) |
| 28 | |
| 29 | /** |
| 30 | * 保存代理配置 |
| 31 | */ |
| 32 | ipcMain.handle( |
| 33 | 'network:saveProxyConfig', |
| 34 | async (_event, config: ProxyConfig): Promise<{ success: boolean; error?: string }> => { |
| 35 | try { |
| 36 | // 如果是手动模式且填写了 URL,验证 URL 格式 |
| 37 | if (config.mode === 'manual' && config.url) { |
| 38 | const validation = validateProxyUrl(config.url) |
| 39 | if (!validation.valid) { |
| 40 | return { success: false, error: validation.error } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | await saveProxyConfig(config) |
| 45 | return { success: true } |
| 46 | } catch (error) { |
| 47 | const errorMessage = error instanceof Error ? error.message : String(error) |
| 48 | return { success: false, error: `保存配置失败: ${errorMessage}` } |
| 49 | } |
| 50 | } |
| 51 | ) |
| 52 | |
| 53 | /** |
| 54 | * 测试代理连接 |
| 55 | */ |
| 56 | ipcMain.handle( |
| 57 | 'network:testProxyConnection', |
| 58 | async (_event, proxyUrl: string): Promise<{ success: boolean; error?: string }> => { |
| 59 | return testProxyConnection(proxyUrl) |
| 60 | } |
| 61 | ) |
| 62 | |
| 63 | console.log('[IpcMain] Network handlers registered') |
| 64 | } |
no test coverage detected