forked from asticode/astilectron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (46 loc) · 1.37 KB
/
main.js
File metadata and controls
52 lines (46 loc) · 1.37 KB
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
"use strict";
const {app} = require("electron");
const {start, getLastWindow, client, consts} = require("./index");
// edge case when the program is launched without arguments
if (process.argv.length == 1) {
app.requestSingleInstanceLock();
app.quit();
return;
}
if (process.argv[3] === "true") {
// Lock
const singlesInstanceLock = app.requestSingleInstanceLock();
if (!singlesInstanceLock) {
app.quit();
return;
}
// Someone tried to run a second instance, we should focus our window.
app.on("second-instance", (event, commandLine, workingDirectory) => {
client.write(consts.targetIds.app, consts.eventNames.appEventSecondInstance, {
secondInstance: {
commandLine: commandLine,
workingDirectory: workingDirectory
}
})
const lastWindow = getLastWindow()
if (lastWindow) {
if (lastWindow.isMinimized()) lastWindow.restore();
lastWindow.show();
}
});
}
// Command line switches
let idx = 4;
for (let i = idx; i < process.argv.length; i++) {
let s = process.argv[i].replace(/^[\-]+/g, "");
let v;
if (
typeof process.argv[i + 1] !== "undefined" &&
!process.argv[i + 1].startsWith("-")
) {
v = process.argv[i + 1];
i++;
}
app.commandLine.appendSwitch(s, v);
}
start();