Browse Source

Auto updater and installer for Windows

pull/3/head
Ramiro Saenz 9 years ago
parent
commit
7b3c650650
  1. 3
      TODO.md
  2. 5
      app/package.json
  3. 30
      build/winstaller.js
  4. 43
      electron/autoupdater.js
  5. 72
      electron/main.js
  6. 51
      package.json
  7. BIN
      resources/installer/loading.gif

3
TODO.md

@ -5,3 +5,6 @@
- Auto Updater
- Dock Menu (http://electron.atom.io/docs/tutorial/desktop-environment-integration/#custom-dock-menu-os-x)
- Auth0
- Group services (Personal, Work, etc)
- Crush Reporter.
- Add Voxer, Yahoo! Messenger and Dasher.

5
app/package.json

@ -23,5 +23,8 @@
"skype"
],
"author": "Ramiro Saenz",
"license": "MIT"
"license": "MIT",
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
}
}

30
build/winstaller.js

@ -0,0 +1,30 @@
'use strict';
var electronInstaller = require('electron-winstaller');
var arch = process.argv.slice(2)[0];
if ( !arch ) {
console.error('No Architecture paramenter specified. [ia32 or x64]');
return;
}
//var appData = require('../app/package.json');
var resultPromise = electronInstaller.createWindowsInstaller({
appDirectory: './dist/Rambox-win32-'+arch
,outputDirectory: './dist'
,title: 'Rambox'
,loadingGif: './resources/installer/loading.gif'
,authors: 'Rambox'
,owners: 'Rambox'
,exe: 'Rambox.exe'
,setupExe: 'RamboxSetup-'+arch+'.exe'
,noMsi: true
,iconUrl: 'https://raw.githubusercontent.com/saenzramiro/rambox/master/resources/installer/icons/64x64.png'
,setupIcon: './resources/Icon.ico'
//,remoteReleases: 'https://getrambox.herokuapp.com/update/'+process.platform+'/'+process.arch+'/'+appData.version
});
console.log('Creating installer... Please wait...')
resultPromise.then(() => console.log("Done!"), (e) => console.log(`Ups!: ${e.message}`));

43
electron/autoupdater.js

@ -0,0 +1,43 @@
'use strict';
const electron = require('electron');
const app = electron.app;
const dialog = electron.dialog;
const autoUpdater = electron.autoUpdater;
const feedUrl = `https://getrambox.herokuapp.com/update/${process.platform}/${process.arch}/${app.getVersion()}`;
autoUpdater.setFeedURL(feedUrl);
autoUpdater.checkForUpdates();
exports.check = win => {
autoUpdater.on('update-available', function(a, b, c, d) {
dialog.showMessageBox({
message: "There is a new version"
,buttons: ["OK"]
});
});
/*
autoUpdater.on('update-not-available', function(a, b, c, d) {
});
*/
autoUpdater.on('update-downloaded', function(e, releaseNotes, releaseName, releaseDate, updateURL) {
var index = dialog.showMessageBox({
message: "New version"
,detail: "Do you want to install the new version ("+releaseName+")?"
,buttons: ["Yes", "No"]
});
if (index === 0) {
autoUpdater.quitAndInstall();
}
});
/*
autoUpdater.on("error", function(error){
dialog.showMessageBox({
message: error.toString()
,buttons: ["OK"]
});
});
*/
};

72
electron/main.js

@ -11,9 +11,79 @@ const shell = require('electron').shell;
const appMenu = require('./menu');
// Require for tray file
const tray = require('./tray');
// Require for autpUpdate file
const autoupdater = require('./autoupdater');
const MenuItem = electron.MenuItem;
// this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
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':
// 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;
}
};
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
@ -43,6 +113,8 @@ function createWindow () {
tray.create(mainWindow);
autoupdater.check(mainWindow);
mainWindow.on('page-title-updated', (e, title) => updateBadge(title));
// Emitted when the window is closed.

51
package.json

@ -10,15 +10,33 @@
"clean:osx": "rm -rf ./dist/Rambox-darwin-*",
"clean:win": "rm -rf ./dist/Rambox-win32-*",
"pack": "npm run pack:osx && npm run pack:win",
"pack:osx": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=darwin --arch=x64 --version=1.1.1 --icon=resources/installer/Icon.icns --app-version=0.2.0 --build-version=64-bit --overwrite",
"pack:win32": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=win32 --arch=ia32 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=32-bit --overwrite",
"pack:win64": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=win32 --arch=x64 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --overwrite",
"pack:osx": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=darwin --arch=x64 --version=1.1.1 --icon=resources/installer/Icon.icns --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite",
"pack:win": "npm run pack:win32 && npm run pack:win64",
"pack:win32": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=win32 --arch=ia32 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=32-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite",
"pack:win64": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=win32 --arch=x64 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite",
"pack:linux": "npm run pack:linux32 && npm run pack:linux64",
"pack:linux32": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=linux --arch=ia32 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite",
"pack:linux64": "electron-packager \"./build/production/Rambox/\" \"Rambox\" --out=dist --platform=linux --arch=x64 --version=1.1.1 --icon=resources/installer/Icon.ico --app-version=0.2.0 --build-version=64-bit --version-string.CompanyName=\"Rambox\" --version-string.ProductName=\"Rambox\" --asar --prune --overwrite",
"build": "npm run build:osx && npm run build:win",
"build:osx": "build \"dist/Rambox-darwin-x64/Rambox.app\" --platform=osx",
"build:win": "build \"dist/Rambox-win32-x64\" --platform=win",
"all:osx": "npm run sencha:clean && npm run sencha:compile && npm run clean:osx && npm run pack:osx && npm run build:osx",
"all:win": "npm run sencha:clean && npm run sencha:compile && npm run clean:win && npm run pack:win && npm run build:win"
"build:win32": "node ./build/winstaller.js ia32",
"build:win64": "node ./build/winstaller.js x64",
"setup:osx": "npm run sencha:clean && npm run sencha:compile && npm run clean:osx && npm run pack:osx && npm run build:osx",
"setup:win": "npm run sencha:clean && npm run sencha:compile && npm run clean:win && npm run pack:win && npm run build:win64",
"zip:win32": "bestzip \"dist/Rambox-win32-ia32-portable.zip\" \"dist/Rambox-win32-ia32/*\"",
"zip:win64": "bestzip \"dist/Rambox-win32-x64-portable.zip\" \"dist/Rambox-win32-x64/*\"",
"zip:linux32": "bestzip \"dist/Rambox-linux-ia32.zip\" \"dist/Rambox-linux-ia32/*\"",
"zip:linux64": "bestzip \"dist/Rambox-linux-x64.zip\" \"dist/Rambox-linux-x64/*\"",
"all:win": "npm run setup:win && npm run zip:win32 && npm run zip:win64",
"all:linux": "npm run setup:win && npm run zip:linux32 && npm run zip:linux64"
},
"name": "Rambox",
"productName": "Rambox",
"authors": [
"Ramiro Saenz"
],
"copyright": "",
"homepage": "http://www.rambox.pro",
"build": {
"productName": "Rambox",
"asar": true,
@ -41,7 +59,18 @@
},
"win": {
"title": "Rambox",
"icon": "resources/installer/Icon.ico"
"licenseUrl": "https://raw.githubusercontent.com/saenzramiro/rambox/master/LICENSE",
"msi": false
},
"linux": {
"target": [
"deb",
"zip",
"tar.gz",
"rpm"
],
"maintainer": "Rambox",
"vendor": "Rambox"
}
},
"directories": {
@ -51,10 +80,13 @@
},
"devDependencies": {
"asar": "^0.11.0",
"bestzip": "^1.1.3",
"electron-builder": "3.25.0",
"electron-installer-windows": "^0.2.0",
"electron-packager": "7.0.1",
"electron-prebuilt": "1.1.1",
"electron-winstaller": "^2.3.0"
"electron-winstaller": "^2.3.0",
"electron-squirrel-startup": "^1.0.0"
},
"config": {
"pre-git": {
@ -65,5 +97,8 @@
"post-checkout": "",
"post-merge": ""
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
}
}

BIN
resources/installer/loading.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Loading…
Cancel
Save