This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
forked from mongodb-js/electron-squirrel-startup
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
75 lines (69 loc) · 2.06 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
var path = require('path');
var spawn = require('child_process').spawn;
var debug = require('debug')('electron-squirrel-startup');
var app = require('electron').app;
var fs = require('fs');
var os = require('os');
var desktopLinkExists = function(channel) {
var linkName
switch (channel) {
case 'nightly':
linkName = 'BraveNightly'
break
case 'developer':
linkName = 'BraveDeveloper'
break
case 'beta':
linkName = 'BraveBeta'
break
case 'dev':
linkName = 'Brave'
break
default:
linkName = 'Brave'
}
return fs.existsSync(path.join(os.homedir(), 'desktop', `${linkName}.lnk`))
}
var run = function(args, done) {
var updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
debug('Spawning `%s` with args `%s`', updateExe, args);
spawn(updateExe, args, {
detached: true
}).on('close', done);
};
var check = function(channel = 'dev') {
if (process.platform === 'win32') {
var cmd = process.argv[1];
debug('processing squirrel command `%s`', cmd);
var target = path.basename(process.execPath);
let userDataDirArg = '--user-data-dir-name=brave-' + channel
if (cmd === '--squirrel-install') {
if (channel === 'dev') {
run(['--createShortcut=' + target + ''], app.quit);
} else {
run(['--createShortcut=' + target + '', '--process-start-args=' + '--user-data-dir-name=brave-' + channel], app.quit);
}
return true;
}
if (cmd === '--squirrel-updated') {
if (desktopLinkExists(channel)) {
if (channel === 'dev') {
run(['--createShortcut=' + target + ''], app.quit);
} else {
run(['--createShortcut=' + target + '', '--process-start-args=' + '--user-data-dir-name=brave-' + channel], app.quit);
}
}
return true;
}
if (cmd === '--squirrel-uninstall') {
run(['--removeShortcut=' + target + ''], app.quit);
return true;
}
if (cmd === '--squirrel-obsolete') {
app.quit();
return true;
}
}
return false;
};
module.exports = check;