From db20bd8eaf0afbe97b5564841fd6dc6a859629d1 Mon Sep 17 00:00:00 2001
From: anonymlol
Date: Tue, 14 Jun 2016 13:30:38 +0200
Subject: [PATCH 01/31] New Handler: stream-magnet
only tested on windows
---
bin/package.js | 6 ++++++
main/handlers.js | 9 ++++++++-
renderer/main.js | 1 +
static/linux/webtorrent-desktop.desktop | 2 +-
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bin/package.js b/bin/package.js
index 09a2dcea..b0597694 100755
--- a/bin/package.js
+++ b/bin/package.js
@@ -206,6 +206,12 @@ function buildDarwin (cb) {
CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns',
CFBundleURLName: 'BitTorrent Magnet URL',
CFBundleURLSchemes: [ 'magnet' ]
+ },
+ {
+ CFBundleTypeRole: 'Editor',
+ CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns',
+ CFBundleURLName: 'BitTorrent Stream-Magnet URL',
+ CFBundleURLSchemes: [ 'stream-magnet' ]
}
]
diff --git a/main/handlers.js b/main/handlers.js
index 33da88fe..5ea9431a 100644
--- a/main/handlers.js
+++ b/main/handlers.js
@@ -36,7 +36,7 @@ function installDarwin () {
// On OS X, only protocols that are listed in `Info.plist` can be set as the
// default handler at runtime.
- app.setAsDefaultProtocolClient('magnet')
+ app.setAsDefaultProtocolClient('stream-magnet')
// File handlers are defined in `Info.plist`.
}
@@ -63,6 +63,12 @@ function installWin32 () {
iconPath,
EXEC_COMMAND
)
+ registerProtocolHandlerWin32(
+ 'stream-magnet',
+ 'URL:BitTorrent Stream-Magnet URL',
+ iconPath,
+ EXEC_COMMAND
+ )
registerFileHandlerWin32(
'.torrent',
'io.webtorrent.torrent',
@@ -201,6 +207,7 @@ function uninstallWin32 () {
var Registry = require('winreg')
unregisterProtocolHandlerWin32('magnet', EXEC_COMMAND)
+ unregisterProtocolHandlerWin32('stream-magnet', EXEC_COMMAND)
unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', EXEC_COMMAND)
function unregisterProtocolHandlerWin32 (protocol, command) {
diff --git a/renderer/main.js b/renderer/main.js
index 39bcc30a..470cfdc5 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -550,6 +550,7 @@ function isTorrent (file) {
var name = typeof file === 'string' ? file : file.name
var isTorrentFile = path.extname(name).toLowerCase() === '.torrent'
var isMagnet = typeof file === 'string' && /^magnet:/.test(file)
+ var isMagnet = typeof file === 'string' && /^stream-magnet:/.test(file)
return isTorrentFile || isMagnet
}
diff --git a/static/linux/webtorrent-desktop.desktop b/static/linux/webtorrent-desktop.desktop
index ac37a056..d47e98a6 100644
--- a/static/linux/webtorrent-desktop.desktop
+++ b/static/linux/webtorrent-desktop.desktop
@@ -13,7 +13,7 @@ Exec=$EXEC_PATH %U
TryExec=$TRY_EXEC_PATH
StartupNotify=false
Categories=Network;FileTransfer;P2P;
-MimeType=application/x-bittorrent;x-scheme-handler/magnet;
+MimeType=application/x-bittorrent;x-scheme-handler/magnet;x-scheme-handler/stream-magnet;
Actions=CreateNewTorrent;OpenTorrentFile;OpenTorrentAddress;
From 8f03ecedaa2872c3ff604fbc53d407c94c700868 Mon Sep 17 00:00:00 2001
From: anonymlol
Date: Tue, 14 Jun 2016 13:53:01 +0200
Subject: [PATCH 02/31] fix 'isMagnet' is already defined error
---
renderer/main.js | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/renderer/main.js b/renderer/main.js
index 470cfdc5..2fe0ff5c 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -549,8 +549,7 @@ function onOpen (files) {
function isTorrent (file) {
var name = typeof file === 'string' ? file : file.name
var isTorrentFile = path.extname(name).toLowerCase() === '.torrent'
- var isMagnet = typeof file === 'string' && /^magnet:/.test(file)
- var isMagnet = typeof file === 'string' && /^stream-magnet:/.test(file)
+ var isMagnet = typeof file === 'string' && /^magnet:/.test(file) || /^stream-magnet:/.test(file)
return isTorrentFile || isMagnet
}
From 4799a032e5c66423e30048b8d06def05730853e8 Mon Sep 17 00:00:00 2001
From: Feross Aboukhadijeh
Date: Thu, 23 Jun 2016 18:57:08 -0700
Subject: [PATCH 03/31] Fixes for PR #640
---
main/handlers.js | 1 +
renderer/main.js | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/main/handlers.js b/main/handlers.js
index 5ea9431a..454871a2 100644
--- a/main/handlers.js
+++ b/main/handlers.js
@@ -36,6 +36,7 @@ function installDarwin () {
// On OS X, only protocols that are listed in `Info.plist` can be set as the
// default handler at runtime.
+ app.setAsDefaultProtocolClient('magnet')
app.setAsDefaultProtocolClient('stream-magnet')
// File handlers are defined in `Info.plist`.
diff --git a/renderer/main.js b/renderer/main.js
index aa357c2a..e34cb512 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -570,7 +570,7 @@ function onOpen (files) {
function isTorrent (file) {
var name = typeof file === 'string' ? file : file.name
var isTorrentFile = path.extname(name).toLowerCase() === '.torrent'
- var isMagnet = typeof file === 'string' && /^magnet:/.test(file) || /^stream-magnet:/.test(file)
+ var isMagnet = typeof file === 'string' && /^(stream-)?magnet:/.test(file)
return isTorrentFile || isMagnet
}
From 4bdc6e3d65cc676c806d1e08f7c8a60d94c69e58 Mon Sep 17 00:00:00 2001
From: Adam Gotlib
Date: Mon, 27 Jun 2016 09:28:19 +0200
Subject: [PATCH 04/31] Fix typo in renderer/views/player.js (#673)
---
renderer/views/player.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/renderer/views/player.js b/renderer/views/player.js
index 97f7f54a..b923679b 100644
--- a/renderer/views/player.js
+++ b/renderer/views/player.js
@@ -413,7 +413,7 @@ function renderPlayerControls (state) {
var buttonIcons = {
'chromecast': {true: 'cast_connected', false: 'cast'},
'airplay': {true: 'airplay', false: 'airplay'},
- 'dnla': {true: 'tv', false: 'tv'}
+ 'dlna': {true: 'tv', false: 'tv'}
}
castTypes.forEach(function (castType) {
// Do we show this button (eg. the Chromecast button) at all?
From 770327c3fa341cd9a1f40dad69098a3c879f2edf Mon Sep 17 00:00:00 2001
From: DC
Date: Mon, 27 Jun 2016 02:38:45 -0700
Subject: [PATCH 05/31] 0.8.1
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 9358f64f..e5797752 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "webtorrent-desktop",
"description": "WebTorrent, the streaming torrent client. For OS X, Windows, and Linux.",
- "version": "0.8.0",
+ "version": "0.8.1",
"author": {
"name": "WebTorrent, LLC",
"email": "feross@webtorrent.io",
From e5df96c82e042fc149db9fae12ea871704baa6b2 Mon Sep 17 00:00:00 2001
From: DC
Date: Mon, 27 Jun 2016 02:39:53 -0700
Subject: [PATCH 06/31] authors
---
AUTHORS.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/AUTHORS.md b/AUTHORS.md
index 53dbbb65..fe8d32e4 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -22,6 +22,8 @@
- Mathias Rasmussen
- Sergey Bargamon
- Thomas Watson Steen
+- anonymlol
- Gediminas Petrikas
+- Adam Gotlib
#### Generated by bin/update-authors.sh.
From 7a61b52d6455df87bbcd07333f79fa070c490b5a Mon Sep 17 00:00:00 2001
From: DC
Date: Mon, 27 Jun 2016 02:42:04 -0700
Subject: [PATCH 07/31] changelog
---
CHANGELOG.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 116244f1..7b323a86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
# WebTorrent Desktop Version History
+## v0.8.1 - 2016-06-24
+
+### Added
+
+- New URI handler: stream-magnet
+
+### Fixed
+
+- DLNA crashing bug
+
## v0.8.0 - 2016-06-23
### Added
From c44943cef7b40a89c3400160cd49da116ab09118 Mon Sep 17 00:00:00 2001
From: Adam Gotlib
Date: Tue, 28 Jun 2016 15:25:26 +0200
Subject: [PATCH 08/31] Fix state.playing.jumpToTime behavior (#672)
Previously, state.playing.jumpToTime = 0 didn't do anything.
This commit fixes that.
---
renderer/views/player.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/renderer/views/player.js b/renderer/views/player.js
index b923679b..d7f4767e 100644
--- a/renderer/views/player.js
+++ b/renderer/views/player.js
@@ -43,7 +43,7 @@ function renderMedia (state) {
mediaElement.play()
}
// When the user clicks or drags on the progress bar, jump to that position
- if (state.playing.jumpToTime) {
+ if (state.playing.jumpToTime != null) {
mediaElement.currentTime = state.playing.jumpToTime
state.playing.jumpToTime = null
}
From 349c5ee22e83c4c86b67944dfe3a4133ccb710f9 Mon Sep 17 00:00:00 2001
From: Feross Aboukhadijeh
Date: Tue, 28 Jun 2016 06:32:28 -0700
Subject: [PATCH 09/31] Clean up thumbar (thumbnail) code (#670)
* Cleanup thumbnail bar code
- rename thumbnail method names for succinctness
- Get rid of 'updateThumbnailBar' event -- use existing events
- Get rid of 'blockPowerSave' and 'unblockPowerSave' events -- use a
new combined 'onPlayerPlay' and 'onPlayerPause' events which apply to
power save and updating the thumbbar
* Consistent naming for enable/disable methods
---
main/ipc.js | 25 ++++++++++--------
main/menu.js | 5 ----
main/power-save-blocker.js | 14 +++++-----
main/shortcuts.js | 8 +++---
main/thumbar.js | 54 ++++++++++++++++++++++++++++++++++++++
main/thumbnail.js | 35 ------------------------
renderer/main.js | 8 ++----
7 files changed, 81 insertions(+), 68 deletions(-)
create mode 100644 main/thumbar.js
delete mode 100644 main/thumbnail.js
diff --git a/main/ipc.js b/main/ipc.js
index 68efb862..99b76a6a 100644
--- a/main/ipc.js
+++ b/main/ipc.js
@@ -15,7 +15,7 @@ var shell = require('./shell')
var shortcuts = require('./shortcuts')
var vlc = require('./vlc')
var windows = require('./windows')
-var thumbnail = require('./thumbnail')
+var thumbar = require('./thumbar')
// Messages from the main process, to be sent once the WebTorrent process starts
var messageQueueMainToWebTorrent = []
@@ -61,24 +61,27 @@ function init () {
ipc.on('onPlayerOpen', function () {
menu.onPlayerOpen()
- shortcuts.onPlayerOpen()
+ powerSaveBlocker.enable()
+ shortcuts.enable()
+ thumbar.enable()
})
ipc.on('onPlayerClose', function () {
menu.onPlayerClose()
- shortcuts.onPlayerOpen()
+ powerSaveBlocker.disable()
+ shortcuts.disable()
+ thumbar.disable()
})
- ipc.on('updateThumbnailBar', function (e, isPaused) {
- thumbnail.updateThumbarButtons(isPaused)
+ ipc.on('onPlayerPlay', function () {
+ powerSaveBlocker.enable()
+ thumbar.onPlayerPlay()
})
- /**
- * Power Save Blocker
- */
-
- ipc.on('blockPowerSave', () => powerSaveBlocker.start())
- ipc.on('unblockPowerSave', () => powerSaveBlocker.stop())
+ ipc.on('onPlayerPause', function () {
+ powerSaveBlocker.disable()
+ thumbar.onPlayerPause()
+ })
/**
* Shell
diff --git a/main/menu.js b/main/menu.js
index 61f17417..a79e0394 100644
--- a/main/menu.js
+++ b/main/menu.js
@@ -16,7 +16,6 @@ var config = require('../config')
var dialog = require('./dialog')
var shell = require('./shell')
var windows = require('./windows')
-var thumbnail = require('./thumbnail')
var menu
@@ -34,8 +33,6 @@ function onPlayerClose () {
getMenuItem('Increase Speed').enabled = false
getMenuItem('Decrease Speed').enabled = false
getMenuItem('Add Subtitles File...').enabled = false
-
- thumbnail.showPlayerThumbnailBar()
}
function onPlayerOpen () {
@@ -47,8 +44,6 @@ function onPlayerOpen () {
getMenuItem('Increase Speed').enabled = true
getMenuItem('Decrease Speed').enabled = true
getMenuItem('Add Subtitles File...').enabled = true
-
- thumbnail.hidePlayerThumbnailBar()
}
function onToggleAlwaysOnTop (flag) {
diff --git a/main/power-save-blocker.js b/main/power-save-blocker.js
index c7d76e42..97acd41e 100644
--- a/main/power-save-blocker.js
+++ b/main/power-save-blocker.js
@@ -1,6 +1,6 @@
module.exports = {
- start,
- stop
+ enable,
+ disable
}
var electron = require('electron')
@@ -12,19 +12,19 @@ var blockId = 0
* Block the system from entering low-power (sleep) mode or turning off the
* display.
*/
-function start () {
- stop() // Stop the previous power saver block, if one exists.
+function enable () {
+ disable() // Stop the previous power saver block, if one exists.
blockId = electron.powerSaveBlocker.start('prevent-display-sleep')
- log(`powerSaveBlocker.start: ${blockId}`)
+ log(`powerSaveBlocker.enable: ${blockId}`)
}
/**
* Stop blocking the system from entering low-power mode.
*/
-function stop () {
+function disable () {
if (!electron.powerSaveBlocker.isStarted(blockId)) {
return
}
electron.powerSaveBlocker.stop(blockId)
- log(`powerSaveBlocker.stop: ${blockId}`)
+ log(`powerSaveBlocker.disable: ${blockId}`)
}
diff --git a/main/shortcuts.js b/main/shortcuts.js
index 4254fd37..02bc2320 100644
--- a/main/shortcuts.js
+++ b/main/shortcuts.js
@@ -1,12 +1,12 @@
module.exports = {
- onPlayerClose,
- onPlayerOpen
+ disable,
+ enable
}
var electron = require('electron')
var windows = require('./windows')
-function onPlayerOpen () {
+function enable () {
// Register play/pause media key, available on some keyboards.
electron.globalShortcut.register(
'MediaPlayPause',
@@ -14,7 +14,7 @@ function onPlayerOpen () {
)
}
-function onPlayerClose () {
+function disable () {
// Return the media key to the OS, so other apps can use it.
electron.globalShortcut.unregister('MediaPlayPause')
}
diff --git a/main/thumbar.js b/main/thumbar.js
new file mode 100644
index 00000000..749aa1a3
--- /dev/null
+++ b/main/thumbar.js
@@ -0,0 +1,54 @@
+module.exports = {
+ disable,
+ enable,
+ onPlayerPause,
+ onPlayerPlay
+}
+
+/**
+ * On Windows, add a "thumbnail toolbar" with a play/pause button in the taskbar.
+ * This provides users a way to access play/pause functionality without restoring
+ * or activating the window.
+ */
+
+var path = require('path')
+var config = require('../config')
+
+var windows = require('./windows')
+
+/**
+ * Show the Windows thumbnail toolbar buttons.
+ */
+function enable () {
+ update(false)
+}
+
+/**
+ * Hide the Windows thumbnail toolbar buttons.
+ */
+function disable () {
+ windows.main.win.setThumbarButtons([])
+}
+
+function onPlayerPause () {
+ update(true)
+}
+
+function onPlayerPlay () {
+ update(false)
+}
+
+function update (isPaused) {
+ var icon = isPaused
+ ? 'PlayThumbnailBarButton.png'
+ : 'PauseThumbnailBarButton.png'
+
+ var buttons = [
+ {
+ tooltip: isPaused ? 'Play' : 'Pause',
+ icon: path.join(config.STATIC_PATH, icon),
+ click: () => windows.main.dispatch('playPause')
+ }
+ ]
+ windows.main.win.setThumbarButtons(buttons)
+}
diff --git a/main/thumbnail.js b/main/thumbnail.js
deleted file mode 100644
index d3336ed8..00000000
--- a/main/thumbnail.js
+++ /dev/null
@@ -1,35 +0,0 @@
-module.exports = {
- showPlayerThumbnailBar,
- hidePlayerThumbnailBar,
- updateThumbarButtons
-}
-
-var path = require('path')
-var config = require('../config')
-
-var windows = require('./windows')
-
-// gets called on player open
-function showPlayerThumbnailBar () {
- updateThumbarButtons(false)
-}
-
-// gets called on player close
-function hidePlayerThumbnailBar () {
- windows.main.win.setThumbarButtons([])
-}
-
-function updateThumbarButtons (isPaused) {
- var icon = isPaused ? 'PlayThumbnailBarButton.png' : 'PauseThumbnailBarButton.png'
- var tooltip = isPaused ? 'Play' : 'Pause'
- var buttons = [
- {
- tooltip: tooltip,
- icon: path.join(config.STATIC_PATH, icon),
- click: function () {
- windows.main.send('dispatch', 'playPause')
- }
- }
- ]
- windows.main.win.setThumbarButtons(buttons)
-}
diff --git a/renderer/main.js b/renderer/main.js
index e34cb512..51a6ad3e 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -358,7 +358,7 @@ function play () {
if (isCasting()) {
Cast.play()
}
- ipcRenderer.send('blockPowerSave')
+ ipcRenderer.send('onPlayerPlay')
}
function pause () {
@@ -367,7 +367,7 @@ function pause () {
if (isCasting()) {
Cast.pause()
}
- ipcRenderer.send('unblockPowerSave')
+ ipcRenderer.send('onPlayerPause')
}
function playPause () {
@@ -382,8 +382,6 @@ function playPause () {
// force rerendering if window is hidden,
// in order to bypass `raf` and play/pause media immediately
if (!state.window.isVisible) render(state)
-
- ipcRenderer.send('updateThumbnailBar', state.playing.isPaused)
}
function jumpToTime (time) {
@@ -1106,8 +1104,6 @@ function closePlayer (cb) {
// Tell the WebTorrent process to kill the torrent-to-HTTP server
ipcRenderer.send('wt-stop-server')
- // Tell the OS we're no longer playing media, laptops allowed to sleep again
- ipcRenderer.send('unblockPowerSave')
ipcRenderer.send('onPlayerClose')
update()
From 1aca9fe7537e8c79f9e9dbb38ae3f00997db1858 Mon Sep 17 00:00:00 2001
From: DC
Date: Mon, 4 Jul 2016 00:37:57 -0700
Subject: [PATCH 10/31] Only send telemetry from production (#668)
---
renderer/lib/telemetry.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/renderer/lib/telemetry.js b/renderer/lib/telemetry.js
index 35bc071f..5c4b6249 100644
--- a/renderer/lib/telemetry.js
+++ b/renderer/lib/telemetry.js
@@ -30,7 +30,13 @@ function init (state) {
telemetry.system = getSystemInfo()
telemetry.approxNumTorrents = getApproxNumTorrents(state)
- postToServer(telemetry)
+ if (config.IS_PRODUCTION) {
+ postToServer()
+ } else {
+ // Development: telemetry used only for local debugging
+ // Empty uncaught errors, etc at the start of every run
+ reset()
+ }
}
function reset () {
From c615e285dbd3baa36de129fc3a92a487f77bf1f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Jouannet?=
Date: Tue, 5 Jul 2016 22:54:59 +0000
Subject: [PATCH 11/31] add debian jessie dependencies (#601)
* add debian jessie dependencies
* update dep for deb package
* gconf2, libgtk2.0-0, libnss3, libxss1
---
bin/package.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bin/package.js b/bin/package.js
index b0597694..4708524b 100755
--- a/bin/package.js
+++ b/bin/package.js
@@ -466,7 +466,7 @@ function buildLinux (cb) {
info: {
arch: destArch === 'x64' ? 'amd64' : 'i386',
targetDir: DIST_PATH,
- depends: 'libc6 (>= 2.4)',
+ depends: 'gconf2, libgtk2.0-0, libnss3, libxss1',
scripts: {
postinst: path.join(config.STATIC_PATH, 'linux', 'postinst'),
prerm: path.join(config.STATIC_PATH, 'linux', 'prerm')
From 59b012e527eda68608393063eac8c55da773bcc3 Mon Sep 17 00:00:00 2001
From: DC
Date: Tue, 28 Jun 2016 07:23:41 -0700
Subject: [PATCH 12/31] Fix README
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1b51ddf9..878eaf45 100644
--- a/README.md
+++ b/README.md
@@ -83,7 +83,9 @@ brew install wine
### Privacy
-WebTorrent Desktop collects some basic usage stats to help us make the app better. For example, we track what OSs are users are on, and how well the play button works (how often does it succeed? time out? show a missing codec error?). The app never sends personally identifying or other private info.
+WebTorrent Desktop collects some basic usage stats to help us make the app better. For example, we track how well the play button works. How often does it succeed? Time out? Show a missing codec error?
+
+The app never sends personally identifying information, nor does it track which swarms you join.
### Code Style
From bac43509d26cd6bcd21fb8d37d8b3ba32b918906 Mon Sep 17 00:00:00 2001
From: DC
Date: Wed, 22 Jun 2016 23:24:40 -0700
Subject: [PATCH 13/31] Refactoring main.js: simplify startup
---
renderer/main.js | 53 +++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/renderer/main.js b/renderer/main.js
index 51a6ad3e..45930bc5 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -22,33 +22,28 @@ var sound = require('./lib/sound')
var State = require('./lib/state')
var TorrentPlayer = require('./lib/torrent-player')
var TorrentSummary = require('./lib/torrent-summary')
-var {setDispatch} = require('./lib/dispatcher')
+
+// Yo-yo pattern: state object lives here and percolates down thru all the views.
+// Events come back up from the views via dispatch(...)
+require('./lib/dispatcher').setDispatch(dispatch)
+
+// This dependency is the slowest-loading, so we lazy load it
+var Cast = null
// Electron apps have two processes: a main process (node) runs first and starts
// a renderer process (essentially a Chrome window). We're in the renderer process,
// and this IPC channel receives from and sends messages to the main process
var ipcRenderer = electron.ipcRenderer
+// All state lives in state.js. `state.saved` is read from and written to a file.
+// All other state is ephemeral. First we load state.saved then initialize the app.
var state, vdomLoop
-// This dependency is the slowest-loading, so we lazy load it
-var Cast = null
+State.load(onState)
-init()
-
-function init () {
- // All state lives in state.js. `state.saved` is read from and written to a file.
- // All other state is ephemeral. First we load state.saved then initialize the app.
- State.load(onState)
-
- setDispatch(dispatch)
-}
-
-/**
- * Called once when the application loads. (Not once per window.)
- * Connects to the torrent networks, sets up the UI and OS integrations like
- * the dock icon and drag+drop.
- */
+// Called once when the application loads. (Not once per window.)
+// Connects to the torrent networks, sets up the UI and OS integrations like
+// the dock icon and drag+drop.
function onState (err, _state) {
if (err) return onError(err)
state = _state
@@ -104,6 +99,7 @@ function onState (err, _state) {
console.timeEnd('init')
}
+// Runs a few seconds after the app loads, to avoid slowing down startup time
function delayedInit () {
lazyLoadCast()
sound.preload()
@@ -136,6 +132,8 @@ function update () {
updateElectron()
}
+// Some state changes can't be reflected in the DOM, instead we have to
+// tell the main process to update the window or OS integrations
function updateElectron () {
if (state.window.title !== state.prev.title) {
state.prev.title = state.window.title
@@ -213,13 +211,7 @@ function dispatch (action, ...args) {
backToList()
}
if (action === 'escapeBack') {
- if (state.modal) {
- dispatch('exitModal')
- } else if (state.window.isFullScreen) {
- dispatch('toggleFullScreen')
- } else {
- dispatch('back')
- }
+ escapeBack()
}
if (action === 'back') {
state.location.back()
@@ -455,6 +447,17 @@ function backToList () {
})
}
+// Quits modals, full screen, or goes back. Happens when the user hits ESC
+function escapeBack() {
+ if (state.modal) {
+ dispatch('exitModal')
+ } else if (state.window.isFullScreen) {
+ dispatch('toggleFullScreen')
+ } else {
+ dispatch('back')
+ }
+}
+
// Checks whether we are connected and already casting
// Returns false if we not casting (state.playing.location === 'local')
// or if we're trying to connect but haven't yet ('chromecast-pending', etc)
From c3a27dbebe1e769eeecd34384182d13738f1daea Mon Sep 17 00:00:00 2001
From: DC
Date: Thu, 23 Jun 2016 02:43:30 -0700
Subject: [PATCH 14/31] Refactor main.js: media and update controllers
---
renderer/controllers/media-controller.js | 56 ++++++++
renderer/controllers/update-controller.js | 26 ++++
renderer/lib/state.js | 13 +-
renderer/main.js | 148 ++++++++++------------
4 files changed, 158 insertions(+), 85 deletions(-)
create mode 100644 renderer/controllers/media-controller.js
create mode 100644 renderer/controllers/update-controller.js
diff --git a/renderer/controllers/media-controller.js b/renderer/controllers/media-controller.js
new file mode 100644
index 00000000..785b168b
--- /dev/null
+++ b/renderer/controllers/media-controller.js
@@ -0,0 +1,56 @@
+const electron = require('electron')
+
+const ipcRenderer = electron.ipcRenderer
+
+// Controls local play back: the
-
+
${info.showAdvanced ? 'Basic' : 'Advanced'}
@@ -87,7 +88,7 @@ function CreateTorrentPage (state) {
-
+
@@ -114,17 +115,6 @@ function CreateTorrentPage (state) {
}
dispatch('createTorrent', options)
}
-
- function handleCancel () {
- dispatch('back')
- }
-
- function handleToggleShowAdvanced () {
- // TODO: what's the clean way to handle this?
- // Should every button on every screen have its own dispatch()?
- info.showAdvanced = !info.showAdvanced
- dispatch('update')
- }
}
function CreateTorrentErrorPage () {
From c15711aae83ff2d6c58ceb455442ca6785bb646c Mon Sep 17 00:00:00 2001
From: Mathias Rasmussen
Date: Sat, 9 Jul 2016 03:26:30 +0200
Subject: [PATCH 23/31] Save selected subtitle (#702)
---
renderer/controllers/playback-controller.js | 5 +++++
renderer/controllers/subtitles-controller.js | 15 +++++++++------
renderer/main.js | 1 +
renderer/views/player.js | 9 +++++++++
4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/renderer/controllers/playback-controller.js b/renderer/controllers/playback-controller.js
index de6c49fe..126fb5df 100644
--- a/renderer/controllers/playback-controller.js
+++ b/renderer/controllers/playback-controller.js
@@ -224,6 +224,11 @@ function openPlayerFromActiveTorrent (state, torrentSummary, index, timeout, cb)
// if it's video, check for subtitles files that are done downloading
dispatch('checkForSubtitles')
+ // enable previously selected subtitle track
+ if (fileSummary.selectedSubtitle) {
+ dispatch('addSubtitles', [fileSummary.selectedSubtitle], true)
+ }
+
ipcRenderer.send('wt-start-server', torrentSummary.infoHash, index)
ipcRenderer.once('wt-server-' + torrentSummary.infoHash, (e, info) => {
clearTimeout(timeout)
diff --git a/renderer/controllers/subtitles-controller.js b/renderer/controllers/subtitles-controller.js
index d95d7e98..e1cb1425 100644
--- a/renderer/controllers/subtitles-controller.js
+++ b/renderer/controllers/subtitles-controller.js
@@ -31,10 +31,11 @@ module.exports = class SubtitlesController {
}
addSubtitles (files, autoSelect) {
+ var state = this.state
// Subtitles are only supported when playing video files
- if (this.state.playing.type !== 'video') return
+ if (state.playing.type !== 'video') return
if (files.length === 0) return
- var subtitles = this.state.playing.subtitles
+ var subtitles = state.playing.subtitles
// Read the files concurrently, then add all resulting subtitle tracks
var tasks = files.map((file) => (cb) => loadSubtitle(file, cb))
@@ -44,15 +45,17 @@ module.exports = class SubtitlesController {
for (var i = 0; i < tracks.length; i++) {
// No dupes allowed
var track = tracks[i]
- if (subtitles.tracks.some(
- (t) => track.filePath === t.filePath)) continue
+ var trackIndex = state.playing.subtitles.tracks
+ .findIndex((t) => track.filePath === t.filePath)
// Add the track
- subtitles.tracks.push(track)
+ if (trackIndex === -1) {
+ trackIndex = state.playing.subtitles.tracks.push(track) - 1
+ }
// If we're auto-selecting a track, try to find one in the user's language
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
- subtitles.selectedIndex = subtitles.tracks.length - 1
+ state.playing.subtitles.selectedIndex = trackIndex
}
}
diff --git a/renderer/main.js b/renderer/main.js
index b94c9875..2c29eaa6 100644
--- a/renderer/main.js
+++ b/renderer/main.js
@@ -199,6 +199,7 @@ const dispatchHandlers = {
'selectSubtitle': (index) => controllers.subtitles.selectSubtitle(index),
'toggleSubtitlesMenu': () => controllers.subtitles.toggleSubtitlesMenu(),
'checkForSubtitles': () => controllers.subtitles.checkForSubtitles(),
+ 'addSubtitles': (files, autoSelect) => controllers.subtitles.addSubtitles(files, autoSelect),
// Local media: