diff --git a/README.md b/README.md index cc37d17..3ec6134 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 \ No newline at end of file +[depstat-image]: https://david-dm.org/teamwork/node-auto-launch.svg?style=flat diff --git a/src/AutoLaunchLinux.coffee b/src/AutoLaunchLinux.coffee index 1c235a7..59f0a2c 100644 --- a/src/AutoLaunchLinux.coffee +++ b/src/AutoLaunchLinux.coffee @@ -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""" @@ -48,4 +50,4 @@ module.exports = # appName - {String} # Returns a {String} - getFilePath: (appName) -> "#{@getDirectory()}#{appName}.desktop" \ No newline at end of file + getFilePath: (appName) -> "#{@getDirectory()}#{appName}.desktop" diff --git a/src/AutoLaunchMac.coffee b/src/AutoLaunchMac.coffee index 1d29a17..52561f1 100644 --- a/src/AutoLaunchMac.coffee +++ b/src/AutoLaunchMac.coffee @@ -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) -> " #{argument}") .join('\n') @@ -96,4 +98,4 @@ module.exports = # appName - {String} # Returns a {String} - getFilePath: (appName) -> "#{@getDirectory()}#{appName}.plist" \ No newline at end of file + getFilePath: (appName) -> "#{@getDirectory()}#{appName}.plist" diff --git a/src/AutoLaunchWindows.coffee b/src/AutoLaunchWindows.coffee index 0c5de6e..c7c3b78 100644 --- a/src/AutoLaunchWindows.coffee +++ b/src/AutoLaunchWindows.coffee @@ -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.replace /^\s+/g, "") + '"' 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) -> diff --git a/src/index.coffee b/src/index.coffee index 3170fbe..e86a883 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -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 @@ -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) \ No newline at end of file + @opts.appName = @opts.appName.substr(0, @opts.appName.length - '.app'.length)