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

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