From aa9310eb1568dfaca7a0764e57066c43dff8e032 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 25 Mar 2016 01:39:44 -0700 Subject: [PATCH] Windows: create desktop/start menu shortcuts on install/update --- main/index.js | 7 +++---- main/squirrel-win32.js | 43 +++++++++++++++++++++++++----------------- package.json | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/main/index.js b/main/index.js index b0a1e88c..b0cd2027 100644 --- a/main/index.js +++ b/main/index.js @@ -16,10 +16,9 @@ var shouldQuit = false var argv = sliceArgv(process.argv) if (process.platform === 'win32') { - shouldQuit = squirrelWin32.handleArgv(argv[0]) - - // Remove any --squirrel-xxxx arguments - argv.shift() + shouldQuit = squirrelWin32.handleEvent(argv[0]) + argv.shift() // Remove any --squirrel-xxxx arguments + // app.setAppUserModelId('com.squirrel.WebTorrent.WebTorrent') } if (!shouldQuit) { diff --git a/main/squirrel-win32.js b/main/squirrel-win32.js index cf6401cb..14fa171d 100644 --- a/main/squirrel-win32.js +++ b/main/squirrel-win32.js @@ -1,34 +1,33 @@ module.exports = { - handleArgv + handleEvent } +var cp = require('child_process') var electron = require('electron') +var path = require('path') var app = electron.app +var config = require('../config') var handlers = require('./handlers') -function handleArgv (cmd) { - if (cmd === '--squirrel-install') { - // App was just installed. - handlers.init() +function handleEvent (cmd) { + if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') { + // App was installed/updated. (Called on new version of app.) - // TODO: - // - Install desktop and start menu shortcuts - // - Add explorer context menus + // Install protocol/file handlers, desktop/start menu shortcuts. + handlers.init() + createShortcuts() // Ensure user sees install splash screen so they realize that Setup.exe actually // installed an application and isn't the application itself. - setTimeout(function () { + if (cmd === '--squirrel-install') { + setTimeout(function () { + app.quit() + }, 5000) + } else { app.quit() - }, 5000) - return true - } - - if (cmd === '--squirrel-updated') { - // App was just updated. (Called on new version of app.) - handlers.init() - app.quit() + } return true } @@ -54,3 +53,13 @@ function handleArgv (cmd) { return false } + +function createShortcuts () { + var updateExe = path.join(process.execPath, '..', 'Update.exe') + var args = [ + '--createShortcut="' + config.APP_NAME + '.exe"', + '--shortcut-locations="Desktop,StartMenu,Startup"', + '--process-start-args="--autostart"' + ] + cp.execSync(updateExe + args.join(' ')) +} diff --git a/package.json b/package.json index 0a548050..22f36fa2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "webtorrent-app", + "name": "WebTorrent", "description": "WebTorrent, the streaming torrent client. For OS X, Windows, and Linux.", "version": "0.0.1", "author": {