diff --git a/README.md b/README.md index ebbaf3b..ee47a01 100644 --- a/README.md +++ b/README.md @@ -144,9 +144,14 @@ If you're using [Squirrel.Windows](https://github.com/Squirrel/Squirrel.Windows) #### Windows App Store apps -If you have your Electron-based app in the Windows Store and would like to include auto launch functionality, simply linking to the executable path will not work. The Appx packages required for Electron are sandboxed and the install location can only be accessed by the system itself. - -There is a way to bypass that - it will require you to know the developer ID, app ID and package name of your app. Then, instead of using the exec path, you will need to set the path in `AutoLaunch()` config to: `explorer.exe shell:AppsFolder\DEV_ID.APP_ID!PACKAGE_NAME`. You can find your apps details by following [this article](http://winaero.com/blog/exclusive-how-to-start-a-modern-app-from-desktop-without-going-to-the-metro-start-screen/). Note that you might need to compile and submit your app to the store first to obtain these details. +It requires some extra steps: + - Install a beta version on your Windows device from Microsoft Store + - Go to Windows apps folder: press `Win+R` and type `shell:AppsFolder` + - Right-click and create shortcut on Desktop + - Right click on the shortcut and check properties + - Find *target* field and copy the content. That will be the auto-launch path + +Example: `new autoLaunch({ name: 'APP_NAME', path:"DEV_ID.APP_ID!PACKAGE_NAME", isHidden: true })` # Would you like to contribute? diff --git a/src/AutoLaunchWindowsAppx.coffee b/src/AutoLaunchWindowsAppx.coffee new file mode 100644 index 0000000..fe23b46 --- /dev/null +++ b/src/AutoLaunchWindowsAppx.coffee @@ -0,0 +1,52 @@ +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} + # Returns a Promise + enable: ({appName, appPath, isHiddenOnLaunch}) -> + return new Promise (resolve, reject) -> + pathToAutoLaunchedApp = appPath + args = '' + + args += ' --hidden' if isHiddenOnLaunch + + regKey.set appName, Winreg.REG_SZ, "\"C:\\Windows\\explorer.exe\" shell:AppsFolder\\#{pathToAutoLaunchedApp}#{args}", (err) -> + return reject(err) if err? + resolve() + + + # appName - {String} + # Returns a Promise + disable: (appName) -> + 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} + # Returns a Promise which resolves to a {Boolean} + isEnabled: (appName) -> + return new Promise (resolve, reject) -> + regKey.get appName, (err, item) -> + return resolve false if err? + resolve(item?) diff --git a/src/index.coffee b/src/index.coffee index 7c81eda..ed2f36b 100644 --- a/src/index.coffee +++ b/src/index.coffee @@ -23,7 +23,7 @@ module.exports = class AutoLaunch versions = process?.versions if path? # Verify that the path is absolute - throw new Error 'path must be absolute' unless pathTools.isAbsolute path + throw new Error 'path must be absolute' unless (pathTools.isAbsolute path) or process.windowsStore @opts.appPath = path else if versions? and (versions.nw? or versions['node-webkit']? or versions.electron?) @@ -36,7 +36,9 @@ module.exports = class AutoLaunch @fixOpts() @api = null - if /^win/.test process.platform + if process.windowsStore + @api = require './AutoLaunchWindowsAppx' + else if /^win/.test process.platform @api = require './AutoLaunchWindows' else if /darwin/.test process.platform @api = require './AutoLaunchMac'