Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bf7618dde | ||
|
|
d02f6c7d18 | ||
|
|
e69a18e548 | ||
|
|
991e2d2024 | ||
|
|
9f31f30925 | ||
|
|
340658c747 | ||
|
|
5bbd9cfabb | ||
|
|
03a8b40ee9 | ||
|
|
d0cc157003 | ||
|
|
01971e2a46 | ||
|
|
08cb82e255 | ||
|
|
cae40b44e6 | ||
|
|
ab0bbcea94 | ||
|
|
a81156b363 | ||
|
|
4b501ab90b | ||
|
|
90347c72e0 | ||
|
|
a51ab3573e | ||
|
|
b02d6f3cdb | ||
|
|
6e67cae494 | ||
|
|
23eef1a058 | ||
|
|
2ad3f6d6e2 | ||
|
|
996a81ddaa | ||
|
|
4a8ab6e1f6 | ||
|
|
7f817241ed | ||
|
|
a6c53d06d2 | ||
|
|
a70c4d1bf2 |
@@ -37,5 +37,10 @@
|
|||||||
- Alexey Romanov (romanalexey@gmail.com)
|
- Alexey Romanov (romanalexey@gmail.com)
|
||||||
- Karan Thakkar (karanjthakkar@gmail.com)
|
- Karan Thakkar (karanjthakkar@gmail.com)
|
||||||
- Nuno Campos (nuno.campos@me.com)
|
- Nuno Campos (nuno.campos@me.com)
|
||||||
|
- Ebrahim Byagowi (ebrahim@gnu.org)
|
||||||
|
- Emil Bay (github@tixz.dk)
|
||||||
|
- Auyer (rafa_auyer@icloud.com)
|
||||||
|
- SimplyAhmazing (ahmad19526@gmail.com)
|
||||||
|
- Cezar Carneiro (cezargcarneiro@gmail.com)
|
||||||
|
|
||||||
#### Generated by bin/update-authors.sh.
|
#### Generated by bin/update-authors.sh.
|
||||||
|
|||||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,6 +1,25 @@
|
|||||||
# WebTorrent Desktop Version History
|
# WebTorrent Desktop Version History
|
||||||
|
|
||||||
## v0.18.0
|
## v0.19.0 - 2018-01-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Added watch folder feature: Automatically add new torrent files added to a folder on disk (#1154)
|
||||||
|
- Added highest playback priority feature: pauses other active torrents when playback starts (#840)
|
||||||
|
- Add 'Start Speaking' and 'Stop Speaking' menu item (Mac) (#439)
|
||||||
|
- Add pinch-to-zoom gesture to enter/exit fullscreen (#1148)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- [SECURITY] Mitigate
|
||||||
|
- Moved project from Feross's GitHub account to the WebTorrent GitHub organization
|
||||||
|
- Updated to electron@1.6.16
|
||||||
|
- Updated to material-ui@0.17
|
||||||
|
- Treat .FLAC as playable audio (#1127)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix time and duration so it doesn't bounce in the UI (#1233)
|
||||||
|
- Fix 'About WebTorrent' menu location on Windows (#1120)
|
||||||
|
|
||||||
|
## v0.18.0 - 2017-02-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Add a new "Transfers" menu for pausing or resuming all torrents (#1027)
|
- Add a new "Transfers" menu for pausing or resuming all torrents (#1027)
|
||||||
@@ -67,7 +86,7 @@
|
|||||||
## v0.16.0 - 2016-09-18
|
## v0.16.0 - 2016-09-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- **Windows 64-bit support!** ([#931](https://github.com/webtorrent/webtorrent-desktop/pull/931))
|
- **Windows 64-bit support!** (#931)
|
||||||
- Existing 32-bit users will update to 64-bit automatically in next release
|
- Existing 32-bit users will update to 64-bit automatically in next release
|
||||||
- 64-bit reduces likelihood of out-of-memory errors by increasing the address space
|
- 64-bit reduces likelihood of out-of-memory errors by increasing the address space
|
||||||
|
|
||||||
|
|||||||
43
SECURITY.md
Normal file
43
SECURITY.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Security Policies and Procedures
|
||||||
|
|
||||||
|
This document outlines security procedures and general policies for the WebTorrent
|
||||||
|
project.
|
||||||
|
|
||||||
|
* [Reporting a Bug](#reporting-a-bug)
|
||||||
|
* [Disclosure Policy](#disclosure-policy)
|
||||||
|
* [Comments on this Policy](#comments-on-this-policy)
|
||||||
|
|
||||||
|
## Reporting a Bug
|
||||||
|
|
||||||
|
The WebTorrent team and community take all security bugs in WebTorrent seriously.
|
||||||
|
Thank you for improving the security of WebTorrent. We appreciate your efforts and
|
||||||
|
responsible disclosure and will make every effort to acknowledge your
|
||||||
|
contributions.
|
||||||
|
|
||||||
|
Report security bugs by emailing the lead maintainer at feross@feross.org.
|
||||||
|
|
||||||
|
The lead maintainer will acknowledge your email within 48 hours, and will send a
|
||||||
|
more detailed response within 48 hours indicating the next steps in handling
|
||||||
|
your report. After the initial reply to your report, the security team will
|
||||||
|
endeavor to keep you informed of the progress towards a fix and full
|
||||||
|
announcement, and may ask for additional information or guidance.
|
||||||
|
|
||||||
|
Report security bugs in third-party modules to the person or team maintaining
|
||||||
|
the module. You can also report a vulnerability through the
|
||||||
|
[Node Security Project](https://nodesecurity.io/report).
|
||||||
|
|
||||||
|
## Disclosure Policy
|
||||||
|
|
||||||
|
When the security team receives a security bug report, they will assign it to a
|
||||||
|
primary handler. This person will coordinate the fix and release process,
|
||||||
|
involving the following steps:
|
||||||
|
|
||||||
|
* Confirm the problem and determine the affected versions.
|
||||||
|
* Audit code to find any potential similar problems.
|
||||||
|
* Prepare fixes for all releases still under maintenance. These fixes will be
|
||||||
|
released as fast as possible to npm.
|
||||||
|
|
||||||
|
## Comments on this Policy
|
||||||
|
|
||||||
|
If you have suggestions on how this process could be improved please submit a
|
||||||
|
pull request.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "webtorrent-desktop",
|
"name": "webtorrent-desktop",
|
||||||
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
||||||
"version": "0.18.0",
|
"version": "0.19.0",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "WebTorrent, LLC",
|
"name": "WebTorrent, LLC",
|
||||||
"email": "feross@webtorrent.io",
|
"email": "feross@webtorrent.io",
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
"auto-launch": "^4.0.1",
|
"auto-launch": "^4.0.1",
|
||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
"capture-frame": "^1.0.0",
|
"capture-frame": "^1.0.0",
|
||||||
|
"chokidar": "^1.6.1",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
"cp-file": "^4.0.1",
|
"cp-file": "^4.0.1",
|
||||||
"create-torrent": "^3.24.5",
|
"create-torrent": "^3.24.5",
|
||||||
@@ -26,16 +27,13 @@
|
|||||||
"drag-drop": "^2.12.1",
|
"drag-drop": "^2.12.1",
|
||||||
"es6-error": "^4.0.0",
|
"es6-error": "^4.0.0",
|
||||||
"fn-getter": "^1.0.0",
|
"fn-getter": "^1.0.0",
|
||||||
"gaze": "^1.1.2",
|
|
||||||
"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",
|
"location-history": "^1.0.0",
|
||||||
"material-ui": "^0.17.0",
|
"material-ui": "^0.17.0",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"ms": "^0.7.2",
|
|
||||||
"musicmetadata": "^2.0.2",
|
"musicmetadata": "^2.0.2",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
"node-notifier": "^5.0.2",
|
|
||||||
"parse-torrent": "^5.7.3",
|
"parse-torrent": "^5.7.3",
|
||||||
"prettier-bytes": "^1.0.1",
|
"prettier-bytes": "^1.0.1",
|
||||||
"react": "^15.4.2",
|
"react": "^15.4.2",
|
||||||
@@ -44,7 +42,6 @@
|
|||||||
"rimraf": "^2.5.2",
|
"rimraf": "^2.5.2",
|
||||||
"run-parallel": "^1.1.6",
|
"run-parallel": "^1.1.6",
|
||||||
"semver": "^5.1.0",
|
"semver": "^5.1.0",
|
||||||
"shell-env": "^0.3.0",
|
|
||||||
"simple-concat": "^1.0.0",
|
"simple-concat": "^1.0.0",
|
||||||
"simple-get": "^2.0.0",
|
"simple-get": "^2.0.0",
|
||||||
"srt-to-vtt": "^1.1.1",
|
"srt-to-vtt": "^1.1.1",
|
||||||
@@ -57,7 +54,7 @@
|
|||||||
"buble": "^0.15.2",
|
"buble": "^0.15.2",
|
||||||
"cross-zip": "^2.0.1",
|
"cross-zip": "^2.0.1",
|
||||||
"depcheck": "^0.6.4",
|
"depcheck": "^0.6.4",
|
||||||
"electron": "1.6.0",
|
"electron": "1.6.16",
|
||||||
"electron-osx-sign": "0.4.3",
|
"electron-osx-sign": "0.4.3",
|
||||||
"electron-packager": "~8.5.1",
|
"electron-packager": "~8.5.1",
|
||||||
"electron-winstaller": "~2.5.2",
|
"electron-winstaller": "~2.5.2",
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
const appConfig = require('application-config')('WebTorrent')
|
const appConfig = require('application-config')('WebTorrent')
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const arch = require('arch')
|
const arch = require('arch')
|
||||||
const gaze = require('gaze')
|
|
||||||
|
|
||||||
const APP_NAME = 'WebTorrent'
|
const APP_NAME = 'WebTorrent'
|
||||||
const APP_TEAM = 'WebTorrent, LLC'
|
const APP_TEAM = 'WebTorrent, LLC'
|
||||||
@@ -19,13 +17,13 @@ const IS_PORTABLE = isPortable()
|
|||||||
const UI_HEADER_HEIGHT = 38
|
const UI_HEADER_HEIGHT = 38
|
||||||
const UI_TORRENT_HEIGHT = 100
|
const UI_TORRENT_HEIGHT = 100
|
||||||
|
|
||||||
const exports = module.exports = {
|
module.exports = {
|
||||||
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
||||||
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
||||||
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
||||||
TELEMETRY_URL: 'https://webtorrent.io/desktop/telemetry',
|
TELEMETRY_URL: 'https://webtorrent.io/desktop/telemetry',
|
||||||
|
|
||||||
APP_COPYRIGHT: 'Copyright © 2014-2017 ' + APP_TEAM,
|
APP_COPYRIGHT: 'Copyright © 2014-2018 ' + APP_TEAM,
|
||||||
APP_FILE_ICON: path.join(__dirname, '..', 'static', 'WebTorrentFile'),
|
APP_FILE_ICON: path.join(__dirname, '..', 'static', 'WebTorrentFile'),
|
||||||
APP_ICON: path.join(__dirname, '..', 'static', 'WebTorrent'),
|
APP_ICON: path.join(__dirname, '..', 'static', 'WebTorrent'),
|
||||||
APP_NAME: APP_NAME,
|
APP_NAME: APP_NAME,
|
||||||
@@ -104,62 +102,6 @@ const exports = module.exports = {
|
|||||||
UI_TORRENT_HEIGHT: UI_TORRENT_HEIGHT
|
UI_TORRENT_HEIGHT: UI_TORRENT_HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
const configFile = appConfig.filePath
|
|
||||||
let config = getConfig()
|
|
||||||
const watchers = []
|
|
||||||
|
|
||||||
function updateConfig () {
|
|
||||||
config = JSON.parse(fs.readFileSync(configFile))
|
|
||||||
}
|
|
||||||
|
|
||||||
function watch () {
|
|
||||||
gaze(configFile, function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
this.on('changed', () => {
|
|
||||||
try {
|
|
||||||
updateConfig()
|
|
||||||
console.log('WebTorrent configuration reloaded!')
|
|
||||||
watchers.forEach(fn => fn())
|
|
||||||
} catch (err) {
|
|
||||||
// TODO: display notification
|
|
||||||
console.log(`An error occurred loading your configuration (${configFile}): ${err.message}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
this.on('error', () => {
|
|
||||||
// Ignore file watching errors
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// start watching for config changes
|
|
||||||
watch()
|
|
||||||
|
|
||||||
exports.subscribe = function (fn) {
|
|
||||||
watchers.push(fn)
|
|
||||||
return () => {
|
|
||||||
watchers.splice(watchers.indexOf(fn), 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPlugins () {
|
|
||||||
return config.plugins || {}
|
|
||||||
}
|
|
||||||
exports.getPlugins = getPlugins
|
|
||||||
|
|
||||||
exports.getConfigPath = getConfigPath
|
|
||||||
exports.getConfig = getConfig
|
|
||||||
|
|
||||||
function getConfig () {
|
|
||||||
const config = {}
|
|
||||||
try {
|
|
||||||
return require(configFile)
|
|
||||||
} catch (e) {
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getConfigPath () {
|
function getConfigPath () {
|
||||||
if (IS_PORTABLE) {
|
if (IS_PORTABLE) {
|
||||||
return PORTABLE_PATH
|
return PORTABLE_PATH
|
||||||
@@ -203,6 +145,8 @@ function isPortable () {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// This line throws if the "Portable Settings" folder does not exist, and does
|
// This line throws if the "Portable Settings" folder does not exist, and does
|
||||||
// nothing otherwise.
|
// nothing otherwise.
|
||||||
|
|||||||
50
src/main/folder-watcher.js
Normal file
50
src/main/folder-watcher.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const chokidar = require('chokidar')
|
||||||
|
const log = require('./log')
|
||||||
|
|
||||||
|
class FolderWatcher {
|
||||||
|
constructor ({window, state}) {
|
||||||
|
this.window = window
|
||||||
|
this.state = state
|
||||||
|
this.torrentsFolderPath = null
|
||||||
|
this.watching = false
|
||||||
|
}
|
||||||
|
|
||||||
|
isEnabled () {
|
||||||
|
return this.state.saved.prefs.autoAddTorrents
|
||||||
|
}
|
||||||
|
|
||||||
|
start () {
|
||||||
|
// Stop watching previous folder before
|
||||||
|
// start watching a new one.
|
||||||
|
if (this.watching) this.stop()
|
||||||
|
|
||||||
|
const torrentsFolderPath = this.state.saved.prefs.torrentsFolderPath
|
||||||
|
this.torrentsFolderPath = torrentsFolderPath
|
||||||
|
if (!torrentsFolderPath) return
|
||||||
|
|
||||||
|
const glob = `${torrentsFolderPath}/**/*.torrent`
|
||||||
|
log('Folder Watcher: watching: ', glob)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
ignoreInitial: true,
|
||||||
|
awaitWriteFinish: true
|
||||||
|
}
|
||||||
|
this.watcher = chokidar.watch(glob, options)
|
||||||
|
this.watcher
|
||||||
|
.on('add', (path) => {
|
||||||
|
log('Folder Watcher: added torrent: ', path)
|
||||||
|
this.window.dispatch('addTorrent', path)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.watching = true
|
||||||
|
}
|
||||||
|
|
||||||
|
stop () {
|
||||||
|
log('Folder Watcher: stop.')
|
||||||
|
if (!this.watching) return
|
||||||
|
this.watcher.close()
|
||||||
|
this.watching = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FolderWatcher
|
||||||
@@ -44,7 +44,7 @@ function installDarwin () {
|
|||||||
|
|
||||||
function uninstallDarwin () {}
|
function uninstallDarwin () {}
|
||||||
|
|
||||||
const EXEC_COMMAND = [ process.execPath ]
|
const EXEC_COMMAND = [ process.execPath, '--' ]
|
||||||
|
|
||||||
if (!config.IS_PRODUCTION) {
|
if (!config.IS_PRODUCTION) {
|
||||||
EXEC_COMMAND.push(config.ROOT_PATH)
|
EXEC_COMMAND.push(config.ROOT_PATH)
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ const log = require('./log')
|
|||||||
const menu = require('./menu')
|
const menu = require('./menu')
|
||||||
const State = require('../renderer/lib/state')
|
const State = require('../renderer/lib/state')
|
||||||
const windows = require('./windows')
|
const windows = require('./windows')
|
||||||
const Plugins = require('./plugins')
|
|
||||||
const plugins = new Plugins()
|
|
||||||
|
|
||||||
let shouldQuit = false
|
let shouldQuit = false
|
||||||
let argv = sliceArgv(process.argv)
|
let argv = sliceArgv(process.argv)
|
||||||
@@ -76,18 +74,14 @@ function init () {
|
|||||||
isReady = true
|
isReady = true
|
||||||
const state = results.state
|
const state = results.state
|
||||||
|
|
||||||
// init new plugins then notify user
|
windows.main.init(state, {hidden: hidden})
|
||||||
plugins.subscribe(() => {
|
windows.webtorrent.init()
|
||||||
// update menu and windows
|
menu.init()
|
||||||
// passing thru new plugin decorators
|
|
||||||
initApp(state)
|
|
||||||
})
|
|
||||||
|
|
||||||
plugins.init(state)
|
|
||||||
initApp(state)
|
|
||||||
|
|
||||||
// To keep app startup fast, some code is delayed.
|
// To keep app startup fast, some code is delayed.
|
||||||
setTimeout(delayedInit, config.DELAYED_INIT)
|
setTimeout(() => {
|
||||||
|
delayedInit(state)
|
||||||
|
}, config.DELAYED_INIT)
|
||||||
|
|
||||||
// Report uncaught exceptions
|
// Report uncaught exceptions
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
@@ -97,26 +91,6 @@ function init () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function initApp (state) {
|
|
||||||
// decorate app
|
|
||||||
plugins.onApp(app)
|
|
||||||
|
|
||||||
// init decorate menu
|
|
||||||
menu.init((tpl) => plugins.decorateMenu(tpl))
|
|
||||||
|
|
||||||
// init and decorate window
|
|
||||||
windows.main.init(
|
|
||||||
state,
|
|
||||||
{hidden: hidden},
|
|
||||||
(options) => plugins.decorateWindow(options)
|
|
||||||
)
|
|
||||||
windows.webtorrent.init((options) => plugins.decorateWindow(options))
|
|
||||||
plugins.onWindow([
|
|
||||||
windows.main.win,
|
|
||||||
windows.webtorrent.win
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
app.on('open-file', onOpen)
|
app.on('open-file', onOpen)
|
||||||
app.on('open-url', onOpen)
|
app.on('open-url', onOpen)
|
||||||
|
|
||||||
@@ -150,17 +124,24 @@ function init () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function delayedInit () {
|
function delayedInit (state) {
|
||||||
if (app.isQuitting) return
|
if (app.isQuitting) return
|
||||||
|
|
||||||
const announcement = require('./announcement')
|
const announcement = require('./announcement')
|
||||||
const dock = require('./dock')
|
const dock = require('./dock')
|
||||||
const updater = require('./updater')
|
const updater = require('./updater')
|
||||||
|
const FolderWatcher = require('./folder-watcher')
|
||||||
|
const folderWatcher = new FolderWatcher({window: windows.main, state})
|
||||||
|
|
||||||
announcement.init()
|
announcement.init()
|
||||||
dock.init()
|
dock.init()
|
||||||
updater.init()
|
updater.init()
|
||||||
|
|
||||||
|
ipc.setModule('folderWatcher', folderWatcher)
|
||||||
|
if (folderWatcher.isEnabled()) {
|
||||||
|
folderWatcher.start()
|
||||||
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
const userTasks = require('./user-tasks')
|
const userTasks = require('./user-tasks')
|
||||||
userTasks.init()
|
userTasks.init()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
init
|
init,
|
||||||
|
setModule
|
||||||
}
|
}
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
@@ -13,6 +14,14 @@ const windows = require('./windows')
|
|||||||
// Messages from the main process, to be sent once the WebTorrent process starts
|
// Messages from the main process, to be sent once the WebTorrent process starts
|
||||||
const messageQueueMainToWebTorrent = []
|
const messageQueueMainToWebTorrent = []
|
||||||
|
|
||||||
|
// Will hold modules injected from the app that will be used on fired
|
||||||
|
// IPC events.
|
||||||
|
const modules = {}
|
||||||
|
|
||||||
|
function setModule (name, module) {
|
||||||
|
modules[name] = module
|
||||||
|
}
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
const ipc = electron.ipcMain
|
const ipc = electron.ipcMain
|
||||||
|
|
||||||
@@ -58,7 +67,7 @@ function init () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events
|
* Player Events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipc.on('onPlayerOpen', function () {
|
ipc.on('onPlayerOpen', function () {
|
||||||
@@ -106,6 +115,28 @@ function init () {
|
|||||||
thumbar.onPlayerPause()
|
thumbar.onPlayerPause()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder Watcher Events
|
||||||
|
*/
|
||||||
|
|
||||||
|
ipc.on('startFolderWatcher', function () {
|
||||||
|
if (!modules['folderWatcher']) {
|
||||||
|
log('IPC ERR: folderWatcher module is not defined.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
modules['folderWatcher'].start()
|
||||||
|
})
|
||||||
|
|
||||||
|
ipc.on('stopFolderWatcher', function () {
|
||||||
|
if (!modules['folderWatcher']) {
|
||||||
|
log('IPC ERR: folderWatcher module is not defined.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
modules['folderWatcher'].stop()
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shell
|
* Shell
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,11 +17,8 @@ const windows = require('./windows')
|
|||||||
|
|
||||||
let menu = null
|
let menu = null
|
||||||
|
|
||||||
function init (decorate) {
|
function init () {
|
||||||
let template = getMenuTemplate()
|
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
|
||||||
if (decorate) template = decorate(template)
|
|
||||||
|
|
||||||
menu = electron.Menu.buildFromTemplate(template)
|
|
||||||
electron.Menu.setApplicationMenu(menu)
|
electron.Menu.setApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,424 +0,0 @@
|
|||||||
const {exec} = require('child_process')
|
|
||||||
const {resolve, basename} = require('path')
|
|
||||||
const {writeFileSync} = require('fs')
|
|
||||||
const State = require('../renderer/lib/state')
|
|
||||||
const notifier = require('node-notifier')
|
|
||||||
const {app} = require('electron')
|
|
||||||
|
|
||||||
const {sync: mkdirpSync} = require('mkdirp')
|
|
||||||
const ms = require('ms')
|
|
||||||
const shellEnv = require('shell-env')
|
|
||||||
const crypto = require('crypto')
|
|
||||||
|
|
||||||
const config = require('../config')
|
|
||||||
|
|
||||||
module.exports = class Plugins {
|
|
||||||
constructor () {
|
|
||||||
// modules path
|
|
||||||
this.path = resolve(config.getConfigPath(), 'plugins')
|
|
||||||
log('Path: ', this.path)
|
|
||||||
this.availableExtensions = new Set([
|
|
||||||
'onApp', 'onWindow', 'decorateMenu', 'decorateWindow', 'decorateConfig'
|
|
||||||
])
|
|
||||||
|
|
||||||
this.forceUpdate = false
|
|
||||||
this.updating = false
|
|
||||||
this.watchers = []
|
|
||||||
}
|
|
||||||
|
|
||||||
init (state) {
|
|
||||||
this.state = state
|
|
||||||
|
|
||||||
// initialize state
|
|
||||||
this.state.saved = Object.assign(this.state.saved || {})
|
|
||||||
|
|
||||||
// init plugin directories if not present
|
|
||||||
mkdirpSync(this.path)
|
|
||||||
|
|
||||||
// caches
|
|
||||||
this.plugins = config.getPlugins()
|
|
||||||
this.paths = this.getPaths(this.plugins)
|
|
||||||
this.id = this.getId(this.plugins)
|
|
||||||
this.modules = this.requirePlugins()
|
|
||||||
|
|
||||||
// we listen on configuration updates to trigger
|
|
||||||
// plugin installation
|
|
||||||
config.subscribe(() => {
|
|
||||||
const plugins = config.getPlugins()
|
|
||||||
if (plugins !== this.plugins) {
|
|
||||||
const id = this.getId(plugins)
|
|
||||||
if (this.id !== id) {
|
|
||||||
this.alert('Installing plugins...')
|
|
||||||
log('UPDATING...')
|
|
||||||
this.id = id
|
|
||||||
this.plugins = plugins
|
|
||||||
this.paths = this.getPaths(this.plugins)
|
|
||||||
this.updatePlugins()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// schedule the initial plugins update
|
|
||||||
// a bit after the user launches the app
|
|
||||||
// to prevent slowness
|
|
||||||
if (this.needsUpdate()) {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.updatePlugins()
|
|
||||||
}, 5000)
|
|
||||||
log('Installation scheduled')
|
|
||||||
}
|
|
||||||
|
|
||||||
// update plugins every 5 hours
|
|
||||||
setInterval(() => {
|
|
||||||
this.updatePlugins()
|
|
||||||
}, ms('5h'))
|
|
||||||
}
|
|
||||||
|
|
||||||
on (action, params) {
|
|
||||||
log(`ON ${action}:`, params)
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
const actionName = this.capitalizeFirstLetter(action)
|
|
||||||
const methodName = `on${actionName}`
|
|
||||||
if (typeof plugin[methodName] === 'function') {
|
|
||||||
plugin[methodName](params)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
capitalizeFirstLetter (string) {
|
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
didPluginsChange () {
|
|
||||||
return this.state.saved.installedPlugins !== this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
hasPlugins () {
|
|
||||||
return !this.isEmptyObject(this.plugins)
|
|
||||||
}
|
|
||||||
|
|
||||||
isFirstInstall () {
|
|
||||||
return (!this.state.saved.installedPlugins && this.hasPlugins())
|
|
||||||
}
|
|
||||||
|
|
||||||
needsUpdate () {
|
|
||||||
return (this.didPluginsChange() || this.isFirstInstall())
|
|
||||||
}
|
|
||||||
|
|
||||||
getId (plugins) {
|
|
||||||
const hash = crypto.createHash('sha256')
|
|
||||||
hash.update(JSON.stringify(plugins))
|
|
||||||
return hash.digest('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePlugins (forceUpdate = false) {
|
|
||||||
this.forceUpdate = forceUpdate
|
|
||||||
if (this.updating) {
|
|
||||||
// TODO
|
|
||||||
// return notify('Plugin update in progress')
|
|
||||||
}
|
|
||||||
this.updating = true
|
|
||||||
this.syncPackageJSON()
|
|
||||||
this.installPackages((err) => this.loadPlugins(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins (err, localOnly = false) {
|
|
||||||
this.updating = false
|
|
||||||
|
|
||||||
// handle errors first
|
|
||||||
if (err) {
|
|
||||||
console.error(err.stack)
|
|
||||||
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
|
||||||
this.alert(
|
|
||||||
'Error updating plugins: We could not find the "npm" command. Make sure it\'s in $PATH'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.alert(`Error updating plugins: Check '${this.path}/npm-debug.log' for more information.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// update state with latest plugins
|
|
||||||
this.state.saved.plugins = this.plugins
|
|
||||||
|
|
||||||
// cache modules
|
|
||||||
this.modules = this.requirePlugins()
|
|
||||||
|
|
||||||
// clear require cache
|
|
||||||
this.clearCache()
|
|
||||||
|
|
||||||
// we're done with local plugins
|
|
||||||
if (localOnly) return
|
|
||||||
|
|
||||||
// OK, no errors
|
|
||||||
// flag successful plugin update
|
|
||||||
this.state.saved.installedPlugins = this.id
|
|
||||||
|
|
||||||
// check if package based plugins were updated
|
|
||||||
const loaded = this.modules.length
|
|
||||||
const total = this.paths.plugins.length
|
|
||||||
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
|
||||||
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
|
||||||
this.state.saved.installedPluginVersions = pluginVersions
|
|
||||||
|
|
||||||
// notify watchers
|
|
||||||
if (this.forceUpdate || changed) {
|
|
||||||
this.watchers.forEach(fn => fn(err, {forceUpdate: this.forceUpdate}))
|
|
||||||
this.alert('Installation completed')
|
|
||||||
log('Installation completed')
|
|
||||||
}
|
|
||||||
|
|
||||||
// save state
|
|
||||||
State.save(this.state)
|
|
||||||
}
|
|
||||||
|
|
||||||
getPluginVersions () {
|
|
||||||
const paths_ = this.paths.plugins
|
|
||||||
return paths_.map(path => {
|
|
||||||
let version = null
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line import/no-dynamic-require
|
|
||||||
version = require(resolve(path, 'package.json')).version
|
|
||||||
} catch (err) { }
|
|
||||||
return [
|
|
||||||
basename(path),
|
|
||||||
version
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
clearCache () {
|
|
||||||
// trigger unload hooks
|
|
||||||
this.modules.forEach(mod => {
|
|
||||||
if (mod.onUnload) {
|
|
||||||
mod.onUnload(app)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// clear require cache
|
|
||||||
for (const entry in require.cache) {
|
|
||||||
if (entry.indexOf(this.path) === 0) {
|
|
||||||
delete require.cache[entry]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isEmptyObject (obj) {
|
|
||||||
return (Object.keys(obj).length === 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
syncPackageJSON () {
|
|
||||||
const dependencies = this.toDependencies(this.plugins)
|
|
||||||
const pkg = {
|
|
||||||
name: 'webtorrent-plugins',
|
|
||||||
description: 'Auto-generated from WebTorrent config.',
|
|
||||||
private: true,
|
|
||||||
version: '0.0.1',
|
|
||||||
repository: 'feross/webtorrent-desktop',
|
|
||||||
license: 'MIT',
|
|
||||||
homepage: 'https://webtorrent.io',
|
|
||||||
dependencies
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = resolve(this.path, 'package.json')
|
|
||||||
try {
|
|
||||||
writeFileSync(file, JSON.stringify(pkg, null, 2))
|
|
||||||
return true
|
|
||||||
} catch (err) {
|
|
||||||
this.alert(`An error occurred writing to ${file}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
alert (message) {
|
|
||||||
notifier.notify({
|
|
||||||
title: 'WebTorrent Plugins',
|
|
||||||
// icon: config.icon, // TODO: save icon in webtorrent local folder and set config.icon
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
isLocalPath (string) {
|
|
||||||
// matches unix and windows local paths
|
|
||||||
return string.match(/^(\/|[a-z]:\/)/i)
|
|
||||||
}
|
|
||||||
|
|
||||||
toDependencies (plugins) {
|
|
||||||
const obj = {}
|
|
||||||
const pluginNames = Object.keys(plugins)
|
|
||||||
|
|
||||||
pluginNames.forEach(name => {
|
|
||||||
let url = plugins[name]
|
|
||||||
if (this.isLocalPath(url)) return
|
|
||||||
obj[name] = url
|
|
||||||
})
|
|
||||||
return obj
|
|
||||||
}
|
|
||||||
|
|
||||||
installPackages (fn) {
|
|
||||||
const {shell = '', npmRegistry} = config
|
|
||||||
|
|
||||||
shellEnv(shell).then(env => {
|
|
||||||
if (npmRegistry) {
|
|
||||||
env.NPM_CONFIG_REGISTRY = npmRegistry
|
|
||||||
}
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
env.npm_config_runtime = 'electron'
|
|
||||||
env.npm_config_target = process.versions.electron
|
|
||||||
env.npm_config_disturl = 'https://atom.io/download/atom-shell'
|
|
||||||
/* eslint-enable camelcase */
|
|
||||||
// Shell-specific installation commands
|
|
||||||
const installCommands = {
|
|
||||||
fish: 'npm prune; and npm install --production',
|
|
||||||
posix: 'npm prune && npm install --production'
|
|
||||||
}
|
|
||||||
// determine the shell we're running in
|
|
||||||
const whichShell = shell.match(/fish/) ? 'fish' : 'posix'
|
|
||||||
|
|
||||||
// Use the install command that is appropriate for our shell
|
|
||||||
exec(installCommands[whichShell], {
|
|
||||||
cwd: this.path
|
|
||||||
}, err => {
|
|
||||||
if (err) return fn(err)
|
|
||||||
fn(null)
|
|
||||||
})
|
|
||||||
}).catch(fn)
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribe (fn) {
|
|
||||||
this.watchers.push(fn)
|
|
||||||
return () => {
|
|
||||||
this.watchers.splice(this.watchers.indexOf(fn), 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getPaths (plugins) {
|
|
||||||
const pluginNames = Object.keys(plugins)
|
|
||||||
|
|
||||||
return {
|
|
||||||
plugins: pluginNames.map(name => {
|
|
||||||
let url = plugins[name]
|
|
||||||
|
|
||||||
// plugin is already on a local folder
|
|
||||||
// directly load it from its current location
|
|
||||||
if (this.isLocalPath(url)) return url
|
|
||||||
|
|
||||||
// plugin will be installed with npm install from a remote url
|
|
||||||
return resolve(this.path, 'node_modules', name.split('#')[0])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requirePlugins () {
|
|
||||||
const {plugins} = this.paths
|
|
||||||
let installNeeded = false
|
|
||||||
|
|
||||||
const load = (path) => {
|
|
||||||
if (!path.match(/\/$/)) {
|
|
||||||
path += '/'
|
|
||||||
}
|
|
||||||
|
|
||||||
const mainPath = `${path}main.js`
|
|
||||||
|
|
||||||
try {
|
|
||||||
const Plugin = require(mainPath) // eslint-disable import/no-dynamic-require
|
|
||||||
const plugin = new Plugin()
|
|
||||||
|
|
||||||
const exposed = plugin && Object.keys(plugin).some(key => this.availableExtensions.has(key))
|
|
||||||
if (!exposed) return
|
|
||||||
|
|
||||||
// populate the name for internal errors here
|
|
||||||
plugin._name = basename(mainPath)
|
|
||||||
|
|
||||||
return plugin
|
|
||||||
} catch (err) {
|
|
||||||
log('Require plugins ERROR:', err)
|
|
||||||
this.alert(`Error loading plugin: ${mainPath}`)
|
|
||||||
// plugin not installed
|
|
||||||
// node_modules removed? did a manual plugin uninstall?
|
|
||||||
// try installing and then loading if successfull
|
|
||||||
installNeeded = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plugin installation happens on the MAIN process.
|
|
||||||
// If plugins haven't finished installing, wait for them.
|
|
||||||
if (installNeeded) {
|
|
||||||
log('Plugins install needed, wait...')
|
|
||||||
setTimeout(() => {
|
|
||||||
this.requirePlugins()
|
|
||||||
}, 3000)
|
|
||||||
}
|
|
||||||
return plugins.map(load).filter(v => Boolean(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
onApp (app) {
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
if (plugin.onApp) {
|
|
||||||
plugin.onApp(app)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
onWindow (win) {
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
if (plugin.onWindow) {
|
|
||||||
plugin.onWindow(win)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// decorates the base object by calling plugin[key]
|
|
||||||
// for all the available plugins
|
|
||||||
decorateObject (base, key) {
|
|
||||||
let decorated = base
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
if (plugin[key]) {
|
|
||||||
const res = plugin[key](decorated)
|
|
||||||
if (res && typeof res === 'object') {
|
|
||||||
decorated = res
|
|
||||||
} else {
|
|
||||||
this.alert(`Plugin error: "${plugin._name}": invalid return type for \`${key}\``)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return decorated
|
|
||||||
}
|
|
||||||
|
|
||||||
decorateMenu (tpl) {
|
|
||||||
return this.decorateObject(tpl, 'decorateMenu')
|
|
||||||
}
|
|
||||||
|
|
||||||
decorateWindow (options) {
|
|
||||||
return this.decorateObject(options, 'decorateWindow')
|
|
||||||
}
|
|
||||||
|
|
||||||
getDecoratedEnv (baseEnv) {
|
|
||||||
return this.decorateObject(baseEnv, 'decorateEnv')
|
|
||||||
}
|
|
||||||
|
|
||||||
getDecoratedConfig () {
|
|
||||||
const baseConfig = config.getConfig()
|
|
||||||
return this.decorateObject(baseConfig, 'decorateConfig')
|
|
||||||
}
|
|
||||||
|
|
||||||
getDecoratedBrowserOptions (defaults) {
|
|
||||||
return this.decorateObject(defaults, 'decorateBrowserOptions')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs passed arguments to console using a prefix.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function log () {
|
|
||||||
const prefix = '[ PLUGINS.Main ]-->'
|
|
||||||
const args = [prefix]
|
|
||||||
|
|
||||||
for (var i = 0; i < arguments.length; ++i) {
|
|
||||||
args.push(arguments[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log.apply(console, args)
|
|
||||||
}
|
|
||||||
@@ -23,14 +23,14 @@ const config = require('../../config')
|
|||||||
const log = require('../log')
|
const log = require('../log')
|
||||||
const menu = require('../menu')
|
const menu = require('../menu')
|
||||||
|
|
||||||
function init (state, options, decorate) {
|
function init (state, options) {
|
||||||
if (main.win) {
|
if (main.win) {
|
||||||
return main.win.show()
|
return main.win.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
|
const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
|
||||||
|
|
||||||
let windowOptions = {
|
const win = main.win = new electron.BrowserWindow({
|
||||||
backgroundColor: '#282828',
|
backgroundColor: '#282828',
|
||||||
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
||||||
darkTheme: true, // Forces dark theme (GTK+3)
|
darkTheme: true, // Forces dark theme (GTK+3)
|
||||||
@@ -45,10 +45,7 @@ function init (state, options, decorate) {
|
|||||||
width: initialBounds.width,
|
width: initialBounds.width,
|
||||||
x: initialBounds.x,
|
x: initialBounds.x,
|
||||||
y: initialBounds.y
|
y: initialBounds.y
|
||||||
}
|
})
|
||||||
if (decorate) windowOptions = decorate(windowOptions)
|
|
||||||
|
|
||||||
const win = main.win = new electron.BrowserWindow(windowOptions)
|
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_MAIN)
|
win.loadURL(config.WINDOW_MAIN)
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ const electron = require('electron')
|
|||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
|
|
||||||
function init (decorate) {
|
function init () {
|
||||||
let options = {
|
const win = webtorrent.win = new electron.BrowserWindow({
|
||||||
backgroundColor: '#1E1E1E',
|
backgroundColor: '#1E1E1E',
|
||||||
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
||||||
center: true,
|
center: true,
|
||||||
@@ -26,9 +26,7 @@ function init (decorate) {
|
|||||||
title: 'webtorrent-hidden-window',
|
title: 'webtorrent-hidden-window',
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
width: 150
|
width: 150
|
||||||
}
|
})
|
||||||
if (decorate) options = decorate(options)
|
|
||||||
const win = webtorrent.win = new electron.BrowserWindow(options)
|
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_WEBTORRENT)
|
win.loadURL(config.WINDOW_WEBTORRENT)
|
||||||
|
|
||||||
|
|||||||
13
src/renderer/controllers/folder-watcher-controller.js
Normal file
13
src/renderer/controllers/folder-watcher-controller.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
|
||||||
|
module.exports = class FolderWatcherController {
|
||||||
|
start () {
|
||||||
|
console.log('-- IPC: start folder watcher')
|
||||||
|
ipcRenderer.send('startFolderWatcher')
|
||||||
|
}
|
||||||
|
|
||||||
|
stop () {
|
||||||
|
console.log('-- IPC: stop folder watcher')
|
||||||
|
ipcRenderer.send('stopFolderWatcher')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -121,7 +121,9 @@ function setupStateSaved (cb) {
|
|||||||
isFileHandler: false,
|
isFileHandler: false,
|
||||||
openExternalPlayer: false,
|
openExternalPlayer: false,
|
||||||
externalPlayerPath: null,
|
externalPlayerPath: null,
|
||||||
startup: false
|
startup: false,
|
||||||
|
autoAddTorrents: false,
|
||||||
|
torrentsFolderPath: ''
|
||||||
},
|
},
|
||||||
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
||||||
torrentsToResume: [],
|
torrentsToResume: [],
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ const telemetry = require('./lib/telemetry')
|
|||||||
const sound = require('./lib/sound')
|
const sound = require('./lib/sound')
|
||||||
const TorrentPlayer = require('./lib/torrent-player')
|
const TorrentPlayer = require('./lib/torrent-player')
|
||||||
|
|
||||||
const Plugins = require('./plugins')
|
|
||||||
const plugins = new Plugins()
|
|
||||||
|
|
||||||
// Perf optimization: Needed immediately, so do not lazy load it below
|
// Perf optimization: Needed immediately, so do not lazy load it below
|
||||||
const TorrentListController = require('./controllers/torrent-list-controller')
|
const TorrentListController = require('./controllers/torrent-list-controller')
|
||||||
|
|
||||||
@@ -114,11 +111,13 @@ function onState (err, _state) {
|
|||||||
update: createGetter(() => {
|
update: createGetter(() => {
|
||||||
const UpdateController = require('./controllers/update-controller')
|
const UpdateController = require('./controllers/update-controller')
|
||||||
return new UpdateController(state)
|
return new UpdateController(state)
|
||||||
|
}),
|
||||||
|
folderWatcher: createGetter(() => {
|
||||||
|
const FolderWatcherController = require('./controllers/folder-watcher-controller')
|
||||||
|
return new FolderWatcherController()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.init({dispatch, state})
|
|
||||||
|
|
||||||
// Add first page to location history
|
// Add first page to location history
|
||||||
state.location.go({
|
state.location.go({
|
||||||
url: 'home',
|
url: 'home',
|
||||||
@@ -301,6 +300,8 @@ const dispatchHandlers = {
|
|||||||
'preferences': () => controllers.prefs().show(),
|
'preferences': () => controllers.prefs().show(),
|
||||||
'updatePreferences': (key, value) => controllers.prefs().update(key, value),
|
'updatePreferences': (key, value) => controllers.prefs().update(key, value),
|
||||||
'checkDownloadPath': checkDownloadPath,
|
'checkDownloadPath': checkDownloadPath,
|
||||||
|
'startFolderWatcher': () => controllers.folderWatcher().start(),
|
||||||
|
'stopFolderWatcher': () => controllers.folderWatcher().stop(),
|
||||||
|
|
||||||
// Update (check for new versions on Linux, where there's no auto updater)
|
// Update (check for new versions on Linux, where there's no auto updater)
|
||||||
'updateAvailable': (version) => controllers.update().updateAvailable(version),
|
'updateAvailable': (version) => controllers.update().updateAvailable(version),
|
||||||
@@ -337,7 +338,6 @@ function dispatch (action, ...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handler = dispatchHandlers[action]
|
const handler = dispatchHandlers[action]
|
||||||
plugins.on(action, args)
|
|
||||||
if (handler) handler(...args)
|
if (handler) handler(...args)
|
||||||
else console.error('Missing dispatch handler: ' + action)
|
else console.error('Missing dispatch handler: ' + action)
|
||||||
|
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ function renderMedia (state) {
|
|||||||
} else {
|
} else {
|
||||||
// When the last video completes, pause the video instead of looping
|
// When the last video completes, pause the video instead of looping
|
||||||
state.playing.isPaused = true
|
state.playing.isPaused = true
|
||||||
|
if (state.window.isFullScreen) dispatch('toggleFullScreen')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +304,7 @@ function renderCastScreen (state) {
|
|||||||
isCast = false
|
isCast = false
|
||||||
} else if (state.playing.location === 'error') {
|
} else if (state.playing.location === 'error') {
|
||||||
castIcon = 'error_outline'
|
castIcon = 'error_outline'
|
||||||
castType = 'Error'
|
castType = 'Unable to Play'
|
||||||
isCast = false
|
isCast = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,8 +524,8 @@ function renderPlayerControls (state) {
|
|||||||
))
|
))
|
||||||
|
|
||||||
// Show video playback progress
|
// Show video playback progress
|
||||||
const currentTimeStr = formatTime(state.playing.currentTime)
|
const currentTimeStr = formatTime(state.playing.currentTime, state.playing.duration)
|
||||||
const durationStr = formatTime(state.playing.duration)
|
const durationStr = formatTime(state.playing.duration, state.playing.duration)
|
||||||
elements.push((
|
elements.push((
|
||||||
<span key='time' className='time float-left'>
|
<span key='time' className='time float-left'>
|
||||||
{currentTimeStr} / {durationStr}
|
{currentTimeStr} / {durationStr}
|
||||||
@@ -646,17 +647,19 @@ function cssBackgroundImageDarkGradient () {
|
|||||||
'rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 100%)'
|
'rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 100%)'
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatTime (time) {
|
function formatTime (time, total) {
|
||||||
if (typeof time !== 'number' || Number.isNaN(time)) {
|
if (typeof time !== 'number' || Number.isNaN(time)) {
|
||||||
return '0:00'
|
return '0:00'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let totalHours = Math.floor(total / 3600)
|
||||||
|
let totalMinutes = Math.floor(total % 3600 / 60)
|
||||||
let hours = Math.floor(time / 3600)
|
let hours = Math.floor(time / 3600)
|
||||||
let minutes = Math.floor(time % 3600 / 60)
|
let minutes = Math.floor(time % 3600 / 60)
|
||||||
if (hours > 0) {
|
if (totalMinutes > 9) {
|
||||||
minutes = zeroFill(2, minutes)
|
minutes = zeroFill(2, minutes)
|
||||||
}
|
}
|
||||||
let seconds = zeroFill(2, Math.floor(time % 60))
|
let seconds = zeroFill(2, Math.floor(time % 60))
|
||||||
|
|
||||||
return (hours > 0 ? hours + ':' : '') + minutes + ':' + seconds
|
return (totalHours > 0 ? hours + ':' : '') + minutes + ':' + seconds
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,59 @@ class PreferencesPage extends React.Component {
|
|||||||
dispatch('updatePreferences', 'externalPlayerPath', filePath)
|
dispatch('updatePreferences', 'externalPlayerPath', filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoAddTorrentsCheckbox () {
|
||||||
|
return (
|
||||||
|
<Preference>
|
||||||
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.unsaved.prefs.autoAddTorrents}
|
||||||
|
label={'Watch for new .torrent files and add them immediately'}
|
||||||
|
onCheck={(e, value) => { this.handleAutoAddTorrentsChange(e, value) }}
|
||||||
|
/>
|
||||||
|
</Preference>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAutoAddTorrentsChange (e, isChecked) {
|
||||||
|
const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath
|
||||||
|
if (isChecked && !torrentsFolderPath) {
|
||||||
|
alert('Select a torrents folder first.') // eslint-disable-line
|
||||||
|
e.preventDefault()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch('updatePreferences', 'autoAddTorrents', isChecked)
|
||||||
|
|
||||||
|
if (isChecked) {
|
||||||
|
dispatch('startFolderWatcher', null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch('stopFolderWatcher', null)
|
||||||
|
}
|
||||||
|
|
||||||
|
torrentsFolderPathSelector () {
|
||||||
|
const torrentsFolderPath = this.props.state.unsaved.prefs.torrentsFolderPath
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Preference>
|
||||||
|
<PathSelector
|
||||||
|
dialog={{
|
||||||
|
title: 'Select folder to watch for new torrents',
|
||||||
|
properties: [ 'openDirectory' ]
|
||||||
|
}}
|
||||||
|
displayValue={torrentsFolderPath || ''}
|
||||||
|
onChange={this.handletorrentsFolderPathChange}
|
||||||
|
title='Folder to watch'
|
||||||
|
value={torrentsFolderPath ? path.dirname(torrentsFolderPath) : null} />
|
||||||
|
</Preference>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
handletorrentsFolderPathChange (filePath) {
|
||||||
|
dispatch('updatePreferences', 'torrentsFolderPath', filePath)
|
||||||
|
}
|
||||||
|
|
||||||
setDefaultAppButton () {
|
setDefaultAppButton () {
|
||||||
const isFileHandler = this.props.state.unsaved.prefs.isFileHandler
|
const isFileHandler = this.props.state.unsaved.prefs.isFileHandler
|
||||||
if (isFileHandler) {
|
if (isFileHandler) {
|
||||||
@@ -163,8 +216,10 @@ class PreferencesPage extends React.Component {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<PreferencesSection title='Downloads'>
|
<PreferencesSection title='Folders'>
|
||||||
{this.downloadPathSelector()}
|
{this.downloadPathSelector()}
|
||||||
|
{this.autoAddTorrentsCheckbox()}
|
||||||
|
{this.torrentsFolderPathSelector()}
|
||||||
</PreferencesSection>
|
</PreferencesSection>
|
||||||
<PreferencesSection title='Playback'>
|
<PreferencesSection title='Playback'>
|
||||||
{this.openExternalPlayerCheckbox()}
|
{this.openExternalPlayerCheckbox()}
|
||||||
|
|||||||
@@ -1,287 +0,0 @@
|
|||||||
const {resolve, basename} = require('path')
|
|
||||||
const notifier = require('node-notifier')
|
|
||||||
const crypto = require('crypto')
|
|
||||||
|
|
||||||
const config = require('../config')
|
|
||||||
|
|
||||||
module.exports = class Plugins {
|
|
||||||
constructor () {
|
|
||||||
// modules path
|
|
||||||
this.path = resolve(config.getConfigPath(), 'plugins')
|
|
||||||
log('Path: ', this.path)
|
|
||||||
this.availableExtensions = [
|
|
||||||
'onCheckForSubtitles'
|
|
||||||
]
|
|
||||||
|
|
||||||
this.forceUpdate = false
|
|
||||||
this.updating = false
|
|
||||||
this.watchers = []
|
|
||||||
this.state = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
init (params) {
|
|
||||||
this.state = params.state
|
|
||||||
|
|
||||||
// initialize state
|
|
||||||
this.state.saved = Object.assign(this.state.saved || {})
|
|
||||||
|
|
||||||
// caches
|
|
||||||
this.plugins = config.getPlugins()
|
|
||||||
this.paths = this.getPaths(this.plugins)
|
|
||||||
this.id = this.getId(this.plugins)
|
|
||||||
this.modules = this.requirePlugins()
|
|
||||||
|
|
||||||
// TODO: fire an event when plugins finish updating and listen to that.
|
|
||||||
// Listen to plugin changes on config.
|
|
||||||
// New plugins added, plugins removed or updated.
|
|
||||||
// The actual plugin update action will take place in the MAIN process.
|
|
||||||
config.subscribe(() => {
|
|
||||||
const plugins = config.getPlugins()
|
|
||||||
if (plugins !== this.plugins) {
|
|
||||||
const id = this.getId(plugins)
|
|
||||||
if (this.id !== id) {
|
|
||||||
log('UPDATING...')
|
|
||||||
this.id = id
|
|
||||||
this.plugins = plugins
|
|
||||||
this.paths = this.getPaths(this.plugins)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Plugins will be updated on the MAIN process after 5s.
|
|
||||||
if (this.needsUpdate()) {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.init(params)
|
|
||||||
}, 6000)
|
|
||||||
log('Plugins need update, init scheduled')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loadPlugins()
|
|
||||||
this.initPlugins(params)
|
|
||||||
}
|
|
||||||
|
|
||||||
initPlugins (params) {
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
if (plugin.init) {
|
|
||||||
plugin.init(params)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
on (action, params) {
|
|
||||||
log(`ON ${action}:`, params)
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
const actionName = this.capitalizeFirstLetter(action)
|
|
||||||
const methodName = `on${actionName}`
|
|
||||||
if (typeof plugin[methodName] === 'function') {
|
|
||||||
plugin[methodName](params)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
capitalizeFirstLetter (string) {
|
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
didPluginsChange () {
|
|
||||||
return this.state.saved.installedPlugins !== this.id
|
|
||||||
}
|
|
||||||
|
|
||||||
hasPlugins () {
|
|
||||||
return !this.isEmptyObject(this.plugins)
|
|
||||||
}
|
|
||||||
|
|
||||||
isFirstInstall () {
|
|
||||||
return (!this.state.saved.installedPlugins && this.hasPlugins())
|
|
||||||
}
|
|
||||||
|
|
||||||
needsUpdate () {
|
|
||||||
return (this.didPluginsChange() || this.isFirstInstall())
|
|
||||||
}
|
|
||||||
|
|
||||||
getId (plugins) {
|
|
||||||
const hash = crypto.createHash('sha256')
|
|
||||||
hash.update(JSON.stringify(plugins))
|
|
||||||
return hash.digest('hex')
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins (err, localOnly = false) {
|
|
||||||
this.updating = false
|
|
||||||
|
|
||||||
// handle errors first
|
|
||||||
if (err) {
|
|
||||||
console.error(err.stack)
|
|
||||||
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
|
||||||
this.alert(
|
|
||||||
'Error updating plugins: We could not find the "npm" command. Make sure it\'s in $PATH'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.alert(`Error updating plugins: Check '${this.path}/npm-debug.log' for more information.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// update state with latest plugins
|
|
||||||
this.state.saved.plugins = this.plugins
|
|
||||||
|
|
||||||
// cache modules
|
|
||||||
this.modules = this.requirePlugins()
|
|
||||||
|
|
||||||
// clear require cache
|
|
||||||
this.clearCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
getPluginVersions () {
|
|
||||||
const paths_ = this.paths.plugins
|
|
||||||
return paths_.map(path => {
|
|
||||||
let version = null
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line import/no-dynamic-require
|
|
||||||
version = require(resolve(path, 'package.json')).version
|
|
||||||
} catch (err) { }
|
|
||||||
return [
|
|
||||||
basename(path),
|
|
||||||
version
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
clearCache () {
|
|
||||||
// clear require cache
|
|
||||||
for (const entry in require.cache) {
|
|
||||||
if (entry.indexOf(this.path) === 0) {
|
|
||||||
delete require.cache[entry]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isEmptyObject (obj) {
|
|
||||||
return (Object.keys(obj).length === 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
alert (message) {
|
|
||||||
notifier.notify({
|
|
||||||
title: 'WebTorrent Plugins',
|
|
||||||
// icon: config.icon, // TODO: save icon in webtorrent local folder and set config.icon
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribe (fn) {
|
|
||||||
this.watchers.push(fn)
|
|
||||||
return () => {
|
|
||||||
this.watchers.splice(this.watchers.indexOf(fn), 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isLocalPath (string) {
|
|
||||||
// matches unix and windows local paths
|
|
||||||
return string.match(/^(\/|[a-z]:\/)/i)
|
|
||||||
}
|
|
||||||
|
|
||||||
getPaths (plugins) {
|
|
||||||
const pluginNames = Object.keys(plugins)
|
|
||||||
|
|
||||||
return {
|
|
||||||
plugins: pluginNames.map(name => {
|
|
||||||
let url = plugins[name]
|
|
||||||
|
|
||||||
// plugin is already on a local folder
|
|
||||||
// directly load it from its current location
|
|
||||||
if (this.isLocalPath(url)) return url
|
|
||||||
|
|
||||||
// plugin will be installed with npm install from a remote url
|
|
||||||
return resolve(this.path, 'node_modules', name.split('#')[0])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exposesSupportedApi (plugin) {
|
|
||||||
if (!plugin) return false
|
|
||||||
|
|
||||||
return this.availableExtensions.some((methodName) => {
|
|
||||||
return (typeof plugin[methodName] === 'function')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
requirePlugins () {
|
|
||||||
const {plugins} = this.paths
|
|
||||||
let installNeeded = false
|
|
||||||
|
|
||||||
const load = (path) => {
|
|
||||||
if (!path.match(/\/$/)) {
|
|
||||||
path += '/'
|
|
||||||
}
|
|
||||||
|
|
||||||
const rendererPath = `${path}renderer.js`
|
|
||||||
|
|
||||||
try {
|
|
||||||
const Plugin = require(rendererPath) // eslint-disable import/no-dynamic-require
|
|
||||||
const plugin = new Plugin()
|
|
||||||
|
|
||||||
const exposed = this.exposesSupportedApi(plugin)
|
|
||||||
if (!exposed) {
|
|
||||||
log('Plugin not exposing any available extensions.', rendererPath, Object.keys(plugin))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// populate the name for internal errors here
|
|
||||||
plugin._name = basename(rendererPath)
|
|
||||||
|
|
||||||
return plugin
|
|
||||||
} catch (err) {
|
|
||||||
log('Require plugins ERROR:', err)
|
|
||||||
this.alert(`Error loading plugin: ${rendererPath}`)
|
|
||||||
// plugin not installed
|
|
||||||
// node_modules removed? did a manual plugin uninstall?
|
|
||||||
// try installing and then loading if successfull
|
|
||||||
installNeeded = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plugin installation happens on the MAIN process.
|
|
||||||
// If plugins haven't finished installing, wait for them.
|
|
||||||
if (installNeeded) {
|
|
||||||
log('Plugins install needed, wait...')
|
|
||||||
setTimeout(() => {
|
|
||||||
this.requirePlugins()
|
|
||||||
}, 3000)
|
|
||||||
}
|
|
||||||
return plugins.map(load).filter(v => Boolean(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// decorates the base object by calling plugin[key]
|
|
||||||
// for all the available plugins
|
|
||||||
decorateObject (base, key) {
|
|
||||||
let decorated = base
|
|
||||||
this.modules.forEach(plugin => {
|
|
||||||
if (plugin[key]) {
|
|
||||||
const res = plugin[key](decorated)
|
|
||||||
if (res && typeof res === 'object') {
|
|
||||||
decorated = res
|
|
||||||
} else {
|
|
||||||
this.alert(`Plugin error: "${plugin._name}": invalid return type for \`${key}\``)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return decorated
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs passed arguments to console using a prefix.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function log () {
|
|
||||||
const prefix = '[ PLUGINS.Renderer ]-->'
|
|
||||||
const args = [prefix]
|
|
||||||
|
|
||||||
for (var i = 0; i < arguments.length; ++i) {
|
|
||||||
args.push(arguments[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log.apply(console, args)
|
|
||||||
}
|
|
||||||
@@ -615,6 +615,7 @@ body.drag .app::after {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
margin: 9px 8px 8px 8px;
|
margin: 9px 8px 8px 8px;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
|
|
||||||
.player .controls .icon.closed-caption {
|
.player .controls .icon.closed-caption {
|
||||||
|
|||||||
Reference in New Issue
Block a user