-
Notifications
You must be signed in to change notification settings - Fork 15k
/
main.mjs
33 lines (26 loc) · 914 Bytes
/
main.mjs
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
import { app, BrowserWindow } from 'electron'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path';
async function createWindow() {
const mainWindow = new BrowserWindow({
show: false,
webPreferences: {
preload: fileURLToPath(new URL('preload.mjs', import.meta.url)),
sandbox: false,
contextIsolation: false
}
})
await mainWindow.loadFile('index.html')
const importMetaPreload = await mainWindow.webContents.executeJavaScript('window.importMetaPath');
const expected = join(dirname(fileURLToPath(import.meta.url)), 'preload.mjs');
process.exit(importMetaPreload === expected ? 0 : 1);
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})