Commit a8d8d63d authored by Eric Eastwood's avatar Eric Eastwood

Update auto-update params and logic

parent 0827f205
......@@ -21,6 +21,14 @@ The Gitter Desktop client is written using [NW.js](http://nwjs.io/), but the onl
* windows cmd: `set OAUTH_KEY=yourkey && set OAUTH_SECRET=yoursecret && npm start`
* alternatively, put your keys and secrets in `nwapp/oauth.json`
### CLI parameters
- `--update-check-url`: The base URL we use to check for `package.json` manifest updates. e.g. `--update-check-url=192.168.0.58:3010`
- `--current-install-path`: The path to install/overwrite and files from an update
- `--new-executable`: In combination with `--current-install-path`, will start the app in update mode and run the specified executable to update
We use nw.js, so you can use any of those CLI parameters like [`--remote-debugging-port=port`](https://github.com/nwjs/nw.js/wiki/debugging-with-devtools)
## Tray Icon on Ubuntu
To see the Gitter tray icon run:
......
......@@ -6,17 +6,22 @@ log.setLevel('debug');
// @CONST
var CLIENT = require('./utils/client-type');
var manifest = require('./package.json');
var gui = require('nw.gui');
var pkg = require('./package.json');
var Gitter = require('gitter-realtime-client');
var os = require('os');
var argv = require('yargs')(gui.App.argv).argv;
var Promise = require('bluebird');
var semver = require('semver');
var autoUpdate = require('./utils/auto-update');
var AutoLaunch = require('auto-launch');
var settings = require('./utils/settings');
var notifier = require('./utils/notifier');
var events = require('./utils/custom-events');
var quitApp = require('./utils/quit-app');
var autoUpdate = require('./utils/auto-update');
var AutoLaunch = require('auto-launch');
// components
var MENU_ITEMS = require('./components/menu-items');
......@@ -44,14 +49,19 @@ var autoLauncher = new AutoLaunch({
(function () {
log.info('version:', pkg.version);
if (gui.App.argv.length) {
var currentInstallPath = argv['current-install-path'];
var newUpdaterExecutablePath = argv['new-executable'];
// We used to just pass in as the first and second paramers but this is not as
// nice when we want to add other CLI parameters in later
if(semver.satisfies(manifest.version, '<=2.4.0')) {
currentInstallPath = argv[0];
newUpdaterExecutablePath = argv[1];
}
if(currentInstallPath && newUpdaterExecutablePath) {
log.info('I am a new app in a temp dir');
log.info('I will overwrite the old app with myself and then restart it');
var oldAppLocation = gui.App.argv[0];
var executable = gui.App.argv[1];
return autoUpdate.overwriteOldApp(oldAppLocation, executable);
return autoUpdate.overwriteOldApp(currentInstallPath, newUpdaterExecutablePath);
}
initGUI(); // intialises menu and tray, setting up event listeners for both
......
......@@ -37,7 +37,10 @@
"open": "0.0.5",
"request": "^2.69.0",
"rimraf": "^2.4.3",
"temp": "^0.8.3"
"semver": "^5.1.0",
"temp": "^0.8.3",
"url-parse": "^1.0.5",
"yargs": "^4.1.0"
},
"packages": {
"win": {
......
'use strict';
var log = require('loglevel');
var notifier = require('./notifier');
var packageJson = require('../package.json');
var gui = window.require('nw.gui');
var manifest = require('../package.json');
var log = require('loglevel');
var argv = require('yargs')(gui.App.argv).argv;
var os = require('./client-type');
var Updater = require('node-webkit-updater');
var urlParse = require('url-parse');
var rimraf = require('rimraf');
var path = require('path');
var temp = require('temp');
var request = require('request');
var extract = require('extract-zip');
var rimraf = require('rimraf');
var path = require('path');
var Updater = require('node-webkit-updater');
var notifier = require('./notifier');
var quitApp = require('./quit-app');
var MANIFEST_URLS = {
......@@ -18,15 +22,47 @@ var MANIFEST_URLS = {
osx: 'https://update.gitter.im/osx/package.json',
linux: 'https://update.gitter.im/linux/package.json'
};
// You can change the place we use to check updates with this CLI parameter `--update-check-url=192.168.0.58:3010`
// We use this for testing a release
var updateCheckUrlOption = argv['update-check-url'];
if(updateCheckUrlOption) {
Object.keys(MANIFEST_URLS).forEach(function(key) {
var parsedManifestUrl = urlParse(MANIFEST_URLS[key]);
var parsedUpdateCheckUrl = urlParse(updateCheckUrlOption);
parsedManifestUrl.protocol = parsedUpdateCheckUrl.protocol || 'http:';
parsedManifestUrl.auth = parsedUpdateCheckUrl.auth;
parsedManifestUrl.hostname = parsedUpdateCheckUrl.hostname;
parsedManifestUrl.port = parsedUpdateCheckUrl.port;
var newManifestUrl = parsedManifestUrl.toString();
MANIFEST_URLS[key] = newManifestUrl;
});
}
var currentManifest = {
name: packageJson.name,
version: packageJson.version,
name: manifest.name,
version: manifest.version,
manifestUrl: MANIFEST_URLS[os]
};
var updater = new Updater(currentManifest);
var getRemoteDebuggingArgArray = function() {
// If we were debugging before, be sure to allow them to see the install
var remoteDebuggingPort = argv['remote-debugging-port'];
if(remoteDebuggingPort) {
log.info('You will be able to monitor the new app launch with the same remote debugging port (just refresh to see new instances)', remoteDebuggingPort);
return ['--remote-debugging-port=' + remoteDebuggingPort];
}
return [];
};
function download(url, cb) {
var tempFileStream = temp.createWriteStream('gitter-update-zip');
......@@ -102,7 +138,12 @@ function notifyWinOsxUser(version, newAppExecutable) {
click: function() {
log.info('Starting new app to install itself', newAppExecutable, updater.getAppPath(), updater.getAppExec());
updater.runInstaller(newAppExecutable, [updater.getAppPath(), updater.getAppExec()], {});
var installerArgs = [
'--current-install-path', updater.getAppPath(),
'--new-executable', updater.getAppExec()
];
// If we were debugging before, be sure to allow them to see the install
installerArgs = installerArgs.concat(getRemoteDebuggingArgArray);
log.info('Quitting outdated app');
quitApp();
......@@ -178,7 +219,10 @@ function overwriteOldApp(oldAppDir, executable) {
// [1] https://github.com/edjafarov/node-webkit-updater/blob/master/examples/basic.js#L29
// https://github.com/edjafarov/node-webkit-updater/blob/master/app/updater.js#L404-L416
log.info('starting new version');
updater.run(executable, [], {});
var newAppArgs = [];
// If we were debugging before, be sure to allow them to see the new app
newAppArgs = newAppArgs.concat(getRemoteDebuggingArgArray);
updater.run(executable, newAppArgs, {});
// wait for new version to get going...
setTimeout(function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment