Skip to content

Commit

Permalink
Add Linux Update Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob4001 committed Sep 18, 2016
1 parent 1c7103f commit de48ba5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
78 changes: 56 additions & 22 deletions app/autoupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const electron = require('electron');
const autoUpdater = electron.autoUpdater;
const dialog = electron.dialog;
const app = electron.app;
const shell = electron.shell;
const os = require('os');
const feed = require("feed-read");
const semver = require('semver');

// this file is run in the main process, not the renderer
console.assert(process.type !== 'renderer');
Expand All @@ -15,31 +18,62 @@ function showAutoupdateDialog(releaseName, callback) {
detail: 'The latest version is '+releaseName+'. You are using '+app.getVersion()+'.',
buttons: ['Update', 'Cancel'],
}, function (buttonId) {
if (buttonId == 0) {
if (buttonId === 0) {
callback();
}
});
};
}

module.exports.setup = function () {
autoUpdater.on('error', function (err) { console.log('Autoupdate: error', err); })
autoUpdater.on('update-available', function () { console.log('Autoupdate: update available, downloading...')})
autoUpdater.on('update-not-available', function () { console.log('Autoupdate: Up to date.')})
autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName) {
showAutoupdateDialog(releaseName, function () {
autoUpdater.quitAndInstall();
});
})

const version = app.getVersion();

if (process.platform === 'darwin') {
const platform = os.platform() + '_' + os.arch();

autoUpdater.setFeedURL('http://tide-download.tingbot.com/update/'+platform+'/'+version);
autoUpdater.checkForUpdates();
} else if (process.platform === 'win32') {
autoUpdater.setFeedURL('http://tide-download.tingbot.com/update/win32/'+version);
autoUpdater.checkForUpdates();
function showNewVersionAvalibleDialog(releaseName, url) {
dialog.showMessageBox({
type: 'question',
title: 'Update available',
message: 'An update to Tide is available',
detail: 'The latest version is '+releaseName+'. You are using '+app.getVersion()+'.',
buttons: ['Download', 'Cancel'],
}, function (buttonId) {
if (buttonId === 0) {
shell.openExternal(url);
}
});
}

function setupOSXWin(){
autoUpdater.on('error', function (err) { console.log('Autoupdate: error', err); });
autoUpdater.on('update-available', function () { console.log('Autoupdate: update available, downloading...');});
autoUpdater.on('update-not-available', function () { console.log('Autoupdate: Up to date.');});
autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName) {
showAutoupdateDialog(releaseName, function () {
autoUpdater.quitAndInstall();
});
});

const version = app.getVersion();

if (process.platform === 'darwin') {
const platform = os.platform() + '_' + os.arch();

autoUpdater.setFeedURL('http://tide-download.tingbot.com/update/'+platform+'/'+version);
autoUpdater.checkForUpdates();
} else if (process.platform === 'win32') {
autoUpdater.setFeedURL('http://tide-download.tingbot.com/update/win32/'+version);
autoUpdater.checkForUpdates();
}
}

function setupLinux(){
feed('http://tide-download.tingbot.com/feed/channel/all.atom',function(err,versions){
var newest = versions[0].title;
if(semver.gt(newest,app.getVersion())){
showNewVersionAvalibleDialog(newest,'https://github.com/tingbot/tide-electron/releases')
}
});
}

module.exports.setup = function () {
if (process.platform === 'linux') {
setupLinux();
} else {
setupOSXWin();
}
};
6 changes: 4 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
"brace": "~0.8.0",
"drivelist": "3.3.3",
"electron-squirrel-startup": "^1.0.0",
"feed-read": "0.0.1",
"fs-extra": "^0.30.0",
"jquery": "^3.1.0",
"mdns-js": "^0.5.0",
"minimatch": "3.0.3",
"node-uuid": "1.4.7",
"ptyw.js": "0.4.0",
"xterm": "github:sourcelair/xterm.js#1.1.2",
"node-uuid": "1.4.7"
"semver": "^5.3.0",
"xterm": "github:sourcelair/xterm.js#1.1.2"
}
}

0 comments on commit de48ba5

Please sign in to comment.