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

Method createWindow

src/main/managers/windowManager.ts:286–526  ·  view source on GitHub ↗

* 创建主窗口

()

Source from the content-addressed store, hash-verified

284 * 创建主窗口
285 */
286 public createWindow(): BrowserWindow {
287 // 智能检测:在鼠标所在的显示器上打开窗口
288 const { width, height, x: displayX, y: displayY } = this.getDisplayAtCursor()
289
290 // 根据平台设置不同的窗口配置
291 const windowConfig: Electron.BrowserWindowConstructorOptions = {
292 type: 'panel',
293 title: 'ZTools',
294 width: WINDOW_WIDTH,
295 height: WINDOW_INITIAL_HEIGHT,
296 alwaysOnTop: true,
297 // 基于最大窗口高度计算居中位置,确保窗口扩展时不会超出屏幕
298 x: displayX + Math.floor((width - WINDOW_WIDTH) / 2),
299 y: displayY + Math.floor((height - WINDOW_DEFAULT_HEIGHT) / 2),
300 frame: false, // 无边框
301 resizable: false, // 禁止用户手动调整窗口大小
302 maximizable: false, // 禁用最大化
303 skipTaskbar: true,
304 show: false,
305 hasShadow: true, // 启用窗口阴影(可调整为 false 来移除阴影)
306 webPreferences: {
307 preload: path.join(__dirname, '../preload/index.js'),
308 backgroundThrottling: false, // 窗口最小化时是否继续动画和定时器
309 contextIsolation: true, // 禁用上下文隔离, 渲染进程和preload共用window对象
310 nodeIntegration: false, // 渲染进程禁止直接使用 Node
311 spellcheck: false, // 禁用拼写检查
312 webSecurity: false
313 }
314 }
315
316 // macOS 系统配置
317 if (platform.isMacOS) {
318 windowConfig.transparent = true
319 windowConfig.vibrancy = 'fullscreen-ui'
320 }
321 // Windows 系统配置(不设置 transparent,让 setBackgroundMaterial 生效)
322 else if (platform.isWindows) {
323 windowConfig.backgroundColor = '#00000000'
324 }
325 // Linux 系统配置
326 else if (platform.isLinux) {
327 // 不设置 type: 'panel':X11 下 panel 类型会启用 focus-follows-mouse,
328 // 会导致鼠标移出窗口时 blur 就被触发从而隐藏窗口。
329 // Linux 下我们通过 setAlwaysOnTop 保持置顶层级,不需要 panel 类型。
330 delete windowConfig.type
331 }
332
333 this.mainWindow = new BrowserWindow(windowConfig)
334
335 // 强化置顶层级并允许在所有桌面和全屏应用上显示
336 this.mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
337 if (platform.isMacOS) {
338 this.mainWindow.setAlwaysOnTop(true, 'modal-panel', 1)
339 } else {
340 this.mainWindow.setAlwaysOnTop(true)
341 }
342
343 // Windows 11 根据用户配置设置背景材质

Callers 2

index.tsFile · 0.45

Calls 15

getDisplayAtCursorMethod · 0.95
buildShortcutStringMethod · 0.95
handleAppShortcutMethod · 0.95
updateFocusTargetMethod · 0.95
isBlurHideSuppressedMethod · 0.95
hideWindowMethod · 0.95
onMethod · 0.80
getCurrentPluginPathMethod · 0.80

Tested by

no test coverage detected