[go: up one dir, main page]

Menu

[2f7d4b]: / main.js  Maximize  Restore  History

Download this file

71 lines (56 with data), 1.5 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
import { app, BrowserWindow ,globalShortcut } from "electron";
let win = null;
const additionalData = { myKey: Date.now() }
const gotTheLock = app.requestSingleInstanceLock(additionalData)
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
// Print out data received from the second instance.
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore()
win.focus()
}
})
}
function createWindow() {
if (win) return;
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// Remove the menu
win.removeMenu();
// Register shortcuts
globalShortcut.register('CmdOrCtrl+W', () => {
win.close(); // Close window shortcut
});
globalShortcut.register('CmdOrCtrl+Shift+I', () => {
win.webContents.toggleDevTools(); // Toggle DevTools
});
win.loadFile("index.html");
win.on("closed", () => {
win = null;
});
}
app.whenReady().then(() => {
createWindow();
app.on('will-quit', () => {
globalShortcut.unregisterAll(); // Unregister all shortcuts on exit
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});