MCPcopy Create free account
hub / github.com/experdot/pointer / createWindow

Function createWindow

src/main/window.ts:7–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import icon from '../../resources/icon.png?asset'
6
7export function createWindow(): void {
8 const mainWindowState = windowStateKeeper({
9 defaultWidth: 960,
10 defaultHeight: 640,
11 fullScreen: false,
12 maximize: false
13 })
14 // Create the browser window.
15 const mainWindow = new BrowserWindow({
16 x: mainWindowState.x,
17 y: mainWindowState.y,
18 width: mainWindowState.width,
19 height: mainWindowState.height,
20 minWidth: 480,
21 minHeight: 320,
22 show: false,
23 autoHideMenuBar: true,
24 // macOS 使用原生窗口控制按钮,其他平台使用自定义
25 ...(process.platform === 'darwin'
26 ? {
27 titleBarStyle: 'hiddenInset', // macOS: 显示原生控制按钮
28 trafficLightPosition: { x: 10, y: 10 } // 调整原生按钮位置
29 }
30 : {
31 frame: false, // Windows/Linux: 完全自定义
32 titleBarStyle: 'hidden'
33 }),
34 ...(process.platform === 'linux' ? { icon } : {}),
35 webPreferences: {
36 preload: join(__dirname, '../preload/index.js'),
37 sandbox: false
38 }
39 })
40
41 mainWindowState.manage(mainWindow)
42 if (mainWindowState.isMaximized) {
43 mainWindow.maximize()
44 }
45
46 mainWindow.on('ready-to-show', () => {
47 mainWindow.show()
48 })
49
50 mainWindow.webContents.setWindowOpenHandler((details) => {
51 shell.openExternal(details.url)
52 return { action: 'deny' }
53 })
54
55 // HMR for renderer base on electron-vite cli.
56 // Load the remote URL for development or the local html file for production.
57 if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
58 mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
59 } else {
60 mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
61 }
62}

Callers 1

index.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected