diff --git a/src/browser/squirrel-update.coffee b/src/browser/squirrel-update.coffee index 04132f393..4874c2c21 100644 --- a/src/browser/squirrel-update.coffee +++ b/src/browser/squirrel-update.coffee @@ -28,11 +28,40 @@ exports.spawn = (args, callback) -> exports.existsSync = -> fs.existsSync(updateDotExe) +installContextMenu = (callback) -> + fileKeyPath = 'HKCU\\Software\\Classes\\*\\shell\\Atom' + + spawnReg = (args) -> + regProcess = ChildProcess.spawn('reg.exe', args) + + error = null + regProcess.on 'error', (processError) -> error ?= processError + regProcess.on 'close', (code, signal) -> + error ?= new Error("Command failed: #{signal}") if code isnt 0 + error?.code ?= code + callback(error) + + installFileMenu = -> + args = [fileKeyPath, '/ve', '/d', 'Open with Atom'] + spawnReg args, (error) -> + return callback(error) if error? + + args = [fileKeyPath, '/v', 'Icon', '/d', process.execPath] + spawnReg args, (error) -> + return callback(error) if error? + + args = ["#{fileKeyPath}\\command", '/ve', '/d', process.execPath] + spawnReg(args, callback) + + installFileMenu(callback) + # Handle squirrel events denoted by --squirrel-* command line arguments. exports.handleStartupEvent = -> switch process.argv[1] when '--squirrel-install', '--squirrel-updated' - exports.spawn ['--createShortcut', exeName], -> app.quit() + exports.spawn ['--createShortcut', exeName], -> + installContextMenu -> + app.quit() true when '--squirrel-uninstall' exports.spawn ['--removeShortcut', exeName], -> app.quit()