-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (53 loc) · 1.31 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
const {
BrowserWindow,
app,
globalShortcut,
screen,
shell,
} = require("electron");
const fs = require("fs");
const path = require("path");
const SETTINGS_PATH = path.resolve("./settings.json");
const PRELOAD_PATH = path.resolve("./preload.js");
const settings = JSON.parse(fs.readFileSync(SETTINGS_PATH));
const createWindow = () => {
const scaleFactor = screen.getPrimaryDisplay().scaleFactor;
const win = new BrowserWindow({
width: 840 / scaleFactor,
height: 85 / scaleFactor,
frame: false,
resizable: false,
skipTaskbar: true,
webPreferences: { preload: PRELOAD_PATH },
});
win.focus();
win.webContents.openDevTools();
globalShortcut.register(settings.appToggleShortcut, () => {
if (win.isFocused()) {
win.hide();
if (!settings.rememberHistory) {
win.webContents.send("history", "clear");
}
} else {
win.show();
}
});
globalShortcut.register("Ctrl+,", () => {
if (win.isFocused()) {
shell.openPath(SETTINGS_PATH);
}
});
globalShortcut.register("Esc", () => {
if (win.isFocused()) {
win.hide();
}
});
win.removeMenu();
win.loadFile("index.html");
};
app.whenReady().then(() => {
createWindow();
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});