-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
136 lines (108 loc) · 3.12 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"use strict";
const { app, BrowserWindow, Menu, shell, session } = require("electron");
const fs = require("fs");
const kebabCase = require("lodash/kebabCase");
const { is, readSheet } = require("./src/util");
const file = require("./src/file");
const menu = require("./src/menu");
const { store } = require("./src/settings");
const shortcut = require("./src/keymap");
const time = require("./src/time");
const tray = require("./src/tray");
const update = require("./src/update");
const url = require("./src/url");
const win = require("./src/win");
const { customTheme } = require("./src/config");
const { log } = console;
require("electron-debug")({ enabled: true });
require("electron-dl")();
require("electron-context-menu")();
let exiting = false;
let shown = false;
let mainWindow;
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
function createMainWindow() {
const kuroWindow = new BrowserWindow(win.defaultOpts);
kuroWindow.loadURL(url.app);
kuroWindow.on("close", (error) => {
if (!exiting) {
error.preventDefault();
if (is.darwin) {
app.hide();
} else {
kuroWindow.hide();
}
}
});
kuroWindow.on("page-title-updated", (error) => {
error.preventDefault();
});
kuroWindow.on("unresponsive", log);
kuroWindow.webContents.on("did-navigate-in-page", (_, url) => {
store.set("lastURL", url);
});
return kuroWindow;
}
app.whenReady().then(() => {
Menu.setApplicationMenu(menu);
const lang = app.getLocale();
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders["Accept-Language"] = `${lang},en-US;q=0.9`;
callback({ cancel: false, requestHeaders: details.requestHeaders });
});
mainWindow = createMainWindow();
if (store.get("useGlobalShortcuts")) {
shortcut.registerGlobal();
}
if (!store.get("hideTray")) {
tray.create();
}
const { webContents } = mainWindow;
webContents.on("dom-ready", () => {
fs.readdir(file.style, (error, files) => {
for (const x of files) {
webContents.insertCSS(readSheet(x));
}
});
const customThemeCss = `html.custom-mode {
${Object.keys(customTheme)
.map((x) => `--${kebabCase(x)}: ${customTheme[x]} !important;`)
.join("")}
}`;
webContents.insertCSS(customThemeCss);
if (!shown) {
if (store.get("launchMinimized")) {
mainWindow.hide();
} else {
mainWindow.show();
}
shown = true;
}
});
webContents.on("new-window", (error, url) => {
error.preventDefault();
shell.openExternal(url);
});
webContents.on("crashed", log);
if (!store.get("disableAutoUpdateCheck")) {
setInterval(() => update.auto(), time.ms(store.get("updateCheckPeriod")));
}
});
process.on("uncaughtException", log);
app.on("activate", () => mainWindow.show());
app.on("before-quit", () => {
exiting = true;
if (!mainWindow.isFullScreen()) {
store.set("lastWindowState", mainWindow.getBounds());
}
});