From 3ee4790dab54385a4cd83a2fab8deb185b19c902 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 14 Mar 2016 20:36:48 -0700 Subject: [PATCH] Automatically set app user model ID We shouldn't ask users to figure out this piece of Windows Arcana when they're using Squirrel, let's just do it automatically. --- lib/browser/init.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/browser/init.js b/lib/browser/init.js index e1105df9b131..471cc3a5a0af 100644 --- a/lib/browser/init.js +++ b/lib/browser/init.js @@ -78,6 +78,35 @@ app.on('quit', function(event, exitCode) { return process.emit('exit', exitCode); }); +if (process.platform === 'win32') { + // If we are a Squirrel.Windows-installed app, set app user model ID + // so that users don't have to do this. + // + // Squirrel packages are always of the form: + // + // PACKAGE-NAME + // - Update.exe + // - app-VERSION + // - OUREXE.exe + // + // Squirrel itself will always set the shortcut's App User Model ID to the + // form `com.squirrel.PACKAGE-NAME.OUREXE`. We need to call + // app.setAppUserModelId with a matching identifier so that renderer processes + // will inherit this value. + var updateDotExe = path.join( + path.dirname(process.execPath), + '..', + 'update.exe'); + + if (fs.statSyncNoException(updateDotExe)) { + var packageDir = path.dirname(path.resolve(updateDotExe)); + var packageName = path.basename(packageDir); + var exeName = path.basename(process.execPath).replace(/\.exe$/i, ''); + + app.setAppUserModelId(`com.squirrel.${packageName}.${exeName}`); + } +} + // Map process.exit to app.exit, which quits gracefully. process.exit = app.exit;