forked from klaudiosinani/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (88 loc) · 2.42 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
'use strict';
const {app, BrowserWindow, Menu, shell} = require('electron');
const fs = require('fs');
const {is, readSheet} = require('./src/util');
const file = require('./src/file');
const menu = require('./src/menu');
const settings = 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 {log} = console;
require('electron-debug')({enabled: true});
require('electron-dl')();
require('electron-context-menu')();
let exiting = false;
let mainWindow;
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
function createMainWindow() {
const aoWindow = new BrowserWindow(win.defaultOpts);
aoWindow.loadURL(url.app);
aoWindow.on('close', e => {
if (!exiting) {
e.preventDefault();
if (is.darwin) {
app.hide();
} else {
aoWindow.hide();
}
}
});
aoWindow.on('page-title-updated', e => {
e.preventDefault();
});
aoWindow.on('unresponsive', log);
aoWindow.webContents.on('did-navigate-in-page', (_, url) => {
settings.set('lastURL', url);
});
return aoWindow;
}
app.on('ready', () => {
Menu.setApplicationMenu(menu);
mainWindow = createMainWindow();
if (settings.get('useGlobalShortcuts')) {
shortcut.registerGlobal();
}
if (!settings.get('hideTray')) {
tray.create();
}
const {webContents} = mainWindow;
webContents.on('dom-ready', () => {
const stylesheets = fs.readdirSync(file.style);
stylesheets.forEach(x => webContents.insertCSS(readSheet(x)));
if (settings.get('launchMinimized')) {
mainWindow.minimize();
} else {
mainWindow.show();
}
});
webContents.on('new-window', (e, url) => {
e.preventDefault();
shell.openExternal(url);
});
webContents.on('crashed', log);
if (!settings.get('disableAutoUpdateCheck')) {
setInterval(() => update.auto(), time.ms(settings.get('updateCheckPeriod')));
}
});
process.on('uncaughtException', log);
app.on('activate', () => mainWindow.show());
app.on('before-quit', () => {
exiting = true;
if (!mainWindow.isFullScreen()) {
settings.set('lastWindowState', mainWindow.getBounds());
}
});