-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.ts
115 lines (89 loc) · 2.98 KB
/
application.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
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
import { app, ipcMain, Menu } from 'electron';
import { isAbsolute, extname } from 'path';
import { existsSync } from 'fs';
import { SessionsService } from './sessions-service';
import { checkFiles } from '~/utils/files';
import { Settings } from './models/settings';
import { isURL, prefixHttp } from '~/utils';
import { WindowsService } from './windows-service';
import { StorageService } from './services/storage';
import { getMainMenu } from './menus/main';
import { runAutoUpdaterService } from './services';
import { DialogsService } from './services/dialogs-service';
import { requestAuth } from './dialogs/auth';
import { NetworkServiceHandler } from './network/network-service-handler';
import { ExtensionServiceHandler } from './extension-service-handler';
export class Application {
public static instance = new Application();
public sessions: SessionsService;
public settings = new Settings();
public storage = new StorageService();
public windows = new WindowsService();
public dialogs = new DialogsService();
public start() {
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
return;
} else {
app.on('second-instance', async (e, argv) => {
const path = argv[argv.length - 1];
if (isAbsolute(path) && existsSync(path)) {
if (process.env.NODE_ENV !== 'development') {
const path = argv[argv.length - 1];
const ext = extname(path);
if (ext === '.html') {
this.windows.current.win.focus();
this.windows.current.viewManager.create({
url: `file:///${path}`,
active: true,
});
}
}
return;
} else if (isURL(path)) {
this.windows.current.win.focus();
this.windows.current.viewManager.create({
url: prefixHttp(path),
active: true,
});
return;
}
this.windows.open();
});
}
app.on('login', async (e, webContents, request, authInfo, callback) => {
e.preventDefault();
const window = this.windows.findByBrowserView(webContents.id);
const credentials = await requestAuth(
window.win,
request.url,
webContents.id,
);
if (credentials) {
callback(credentials.username, credentials.password);
}
});
ipcMain.on('create-window', (e, incognito = false) => {
this.windows.open(incognito);
});
this.onReady();
}
private async onReady() {
await app.whenReady();
new ExtensionServiceHandler();
NetworkServiceHandler.get();
checkFiles();
this.storage.run();
this.dialogs.run();
this.windows.open();
this.sessions = new SessionsService();
Menu.setApplicationMenu(getMainMenu());
runAutoUpdaterService();
app.on('activate', () => {
if (this.windows.list.filter((x) => x !== null).length === 0) {
this.windows.open();
}
});
}
}