Skip to content

Commit

Permalink
Merge pull request #111 from miguelx97/feature/microsoft-store-support
Browse files Browse the repository at this point in the history
Add microsoft store support
  • Loading branch information
Oxalin authored Dec 11, 2023
2 parents df6b3b6 + 5ec5cdd commit 646808f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
52 changes: 52 additions & 0 deletions src/AutoLaunchWindowsAppx.coffee
Original file line number Diff line number Diff line change
@@ -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?)
6 changes: 4 additions & 2 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand All @@ -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'
Expand Down

0 comments on commit 646808f

Please sign in to comment.