()
| 233 | |
| 234 | // 创建主窗口 |
| 235 | async createWindow() { |
| 236 | // 平台差异化窗口配置 |
| 237 | const windowOptions: Electron.BrowserWindowConstructorOptions = { |
| 238 | width: 1180, |
| 239 | height: 752, |
| 240 | minWidth: 1180, |
| 241 | minHeight: 752, |
| 242 | show: false, |
| 243 | autoHideMenuBar: true, |
| 244 | webPreferences: { |
| 245 | preload: join(__dirname, '../preload/index.js'), |
| 246 | sandbox: false, |
| 247 | devTools: true, |
| 248 | }, |
| 249 | } |
| 250 | |
| 251 | // macOS: 使用 hiddenInset 保留红绿灯按钮 |
| 252 | // Windows: 使用 titleBarOverlay,在自定义标题栏区域右侧显示原生窗口按钮 |
| 253 | // Linux: 使用自定义标题栏和自定义按钮 |
| 254 | if (platform.isMacOS) { |
| 255 | windowOptions.titleBarStyle = 'hiddenInset' |
| 256 | } else if (platform.isWindows) { |
| 257 | // 保留系统框架,只隐藏标题栏内容,把内容区域顶到最上方 |
| 258 | windowOptions.titleBarStyle = 'hidden' |
| 259 | // 获取当前主题状态 |
| 260 | const isDark = nativeTheme.shouldUseDarkColors |
| 261 | windowOptions.titleBarOverlay = getTitleBarOverlayOptions(isDark) |
| 262 | windowOptions.backgroundColor = isDark ? '#111827' : '#f9fafb' |
| 263 | } else { |
| 264 | // Linux 继续使用无边框 + 自定义按钮 |
| 265 | windowOptions.frame = false |
| 266 | } |
| 267 | |
| 268 | this.mainWindow = new BrowserWindow(windowOptions) |
| 269 | |
| 270 | this.mainWindow.once('ready-to-show', () => { |
| 271 | this.mainWindow?.show() |
| 272 | |
| 273 | // Windows 上根据当前主题设置 titleBarOverlay 颜色 |
| 274 | if (platform.isWindows) { |
| 275 | applyCurrentTitleBarOverlay(this.mainWindow, nativeTheme.shouldUseDarkColors) |
| 276 | |
| 277 | // 监听主题变化,动态更新颜色 |
| 278 | nativeTheme.on('updated', () => { |
| 279 | if (this.mainWindow && platform.isWindows) { |
| 280 | resetCurrentTitleBarOverlayColor() |
| 281 | applyCurrentTitleBarOverlay(this.mainWindow, nativeTheme.shouldUseDarkColors) |
| 282 | } |
| 283 | }) |
| 284 | } |
| 285 | }) |
| 286 | |
| 287 | // 主窗口事件 |
| 288 | this.mainWindowEvents() |
| 289 | |
| 290 | this.mainWindow.webContents.setWindowOpenHandler((details) => { |
| 291 | shell.openExternal(details.url) |
| 292 | return { action: 'deny' } |
no test coverage detected