Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
Update notification handling and auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Feb 23, 2016
1 parent 420cc6e commit 0eea381
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ On osx/linux, run the following commands
3. On windows, run `node ./windows/build.js -p thepfxcertpasswordhere`. For more information, see the [windows build readme](https://github.com/gitterHQ/desktop/blob/master/windows/README.md)
4. On osx/linux, run `gulp autoupdate:zip:win`
4. On osx/linux, run `gulp autoupdate:zip:osx`
4. On osx/linux, run `gulp autoupdate:zip:linux`
5. On osx/linux, create the redirect pages with `gulp redirect:source`
2. **Check that all the binaries work**. You should have:
* GitterSetup-X.X.X.exe
Expand All @@ -100,6 +101,7 @@ On osx/linux, run the following commands
* `gulp artefacts:push:linux64`
* `gulp autoupdate:push:win`
* `gulp autoupdate:push:osx`
* `gulp autoupdate:push:linux`
2. on osx/linux, publish the redirects by running:
* `gulp redirect:push:win`
* `gulp redirect:push:linux32`
Expand Down
48 changes: 42 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ var dmg_cmd = template('./osx/create-dmg/create-dmg --icon "<%= name %>" 311 50

// Only runs on OSX (requires XCode properly configured)
gulp.task('sign:osx', ['build'], shell.task([
/* * /
'codesign -v -f -s "'+ SIGN_IDENTITY +'" '+ OUTPUT_DIR +'/Gitter/osx64/Gitter.app/Contents/Frameworks/*',
'codesign -v -f -s "'+ SIGN_IDENTITY +'" '+ OUTPUT_DIR +'/Gitter/osx64/Gitter.app',
'codesign -v --display '+ OUTPUT_DIR +'/Gitter/osx64/Gitter.app',
'codesign -v --verify '+ OUTPUT_DIR +'/Gitter/osx64/Gitter.app'
/* */
]));

// Only runs on OSX
Expand All @@ -238,31 +240,65 @@ gulp.task('autoupdate:zip:osx', shell.task([
'mv '+ OUTPUT_DIR + '/Gitter/osx64/osx.zip '+ ARTEFACTS_DIR + '/osx.zip',
]));

gulp.task('autoupdate:push:osx', function() {
// Generate auto-updater packages for linux
gulp.task('autoupdate:zip:linux', shell.task([
'cd '+ OUTPUT_DIR + '/Gitter/osx64; zip -r osx.zip ./Gitter.app > /dev/null 2>&1',
'mv '+ OUTPUT_DIR + '/Gitter/osx64/osx.zip '+ ARTEFACTS_DIR + '/linux32.zip',
'cd '+ OUTPUT_DIR + '/Gitter/osx64; zip -r osx.zip ./Gitter.app > /dev/null 2>&1',
'mv '+ OUTPUT_DIR + '/Gitter/osx64/osx.zip '+ ARTEFACTS_DIR + '/linux64.zip',
]));

gulp.task('autoupdate:push:win', function() {
return pushS3({
localFile: ARTEFACTS_DIR + '/osx.zip',
localFile: ARTEFACTS_DIR + '/win32.zip',
s3Params: {
Bucket: S3_CONSTS.buckets.updates,
Key: 'osx/osx.zip',
Key: 'win/win32.zip',
CacheControl: 'public, max-age=0, no-cache',
ACL: 'public-read'
}
});
});

gulp.task('autoupdate:push:win', function() {
gulp.task('autoupdate:push:osx', function() {
return pushS3({
localFile: ARTEFACTS_DIR + '/win32.zip',
localFile: ARTEFACTS_DIR + '/osx.zip',
s3Params: {
Bucket: S3_CONSTS.buckets.updates,
Key: 'win/win32.zip',
Key: 'osx/osx.zip',
CacheControl: 'public, max-age=0, no-cache',
ACL: 'public-read'
}
});
});


gulp.task('autoupdate:push:linux', function() {
return Promise.all([
pushS3({
localFile: ARTEFACTS_DIR + '/linux32.zip',
s3Params: {
Bucket: S3_CONSTS.buckets.updates,
Key: 'linux32/linux32.zip',
CacheControl: 'public, max-age=0, no-cache',
ACL: 'public-read'
}
}),
pushS3({
localFile: ARTEFACTS_DIR + '/linux64.zip',
s3Params: {
Bucket: S3_CONSTS.buckets.updates,
Key: 'linux64/linux64.zip',
CacheControl: 'public, max-age=0, no-cache',
ACL: 'public-read'
}
})
]);
});





var pushManifestToDest = function(destinationKey) {
return pushS3({
Expand Down
7 changes: 4 additions & 3 deletions nwapp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ function initApp() {

if (msg.notification === 'user_notification') {
notifier({
title: msg.title,
title: msg.title,
message: msg.text,
icon: msg.icon,
click: function () {
icon: msg.icon,
click: function() {
log.info('Notification user_notification clicked. Moving to', msg.link);
navigateWindowTo(msg.link);
}
});
Expand Down
6 changes: 6 additions & 0 deletions nwapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
},
"mac": {
"url": "https://update.gitter.im/osx/osx.zip"
},
"linux32": {
"url": "https://update.gitter.im/linux32/linux32.zip"
},
"linux64": {
"url": "https://update.gitter.im/linux64/linux64.zip"
}
},
"single-instance": false,
Expand Down
8 changes: 6 additions & 2 deletions nwapp/utils/auto-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var quitApp = require('./quit-app');

// You can change the place we use to check and download updates with this CLI parameter `--update-url=192.168.0.58:3010`
// We use this for testing a release
var updateUrlOption = argv['update-url'] || '';
var updateUrlOption = argv['update-url'] || 'https://update.gitter.im';
var transposeUpdateUrl = function(targetUrl) {
targetUrl = targetUrl || '';
var parsedTargetUrl = urlParse(targetUrl);
Expand All @@ -39,7 +39,7 @@ var transposeUpdateUrl = function(targetUrl) {
var MANIFEST_URLS = {
win: 'https://update.gitter.im/win/package.json',
osx: 'https://update.gitter.im/osx/package.json',
linux: 'https://update.gitter.im/linux/package.json'
linux: 'https://update.gitter.im/linux64/package.json'
};
Object.keys(MANIFEST_URLS).forEach(function(key) {
MANIFEST_URLS[key] = transposeUpdateUrl(MANIFEST_URLS[key]);
Expand Down Expand Up @@ -145,6 +145,7 @@ function notifyWinOsxUser(version, newAppExecutable) {
title: 'Gitter ' + version + ' Available',
message: 'Click to restart and apply update.',
click: function() {
log.info('Update notification clicked');

var installerArgs = [
'--current-install-path=' + updater.getAppPath(),
Expand Down Expand Up @@ -206,6 +207,9 @@ function poll() {
});
}

// A debug way to trigger another update
window.debugUpdateGitter = update;

// polling with setInterval can cause multiple downloads
// to occur if left unattended, so its best to wait for the updater
// to finish each poll before triggering a new request.
Expand Down
32 changes: 25 additions & 7 deletions nwapp/utils/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ function playNotificationSound() {
audio = null;
}

var checkActivationNotifierResponse = function(response) {
// 'activated', `timeout'`
var resp = response.trim().toLowerCase();
if(resp.match(/^activate/)) {
return true;
}

return false;
};


// Cache lookup
var urlFilePathCacheMap = new Map();
Expand Down Expand Up @@ -128,16 +138,24 @@ module.exports = function (options) {
// And we set to false because Windows 10 by default makes a separate sound
sound: false,
// wait with callback until user action is taken on notification
wait: false
}, function (err) {
if(err) throw err;
});
notifier.on('click', function() {
if(opts.click) opts.click();
wait: true
}, function(err, response) {
log.info('Notification response', response);
var didActivate = checkActivationNotifierResponse(response);

if(err) {
// If you are seeing errors on each notification on Windows,
// it isn't really a issue because everything works normally and
// we are blocked until it gets fixed: https://github.com/mikaelbr/node-notifier/issues/97
log.error('Problem with notification', err, err.stack);
}
if(didActivate && opts.click) {
opts.click();
}
});
})
.catch(function(err) {
log.error('Problem with notification', err, err.stack);
log.error('Problem initializing notification', err, err.stack);
});

};

0 comments on commit 0eea381

Please sign in to comment.