()
| 27 | } |
| 28 | |
| 29 | private setupIPC(): void { |
| 30 | // 测试 WebDAV 连接 |
| 31 | ipcMain.handle('sync:test-connection', async (_event, config: SyncConfig) => { |
| 32 | try { |
| 33 | const client = new WebDAVSyncClient() |
| 34 | await client.init(config) |
| 35 | return { success: true } |
| 36 | } catch (error: any) { |
| 37 | return { success: false, error: error.message } |
| 38 | } |
| 39 | }) |
| 40 | |
| 41 | // 保存同步配置 |
| 42 | ipcMain.handle('sync:save-config', async (_event, config: SyncConfig) => { |
| 43 | try { |
| 44 | // 生成设备 ID(如果没有) |
| 45 | if (!config.deviceId) { |
| 46 | config.deviceId = pluginDeviceAPI.getDeviceIdPublic() |
| 47 | } |
| 48 | |
| 49 | // 加密密码 |
| 50 | if (config.password && safeStorage.isEncryptionAvailable()) { |
| 51 | const encrypted = safeStorage.encryptString(config.password) |
| 52 | config.password = encrypted.toString('base64') |
| 53 | } |
| 54 | |
| 55 | await this.syncEngine!.saveSyncConfig(config) |
| 56 | |
| 57 | // 重新初始化同步引擎 |
| 58 | if (config.enabled) { |
| 59 | await this.syncEngine!.init() |
| 60 | } else { |
| 61 | this.syncEngine!.stopAutoSync() |
| 62 | } |
| 63 | |
| 64 | // 管理插件同步监听器生命周期 |
| 65 | if (config.enabled && config.syncPlugins) { |
| 66 | pluginSyncWatcher.start() |
| 67 | } else { |
| 68 | pluginSyncWatcher.stop() |
| 69 | } |
| 70 | |
| 71 | return { success: true } |
| 72 | } catch (error: any) { |
| 73 | return { success: false, error: error.message } |
| 74 | } |
| 75 | }) |
| 76 | |
| 77 | // 获取同步配置 |
| 78 | ipcMain.handle('sync:get-config', async () => { |
| 79 | try { |
| 80 | const doc = await lmdbInstance.promises.get('SYNC/config') |
| 81 | if (!doc?.data) { |
| 82 | return { success: true, config: null } |
| 83 | } |
| 84 | |
| 85 | const config = doc.data as SyncConfig |
| 86 |
no test coverage detected