-
Notifications
You must be signed in to change notification settings - Fork 735
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (65 loc) · 1.84 KB
/
Copy pathmain.js
File metadata and controls
77 lines (65 loc) · 1.84 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { app, BrowserWindow, shell } = require('electron');
const path = require('path');
const isDev = process.env.NODE_ENV === 'development';
if (isDev) {
try {
// Enable live-reload for the main and renderer processes during development
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
ignored: /server|node_modules/
});
} catch (err) {
console.warn('Live reload unavailable:', err);
}
}
// Global window reference
let mainWindow;
// Create Electron window
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
enableWebSQL: false,
webSecurity: true
}
});
// Load the app
mainWindow.loadFile(path.join(__dirname, 'renderer', 'index.html'));
// Open DevTools in development (comment out for production)
// mainWindow.webContents.openDevTools();
mainWindow.on('closed', () => {
mainWindow = null;
});
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
mainWindow.webContents.on('will-navigate', (event, url) => {
// If navigating away from our app, open in external browser
if (!url.startsWith('file://')) {
event.preventDefault();
shell.openExternal(url);
}
});
}
// App lifecycle
app.on('ready', () => {
console.log('Electron app ready');
createWindow();
});
app.on('window-all-closed', () => {
// On macOS, apps stay active until user explicitly quits
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On macOS, re-create window when dock icon is clicked
if (mainWindow === null) {
createWindow();
}
});