-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.js
57 lines (54 loc) · 1.46 KB
/
package.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
var handleStartupEvent = function() {
if (process.platform !== "win32") {
return false;
}
var squirrelCommand = process.argv[1];
switch (squirrelCommand) {
case "--squirrel-install":
case "--squirrel-updated":
install();
return true;
case "--squirrel-uninstall":
uninstall();
app.quit();
return true;
case "--squirrel-obsolete":
app.quit();
return true;
}
// 安装
function install() {
var cp = require("child_process");
var updateDotExe = path.resolve(
path.dirname(process.execPath),
"..",
"update.exe"
);
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--createShortcut", target], {
detached: true
});
child.on("close", function(code) {
app.quit();
});
}
// 卸载
function uninstall() {
var cp = require("child_process");
var updateDotExe = path.resolve(
path.dirname(process.execPath),
"..",
"update.exe"
);
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--removeShortcut", target], {
detached: true
});
child.on("close", function(code) {
app.quit();
});
}
};
if (handleStartupEvent()) {
return;
}