update player window title to torrent name (Windows, Linux)
This also moves all the state “diffing” for purposes of updating the app’s window via Electron APIs into one function updateElectron().
This commit is contained in:
@@ -32,6 +32,10 @@ function init () {
|
|||||||
windows.main.setFullScreen(!windows.main.isFullScreen())
|
windows.main.setFullScreen(!windows.main.isFullScreen())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('setTitle', function (e, title) {
|
||||||
|
windows.main.setTitle(title)
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.on('log', function (e, message) {
|
ipcMain.on('log', function (e, message) {
|
||||||
console.log(message)
|
console.log(message)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ function init () {
|
|||||||
// Calling update() updates the UI given the current state
|
// Calling update() updates the UI given the current state
|
||||||
// Do this at least once a second to show latest state for each torrent
|
// Do this at least once a second to show latest state for each torrent
|
||||||
// (eg % downloaded) and to keep the cursor in sync when playing a video
|
// (eg % downloaded) and to keep the cursor in sync when playing a video
|
||||||
setInterval(update, 1000)
|
setInterval(function () {
|
||||||
|
update()
|
||||||
|
updateClientProgress()
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
// All state lives in state.js. `state.saved` is read from and written to a
|
// All state lives in state.js. `state.saved` is read from and written to a
|
||||||
// file. All other state is ephemeral. Here we'll load state.saved:
|
// file. All other state is ephemeral. Here we'll load state.saved:
|
||||||
@@ -105,7 +108,6 @@ function init () {
|
|||||||
// ...focus and blur. Needed to show correct dock icon text ("badge") in OSX
|
// ...focus and blur. Needed to show correct dock icon text ("badge") in OSX
|
||||||
window.addEventListener('focus', function () {
|
window.addEventListener('focus', function () {
|
||||||
state.isFocused = true
|
state.isFocused = true
|
||||||
if (state.dock.badge > 0) ipcRenderer.send('setBadge', '')
|
|
||||||
state.dock.badge = 0
|
state.dock.badge = 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -127,7 +129,21 @@ function render (state) {
|
|||||||
// Calls render() to go from state -> UI, then applies to vdom to the real DOM.
|
// Calls render() to go from state -> UI, then applies to vdom to the real DOM.
|
||||||
function update () {
|
function update () {
|
||||||
vdomLoop.update(state)
|
vdomLoop.update(state)
|
||||||
updateDockIcon()
|
updateElectron()
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateElectron () {
|
||||||
|
if (state.title !== state.prev.title) {
|
||||||
|
state.prev.title = state.title
|
||||||
|
ipcRenderer.send('setTitle', state.title)
|
||||||
|
}
|
||||||
|
if (state.dock.progress !== state.prev.progress) {
|
||||||
|
state.prev.progress = state.dock.progress
|
||||||
|
ipcRenderer.send('setProgress', state.dock.progress)
|
||||||
|
}
|
||||||
|
if (state.dock.badge !== state.prev.badge) {
|
||||||
|
ipcRenderer.send('setBadge', state.dock.badge || '')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events from the UI never modify state directly. Instead they call dispatch()
|
// Events from the UI never modify state directly. Instead they call dispatch()
|
||||||
@@ -247,7 +263,7 @@ function saveState () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDockIcon () {
|
function updateClientProgress () {
|
||||||
var progress = state.client.progress
|
var progress = state.client.progress
|
||||||
var activeTorrentsExist = state.client.torrents.some(function (torrent) {
|
var activeTorrentsExist = state.client.torrents.some(function (torrent) {
|
||||||
return torrent.progress !== 1
|
return torrent.progress !== 1
|
||||||
@@ -256,10 +272,7 @@ function updateDockIcon () {
|
|||||||
if (!activeTorrentsExist || progress === 1) {
|
if (!activeTorrentsExist || progress === 1) {
|
||||||
progress = -1
|
progress = -1
|
||||||
}
|
}
|
||||||
if (progress !== state.dock.progress) {
|
state.dock.progress = progress
|
||||||
state.dock.progress = progress
|
|
||||||
ipcRenderer.send('setProgress', progress)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFiles (files) {
|
function onFiles (files) {
|
||||||
@@ -367,7 +380,6 @@ function addTorrentEvents (torrent) {
|
|||||||
|
|
||||||
if (!state.isFocused) {
|
if (!state.isFocused) {
|
||||||
state.dock.badge += 1
|
state.dock.badge += 1
|
||||||
ipcRenderer.send('setBadge', state.dock.badge)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update()
|
update()
|
||||||
@@ -433,6 +445,8 @@ function openPlayer (infoHash) {
|
|||||||
function closePlayer () {
|
function closePlayer () {
|
||||||
state.url = '/'
|
state.url = '/'
|
||||||
state.title = config.APP_NAME
|
state.title = config.APP_NAME
|
||||||
|
update()
|
||||||
|
|
||||||
if (state.isFullScreen) {
|
if (state.isFullScreen) {
|
||||||
ipcRenderer.send('toggleFullScreen')
|
ipcRenderer.send('toggleFullScreen')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ module.exports = {
|
|||||||
duration: 1, /* seconds */
|
duration: 1, /* seconds */
|
||||||
mouseStationarySince: 0 /* Unix time in ms */
|
mouseStationarySince: 0 /* Unix time in ms */
|
||||||
},
|
},
|
||||||
|
prev: {}, /* used for state diffing in updateElectron() */
|
||||||
|
|
||||||
/* Saved state is read from and written to a file every time the app runs.
|
/* Saved state is read from and written to a file every time the app runs.
|
||||||
* It should be simple and minimal and must be JSON.
|
* It should be simple and minimal and must be JSON.
|
||||||
|
|||||||
Reference in New Issue
Block a user