diff --git a/assets/icons/win/icon.icns b/assets/icons/win/icon.icns new file mode 100644 index 0000000..3e9c89e Binary files /dev/null and b/assets/icons/win/icon.icns differ diff --git a/assets/icons/win/icon.ico b/assets/icons/win/icon.ico new file mode 100644 index 0000000..48286dc Binary files /dev/null and b/assets/icons/win/icon.ico differ diff --git a/installers/setupEvents.js b/installers/setupEvents.js new file mode 100644 index 0000000..e9b1349 --- /dev/null +++ b/installers/setupEvents.js @@ -0,0 +1,65 @@ +const electron = require('electron') +const app = electron.app + +module.exports = { +handleSquirrelEvent function() { + 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' + Optionally do things such as + - Add your .exe to the PATH + - Write to the registry for things like file associations and + explorer context menus + + Install desktop and start menu shortcuts + spawnUpdate(['--createShortcut', exeName]); + + setTimeout(app.quit, 1000); + return true; + + case '--squirrel-uninstall' + Undo anything you did in the --squirrel-install and + --squirrel-updated handlers + + Remove desktop and start menu shortcuts + spawnUpdate(['--removeShortcut', exeName]); + + setTimeout(app.quit, 1000); + return true; + + case '--squirrel-obsolete' + This is called on the outgoing version of your app before + we update to the new version - it's the opposite of + --squirrel-updated + + app.quit(); + return true; +} +} +} \ No newline at end of file diff --git a/installers/windows/createinstaller.js b/installers/windows/createinstaller.js new file mode 100644 index 0000000..dcb2688 --- /dev/null +++ b/installers/windows/createinstaller.js @@ -0,0 +1,25 @@ +const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller +const path = require('path') + +getInstallerConfig() + .then(createWindowsInstaller) + .catch((error) => { + console.error(error.message || error) + process.exit(1) + }) + +function getInstallerConfig () { + console.log('creating windows installer') + const rootPath = path.join('./') + const outPath = path.join(rootPath, 'release-builds') + + return Promise.resolve({ + appDirectory: path.join(outPath, 'bitbox-win32-ia32/'), + authors: 'Gabriel Cardona', + noMsi: true, + outputDirectory: path.join(outPath, 'windows-installer'), + exe: 'BITBOX.exe', + setupExe: 'BITBOXInstaller.exe', + setupIcon: path.join(rootPath, 'assets', 'icons', 'win', 'icon.ico') + }) +} \ No newline at end of file diff --git a/main.js b/main.js index 779d56d..b35260d 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,14 @@ require("babel-register"); +//handle setupevents as quickly as possible + const setupEvents = require('./installers/setupEvents') + if (setupEvents.handleSquirrelEvent()) { + // squirrel event handled and app will exit in 1000ms, so don't do anything else + return; + } + + let electron = require('electron'); // Module to control application life. diff --git a/package.json b/package.json index d1ee3e9..25ede39 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "build": "webpack", "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds", "create-installer-mac": "electron-installer-dmg ./release-builds/BITBOX-darwin-x64/BITBOX.app BITBOX --out=release-builds --overwrite --icon=assets/icons/mac/icon.icns", + "package-win": "electron-packager . bitbox --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"BITBOX\"", + "create-installer-win": "node /installers/windows/createinstaller.js", "test": "mocha --compilers js:babel-core/register" }, "repository": "https://github.com/bigearth/bitbox-electron", @@ -21,7 +23,11 @@ ], "author": "Gabriel Cardona w/ EARTH", "license": "MIT", - "devDependencies": {}, + "devDependencies": { + "electron": "^1.8.4", + "electron-packager": "^10.1.2", + "electron-winstaller": "^2.6.4" + }, "dependencies": { "axios": "^0.18.0", "babel-core": "^6.26.0", @@ -37,8 +43,6 @@ "chai": "^4.1.2", "cors": "^2.8.4", "css-loader": "^0.28.9", - "electron": "^1.7.12", - "electron-packager": "^10.1.2", "electron-store": "^1.3.0", "express": "^4.16.2", "mocha": "^5.0.1",