diff --git a/main.js b/main.js index 30f0201..efbaba2 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,7 @@ const https = require('https') let websiteUrl = 'firebaseadmin.com' let template = require('./js/menu') +if (process.platform === 'win32') require('./squirrel') if (process.mas) app.setName('Firebase Admin') // Keep a global reference of the window object, if you don't, the window will diff --git a/package.json b/package.json index 5cea87b..2bcf636 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,10 @@ "type": "file" } ] + }, + "linux": { + "target": "deb", + "maintainer": "dev@codefoxes.com" } } } diff --git a/squirrel.js b/squirrel.js new file mode 100644 index 0000000..330d20b --- /dev/null +++ b/squirrel.js @@ -0,0 +1,52 @@ +const app = require('electron').app + +if (handleSquirrelEvent()) { + return +} + +function handleSquirrelEvent() { + if (process.argv.length === 1) { + return false + } + + const ChildProcess = require('child_process') + const path = require('path') + const appFolder = path.resolve(process.execPath, '..') + const rootAtomFolder = path.resolve(appFolder, '..') + const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe')) + const exeName = path.basename(process.execPath) + + const spawn = function(command, args) { + let spawnedProcess, error + + try { + spawnedProcess = ChildProcess.spawn(command, args, {detached: true}) + } catch (error) {} + + return spawnedProcess + } + + const spawnUpdate = function(args) { + return spawn(updateDotExe, args) + } + + const squirrelEvent = process.argv[1] + switch (squirrelEvent) { + case '--squirrel-install': + case '--squirrel-updated': + // Install desktop and start menu shortcuts + spawnUpdate(['--createShortcut', exeName]) + setTimeout(app.quit, 1000) + return true + + case '--squirrel-uninstall': + // Remove desktop and start menu shortcuts + spawnUpdate(['--removeShortcut', exeName]) + setTimeout(app.quit, 1000) + return true + + case '--squirrel-obsolete': + app.quit() + return true + } +} \ No newline at end of file