From 6d40475a54c40d4ec3f191fd309dfeb8ce3af106 Mon Sep 17 00:00:00 2001 From: Miguel Martin Date: Tue, 3 May 2022 15:36:32 +0200 Subject: [PATCH 1/4] copied AutoLaunchWindows to AutoLaunchWindowsAppx --- src/AutoLaunchWindowsAppx.coffee | 60 ++++++++++++++++++++++++++++++++ src/index.coffee | 6 ++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/AutoLaunchWindowsAppx.coffee diff --git a/src/AutoLaunchWindowsAppx.coffee b/src/AutoLaunchWindowsAppx.coffee new file mode 100644 index 0000000..0c5de6e --- /dev/null +++ b/src/AutoLaunchWindowsAppx.coffee @@ -0,0 +1,60 @@ +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 = '' + 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} + # 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 4a01536..da17c71 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 isPathAbsolute path + throw new Error 'path must be absolute' unless (isPathAbsolute path) and !process.windowsStore @opts.appPath = path else if versions? and (versions.nw? or versions['node-webkit']? or versions.electron?) @@ -35,7 +35,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' From c33f406664383c4b034f17f14c58a7d0014b9949 Mon Sep 17 00:00:00 2001 From: Miguel Martin Date: Tue, 3 May 2022 15:37:56 +0200 Subject: [PATCH 2/4] changed route to auto launch appx app --- src/AutoLaunchWindowsAppx.coffee | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/AutoLaunchWindowsAppx.coffee b/src/AutoLaunchWindowsAppx.coffee index 0c5de6e..fe23b46 100644 --- a/src/AutoLaunchWindowsAppx.coffee +++ b/src/AutoLaunchWindowsAppx.coffee @@ -21,18 +21,10 @@ module.exports = 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) -> + + 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() From 3ff4373a867105eb5e96c46b6928f6e312cc3b7c Mon Sep 17 00:00:00 2001 From: Miguel Martin Date: Tue, 3 May 2022 15:43:53 +0200 Subject: [PATCH 3/4] appx auto-launch documented on readme --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a8c31d..c1be1e8 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? From d392f8831b5630def38f42379a6a9fb86a372d40 Mon Sep 17 00:00:00 2001 From: Miguel Martin Date: Fri, 20 May 2022 11:49:14 +0200 Subject: [PATCH 4/4] fixed 'path must be absolute' bug --- src/index.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.coffee b/src/index.coffee index da17c71..a8ac8ea 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 (isPathAbsolute path) and !process.windowsStore + throw new Error 'path must be absolute' unless (isPathAbsolute path) or process.windowsStore @opts.appPath = path else if versions? and (versions.nw? or versions['node-webkit']? or versions.electron?)