-
-
Notifications
You must be signed in to change notification settings - Fork 442
/
Copy pathelectron.ts
90 lines (80 loc) · 3.07 KB
/
electron.ts
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
import { app, ipcMain, Menu, nativeTheme } from "electron"
import { ThemeSettings, SchemaTypes } from "./schema-types"
import { store } from "./main/settings"
import performUpdate from "./main/update-scripts"
import { WindowManager } from "./main/window"
if (!process.mas) {
const locked = app.requestSingleInstanceLock()
if (!locked) {
app.quit()
}
}
if (!app.isPackaged) app.setAppUserModelId(process.execPath)
else if (process.platform === "win32") app.setAppUserModelId("me.hyliu.fluentreader")
let restarting = false
// Usage of any user agent will promt youtube to redirect url, causing issues reading response
app.userAgentFallback = " "
function init() {
performUpdate(store)
nativeTheme.themeSource = store.get("theme", ThemeSettings.Default)
}
init()
if (process.platform === "darwin") {
const template = [
{
label: "Application",
submenu: [
{ label: "Hide", accelerator:"Command+H", click: () => { app.hide() } },
{ label: "Quit", accelerator: "Command+Q", click: () => { if (winManager.hasWindow) winManager.mainWindow.close() } }
]
},
{
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]
},
{
label: "Window",
submenu: [
{ label: "Close", accelerator: "Command+W", click: () => { if (winManager.hasWindow) winManager.mainWindow.close() } },
{ label: "Minimize", accelerator: "Command+M", click: () => { if (winManager.hasWindow()) winManager.mainWindow.minimize() } },
{ label: "Zoom", click: () => winManager.zoom() }
]
}
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
} else {
Menu.setApplicationMenu(null)
}
const winManager = new WindowManager()
app.on("window-all-closed", () => {
if (winManager.hasWindow()) {
winManager.mainWindow.webContents.session.clearStorageData({ storages: ["cookies", "localstorage"] })
}
winManager.mainWindow = null
if (restarting) {
restarting = false
winManager.createWindow()
} else {
app.quit()
}
})
ipcMain.handle("import-all-settings", (_, configs: SchemaTypes) => {
restarting = true
store.clear()
for (let [key, value] of Object.entries(configs)) {
// @ts-ignore
store.set(key, value)
}
performUpdate(store)
nativeTheme.themeSource = store.get("theme", ThemeSettings.Default)
setTimeout(() => {
winManager.mainWindow.close()
}, process.platform === "darwin" ? 1000 : 0); // Why ???
})