This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
92 lines (79 loc) · 2.75 KB
/
main.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron');
const path = require('path');
const index = `file://${__dirname}/dist/index.html`;
const land = `file://${__dirname}/dist/land.html`;
let mainWindow;
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('id-electron', process.execPath, [path.resolve(process.argv[1])]);
}
} else {
app.setAsDefaultProtocolClient('id-electron');
}
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.focus();
commandLine.forEach((value) => {
if (value.startsWith('id-electron://open')) {
let command = value.replace('id-electron://open', '');
mainWindow.loadURL(index + command);
} else if (value.startsWith('id-electron://auth')) {
let command = value.replace('id-electron://auth', '');
mainWindow.loadURL(land + command);
}
});
}
});
// Create mainWindow, load the rest of the app, etc...
app.whenReady().then(() => {
createWindow();
});
}
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
}
})
mainWindow.loadURL(index);
mainWindow.webContents.openDevTools();
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
if (url === 'about:blank') {
return {
action: 'allow',
overrideBrowserWindowOptions: {
frame: true,
autoHideMenuBar: true,
fullscreenable: false,
backgroundColor: 'black',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
}
}
}
} else {
shell.openExternal(url);
return { action: 'deny' }
}
});
}
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});