Linux update notifications

Fixes #257
This commit is contained in:
DC
2016-03-28 16:16:43 -07:00
parent 25db4eec9d
commit 86069a7173
7 changed files with 86 additions and 5 deletions

View File

@@ -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)
})
}

View File

@@ -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",

View File

@@ -242,6 +242,10 @@ i:not(.disabled):hover {
* MODAL POPOVERS
*/
.modal {
z-index: 2;
}
.modal .modal-background {
content: ' ';
position: fixed;

View File

@@ -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()
})

View File

@@ -40,6 +40,7 @@ module.exports = {
badge: 0,
progress: 0
},
modal: null, /* modal popover */
errors: [], /* user-facing errors */
/*

View File

@@ -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`
<div class='modal'>
<div class='modal-background'></div>

View File

@@ -0,0 +1,36 @@
module.exports = UpdateAvailableModal
var h = require('virtual-dom/h')
var hyperx = require('hyperx')
var hx = hyperx(h)
var electron = require('electron')
var {dispatch} = require('../lib/dispatcher')
function UpdateAvailableModal (state) {
return hx`
<div class='update-available-modal'>
<p><strong>A new version of WebTorrent is available: v${state.modal.version}</strong></p>
<p>We have an auto-updater for Windows and Mac, but not yet for Linux, so you'll have to download it manually. Sorry.</p>
<p>
<button class='primary' onclick=${handleOK}>Show Download Page</button>
<button class='cancel' onclick=${handleCancel}>Skip This Release</button>
</p>
</div>
`
}
function handleKeyPress (e) {
if (e.which === 13) handleOK() /* hit Enter to submit */
}
function handleOK () {
electron.shell.openExternal('https://github.com/feross/webtorrent-desktop/releases')
dispatch('exitModal')
}
function handleCancel () {
dispatch('skipVersion', state.modal.version)
dispatch('exitModal')
}