From de48ba5565a035d1d36028836ad9c4a70e51a73e Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Sun, 18 Sep 2016 16:08:21 +0100 Subject: [PATCH] Add Linux Update Notifications --- app/autoupdate.js | 78 ++++++++++++++++++++++++++++++++++------------- app/package.json | 6 ++-- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/app/autoupdate.js b/app/autoupdate.js index 1949313..ce2ff1f 100644 --- a/app/autoupdate.js +++ b/app/autoupdate.js @@ -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'); @@ -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(); + } +}; diff --git a/app/package.json b/app/package.json index b64f173..738c19e 100644 --- a/app/package.json +++ b/app/package.json @@ -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" } }