From 60a8969abc7d8b2fbbdad64bcd722e580f3b43f1 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 May 2016 18:54:44 -0700 Subject: [PATCH] Add location.url() shorthand location.url() === location.current().url --- renderer/index.js | 6 +++--- renderer/lib/location-history.js | 5 +++++ renderer/views/app.js | 8 ++++---- renderer/views/header.js | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 601bc0a7..67a367c2 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -306,7 +306,7 @@ function dispatch (action, ...args) { state.playing.isStalled = true } if (action === 'mediaError') { - if (state.location.current().url === 'player') { + if (state.location.url() === 'player') { state.playing.location = 'error' ipcRenderer.send('checkForVLC') ipcRenderer.once('checkForVLC', function (e, isInstalled) { @@ -386,7 +386,7 @@ function pause () { } function playPause () { - if (state.location.current().url !== 'player') return + if (state.location.url() !== 'player') return if (state.playing.isPaused) { play() } else { @@ -1236,7 +1236,7 @@ function showDoneNotification (torrent) { // * The video is paused // * The video is playing remotely on Chromecast or Airplay function showOrHidePlayerControls () { - var hideControls = state.location.current().url === 'player' && + var hideControls = state.location.url() === 'player' && state.playing.mouseStationarySince !== 0 && new Date().getTime() - state.playing.mouseStationarySince > 2000 && !state.playing.isPaused && diff --git a/renderer/lib/location-history.js b/renderer/lib/location-history.js index fbbaf7aa..2c5d88f3 100644 --- a/renderer/lib/location-history.js +++ b/renderer/lib/location-history.js @@ -6,6 +6,11 @@ function LocationHistory () { this._forward = [] this._pending = false } + +LocationHistory.prototype.url = function () { + return this.current() && this.current().url +} + LocationHistory.prototype.current = function () { return this._history[this._history.length - 1] } diff --git a/renderer/views/app.js b/renderer/views/app.js index a834c15b..863fcc60 100644 --- a/renderer/views/app.js +++ b/renderer/views/app.js @@ -22,7 +22,7 @@ function App (state) { // * The mouse is over the controls or we're scrubbing (see CSS) // * The video is paused // * The video is playing remotely on Chromecast or Airplay - var hideControls = state.location.current().url === 'player' && + var hideControls = state.location.url() === 'player' && state.playing.mouseStationarySince !== 0 && new Date().getTime() - state.playing.mouseStationarySince > 2000 && !state.playing.isPaused && @@ -30,10 +30,10 @@ function App (state) { // Hide the header on Windows/Linux when in the player // On OSX, the header appears as part of the title bar - var hideHeader = process.platform !== 'darwin' && state.location.current().url === 'player' + var hideHeader = process.platform !== 'darwin' && state.location.url() === 'player' var cls = [ - 'view-' + state.location.current().url, /* e.g. view-home, view-player */ + 'view-' + state.location.url(), /* e.g. view-home, view-player */ 'is-' + process.platform /* e.g. is-darwin, is-win32, is-linux */ ] if (state.window.isFullScreen) cls.push('is-fullscreen') @@ -81,6 +81,6 @@ function getModal (state) { } function getView (state) { - var url = state.location.current().url + var url = state.location.url() return Views[url](state) } diff --git a/renderer/views/header.js b/renderer/views/header.js index dc4c09dd..49ff6e3f 100644 --- a/renderer/views/header.js +++ b/renderer/views/header.js @@ -37,7 +37,7 @@ function Header (state) { } function getAddButton () { - if (state.location.current().url !== 'player') { + if (state.location.url() !== 'player') { return hx`