From 9030f23278d7375bc75bad56e96fd6a15e95f93a Mon Sep 17 00:00:00 2001 From: DC Date: Mon, 28 Mar 2016 16:16:43 -0700 Subject: [PATCH] Linux update notifications Fixes #257 --- main/auto-updater.js | 23 ++++++++++++++- package.json | 3 +- renderer/index.css | 4 +++ renderer/index.js | 19 ++++++++++++- renderer/state.js | 1 + renderer/views/app.js | 5 ++-- renderer/views/update-available-modal.js | 36 ++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 renderer/views/update-available-modal.js diff --git a/main/auto-updater.js b/main/auto-updater.js index 37a400b1..f762e2ab 100644 --- a/main/auto-updater.js +++ b/main/auto-updater.js @@ -3,9 +3,11 @@ module.exports = { } var electron = require('electron') +var get = require('simple-get') var config = require('../config') var log = require('./log') +var windows = require('./windows') var autoUpdater = electron.autoUpdater @@ -20,7 +22,7 @@ function init () { * We always check for updates on app startup. To keep app startup fast, we delay this * first check so it happens when there is less going on. */ - setTimeout(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_STARTUP_DELAY) + setTimeout(checkForUpdates, config.AUTO_UPDATE_CHECK_STARTUP_DELAY) autoUpdater.on('checking-for-update', () => log('Checking for app update')) autoUpdater.on('update-available', () => log('App update available')) @@ -29,3 +31,22 @@ function init () { log('App update downloaded: ', releaseName, updateURL) }) } + +function checkForUpdates () { + // Electron's built-in auto updater only supports Mac and Windows, for now + if (process.platform !== 'linux') { + return autoUpdater.checkForUpdates() + } + + // If we're on Linux, we have to do it ourselves + get.concat(config.AUTO_UPDATE_URL, function (err, res, data) { + if (err) return log('Error checking for app update: ' + err.message) + if (![200, 204].includes(res.statusCode)) return log('Error checking for app update, got HTTP ' + res.statusCode) + if (res.statusCode !== 200) return + + var obj = JSON.parse(data) + // TODO: version should be included in the response object, we shouldn'v have to parse obj.name + var version = obj.name.slice(obj.name.lastIndexOf('v') + 1) + windows.main.send('dispatch', 'updateAvailable', version) + }) +} diff --git a/package.json b/package.json index 27a93efa..95e34c27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "webtorrent-desktop", "description": "WebTorrent, the streaming torrent client. For OS X, Windows, and Linux.", - "version": "0.1.1", + "version": "0.1.0", "author": { "name": "Feross Aboukhadijeh", "email": "feross@feross.org", @@ -27,6 +27,7 @@ "network-address": "^1.1.0", "path-exists": "^2.1.0", "prettier-bytes": "^1.0.1", + "simple-get": "^2.0.0", "upload-element": "^1.0.1", "virtual-dom": "^2.1.1", "webtorrent": "^0.87.1", diff --git a/renderer/index.css b/renderer/index.css index 9e92d58d..814b74bd 100644 --- a/renderer/index.css +++ b/renderer/index.css @@ -242,6 +242,10 @@ i:not(.disabled):hover { * MODAL POPOVERS */ +.modal { + z-index: 2; +} + .modal .modal-background { content: ' '; position: fixed; diff --git a/renderer/index.js b/renderer/index.js index d93275e8..8c9f653e 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -293,6 +293,14 @@ function dispatch (action, ...args) { if (action === 'exitModal') { state.modal = null } + if (action === 'updateAvailable') { + updateAvailable(args[0] /* version */) + } + if (action === 'skipVersion') { + if (!state.saved.skippedVersions) state.saved.skippedVersions = [] + state.saved.skippedVersions.push(args[0] /* version */) + saveState() + } // Update the virtual-dom, unless it's just a mouse move event if (action !== 'mediaMouseMoved') { @@ -300,6 +308,15 @@ function dispatch (action, ...args) { } } +// Shows a modal saying that we have an update +function updateAvailable(version) { + if (state.saved.skippedVersions && state.saved.skippedVersions.includes(version)) { + console.log('new version skipped by user: v' + version) + return + } + state.modal = { id: 'update-available-modal', version: version } +} + // Plays or pauses the video. If isPaused is undefined, acts as a toggle function playPause (isPaused) { if (isPaused === state.playing.isPaused) { @@ -347,7 +364,7 @@ function setupIpc () { ipcRenderer.on('dispatch', (e, ...args) => dispatch(...args)) ipcRenderer.on('showOpenTorrentAddress', function (e) { - state.modal = 'open-torrent-address-modal' + state.modal = { id: 'open-torrent-address-modal' } update() }) diff --git a/renderer/state.js b/renderer/state.js index 8af56bdc..7d731b1c 100644 --- a/renderer/state.js +++ b/renderer/state.js @@ -40,6 +40,7 @@ module.exports = { badge: 0, progress: 0 }, + modal: null, /* modal popover */ errors: [], /* user-facing errors */ /* diff --git a/renderer/views/app.js b/renderer/views/app.js index 00f597ab..83d46853 100644 --- a/renderer/views/app.js +++ b/renderer/views/app.js @@ -8,7 +8,8 @@ var Header = require('./header') var Player = require('./player') var TorrentList = require('./torrent-list') var Modals = { - 'open-torrent-address-modal': require('./open-torrent-address-modal') + 'open-torrent-address-modal': require('./open-torrent-address-modal'), + 'update-available-modal': require('./update-available-modal') } function App (state, dispatch) { @@ -62,7 +63,7 @@ function App (state, dispatch) { function getModal () { if (state.modal) { - var contents = Modals[state.modal](state, dispatch) + var contents = Modals[state.modal.id](state, dispatch) return hx`