diff --git a/packages/client-app/src/browser/main.js b/packages/client-app/src/browser/main.js index 8a48346bc..ba94fcc3a 100644 --- a/packages/client-app/src/browser/main.js +++ b/packages/client-app/src/browser/main.js @@ -143,6 +143,13 @@ const parseCommandLine = (argv) => { }; }; +/* + * "Squirrel will spawn your app with command line flags on first run, updates,] + * and uninstalls." + * + * Read: https://github.com/electron-archive/grunt-electron-installer#handling-squirrel-events + * Read: https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#windows + */ const handleStartupEventWithSquirrel = () => { if (process.platform !== 'win32') { return false; diff --git a/packages/client-app/src/browser/windows-updater.js b/packages/client-app/src/browser/windows-updater.js index b36dd1b64..238d7777a 100644 --- a/packages/client-app/src/browser/windows-updater.js +++ b/packages/client-app/src/browser/windows-updater.js @@ -1,11 +1,41 @@ +/* + * "Squirrel will spawn your app with command line flags on first run, updates,] + * and uninstalls." + * + * Read: https://github.com/electron-archive/grunt-electron-installer#handling-squirrel-events + * Read: https://github.com/electron/electron/blob/master/docs/api/auto-updater.md#windows + * + * When Nylas Mail gets installed on a Windows machine it gets put in: + * C:\Users\\AppData\Local\Nylas\app-x.x.x + * + * The `process.execPath` is: + * C:\Users\\AppData\Local\Nylas\app-x.x.x\nylas.exe + * + * We manually copy everything in build/resources/win into a 'resources' folder + * located inside the main app directory. See runCopyPlatformSpecificResources + * in package-task.js + * + * This means `__dirname` should be: + * C:\Users\\AppData\Local\Nylas\app-x.x.x\resources + * + * We also expect Squirrel Windows to have a file called `nylas.exe` at: + * C:\Users\\AppData\Local\Nylas\nylas.exe + */ const ChildProcess = require('child_process'); const fs = require('fs-plus'); const path = require('path'); const os = require('os'); +// C:\Users\\AppData\Local\Nylas\app-x.x.x const appFolder = path.resolve(process.execPath, '..'); + +// C:\Users\\AppData\Local\Nylas\ const rootN1Folder = path.resolve(appFolder, '..'); + +// C:\Users\\AppData\Local\Nylas\Update.exe const updateDotExe = path.join(rootN1Folder, 'Update.exe'); + +// "nylas.exe" const exeName = path.basename(process.execPath); // Spawn a command and invoke the callback when it completes with an error @@ -118,29 +148,6 @@ function createRegistryEntries({allowEscalation, registerDefaultIfPossible}, cal }); } -// Update the desktop and start menu shortcuts by using the command line API -// provided by Squirrel's Update.exe -function updateShortcuts(callback) { - const homeDirectory = fs.getHomeDirectory(); - if (homeDirectory) { - const desktopShortcutPath = path.join(homeDirectory, 'Desktop', 'N1.lnk') - // Check if the desktop shortcut has been previously deleted and - // and keep it deleted if it was - fs.exists(desktopShortcutPath, (desktopShortcutExists) => { - createShortcuts(() => { - if (desktopShortcutExists) { - callback() - } else { - // Remove the unwanted desktop shortcut that was recreated - fs.unlink(desktopShortcutPath, callback); - } - }); - }); - } else { - createShortcuts(callback); - } -} - // Remove the desktop and start menu shortcuts by using the command line API // provided by Squirrel's Update.exe function removeShortcuts(callback) { @@ -149,7 +156,6 @@ function removeShortcuts(callback) { exports.spawn = spawnUpdate; exports.createShortcuts = createShortcuts; -exports.updateShortcuts = updateShortcuts; exports.removeShortcuts = removeShortcuts; exports.createRegistryEntries = createRegistryEntries;