()
| 95 | |
| 96 | // 加载并应用设置 |
| 97 | private async loadAndApplySettings(): Promise<void> { |
| 98 | try { |
| 99 | const data = databaseAPI.dbGet('settings-general') |
| 100 | console.log('[Settings] 加载到的设置:', data) |
| 101 | // 应用托盘图标显示设置(默认显示,在 if(data) 块外确保首次启动也能创建托盘) |
| 102 | windowManager.setTrayIconVisible(data?.showTrayIcon ?? true) |
| 103 | console.log('[Settings] 启动时应用托盘图标显示设置:', data?.showTrayIcon ?? true) |
| 104 | |
| 105 | if (data) { |
| 106 | // 应用透明度设置 |
| 107 | if (data.opacity !== undefined && this.mainWindow) { |
| 108 | const clampedOpacity = Math.max(0.3, Math.min(1, data.opacity)) |
| 109 | this.mainWindow.setOpacity(clampedOpacity) |
| 110 | console.log('[Settings] 启动时应用透明度设置:', data.opacity) |
| 111 | } |
| 112 | // 应用快捷键设置 |
| 113 | if (data.hotkey) { |
| 114 | const success = updateShortcut(data.hotkey) |
| 115 | console.log('[Settings] 启动时应用快捷键设置:', data.hotkey, success ? '成功' : '失败') |
| 116 | } |
| 117 | // 应用主题设置 |
| 118 | if (data.theme) { |
| 119 | this.setTheme(data.theme) |
| 120 | console.log('[Settings] 启动时应用主题设置:', data.theme) |
| 121 | } |
| 122 | // 应用自动返回搜索设置 |
| 123 | if (data.autoBackToSearch) { |
| 124 | await windowManager.updateAutoBackToSearch(data.autoBackToSearch) |
| 125 | console.log('[Settings] 启动时应用自动返回搜索设置:', data.autoBackToSearch) |
| 126 | } |
| 127 | // 应用代理配置 |
| 128 | if (data.proxyEnabled !== undefined && data.proxyUrl !== undefined) { |
| 129 | proxyManager.setProxyConfig({ |
| 130 | enabled: data.proxyEnabled, |
| 131 | url: data.proxyUrl |
| 132 | }) |
| 133 | // 应用全局代理 |
| 134 | await proxyManager.applyProxyToDefaultSession() |
| 135 | console.log('[Settings] 启动时应用代理配置:', { |
| 136 | enabled: data.proxyEnabled, |
| 137 | url: data.proxyUrl |
| 138 | }) |
| 139 | } |
| 140 | // 应用窗口默认高度设置 |
| 141 | if (data.windowDefaultHeight !== undefined) { |
| 142 | this.pluginManager?.setPluginDefaultHeight(data.windowDefaultHeight) |
| 143 | console.log('[Settings] 启动时应用插件默认高度设置:', data.windowDefaultHeight) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // 窗口位置现在由 windowManager.moveWindowToCursor() 处理 |
| 148 | // 每个显示器会自动恢复该显示器上次保存的位置 |
| 149 | |
| 150 | // 加载并注册全局快捷键 |
| 151 | await this.loadAndRegisterGlobalShortcuts() |
| 152 | // 加载并注册应用快捷键 |
| 153 | await this.loadAndRegisterAppShortcuts() |
| 154 | } catch (error) { |
no test coverage detected