-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathAutoLaunchWindows.coffee
More file actions
69 lines (57 loc) · 2.45 KB
/
AutoLaunchWindows.coffee
File metadata and controls
69 lines (57 loc) · 2.45 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
fs = require 'fs'
path = require 'path'
Winreg = require 'winreg'
regKey = new Winreg
hive: Winreg.HKCU
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
module.exports =
### Public ###
# options - {Object}
# :appName - {String}
# :appPath - {String}
# :isHiddenOnLaunch - {Boolean}
# :onlyMe - (Optional) {Boolean}
# Returns a Promise
enable: ({appName, appPath, isHiddenOnLaunch,onlyMe}) ->
if(!onlyMe)
regKey.hive = Winreg.HKLM
return new Promise (resolve, reject) ->
pathToAutoLaunchedApp = appPath
args = ''
updateDotExe = path.join(path.dirname(process.execPath), '..', 'update.exe')
# If they're using Electron and Squirrel.Windows, point to its Update.exe instead
# Otherwise, we'll auto-launch an old version after the app has updated
if process.versions?.electron? and fs.existsSync updateDotExe
pathToAutoLaunchedApp = updateDotExe
args = " --processStart \"#{path.basename(process.execPath)}\""
args += ' --process-start-args "--hidden"' if isHiddenOnLaunch
else
args += ' --hidden' if isHiddenOnLaunch
regKey.set appName, Winreg.REG_SZ, "\"#{pathToAutoLaunchedApp}\"#{args}", (err) ->
return reject(err) if err?
resolve()
# appName - {String}
# onlyMe - (Optional) {Boolean}
# Returns a Promise
disable: (appName,onlyMe) ->
if(!onlyMe)
regKey.hive = Winreg.HKLM
return new Promise (resolve, reject) ->
regKey.remove appName, (err) ->
if err?
# The registry key should exist but in case it fails because it doesn't exist, resolve false instead
# rejecting with an error
if err.message.indexOf('The system was unable to find the specified registry key or value') isnt -1
return resolve false
return reject err
resolve()
# appName - {String}
# onlyMe - (Optional) {Boolean}
# Returns a Promise which resolves to a {Boolean}
isEnabled: (appName,mac,onlyMe) ->
if(!onlyMe)
regKey.hive = Winreg.HKLM
return new Promise (resolve, reject) ->
regKey.get appName, (err, item) ->
return resolve false if err?
resolve(item?)