Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ For NW.js and Electron apps, you don't have to specify the path. We guess based

If `true`, we instruct the operating system to launch your app in hidden mode when launching at login. Defaults to `false`.

**`options.extraArgs`** - (Optional) String

A string of additional command-line arguments to call at launch, including the leading hyphens, e.g. `"--foo --bar --baz"`.

_Note: this is not compatible with the AppleScript Login Item on Mac._

**`options.mac`** (Optional) object

For Mac-only options.
Expand Down Expand Up @@ -157,4 +163,4 @@ We're always open to your help and feedback. See our [CONTRIBUTING.md](CONTRIBUT
[travis-image]: http://img.shields.io/travis/Teamwork/node-auto-launch.svg?style=flat

[depstat-url]: https://david-dm.org/teamwork/node-auto-launch
[depstat-image]: https://david-dm.org/teamwork/node-auto-launch.svg?style=flat
[depstat-image]: https://david-dm.org/teamwork/node-auto-launch.svg?style=flat
10 changes: 6 additions & 4 deletions src/AutoLaunchLinux.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ module.exports =
# :appName - {String}
# :appPath - {String}
# :isHiddenOnLaunch - {Boolean}
# :extraArgs - {Sting}
# Returns a Promise
enable: ({appName, appPath, isHiddenOnLaunch}) ->
enable: ({appName, appPath, isHiddenOnLaunch, extraArgs}) ->
hiddenArg = if isHiddenOnLaunch then ' --hidden' else ''
args = if extraArgs? then (hiddenArg + ' ' + extraArgs) else hiddenArg

data = """[Desktop Entry]
Type=Application
Version=1.0
Name=#{appName}
Comment=#{appName}startup script
Exec=#{appPath}#{hiddenArg}
Comment=#{appName} startup script
Exec=#{appPath}#{args}
StartupNotify=false
Terminal=false"""

Expand Down Expand Up @@ -48,4 +50,4 @@ module.exports =

# appName - {String}
# Returns a {String}
getFilePath: (appName) -> "#{@getDirectory()}#{appName}.desktop"
getFilePath: (appName) -> "#{@getDirectory()}#{appName}.desktop"
6 changes: 4 additions & 2 deletions src/AutoLaunchMac.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ module.exports =
# :appName - {String}
# :appPath - {String}
# :isHiddenOnLaunch - {Boolean}
# :extraArgs - {Sting}
# :mac - (Optional) {Object}
# :useLaunchAgent - (Optional) {Boolean}
# Returns a Promise
enable: ({appName, appPath, isHiddenOnLaunch, mac}) ->
enable: ({appName, appPath, isHiddenOnLaunch, extraArgs, mac}) ->

# Add the file if we're using a Launch Agent
if mac.useLaunchAgent
programArguments = [appPath]
programArguments.push '--hidden' if isHiddenOnLaunch
programArguments = programArguments.concat extraArgs.split(" ") if extraArgs?
programArgumentsSection = programArguments
.map((argument) -> " <string>#{argument}</string>")
.join('\n')
Expand Down Expand Up @@ -96,4 +98,4 @@ module.exports =

# appName - {String}
# Returns a {String}
getFilePath: (appName) -> "#{@getDirectory()}#{appName}.plist"
getFilePath: (appName) -> "#{@getDirectory()}#{appName}.plist"
12 changes: 8 additions & 4 deletions src/AutoLaunchWindows.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ module.exports =
# :appName - {String}
# :appPath - {String}
# :isHiddenOnLaunch - {Boolean}
# :extraArgs - {Sting}
# Returns a Promise
enable: ({appName, appPath, isHiddenOnLaunch}) ->
enable: ({appName, appPath, isHiddenOnLaunch, extraArgs}) ->
return new Promise (resolve, reject) ->
pathToAutoLaunchedApp = appPath
args = ''
process_args = ''
process_args += ' --hidden' if isHiddenOnLaunch
process_args += (' ' + extraArgs) if extraArgs?
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
args += ' --process-start-args "' + process_args + '"' if isHiddenOnLaunch
else
args += ' --hidden' if isHiddenOnLaunch
args += process_args

regKey.set appName, Winreg.REG_SZ, "\"#{pathToAutoLaunchedApp}\"#{args}", (err) ->
return reject(err) if err?
resolve()


# appName - {String}
# Returns a Promise
disable: (appName) ->
Expand Down
6 changes: 4 additions & 2 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ module.exports = class AutoLaunch
# to add Login Item
# :name - {String}
# :path - (Optional) {String}
constructor: ({name, isHidden, mac, path}) ->
# :extraArgs - (Optional) {String}
constructor: ({name, isHidden, mac, extraArgs, path}) ->
throw new Error 'You must specify a name' unless name?

@opts =
appName: name
isHiddenOnLaunch: if isHidden? then isHidden else false
extraArgs: if extraArgs? then extraArgs else ''
mac: mac ? {}

versions = process?.versions
Expand Down Expand Up @@ -89,4 +91,4 @@ module.exports = class AutoLaunch
if /darwin/.test process.platform
# Remove ".app" from the appName if it exists
if @opts.appName.indexOf('.app', @opts.appName.length - '.app'.length) isnt -1
@opts.appName = @opts.appName.substr(0, @opts.appName.length - '.app'.length)
@opts.appName = @opts.appName.substr(0, @opts.appName.length - '.app'.length)