MCPcopy
hub / github.com/ZToolsCenter/ZTools / createUpdateWindow

Method createUpdateWindow

src/main/api/updater.ts:493–559  ·  view source on GitHub ↗

* 创建更新窗口

()

Source from the content-addressed store, hash-verified

491 * 创建更新窗口
492 */
493 private createUpdateWindow(): void {
494 if (this.updateWindow && !this.updateWindow.isDestroyed()) {
495 this.updateWindow.show()
496 this.updateWindow.focus()
497 return
498 }
499
500 const width = 500
501 const height = 450
502
503 // 计算窗口位置(居中)
504 const primaryDisplay = screen.getPrimaryDisplay()
505 const { workArea } = primaryDisplay
506 const x = Math.round(workArea.x + (workArea.width - width) / 2)
507 const y = Math.round(workArea.y + (workArea.height - height) / 2)
508
509 const windowConfig: Electron.BrowserWindowConstructorOptions = {
510 width,
511 height,
512 x,
513 y,
514 frame: false,
515 resizable: false,
516 maximizable: false,
517 minimizable: false,
518 alwaysOnTop: true,
519 hasShadow: true,
520 type: 'panel', // 尝试使用 panel 类型,类似 SuperPanel
521 webPreferences: {
522 preload: path.join(__dirname, '../preload/index.js'),
523 sandbox: false,
524 contextIsolation: true,
525 nodeIntegration: false
526 }
527 }
528
529 // macOS 系统配置
530 if (process.platform === 'darwin') {
531 windowConfig.transparent = true
532 windowConfig.vibrancy = 'fullscreen-ui'
533 }
534 // Windows 系统配置(不设置 transparent,让 setBackgroundMaterial 生效)
535 else if (process.platform === 'win32') {
536 windowConfig.backgroundColor = '#00000000'
537 }
538
539 this.updateWindow = new BrowserWindow(windowConfig)
540
541 if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
542 this.updateWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/updater.html`)
543 } else {
544 this.updateWindow.loadFile(path.join(__dirname, '../renderer/updater.html'))
545 }
546
547 // 应用材质 (仅 Windows)
548 if (process.platform === 'win32') {
549 this.applyMaterialToUpdateWindow(this.updateWindow)
550 }

Callers 1

autoCheckAndDownloadMethod · 0.95

Calls 4

showMethod · 0.80
focusMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected