-
Notifications
You must be signed in to change notification settings - Fork 332
/
index.ts
90 lines (81 loc) · 2.6 KB
/
index.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 } from "electron";
import { initialize as initialiseElectronRemote } from "@electron/remote/main";
import "./ipc";
import { initialise } from "./services/init";
import { openMainWindow } from "./services/windows";
import { handleProtocolCall } from "./services/protocol";
import { getConfigValue } from "./services/config";
import { shouldShowMainWindow, wasAutostarted } from "./services/arguments";
import { logErr, logInfo } from "./library/log";
import { BUTTERCUP_PROTOCOL } from "./symbols";
import { AppStartMode } from "./types";
logInfo("Application starting");
const lock = app.requestSingleInstanceLock();
if (!lock) {
app.quit();
}
// app.on("window-all-closed", () => {
// if (process.platform !== PLATFORM_MACOS) {
// app.quit();
// }
// });
app.on("window-all-closed", (event: Event) => {
event.preventDefault();
});
app.on("activate", () => {
openMainWindow();
});
// **
// ** App protocol handling
// **
app.on("second-instance", async (event, args) => {
await openMainWindow();
// Protocol URL for Linux/Windows
const protocolURL = args.find((arg) => arg.startsWith(BUTTERCUP_PROTOCOL));
if (protocolURL) {
handleProtocolCall(protocolURL);
}
});
app.on("open-url", (e, url) => {
// Protocol URL for MacOS
if (url.startsWith(BUTTERCUP_PROTOCOL)) {
handleProtocolCall(url);
}
});
// **
// ** Boot
// **
app.whenReady()
.then(() => {
logInfo("Application ready");
initialiseElectronRemote();
})
.then(() => initialise())
.then(() => {
const protocol = BUTTERCUP_PROTOCOL.replace("://", "");
if (!app.isDefaultProtocolClient(protocol)) {
logInfo(`Registering protocol: ${protocol}`);
const protoReg = app.setAsDefaultProtocolClient(protocol);
if (!protoReg) {
logErr(`Failed registering protocol: ${protocol}`);
}
} else {
logInfo(`Protocol already registered: ${protocol}`);
}
})
.then(async () => {
const preferences = await getConfigValue("preferences");
const autostarted = wasAutostarted();
if (!shouldShowMainWindow() || preferences.startMode === AppStartMode.HiddenAlways) {
logInfo("Not opening initial window: disabled by CL or preferences");
return;
} else if (autostarted && preferences.startMode === AppStartMode.HiddenOnBoot) {
logInfo("Not opening initial window: disabled for autostart");
return;
}
openMainWindow();
})
.catch((err) => {
logErr(err);
app.quit();
});