Merge pull request #748 from feross/location-history
Switch to using `location-history` package
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
"hat": "0.0.3",
|
"hat": "0.0.3",
|
||||||
"iso-639-1": "^1.2.1",
|
"iso-639-1": "^1.2.1",
|
||||||
"languagedetect": "^1.1.1",
|
"languagedetect": "^1.1.1",
|
||||||
|
"location-history": "^1.0.0",
|
||||||
"musicmetadata": "^2.0.2",
|
"musicmetadata": "^2.0.2",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
"parse-torrent": "^5.7.3",
|
"parse-torrent": "^5.7.3",
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ module.exports = class PlaybackController {
|
|||||||
playFile (infoHash, index /* optional */) {
|
playFile (infoHash, index /* optional */) {
|
||||||
this.state.location.go({
|
this.state.location.go({
|
||||||
url: 'player',
|
url: 'player',
|
||||||
onbeforeload: (cb) => {
|
setup: (cb) => {
|
||||||
this.play()
|
this.play()
|
||||||
this.openPlayer(infoHash, index, cb)
|
this.openPlayer(infoHash, index, cb)
|
||||||
},
|
},
|
||||||
onbeforeunload: (cb) => this.closePlayer(cb)
|
destroy: () => this.closePlayer()
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err) dispatch('error', err)
|
if (err) dispatch('error', err)
|
||||||
})
|
})
|
||||||
@@ -251,7 +251,7 @@ module.exports = class PlaybackController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
closePlayer (cb) {
|
closePlayer () {
|
||||||
console.log('closePlayer')
|
console.log('closePlayer')
|
||||||
|
|
||||||
// Quit any external players, like Chromecast/Airplay/etc or VLC
|
// Quit any external players, like Chromecast/Airplay/etc or VLC
|
||||||
@@ -274,7 +274,6 @@ module.exports = class PlaybackController {
|
|||||||
else console.error('Unknown state.playing.result', state.playing.result)
|
else console.error('Unknown state.playing.result', state.playing.result)
|
||||||
|
|
||||||
// Reset the window contents back to the home screen
|
// Reset the window contents back to the home screen
|
||||||
dispatch('resetTitle')
|
|
||||||
state.playing = State.getDefaultPlayState()
|
state.playing = State.getDefaultPlayState()
|
||||||
state.server = null
|
state.server = null
|
||||||
|
|
||||||
@@ -290,7 +289,6 @@ module.exports = class PlaybackController {
|
|||||||
ipcRenderer.send('onPlayerClose')
|
ipcRenderer.send('onPlayerClose')
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
cb()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,24 +13,19 @@ module.exports = class PrefsController {
|
|||||||
var state = this.state
|
var state = this.state
|
||||||
state.location.go({
|
state.location.go({
|
||||||
url: 'preferences',
|
url: 'preferences',
|
||||||
onbeforeload: function (cb) {
|
setup: function (cb) {
|
||||||
// initialize preferences
|
// initialize preferences
|
||||||
dispatch('setTitle', 'Preferences')
|
dispatch('setTitle', 'Preferences')
|
||||||
state.unsaved = Object.assign(state.unsaved || {}, {prefs: state.saved.prefs || {}})
|
state.unsaved = Object.assign(state.unsaved || {}, {prefs: state.saved.prefs || {}})
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
onbeforeunload: (cb) => {
|
destroy: () => this.save()
|
||||||
// save state after preferences
|
|
||||||
this.save()
|
|
||||||
dispatch('resetTitle')
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates a single property in the UNSAVED prefs
|
// Updates a single property in the UNSAVED prefs
|
||||||
// For example: updatePreferences('foo.bar', 'baz')
|
// For example: updatePreferences('foo.bar', 'baz')
|
||||||
// Call savePreferences to save to config.json
|
// Call save() to save to config.json
|
||||||
update (property, value) {
|
update (property, value) {
|
||||||
var path = property.split('.')
|
var path = property.split('.')
|
||||||
var key = this.state.unsaved.prefs
|
var key = this.state.unsaved.prefs
|
||||||
|
|||||||
@@ -1,125 +0,0 @@
|
|||||||
module.exports = LocationHistory
|
|
||||||
|
|
||||||
function LocationHistory () {
|
|
||||||
this._history = []
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.go = function (page, cb) {
|
|
||||||
if (!cb) cb = noop
|
|
||||||
if (this._pending) return cb(null)
|
|
||||||
|
|
||||||
console.log('go', page)
|
|
||||||
|
|
||||||
this.clearForward()
|
|
||||||
this._go(page, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.back = function (cb) {
|
|
||||||
var self = this
|
|
||||||
if (!cb) cb = noop
|
|
||||||
if (self._history.length <= 1 || self._pending) return cb(null)
|
|
||||||
|
|
||||||
var page = self._history.pop()
|
|
||||||
self._unload(page, done)
|
|
||||||
|
|
||||||
function done (err) {
|
|
||||||
if (err) return cb(err)
|
|
||||||
self._forward.push(page)
|
|
||||||
self._load(self.current(), cb)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.hasBack = function () {
|
|
||||||
return this._history.length > 1
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.forward = function (cb) {
|
|
||||||
if (!cb) cb = noop
|
|
||||||
if (this._forward.length === 0 || this._pending) return cb(null)
|
|
||||||
|
|
||||||
var page = this._forward.pop()
|
|
||||||
this._go(page, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.hasForward = function () {
|
|
||||||
return this._forward.length > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.clearForward = function (url) {
|
|
||||||
if (url == null) {
|
|
||||||
this._forward = []
|
|
||||||
} else {
|
|
||||||
console.log(this._forward)
|
|
||||||
console.log(url)
|
|
||||||
this._forward = this._forward.filter(function (page) {
|
|
||||||
return page.url !== url
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype.backToFirst = function (cb) {
|
|
||||||
var self = this
|
|
||||||
if (!cb) cb = noop
|
|
||||||
if (self._history.length <= 1) return cb(null)
|
|
||||||
|
|
||||||
self.back(function (err) {
|
|
||||||
if (err) return cb(err)
|
|
||||||
self.backToFirst(cb)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype._go = function (page, cb) {
|
|
||||||
var self = this
|
|
||||||
if (!cb) cb = noop
|
|
||||||
|
|
||||||
self._unload(self.current(), done1)
|
|
||||||
|
|
||||||
function done1 (err) {
|
|
||||||
if (err) return cb(err)
|
|
||||||
self._load(page, done2)
|
|
||||||
}
|
|
||||||
|
|
||||||
function done2 (err) {
|
|
||||||
if (err) return cb(err)
|
|
||||||
self._history.push(page)
|
|
||||||
cb(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype._load = function (page, cb) {
|
|
||||||
var self = this
|
|
||||||
self._pending = true
|
|
||||||
|
|
||||||
if (page && page.onbeforeload) page.onbeforeload(done)
|
|
||||||
else done(null)
|
|
||||||
|
|
||||||
function done (err) {
|
|
||||||
self._pending = false
|
|
||||||
cb(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LocationHistory.prototype._unload = function (page, cb) {
|
|
||||||
var self = this
|
|
||||||
self._pending = true
|
|
||||||
|
|
||||||
if (page && page.onbeforeunload) page.onbeforeunload(done)
|
|
||||||
else done(null)
|
|
||||||
|
|
||||||
function done (err) {
|
|
||||||
self._pending = false
|
|
||||||
cb(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function noop () {}
|
|
||||||
@@ -15,7 +15,7 @@ var State = module.exports = Object.assign(new EventEmitter(), {
|
|||||||
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
||||||
|
|
||||||
function getDefaultState () {
|
function getDefaultState () {
|
||||||
var LocationHistory = require('./location-history')
|
var LocationHistory = require('location-history')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -66,7 +66,13 @@ function onState (err, _state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add first page to location history
|
// Add first page to location history
|
||||||
state.location.go({ url: 'home' })
|
state.location.go({
|
||||||
|
url: 'home',
|
||||||
|
setup: (cb) => {
|
||||||
|
dispatch('resetTitle')
|
||||||
|
cb(null)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Restart everything we were torrenting last time the app ran
|
// Restart everything we were torrenting last time the app ran
|
||||||
resumeTorrents()
|
resumeTorrents()
|
||||||
|
|||||||
Reference in New Issue
Block a user