Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows Installer #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/icons/win/icon.icns
Binary file not shown.
Binary file added assets/icons/win/icon.ico
Binary file not shown.
65 changes: 65 additions & 0 deletions installers/setupEvents.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
25 changes: 25 additions & 0 deletions installers/windows/createinstaller.js
Original file line number Diff line number Diff line change
@@ -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')
})
}
8 changes: 8 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down