-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
51 lines (42 loc) · 1.25 KB
/
main.js
File metadata and controls
51 lines (42 loc) · 1.25 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
import { app, BrowserWindow, protocol } from 'electron';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const setupProtocols = () => {
protocol.registerFileProtocol('app', (request, callback) => {
const url = request.url.replace('app://', '');
try {
return callback(path.join(__dirname, url));
} catch (error) {
return callback({ error: -2 /* ENOENT */ });
}
});
};
function createWindow() {
const preloadPath = path.join(__dirname, 'preload.js');
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: preloadPath,
webSecurity: false,
},
});
win.loadFile('dist/index.html');
if (process.env.NODE_ENV === 'development') {
win.webContents.openDevTools();
}
}
app.whenReady().then(() => {
setupProtocols();
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});