-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_step4.cjs
More file actions
51 lines (42 loc) · 1.41 KB
/
test_step4.cjs
File metadata and controls
51 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const { app, BrowserWindow } = require('electron');
class WindowManager {
constructor() {
this.mainWindow = null;
}
async createMainWindow() {
const preloadPath = '/Users/gzp/Github/anime1-desktop-electron/dist-electron/preload/index.cjs';
console.log('[WM] Step 4: Adding openDevTools and event listeners');
this.mainWindow = new BrowserWindow({
width: 1200,
height: 800,
title: 'Anime1 Desktop',
titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default',
show: false,
webPreferences: {
preload: preloadPath,
contextIsolation: true,
nodeIntegration: false,
sandbox: false,
allowRunningInsecureContent: true
}
});
// 新增: openDevTools
this.mainWindow.webContents.openDevTools();
// 新增: preload-error 监听
this.mainWindow.webContents.on('preload-error', (event, preloadPath, error) => {
console.error('[WM] Preload error:', preloadPath, error);
});
this.mainWindow.loadURL('http://localhost:5173/');
this.mainWindow.once('ready-to-show', () => {
this.mainWindow.show();
console.log('[WM] Window shown');
});
this.mainWindow.webContents.on('console-message', (e) => {
console.log('[Console]', e.message);
});
}
}
app.whenReady().then(async () => {
const wm = new WindowManager();
await wm.createMainWindow();
});