Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9749b43cfa | ||
|
|
a22f94df80 | ||
|
|
a60e817e0c | ||
|
|
f1865dda4f | ||
|
|
8cdc6b1307 | ||
|
|
660facf8c2 | ||
|
|
fee5b42813 | ||
|
|
ddb8500082 | ||
|
|
cc6af9829e | ||
|
|
cfba6b503a | ||
|
|
04c766bb53 | ||
|
|
2389a1aa35 | ||
|
|
430b4c409a | ||
|
|
810952f234 | ||
|
|
ae4a8e40f8 | ||
|
|
ea100dda36 | ||
|
|
46cbce00ca | ||
|
|
00ebbc7e17 | ||
|
|
8109ce5410 | ||
|
|
9200070269 | ||
|
|
16ab96e4ac | ||
|
|
d8632f6386 | ||
|
|
5558bad0de | ||
|
|
0f5b7fd80e | ||
|
|
6a288efb57 | ||
|
|
f07a307b0d | ||
|
|
cb1de722fe | ||
|
|
45036451c7 | ||
|
|
58a4f7a34a | ||
|
|
9082c6f63e | ||
|
|
9fb8a2ae09 | ||
|
|
0e501b498e | ||
|
|
85e0c5709e | ||
|
|
cee88a7e24 | ||
|
|
f503a46447 | ||
|
|
1cdd54e421 | ||
|
|
73be2513ad | ||
|
|
e9eb22a530 | ||
|
|
d17f287ba2 | ||
|
|
06b904b837 | ||
|
|
807c6aebdd | ||
|
|
ab54a7cfb3 | ||
|
|
77d4eed9fc | ||
|
|
9c73638d1b | ||
|
|
3dd7ebb34b | ||
|
|
c943f39f6b | ||
|
|
401698e616 | ||
|
|
c85b3e4fd1 | ||
|
|
be15ee073d | ||
|
|
d838e6276d | ||
|
|
35af086fad | ||
|
|
cf9fbf2b0e | ||
|
|
ef2225c8a5 | ||
|
|
ffacb6085d | ||
|
|
20a84359cd | ||
|
|
a3d123537f | ||
|
|
30fb222fb9 | ||
|
|
4c2a08dd52 | ||
|
|
406c568c1e | ||
|
|
a86424b7df | ||
|
|
f6ffc16964 | ||
|
|
05e8a0d284 | ||
|
|
1dc38afc85 | ||
|
|
ca73b3c286 | ||
|
|
bad30e8f1a | ||
|
|
56036e89af | ||
|
|
bb7a9bb018 | ||
|
|
f9ba0750d6 | ||
|
|
d98299268f | ||
|
|
601d01fe85 | ||
|
|
b24cc29523 | ||
|
|
dd06ac7cc5 | ||
|
|
4097c5ee18 | ||
|
|
240128943c | ||
|
|
6d8a2a0b9e | ||
|
|
6433da4901 | ||
|
|
96b27fa1cb | ||
|
|
9134620fe7 | ||
|
|
1ff1c035b7 | ||
|
|
58e165eb30 | ||
|
|
4fdafc91c1 | ||
|
|
7ef740ebe0 | ||
|
|
138ece60fd | ||
|
|
a2d0cc09eb | ||
|
|
a701d44d25 | ||
|
|
4a67d1c679 | ||
|
|
450ecedad4 | ||
|
|
55ea243862 | ||
|
|
319a27399e | ||
|
|
f532d15222 | ||
|
|
3b4a2da2be | ||
|
|
c464074c92 | ||
|
|
4945ba9073 | ||
|
|
a4b7cfea3f | ||
|
|
d0ed20f10b | ||
|
|
8964d9f349 | ||
|
|
e1525a64fc | ||
|
|
3a0415578a | ||
|
|
3dc023828d | ||
|
|
3d01225b6d | ||
|
|
0feb97275c | ||
|
|
036ac72e3c | ||
|
|
f097a1ed52 | ||
|
|
16485f29c8 | ||
|
|
0b2cb410bd | ||
|
|
330b4adb0e | ||
|
|
32818c60a4 | ||
|
|
a55d7e897d | ||
|
|
bd34106a31 | ||
|
|
85fb83fb67 | ||
|
|
0cfce0ff26 | ||
|
|
65147eb53a | ||
|
|
5b6d29efcb | ||
|
|
c5c53646eb | ||
|
|
0927cedfa0 | ||
|
|
22962e9b7c | ||
|
|
13932b0567 | ||
|
|
ed38a55711 | ||
|
|
e55d9b6d15 | ||
|
|
e15ae42c32 | ||
|
|
a71808445e | ||
|
|
b742b10553 | ||
|
|
e8e9314486 | ||
|
|
0b16be24c1 | ||
|
|
a90df37123 | ||
|
|
fc7608fa87 | ||
|
|
82a61e9da4 | ||
|
|
2d0c1d597f | ||
|
|
4a9566665e | ||
|
|
fad7a21287 | ||
|
|
7893da9426 | ||
|
|
f0ddc79fcc | ||
|
|
f92afd3f10 | ||
|
|
9ce6c3b461 | ||
|
|
b404b44aa1 | ||
|
|
8c38377e38 | ||
|
|
eda83e858d | ||
|
|
a6639aadcf |
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -12,8 +12,8 @@ jobs:
|
|||||||
node:
|
node:
|
||||||
- '16'
|
- '16'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- run: npm install
|
- run: npm install
|
||||||
|
|||||||
24
.github/workflows/package.yml
vendored
24
.github/workflows/package.yml
vendored
@@ -5,11 +5,11 @@ jobs:
|
|||||||
package_linux:
|
package_linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run package -- linux
|
- run: npm run package -- linux
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: linux
|
name: linux
|
||||||
path: |
|
path: |
|
||||||
@@ -27,11 +27,11 @@ jobs:
|
|||||||
package_macos:
|
package_macos:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run package -- darwin
|
- run: npm run package -- darwin
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: macos
|
name: macos
|
||||||
path: |
|
path: |
|
||||||
@@ -48,11 +48,11 @@ jobs:
|
|||||||
package_windows:
|
package_windows:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
@@ -60,7 +60,7 @@ jobs:
|
|||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run package -- win32
|
- run: npm run package -- win32
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: windows
|
name: windows
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
6
.github/workflows/stale.yml
vendored
6
.github/workflows/stale.yml
vendored
@@ -12,12 +12,12 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v4
|
- uses: actions/stale@v6
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?'
|
stale-issue-message: 'Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?'
|
||||||
stale-pr-message: 'Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?'
|
stale-pr-message: 'Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?'
|
||||||
exempt-issue-labels: accepted,blocked,bug,dependency,enhancement,'help wanted',question,security,meta
|
exempt-issue-labels: accepted,blocked,dependency,security,meta
|
||||||
exempt-pr-labels: accepted,blocked,bug,dependency,enhancement,'help wanted',question,security,meta
|
exempt-pr-labels: accepted,blocked,bug,dependency,security,meta
|
||||||
stale-issue-label: 'stale'
|
stale-issue-label: 'stale'
|
||||||
stale-pr-label: 'stale'
|
stale-pr-label: 'stale'
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ to be installed. For example on Mac, first install
|
|||||||
[XQuartz](http://www.xquartz.org/), then run:
|
[XQuartz](http://www.xquartz.org/), then run:
|
||||||
|
|
||||||
```
|
```
|
||||||
brew install wine mono
|
$ brew install wine mono
|
||||||
```
|
```
|
||||||
|
|
||||||
(Requires the [Homebrew](http://brew.sh/) package manager.)
|
(Requires the [Homebrew](http://brew.sh/) package manager.)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
module.exports = require('electron')
|
|
||||||
18654
package-lock.json
generated
18654
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
67
package.json
67
package.json
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "webtorrent-desktop",
|
"name": "webtorrent-desktop",
|
||||||
"type": "module",
|
|
||||||
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
||||||
"version": "0.24.0",
|
"version": "0.24.0",
|
||||||
"author": {
|
"author": {
|
||||||
@@ -22,67 +21,67 @@
|
|||||||
"url": "https://github.com/webtorrent/webtorrent-desktop/issues"
|
"url": "https://github.com/webtorrent/webtorrent-desktop/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron/remote": "2.0.1",
|
"@electron/remote": "2.0.8",
|
||||||
|
"@material-ui/core": "4.12.4",
|
||||||
"airplayer": "github:webtorrent/airplayer#fix-security",
|
"airplayer": "github:webtorrent/airplayer#fix-security",
|
||||||
"application-config": "2.0.0",
|
"application-config": "2.0.0",
|
||||||
"arch": "2.2.0",
|
"arch": "2.2.0",
|
||||||
"auto-launch": "5.0.5",
|
"auto-launch": "5.0.5",
|
||||||
"bitfield": "4.0.0",
|
"bitfield": "4.1.0",
|
||||||
"capture-frame": "4.0.0",
|
"capture-frame": "4.0.0",
|
||||||
"chokidar": "3.5.2",
|
"chokidar": "3.5.3",
|
||||||
"chromecasts": "1.10.2",
|
"chromecasts": "1.10.2",
|
||||||
"create-torrent": "5.0.1",
|
"create-torrent": "5.0.6",
|
||||||
"debounce": "1.2.1",
|
"debounce": "1.2.1",
|
||||||
"dlnacasts": "0.1.0",
|
"dlnacasts": "0.1.0",
|
||||||
"drag-drop": "7.2.0",
|
"drag-drop": "7.2.0",
|
||||||
"es6-error": "4.1.1",
|
"es6-error": "4.1.1",
|
||||||
"fn-getter": "1.0.0",
|
"fn-getter": "1.0.0",
|
||||||
"iso-639-1": "2.1.9",
|
"iso-639-1": "2.1.15",
|
||||||
"languagedetect": "2.0.0",
|
"languagedetect": "2.0.0",
|
||||||
"location-history": "1.1.2",
|
"location-history": "1.1.2",
|
||||||
"material-ui": "0.20.2",
|
"music-metadata": "7.13.0",
|
||||||
"music-metadata": "7.11.4",
|
|
||||||
"network-address": "1.1.2",
|
"network-address": "1.1.2",
|
||||||
"parse-torrent": "9.1.4",
|
"parse-torrent": "9.1.5",
|
||||||
"prettier-bytes": "1.0.4",
|
"prettier-bytes": "1.0.4",
|
||||||
"prop-types": "15.7.2",
|
"prop-types": "15.8.1",
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-dom": "17.0.2",
|
"react-dom": "17.0.2",
|
||||||
"rimraf": "3.0.2",
|
"rimraf": "3.0.2",
|
||||||
"run-parallel": "1.2.0",
|
"run-parallel": "1.2.0",
|
||||||
"semver": "7.3.5",
|
"semver": "7.3.8",
|
||||||
"simple-concat": "1.0.1",
|
"simple-concat": "1.0.1",
|
||||||
"simple-get": "4.0.0",
|
"simple-get": "4.0.1",
|
||||||
"srt-to-vtt": "1.1.3",
|
"srt-to-vtt": "1.1.3",
|
||||||
"vlc-command": "1.2.0",
|
"vlc-command": "1.2.0",
|
||||||
"webtorrent": "1.5.6",
|
"webtorrent": "1.8.32",
|
||||||
"winreg": "1.2.4"
|
"winreg": "1.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.15.7",
|
"@babel/cli": "7.19.3",
|
||||||
"@babel/core": "7.15.8",
|
"@babel/core": "7.19.3",
|
||||||
"@babel/eslint-parser": "7.15.8",
|
"@babel/eslint-parser": "7.19.1",
|
||||||
"@babel/plugin-transform-react-jsx": "7.14.9",
|
"@babel/plugin-transform-react-jsx": "7.19.0",
|
||||||
"cross-zip": "4.0.0",
|
"cross-zip": "4.0.0",
|
||||||
"depcheck": "1.4.2",
|
"depcheck": "1.4.3",
|
||||||
"electron": "15.2.0",
|
"electron": "15.5.7",
|
||||||
"electron-notarize": "1.1.1",
|
"electron-notarize": "1.2.1",
|
||||||
"electron-osx-sign": "0.5.0",
|
"electron-osx-sign": "0.6.0",
|
||||||
"electron-packager": "15.4.0",
|
"electron-packager": "15.5.2",
|
||||||
"electron-winstaller": "5.0.0",
|
"electron-winstaller": "5.0.0",
|
||||||
"gh-release": "6.0.1",
|
"gh-release": "6.0.4",
|
||||||
"minimist": "1.2.5",
|
"minimist": "1.2.6",
|
||||||
"nodemon": "2.0.13",
|
"nodemon": "2.0.20",
|
||||||
"open": "8.3.0",
|
"open": "8.4.0",
|
||||||
"plist": "3.0.4",
|
"plist": "3.0.6",
|
||||||
"pngjs": "6.0.0",
|
"pngjs": "6.0.0",
|
||||||
"run-series": "1.1.9",
|
"run-series": "1.1.9",
|
||||||
"spectron": "15.0.0",
|
"spectron": "19.0.0",
|
||||||
"standard": "16.0.4",
|
"standard": "17.0.0",
|
||||||
"tape": "5.3.1"
|
"tape": "5.6.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.0.0",
|
"node": "^16.0.0 || ^18.0.0",
|
||||||
"npm": "^7.10.0 || ^8.0.0"
|
"npm": "^7.10.0 || ^8.0.0"
|
||||||
},
|
},
|
||||||
"homepage": "https://webtorrent.io",
|
"homepage": "https://webtorrent.io",
|
||||||
@@ -97,7 +96,7 @@
|
|||||||
"webtorrent"
|
"webtorrent"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.cjs",
|
"main": "index.js",
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"appdmg": "^0.6.0",
|
"appdmg": "^0.6.0",
|
||||||
"electron-installer-debian": "^3.1.0",
|
"electron-installer-debian": "^3.1.0",
|
||||||
@@ -114,10 +113,12 @@
|
|||||||
"clean": "node ./bin/clean.js",
|
"clean": "node ./bin/clean.js",
|
||||||
"gh-release": "gh-release",
|
"gh-release": "gh-release",
|
||||||
"install-system-deps": "brew install fakeroot dpkg rpm",
|
"install-system-deps": "brew install fakeroot dpkg rpm",
|
||||||
|
"lint": "standard",
|
||||||
|
"lint:fix": "standard --fix",
|
||||||
"open-config": "node ./bin/open-config.js",
|
"open-config": "node ./bin/open-config.js",
|
||||||
"package": "node ./bin/package.js",
|
"package": "node ./bin/package.js",
|
||||||
"start": "npm run build && electron --no-sandbox .",
|
"start": "npm run build && electron --no-sandbox .",
|
||||||
"test": "standard && depcheck --ignores=standard,@babel/eslint-parser --ignore-dirs=build,dist",
|
"test": "npm run lint && depcheck --ignores=standard,@babel/eslint-parser --ignore-dirs=build,dist",
|
||||||
"test-integration": "npm run build && node ./test",
|
"test-integration": "npm run build && node ./test",
|
||||||
"update-authors": "./bin/update-authors.sh",
|
"update-authors": "./bin/update-authors.sh",
|
||||||
"watch": "nodemon --exec \"npm run start\" --ext js,css --ignore build/ --ignore dist/"
|
"watch": "nodemon --exec \"npm run start\" --ext js,css --ignore build/ --ignore dist/"
|
||||||
|
|||||||
226
src/config.js
226
src/config.js
@@ -1,13 +1,12 @@
|
|||||||
import applicationConfig from 'application-config'
|
const appConfig = require('application-config')('WebTorrent')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import arch from 'arch'
|
const { app } = require('electron')
|
||||||
import fs from 'fs'
|
const arch = require('arch')
|
||||||
import electron from '../electron.cjs'
|
|
||||||
|
|
||||||
const appConfig = applicationConfig('WebTorrent')
|
|
||||||
const APP_NAME = 'WebTorrent'
|
const APP_NAME = 'WebTorrent'
|
||||||
const APP_TEAM = 'WebTorrent, LLC'
|
const APP_TEAM = 'WebTorrent, LLC'
|
||||||
const APP_VERSION = JSON.parse(fs.readFileSync('package.json').toString()).version
|
const APP_VERSION = require('../package.json').version
|
||||||
|
|
||||||
const IS_TEST = isTest()
|
const IS_TEST = isTest()
|
||||||
const PORTABLE_PATH = IS_TEST
|
const PORTABLE_PATH = IS_TEST
|
||||||
? path.join(process.platform === 'win32' ? 'C:\\Windows\\Temp' : '/tmp', 'WebTorrentTest')
|
? path.join(process.platform === 'win32' ? 'C:\\Windows\\Temp' : '/tmp', 'WebTorrentTest')
|
||||||
@@ -18,6 +17,93 @@ const IS_PORTABLE = isPortable()
|
|||||||
const UI_HEADER_HEIGHT = 38
|
const UI_HEADER_HEIGHT = 38
|
||||||
const UI_TORRENT_HEIGHT = 100
|
const UI_TORRENT_HEIGHT = 100
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
||||||
|
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
||||||
|
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
||||||
|
TELEMETRY_URL: 'https://webtorrent.io/desktop/telemetry',
|
||||||
|
|
||||||
|
APP_COPYRIGHT: `Copyright © 2014-${new Date().getFullYear()} ${APP_TEAM}`,
|
||||||
|
APP_FILE_ICON: path.join(__dirname, '..', 'static', 'WebTorrentFile'),
|
||||||
|
APP_ICON: path.join(__dirname, '..', 'static', 'WebTorrent'),
|
||||||
|
APP_NAME,
|
||||||
|
APP_TEAM,
|
||||||
|
APP_VERSION,
|
||||||
|
APP_WINDOW_TITLE: APP_NAME,
|
||||||
|
|
||||||
|
CONFIG_PATH: getConfigPath(),
|
||||||
|
|
||||||
|
DEFAULT_TORRENTS: [
|
||||||
|
{
|
||||||
|
testID: 'bbb',
|
||||||
|
name: 'Big Buck Bunny',
|
||||||
|
posterFileName: 'bigBuckBunny.jpg',
|
||||||
|
torrentFileName: 'bigBuckBunny.torrent'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testID: 'cosmos',
|
||||||
|
name: 'Cosmos Laundromat (Preview)',
|
||||||
|
posterFileName: 'cosmosLaundromat.jpg',
|
||||||
|
torrentFileName: 'cosmosLaundromat.torrent'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testID: 'sintel',
|
||||||
|
name: 'Sintel',
|
||||||
|
posterFileName: 'sintel.jpg',
|
||||||
|
torrentFileName: 'sintel.torrent'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testID: 'tears',
|
||||||
|
name: 'Tears of Steel',
|
||||||
|
posterFileName: 'tearsOfSteel.jpg',
|
||||||
|
torrentFileName: 'tearsOfSteel.torrent'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testID: 'wired',
|
||||||
|
name: 'The WIRED CD - Rip. Sample. Mash. Share',
|
||||||
|
posterFileName: 'wiredCd.jpg',
|
||||||
|
torrentFileName: 'wiredCd.torrent'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
DELAYED_INIT: 3000 /* 3 seconds */,
|
||||||
|
|
||||||
|
DEFAULT_DOWNLOAD_PATH: getDefaultDownloadPath(),
|
||||||
|
|
||||||
|
GITHUB_URL: 'https://github.com/webtorrent/webtorrent-desktop',
|
||||||
|
GITHUB_URL_ISSUES: 'https://github.com/webtorrent/webtorrent-desktop/issues',
|
||||||
|
GITHUB_URL_RAW: 'https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/master',
|
||||||
|
GITHUB_URL_RELEASES: 'https://github.com/webtorrent/webtorrent-desktop/releases',
|
||||||
|
|
||||||
|
HOME_PAGE_URL: 'https://webtorrent.io',
|
||||||
|
TWITTER_PAGE_URL: 'https://twitter.com/WebTorrentApp',
|
||||||
|
|
||||||
|
IS_PORTABLE,
|
||||||
|
IS_PRODUCTION,
|
||||||
|
IS_TEST,
|
||||||
|
|
||||||
|
OS_SYSARCH: arch() === 'x64' ? 'x64' : 'ia32',
|
||||||
|
|
||||||
|
POSTER_PATH: path.join(getConfigPath(), 'Posters'),
|
||||||
|
ROOT_PATH: path.join(__dirname, '..'),
|
||||||
|
STATIC_PATH: path.join(__dirname, '..', 'static'),
|
||||||
|
TORRENT_PATH: path.join(getConfigPath(), 'Torrents'),
|
||||||
|
|
||||||
|
WINDOW_ABOUT: 'file://' + path.join(__dirname, '..', 'static', 'about.html'),
|
||||||
|
WINDOW_MAIN: 'file://' + path.join(__dirname, '..', 'static', 'main.html'),
|
||||||
|
WINDOW_WEBTORRENT: 'file://' + path.join(__dirname, '..', 'static', 'webtorrent.html'),
|
||||||
|
|
||||||
|
WINDOW_INITIAL_BOUNDS: {
|
||||||
|
width: 500,
|
||||||
|
height: UI_HEADER_HEIGHT + (UI_TORRENT_HEIGHT * 6) // header + 6 torrents
|
||||||
|
},
|
||||||
|
WINDOW_MIN_HEIGHT: UI_HEADER_HEIGHT + (UI_TORRENT_HEIGHT * 2), // header + 2 torrents
|
||||||
|
WINDOW_MIN_WIDTH: 425,
|
||||||
|
|
||||||
|
UI_HEADER_HEIGHT,
|
||||||
|
UI_TORRENT_HEIGHT
|
||||||
|
}
|
||||||
|
|
||||||
function getConfigPath () {
|
function getConfigPath () {
|
||||||
if (IS_PORTABLE) {
|
if (IS_PORTABLE) {
|
||||||
return PORTABLE_PATH
|
return PORTABLE_PATH
|
||||||
@@ -35,12 +121,16 @@ function getDefaultDownloadPath () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPath (key) {
|
function getPath (key) {
|
||||||
if (!process.versions.electron || process.type !== 'browser') {
|
if (!process.versions.electron) {
|
||||||
// Node.js process
|
// Node.js process
|
||||||
return ''
|
return ''
|
||||||
|
} else if (process.type === 'renderer') {
|
||||||
|
// Electron renderer process
|
||||||
|
return require('@electron/remote').app.getPath(key)
|
||||||
|
} else {
|
||||||
|
// Electron main process
|
||||||
|
return app.getPath(key)
|
||||||
}
|
}
|
||||||
// Electron main process
|
|
||||||
return electron.app.getPath(key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTest () {
|
function isTest () {
|
||||||
@@ -57,6 +147,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.
|
||||||
@@ -82,117 +174,3 @@ function isProduction () {
|
|||||||
return !/\/electron$/.test(process.execPath)
|
return !/\/electron$/.test(process.execPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ANNOUNCEMENT_URL = 'https://webtorrent.io/desktop/announcement'
|
|
||||||
export const AUTO_UPDATE_URL = 'https://webtorrent.io/desktop/update'
|
|
||||||
export const CRASH_REPORT_URL = 'https://webtorrent.io/desktop/crash-report'
|
|
||||||
export const TELEMETRY_URL = 'https://webtorrent.io/desktop/telemetry'
|
|
||||||
export const APP_COPYRIGHT = `Copyright © 2014-${new Date().getFullYear()} ${APP_TEAM}`
|
|
||||||
export const APP_FILE_ICON = new URL('../static/WebTorrentFile', import.meta.url).pathname // path.join(__dirname, '..',
|
|
||||||
// 'static', 'WebTorrentFile')
|
|
||||||
export const APP_ICON = new URL('../static/WebTorrent', import.meta.url).pathname // path.join(__dirname, '..',
|
|
||||||
// 'static',
|
|
||||||
// 'WebTorrent')
|
|
||||||
export const CONFIG_PATH = getConfigPath()
|
|
||||||
export const DEFAULT_TORRENTS = [
|
|
||||||
{
|
|
||||||
testID: 'bbb',
|
|
||||||
name: 'Big Buck Bunny',
|
|
||||||
posterFileName: 'bigBuckBunny.jpg',
|
|
||||||
torrentFileName: 'bigBuckBunny.torrent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testID: 'cosmos',
|
|
||||||
name: 'Cosmos Laundromat (Preview)',
|
|
||||||
posterFileName: 'cosmosLaundromat.jpg',
|
|
||||||
torrentFileName: 'cosmosLaundromat.torrent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testID: 'sintel',
|
|
||||||
name: 'Sintel',
|
|
||||||
posterFileName: 'sintel.jpg',
|
|
||||||
torrentFileName: 'sintel.torrent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testID: 'tears',
|
|
||||||
name: 'Tears of Steel',
|
|
||||||
posterFileName: 'tearsOfSteel.jpg',
|
|
||||||
torrentFileName: 'tearsOfSteel.torrent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
testID: 'wired',
|
|
||||||
name: 'The WIRED CD - Rip. Sample. Mash. Share',
|
|
||||||
posterFileName: 'wiredCd.jpg',
|
|
||||||
torrentFileName: 'wiredCd.torrent'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
export const DELAYED_INIT = 3000 /* 3 seconds */
|
|
||||||
export const DEFAULT_DOWNLOAD_PATH = getDefaultDownloadPath()
|
|
||||||
export const GITHUB_URL = 'https://github.com/webtorrent/webtorrent-desktop'
|
|
||||||
export const GITHUB_URL_ISSUES = 'https://github.com/webtorrent/webtorrent-desktop/issues'
|
|
||||||
export const GITHUB_URL_RAW = 'https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/master'
|
|
||||||
export const GITHUB_URL_RELEASES = 'https://github.com/webtorrent/webtorrent-desktop/releases'
|
|
||||||
export const HOME_PAGE_URL = 'https://webtorrent.io'
|
|
||||||
export const TWITTER_PAGE_URL = 'https://twitter.com/WebTorrentApp'
|
|
||||||
export const OS_SYSARCH = arch() === 'x64' ? 'x64' : 'ia32'
|
|
||||||
export const POSTER_PATH = path.join(getConfigPath(), 'Posters')
|
|
||||||
export const ROOT_PATH = new URL('../', import.meta.url).pathname
|
|
||||||
export const STATIC_PATH = new URL('../static', import.meta.url).pathname
|
|
||||||
export const TORRENT_PATH = path.join(getConfigPath(), 'Torrents')
|
|
||||||
export const WINDOW_ABOUT = 'file://' + new URL('../static/about.html', import.meta.url).pathname
|
|
||||||
export const WINDOW_MAIN = 'file://' + new URL('../static/main.html', import.meta.url).pathname
|
|
||||||
export const WINDOW_WEBTORRENT = 'file://' + new URL('../static/webtorrent.html', import.meta.url).pathname
|
|
||||||
export const WINDOW_INITIAL_BOUNDS = {
|
|
||||||
width: 500,
|
|
||||||
height: UI_HEADER_HEIGHT + (UI_TORRENT_HEIGHT * 6) // header + 6 torrents
|
|
||||||
}
|
|
||||||
export const WINDOW_MIN_HEIGHT = UI_HEADER_HEIGHT + (UI_TORRENT_HEIGHT * 2)
|
|
||||||
export const WINDOW_MIN_WIDTH = 425
|
|
||||||
export { APP_NAME }
|
|
||||||
export { APP_TEAM }
|
|
||||||
export { APP_VERSION }
|
|
||||||
export { APP_NAME as APP_WINDOW_TITLE }
|
|
||||||
export { IS_PORTABLE }
|
|
||||||
export { IS_PRODUCTION }
|
|
||||||
export { IS_TEST }
|
|
||||||
export { UI_HEADER_HEIGHT }
|
|
||||||
export { UI_TORRENT_HEIGHT }
|
|
||||||
export default {
|
|
||||||
ANNOUNCEMENT_URL,
|
|
||||||
AUTO_UPDATE_URL,
|
|
||||||
CRASH_REPORT_URL,
|
|
||||||
TELEMETRY_URL,
|
|
||||||
APP_COPYRIGHT,
|
|
||||||
APP_FILE_ICON,
|
|
||||||
APP_ICON,
|
|
||||||
APP_NAME,
|
|
||||||
APP_TEAM,
|
|
||||||
APP_VERSION,
|
|
||||||
APP_WINDOW_TITLE: APP_NAME,
|
|
||||||
CONFIG_PATH,
|
|
||||||
DEFAULT_TORRENTS,
|
|
||||||
DELAYED_INIT,
|
|
||||||
DEFAULT_DOWNLOAD_PATH,
|
|
||||||
GITHUB_URL,
|
|
||||||
GITHUB_URL_ISSUES,
|
|
||||||
GITHUB_URL_RAW,
|
|
||||||
GITHUB_URL_RELEASES,
|
|
||||||
HOME_PAGE_URL,
|
|
||||||
TWITTER_PAGE_URL,
|
|
||||||
IS_PORTABLE,
|
|
||||||
IS_PRODUCTION,
|
|
||||||
IS_TEST,
|
|
||||||
OS_SYSARCH,
|
|
||||||
POSTER_PATH,
|
|
||||||
ROOT_PATH,
|
|
||||||
STATIC_PATH,
|
|
||||||
TORRENT_PATH,
|
|
||||||
WINDOW_ABOUT,
|
|
||||||
WINDOW_MAIN,
|
|
||||||
WINDOW_WEBTORRENT,
|
|
||||||
WINDOW_INITIAL_BOUNDS,
|
|
||||||
WINDOW_MIN_HEIGHT,
|
|
||||||
WINDOW_MIN_WIDTH,
|
|
||||||
UI_HEADER_HEIGHT,
|
|
||||||
UI_TORRENT_HEIGHT
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import electron from '../electron.cjs'
|
module.exports = {
|
||||||
|
init
|
||||||
|
}
|
||||||
|
|
||||||
async function init () {
|
function init () {
|
||||||
const config = await import('./config.js')
|
const config = require('./config')
|
||||||
electron.crashReporter.start({
|
const { crashReporter } = require('electron')
|
||||||
|
|
||||||
|
crashReporter.start({
|
||||||
productName: config.APP_NAME,
|
productName: config.APP_NAME,
|
||||||
submitURL: config.CRASH_REPORT_URL,
|
submitURL: config.CRASH_REPORT_URL,
|
||||||
globalExtra: { _companyName: config.APP_NAME },
|
globalExtra: { _companyName: config.APP_NAME },
|
||||||
compress: true
|
compress: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { init }
|
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import config from '../config.js'
|
init
|
||||||
import log from './log.js'
|
}
|
||||||
|
|
||||||
|
const { dialog } = require('electron')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
const log = require('./log')
|
||||||
|
|
||||||
const ANNOUNCEMENT_URL =
|
const ANNOUNCEMENT_URL =
|
||||||
`${config.ANNOUNCEMENT_URL}?version=${config.APP_VERSION}&platform=${process.platform}`
|
`${config.ANNOUNCEMENT_URL}?version=${config.APP_VERSION}&platform=${process.platform}`
|
||||||
@@ -19,8 +24,8 @@ const ANNOUNCEMENT_URL =
|
|||||||
* "detail": "Please update to v0.xx as soon as possible..."
|
* "detail": "Please update to v0.xx as soon as possible..."
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
async function init () {
|
function init () {
|
||||||
const { default: get } = await import('simple-get')
|
const get = require('simple-get')
|
||||||
get.concat(ANNOUNCEMENT_URL, onResponse)
|
get.concat(ANNOUNCEMENT_URL, onResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +44,7 @@ function onResponse (err, res, data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
electron.dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
buttons: ['OK'],
|
buttons: ['OK'],
|
||||||
title: data.title,
|
title: data.title,
|
||||||
@@ -47,5 +52,3 @@ function onResponse (err, res, data) {
|
|||||||
detail: data.detail
|
detail: data.detail
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { init }
|
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import log from './log.js'
|
openSeedFile,
|
||||||
import * as windows from './windows/index.js'
|
openSeedDirectory,
|
||||||
|
openTorrentFile,
|
||||||
|
openTorrentAddress,
|
||||||
|
openFiles
|
||||||
|
}
|
||||||
|
|
||||||
const { dialog } = electron
|
const { dialog } = require('electron')
|
||||||
|
|
||||||
|
const log = require('./log')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show open dialog to create a single-file torrent.
|
* Show open dialog to create a single-file torrent.
|
||||||
*/
|
*/
|
||||||
export function openSeedFile () {
|
function openSeedFile () {
|
||||||
if (!windows.main.win) return
|
if (!windows.main.win) return
|
||||||
log('openSeedFile')
|
log('openSeedFile')
|
||||||
const opts = {
|
const opts = {
|
||||||
@@ -22,7 +29,7 @@ export function openSeedFile () {
|
|||||||
* Windows and Linux, open dialogs are for files *or* directories only, not both,
|
* Windows and Linux, open dialogs are for files *or* directories only, not both,
|
||||||
* so this function shows a directory dialog on those platforms.
|
* so this function shows a directory dialog on those platforms.
|
||||||
*/
|
*/
|
||||||
export function openSeedDirectory () {
|
function openSeedDirectory () {
|
||||||
if (!windows.main.win) return
|
if (!windows.main.win) return
|
||||||
log('openSeedDirectory')
|
log('openSeedDirectory')
|
||||||
const opts = process.platform === 'darwin'
|
const opts = process.platform === 'darwin'
|
||||||
@@ -41,7 +48,7 @@ export function openSeedDirectory () {
|
|||||||
* Show flexible open dialog that supports selecting .torrent files to add, or
|
* Show flexible open dialog that supports selecting .torrent files to add, or
|
||||||
* a file or folder to create a single-file or single-directory torrent.
|
* a file or folder to create a single-file or single-directory torrent.
|
||||||
*/
|
*/
|
||||||
export function openFiles () {
|
function openFiles () {
|
||||||
if (!windows.main.win) return
|
if (!windows.main.win) return
|
||||||
log('openFiles')
|
log('openFiles')
|
||||||
const opts = process.platform === 'darwin'
|
const opts = process.platform === 'darwin'
|
||||||
@@ -63,7 +70,7 @@ export function openFiles () {
|
|||||||
/*
|
/*
|
||||||
* Show open dialog to open a .torrent file.
|
* Show open dialog to open a .torrent file.
|
||||||
*/
|
*/
|
||||||
export function openTorrentFile () {
|
function openTorrentFile () {
|
||||||
if (!windows.main.win) return
|
if (!windows.main.win) return
|
||||||
log('openTorrentFile')
|
log('openTorrentFile')
|
||||||
const opts = {
|
const opts = {
|
||||||
@@ -83,7 +90,7 @@ export function openTorrentFile () {
|
|||||||
/*
|
/*
|
||||||
* Show modal dialog to open a torrent URL (magnet uri, http torrent link, etc.)
|
* Show modal dialog to open a torrent URL (magnet uri, http torrent link, etc.)
|
||||||
*/
|
*/
|
||||||
export function openTorrentAddress () {
|
function openTorrentAddress () {
|
||||||
log('openTorrentAddress')
|
log('openTorrentAddress')
|
||||||
windows.main.dispatch('openTorrentAddress')
|
windows.main.dispatch('openTorrentAddress')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import * as dialog from './dialog.js'
|
downloadFinished,
|
||||||
import log from './log.js'
|
init,
|
||||||
|
setBadge
|
||||||
|
}
|
||||||
|
|
||||||
const { app, Menu } = electron
|
const { app, Menu } = require('electron')
|
||||||
|
|
||||||
|
const dialog = require('./dialog')
|
||||||
|
const log = require('./log')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a right-click menu to the dock icon. (Mac)
|
* Add a right-click menu to the dock icon. (Mac)
|
||||||
@@ -52,5 +57,3 @@ function getMenuTemplate () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { downloadFinished, init, setBadge }
|
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
import cp from 'child_process'
|
module.exports = {
|
||||||
import path from 'path'
|
spawn,
|
||||||
import vlcCommand from 'vlc-command'
|
kill,
|
||||||
import log from './log.js'
|
checkInstall
|
||||||
import * as windows from './windows'
|
}
|
||||||
|
|
||||||
|
const cp = require('child_process')
|
||||||
|
const path = require('path')
|
||||||
|
const vlcCommand = require('vlc-command')
|
||||||
|
|
||||||
|
const log = require('./log')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
// holds a ChildProcess while we're playing a video in an external player, null otherwise
|
// holds a ChildProcess while we're playing a video in an external player, null otherwise
|
||||||
let proc = null
|
let proc = null
|
||||||
|
|
||||||
export function checkInstall (playerPath, cb) {
|
function checkInstall (playerPath, cb) {
|
||||||
// check for VLC if external player has not been specified by the user
|
// check for VLC if external player has not been specified by the user
|
||||||
// otherwise assume the player is installed
|
// otherwise assume the player is installed
|
||||||
if (!playerPath) return vlcCommand(cb)
|
if (!playerPath) return vlcCommand(cb)
|
||||||
process.nextTick(() => cb(null))
|
process.nextTick(() => cb(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function spawn (playerPath, url, title) {
|
function spawn (playerPath, url, title) {
|
||||||
if (playerPath) return spawnExternal(playerPath, [url])
|
if (playerPath) return spawnExternal(playerPath, [url])
|
||||||
|
|
||||||
// Try to find and use VLC if external player is not specified
|
// Try to find and use VLC if external player is not specified
|
||||||
@@ -29,7 +37,7 @@ export function spawn (playerPath, url, title) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function kill () {
|
function kill () {
|
||||||
if (!proc) return
|
if (!proc) return
|
||||||
log(`Killing external player, pid ${proc.pid}`)
|
log(`Killing external player, pid ${proc.pid}`)
|
||||||
proc.kill('SIGKILL') // kill -9
|
proc.kill('SIGKILL') // kill -9
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as chokidar from 'chokidar'
|
const chokidar = require('chokidar')
|
||||||
import log from './log.js'
|
const log = require('./log')
|
||||||
|
|
||||||
export class FolderWatcher {
|
class FolderWatcher {
|
||||||
constructor ({ window, state }) {
|
constructor ({ window, state }) {
|
||||||
this.window = window
|
this.window = window
|
||||||
this.state = state
|
this.state = state
|
||||||
@@ -46,3 +46,5 @@ export class FolderWatcher {
|
|||||||
this.watching = false
|
this.watching = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = FolderWatcher
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import config from '../config.js'
|
module.exports = {
|
||||||
import path from 'path'
|
install,
|
||||||
|
uninstall
|
||||||
|
}
|
||||||
|
|
||||||
export function install () {
|
const config = require('../config')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
function install () {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'darwin': installDarwin()
|
case 'darwin': installDarwin()
|
||||||
break
|
break
|
||||||
@@ -10,7 +15,7 @@ export function install () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uninstall () {
|
function uninstall () {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'darwin': uninstallDarwin()
|
case 'darwin': uninstallDarwin()
|
||||||
break
|
break
|
||||||
@@ -19,8 +24,9 @@ export function uninstall () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installDarwin () {
|
function installDarwin () {
|
||||||
const { app } = await import('electron')
|
const { app } = require('electron')
|
||||||
|
|
||||||
// On Mac, only protocols that are listed in `Info.plist` can be set as the
|
// On Mac, only protocols that are listed in `Info.plist` can be set as the
|
||||||
// default handler at runtime.
|
// default handler at runtime.
|
||||||
app.setAsDefaultProtocolClient('magnet')
|
app.setAsDefaultProtocolClient('magnet')
|
||||||
@@ -37,14 +43,33 @@ if (!config.IS_PRODUCTION) {
|
|||||||
EXEC_COMMAND.push(config.ROOT_PATH)
|
EXEC_COMMAND.push(config.ROOT_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installWin32 () {
|
function installWin32 () {
|
||||||
const Registry = await import('wingreg')
|
const Registry = require('winreg')
|
||||||
const log = await import('./log')
|
|
||||||
|
|
||||||
const iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
|
const log = require('./log')
|
||||||
registerProtocolHandlerWin32('magnet', 'URL:BitTorrent Magnet URL', iconPath, EXEC_COMMAND)
|
|
||||||
registerProtocolHandlerWin32('stream-magnet', 'URL:BitTorrent Stream-Magnet URL', iconPath, EXEC_COMMAND)
|
const iconPath = path.join(
|
||||||
registerFileHandlerWin32('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', iconPath, EXEC_COMMAND)
|
process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico'
|
||||||
|
)
|
||||||
|
registerProtocolHandlerWin32(
|
||||||
|
'magnet',
|
||||||
|
'URL:BitTorrent Magnet URL',
|
||||||
|
iconPath,
|
||||||
|
EXEC_COMMAND
|
||||||
|
)
|
||||||
|
registerProtocolHandlerWin32(
|
||||||
|
'stream-magnet',
|
||||||
|
'URL:BitTorrent Stream-Magnet URL',
|
||||||
|
iconPath,
|
||||||
|
EXEC_COMMAND
|
||||||
|
)
|
||||||
|
registerFileHandlerWin32(
|
||||||
|
'.torrent',
|
||||||
|
'io.webtorrent.torrent',
|
||||||
|
'BitTorrent Document',
|
||||||
|
iconPath,
|
||||||
|
EXEC_COMMAND
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To add a protocol handler, the following keys must be added to the Windows registry:
|
* To add a protocol handler, the following keys must be added to the Windows registry:
|
||||||
@@ -172,8 +197,9 @@ async function installWin32 () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uninstallWin32 () {
|
function uninstallWin32 () {
|
||||||
const Registry = await import('winreg')
|
const Registry = require('winreg')
|
||||||
|
|
||||||
unregisterProtocolHandlerWin32('magnet', EXEC_COMMAND)
|
unregisterProtocolHandlerWin32('magnet', EXEC_COMMAND)
|
||||||
unregisterProtocolHandlerWin32('stream-magnet', EXEC_COMMAND)
|
unregisterProtocolHandlerWin32('stream-magnet', EXEC_COMMAND)
|
||||||
unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', EXEC_COMMAND)
|
unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', EXEC_COMMAND)
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
/* eslint-disable import/first */
|
|
||||||
console.time('init')
|
console.time('init')
|
||||||
|
|
||||||
import * as RemoteMain from '@electron/remote/main/index.js'
|
require('@electron/remote/main').initialize()
|
||||||
RemoteMain.initialize()
|
const { app, ipcMain } = require('electron')
|
||||||
import electron from '../../electron.cjs'
|
|
||||||
const { app, ipcMain } = electron
|
|
||||||
|
|
||||||
// Start crash reporter early, so it takes effect for child processes
|
// Start crash reporter early, so it takes effect for child processes
|
||||||
import crashReporter from '../crash-reporter.js'
|
const crashReporter = require('../crash-reporter')
|
||||||
crashReporter.init()
|
crashReporter.init()
|
||||||
|
|
||||||
import fs from 'fs'
|
const parallel = require('run-parallel')
|
||||||
import parallel from 'run-parallel'
|
|
||||||
import config from '../config.js'
|
|
||||||
import ipc from './ipc.js'
|
|
||||||
import log from './log.js'
|
|
||||||
import menu from './menu.js'
|
|
||||||
import State from '../renderer/lib/state.js'
|
|
||||||
import * as windows from './windows/index.js'
|
|
||||||
|
|
||||||
const WEBTORRENT_VERSION = JSON.parse(fs.readFileSync('node_modules/webtorrent/package.json').toString()).version
|
const config = require('../config')
|
||||||
|
const ipc = require('./ipc')
|
||||||
|
const log = require('./log')
|
||||||
|
const menu = require('./menu')
|
||||||
|
const State = require('../renderer/lib/state')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
|
const WEBTORRENT_VERSION = require('webtorrent/package.json').version
|
||||||
|
|
||||||
let shouldQuit = false
|
let shouldQuit = false
|
||||||
let argv = sliceArgv(process.argv)
|
let argv = sliceArgv(process.argv)
|
||||||
@@ -57,18 +54,13 @@ if (!shouldQuit && !config.IS_PORTABLE) {
|
|||||||
if (shouldQuit) {
|
if (shouldQuit) {
|
||||||
app.quit()
|
app.quit()
|
||||||
} else {
|
} else {
|
||||||
init().catch(console.error)
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init () {
|
function init () {
|
||||||
console.log('index init')
|
|
||||||
app.whenReady().then(() => {
|
|
||||||
console.log('readyyyy')
|
|
||||||
})
|
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => onAppOpen(commandLine))
|
app.on('second-instance', (event, commandLine, workingDirectory) => onAppOpen(commandLine))
|
||||||
if (config.IS_PORTABLE) {
|
if (config.IS_PORTABLE) {
|
||||||
console.log('is portable')
|
const path = require('path')
|
||||||
const path = await import('path')
|
|
||||||
// Put all user data into the "Portable Settings" folder
|
// Put all user data into the "Portable Settings" folder
|
||||||
app.setPath('userData', config.CONFIG_PATH)
|
app.setPath('userData', config.CONFIG_PATH)
|
||||||
// Put Electron crash files, etc. into the "Portable Settings\Temp" folder
|
// Put Electron crash files, etc. into the "Portable Settings\Temp" folder
|
||||||
@@ -80,7 +72,7 @@ async function init () {
|
|||||||
app.isQuitting = false
|
app.isQuitting = false
|
||||||
|
|
||||||
parallel({
|
parallel({
|
||||||
appReady: (cb) => app.whenReady().then(cb),
|
appReady: (cb) => app.on('ready', () => cb(null)),
|
||||||
state: (cb) => State.load(cb)
|
state: (cb) => State.load(cb)
|
||||||
}, onReady)
|
}, onReady)
|
||||||
|
|
||||||
@@ -138,18 +130,17 @@ async function init () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
console.log('activate')
|
|
||||||
if (isReady) windows.main.show()
|
if (isReady) windows.main.show()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function delayedInit (state) {
|
function delayedInit (state) {
|
||||||
if (app.isQuitting) return
|
if (app.isQuitting) return
|
||||||
|
|
||||||
const { default: announcement } = await import('./announcement.js')
|
const announcement = require('./announcement')
|
||||||
const { default: dock } = await import('./dock.js')
|
const dock = require('./dock')
|
||||||
const { default: updater } = await import('./updater.js')
|
const updater = require('./updater')
|
||||||
const { FolderWatcher } = await import('./folder-watcher.js')
|
const FolderWatcher = require('./folder-watcher')
|
||||||
const folderWatcher = new FolderWatcher({ window: windows.main, state })
|
const folderWatcher = new FolderWatcher({ window: windows.main, state })
|
||||||
|
|
||||||
announcement.init()
|
announcement.init()
|
||||||
@@ -162,13 +153,13 @@ async function delayedInit (state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
const userTasks = await import('./user-tasks.js')
|
const userTasks = require('./user-tasks')
|
||||||
userTasks.init()
|
userTasks.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
const { init: trayInit } = await import('./tray.js')
|
const tray = require('./tray')
|
||||||
trayInit()
|
tray.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,12 +205,12 @@ function sliceArgv (argv) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processArgv (argv) {
|
function processArgv (argv) {
|
||||||
const torrentIds = []
|
const torrentIds = []
|
||||||
await Promise.all(argv.forEach(async arg => {
|
argv.forEach(arg => {
|
||||||
if (arg === '-n' || arg === '-o' || arg === '-u') {
|
if (arg === '-n' || arg === '-o' || arg === '-u') {
|
||||||
// Critical path: Only load the 'dialog' package if it is needed
|
// Critical path: Only load the 'dialog' package if it is needed
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
if (arg === '-n') {
|
if (arg === '-n') {
|
||||||
dialog.openSeedDirectory()
|
dialog.openSeedDirectory()
|
||||||
} else if (arg === '-o') {
|
} else if (arg === '-o') {
|
||||||
@@ -242,7 +233,7 @@ async function processArgv (argv) {
|
|||||||
// running.
|
// running.
|
||||||
torrentIds.push(arg)
|
torrentIds.push(arg)
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
if (torrentIds.length > 0) {
|
if (torrentIds.length > 0) {
|
||||||
windows.main.dispatch('onOpen', torrentIds)
|
windows.main.dispatch('onOpen', torrentIds)
|
||||||
}
|
}
|
||||||
|
|||||||
104
src/main/ipc.js
104
src/main/ipc.js
@@ -1,10 +1,13 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
|
init,
|
||||||
|
setModule
|
||||||
|
}
|
||||||
|
|
||||||
import log from './log.js'
|
const { app, ipcMain } = require('electron')
|
||||||
import menu from './menu.js'
|
|
||||||
import * as windows from './windows/index.js'
|
|
||||||
|
|
||||||
const { app, ipcMain } = electron
|
const log = require('./log')
|
||||||
|
const menu = require('./menu')
|
||||||
|
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 = []
|
||||||
@@ -37,12 +40,12 @@ function init () {
|
|||||||
* Dialog
|
* Dialog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('openTorrentFile', async () => {
|
ipcMain.on('openTorrentFile', () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openTorrentFile()
|
dialog.openTorrentFile()
|
||||||
})
|
})
|
||||||
ipcMain.on('openFiles', async () => {
|
ipcMain.on('openFiles', () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openFiles()
|
dialog.openFiles()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -50,12 +53,12 @@ function init () {
|
|||||||
* Dock
|
* Dock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('setBadge', async (e, ...args) => {
|
ipcMain.on('setBadge', (e, ...args) => {
|
||||||
const dock = await import('./dock')
|
const dock = require('./dock')
|
||||||
dock.setBadge(...args)
|
dock.setBadge(...args)
|
||||||
})
|
})
|
||||||
ipcMain.on('downloadFinished', async (e, ...args) => {
|
ipcMain.on('downloadFinished', (e, ...args) => {
|
||||||
const dock = await import('./dock')
|
const dock = require('./dock')
|
||||||
dock.downloadFinished(...args)
|
dock.downloadFinished(...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -63,10 +66,10 @@ function init () {
|
|||||||
* Player Events
|
* Player Events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('onPlayerOpen', async () => {
|
ipcMain.on('onPlayerOpen', () => {
|
||||||
const powerSaveBlocker = await import('./power-save-blocker')
|
const powerSaveBlocker = require('./power-save-blocker')
|
||||||
const shortcuts = await import('./shortcuts')
|
const shortcuts = require('./shortcuts')
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
menu.togglePlaybackControls(true)
|
menu.togglePlaybackControls(true)
|
||||||
powerSaveBlocker.enable()
|
powerSaveBlocker.enable()
|
||||||
@@ -74,17 +77,17 @@ function init () {
|
|||||||
thumbar.enable()
|
thumbar.enable()
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('onPlayerUpdate', async (e, ...args) => {
|
ipcMain.on('onPlayerUpdate', (e, ...args) => {
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
menu.onPlayerUpdate(...args)
|
menu.onPlayerUpdate(...args)
|
||||||
thumbar.onPlayerUpdate(...args)
|
thumbar.onPlayerUpdate(...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('onPlayerClose', async () => {
|
ipcMain.on('onPlayerClose', () => {
|
||||||
const powerSaveBlocker = await import('./power-save-blocker')
|
const powerSaveBlocker = require('./power-save-blocker')
|
||||||
const shortcuts = await import('./shortcuts')
|
const shortcuts = require('./shortcuts')
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
menu.togglePlaybackControls(false)
|
menu.togglePlaybackControls(false)
|
||||||
powerSaveBlocker.disable()
|
powerSaveBlocker.disable()
|
||||||
@@ -92,17 +95,17 @@ function init () {
|
|||||||
thumbar.disable()
|
thumbar.disable()
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('onPlayerPlay', async () => {
|
ipcMain.on('onPlayerPlay', () => {
|
||||||
const powerSaveBlocker = await import('./power-save-blocker')
|
const powerSaveBlocker = require('./power-save-blocker')
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
powerSaveBlocker.enable()
|
powerSaveBlocker.enable()
|
||||||
thumbar.onPlayerPlay()
|
thumbar.onPlayerPlay()
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('onPlayerPause', async () => {
|
ipcMain.on('onPlayerPause', () => {
|
||||||
const powerSaveBlocker = await import('./power-save-blocker')
|
const powerSaveBlocker = require('./power-save-blocker')
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
powerSaveBlocker.disable()
|
powerSaveBlocker.disable()
|
||||||
thumbar.onPlayerPause()
|
thumbar.onPlayerPause()
|
||||||
@@ -134,16 +137,16 @@ function init () {
|
|||||||
* Shell
|
* Shell
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('openPath', async (e, ...args) => {
|
ipcMain.on('openPath', (e, ...args) => {
|
||||||
const shell = await import('./shell')
|
const shell = require('./shell')
|
||||||
shell.openPath(...args)
|
shell.openPath(...args)
|
||||||
})
|
})
|
||||||
ipcMain.on('showItemInFolder', async (e, ...args) => {
|
ipcMain.on('showItemInFolder', (e, ...args) => {
|
||||||
const shell = await import('./shell')
|
const shell = require('./shell')
|
||||||
shell.showItemInFolder(...args)
|
shell.showItemInFolder(...args)
|
||||||
})
|
})
|
||||||
ipcMain.on('moveItemToTrash', async (e, ...args) => {
|
ipcMain.on('moveItemToTrash', (e, ...args) => {
|
||||||
const shell = await import('./shell')
|
const shell = require('./shell')
|
||||||
shell.moveItemToTrash(...args)
|
shell.moveItemToTrash(...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -151,8 +154,8 @@ function init () {
|
|||||||
* File handlers
|
* File handlers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('setDefaultFileHandler', async (e, flag) => {
|
ipcMain.on('setDefaultFileHandler', (e, flag) => {
|
||||||
const handlers = await import('./handlers')
|
const handlers = require('./handlers')
|
||||||
|
|
||||||
if (flag) handlers.install()
|
if (flag) handlers.install()
|
||||||
else handlers.uninstall()
|
else handlers.uninstall()
|
||||||
@@ -162,8 +165,8 @@ function init () {
|
|||||||
* Auto start on login
|
* Auto start on login
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('setStartup', async (e, flag) => {
|
ipcMain.on('setStartup', (e, flag) => {
|
||||||
const startup = await import('./startup')
|
const startup = require('./startup')
|
||||||
|
|
||||||
if (flag) startup.install()
|
if (flag) startup.install()
|
||||||
else startup.uninstall()
|
else startup.uninstall()
|
||||||
@@ -187,18 +190,18 @@ function init () {
|
|||||||
* External Media Player
|
* External Media Player
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ipcMain.on('checkForExternalPlayer', async (e, path) => {
|
ipcMain.on('checkForExternalPlayer', (e, path) => {
|
||||||
const externalPlayer = await import('./external-player')
|
const externalPlayer = require('./external-player')
|
||||||
|
|
||||||
externalPlayer.checkInstall(path, err => {
|
externalPlayer.checkInstall(path, err => {
|
||||||
windows.main.send('checkForExternalPlayer', !err)
|
windows.main.send('checkForExternalPlayer', !err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('openExternalPlayer', async (e, ...args) => {
|
ipcMain.on('openExternalPlayer', (e, ...args) => {
|
||||||
const externalPlayer = await import('./external-player')
|
const externalPlayer = require('./external-player')
|
||||||
const shortcuts = await import('./shortcuts')
|
const shortcuts = require('./shortcuts')
|
||||||
const thumbar = await import('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
|
||||||
menu.togglePlaybackControls(false)
|
menu.togglePlaybackControls(false)
|
||||||
shortcuts.disable()
|
shortcuts.disable()
|
||||||
@@ -206,8 +209,8 @@ function init () {
|
|||||||
externalPlayer.spawn(...args)
|
externalPlayer.spawn(...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('quitExternalPlayer', async () => {
|
ipcMain.on('quitExternalPlayer', () => {
|
||||||
const externalPlayer = await import('./external-player')
|
const externalPlayer = require('./external-player')
|
||||||
externalPlayer.kill()
|
externalPlayer.kill()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -243,10 +246,3 @@ function init () {
|
|||||||
oldEmit.call(ipcMain, name, e, ...args)
|
oldEmit.call(ipcMain, name, e, ...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { init }
|
|
||||||
export { setModule }
|
|
||||||
export default {
|
|
||||||
init,
|
|
||||||
setModule
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = log
|
||||||
import * as windows from './windows/index.js'
|
module.exports.error = error
|
||||||
|
|
||||||
const { app } = electron
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In the main electron process, we do not use console.log() statements because they do
|
* In the main electron process, we do not use console.log() statements because they do
|
||||||
@@ -9,7 +7,11 @@ const { app } = electron
|
|||||||
* version of the app. Instead use this module, which sends the logs to the main window
|
* version of the app. Instead use this module, which sends the logs to the main window
|
||||||
* where they can be viewed in Developer Tools.
|
* where they can be viewed in Developer Tools.
|
||||||
*/
|
*/
|
||||||
export default function log (...args) {
|
|
||||||
|
const { app } = require('electron')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
|
function log (...args) {
|
||||||
if (app.ipcReady) {
|
if (app.ipcReady) {
|
||||||
windows.main.send('log', ...args)
|
windows.main.send('log', ...args)
|
||||||
} else {
|
} else {
|
||||||
@@ -17,7 +19,7 @@ export default function log (...args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function error (...args) {
|
function error (...args) {
|
||||||
if (app.ipcReady) {
|
if (app.ipcReady) {
|
||||||
windows.main.send('error', ...args)
|
windows.main.send('error', ...args)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import config from '../config.js'
|
init,
|
||||||
import * as windows from './windows/index.js'
|
togglePlaybackControls,
|
||||||
import shell from './shell.js'
|
setWindowFocus,
|
||||||
|
setAllowNav,
|
||||||
|
onPlayerUpdate,
|
||||||
|
onToggleAlwaysOnTop,
|
||||||
|
onToggleFullScreen
|
||||||
|
}
|
||||||
|
|
||||||
|
const { app, Menu } = require('electron')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
let menu = null
|
let menu = null
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
console.log('menu init')
|
menu = Menu.buildFromTemplate(getMenuTemplate())
|
||||||
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
|
Menu.setApplicationMenu(menu)
|
||||||
electron.Menu.setApplicationMenu(menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function togglePlaybackControls (flag) {
|
function togglePlaybackControls (flag) {
|
||||||
@@ -76,24 +85,24 @@ function getMenuTemplate () {
|
|||||||
? 'Create New Torrent...'
|
? 'Create New Torrent...'
|
||||||
: 'Create New Torrent from Folder...',
|
: 'Create New Torrent from Folder...',
|
||||||
accelerator: 'CmdOrCtrl+N',
|
accelerator: 'CmdOrCtrl+N',
|
||||||
click: async () => {
|
click: () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openSeedDirectory()
|
dialog.openSeedDirectory()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open Torrent File...',
|
label: 'Open Torrent File...',
|
||||||
accelerator: 'CmdOrCtrl+O',
|
accelerator: 'CmdOrCtrl+O',
|
||||||
click: async () => {
|
click: () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openTorrentFile()
|
dialog.openTorrentFile()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open Torrent Address...',
|
label: 'Open Torrent Address...',
|
||||||
accelerator: 'CmdOrCtrl+U',
|
accelerator: 'CmdOrCtrl+U',
|
||||||
click: async () => {
|
click: () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openTorrentAddress()
|
dialog.openTorrentAddress()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -294,18 +303,21 @@ function getMenuTemplate () {
|
|||||||
{
|
{
|
||||||
label: 'Learn more about ' + config.APP_NAME,
|
label: 'Learn more about ' + config.APP_NAME,
|
||||||
click: () => {
|
click: () => {
|
||||||
|
const shell = require('./shell')
|
||||||
shell.openExternal(config.HOME_PAGE_URL)
|
shell.openExternal(config.HOME_PAGE_URL)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Release Notes',
|
label: 'Release Notes',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
const shell = require('./shell')
|
||||||
shell.openExternal(config.GITHUB_URL_RELEASES)
|
shell.openExternal(config.GITHUB_URL_RELEASES)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Contribute on GitHub',
|
label: 'Contribute on GitHub',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
const shell = require('./shell')
|
||||||
shell.openExternal(config.GITHUB_URL)
|
shell.openExternal(config.GITHUB_URL)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -315,18 +327,21 @@ function getMenuTemplate () {
|
|||||||
{
|
{
|
||||||
label: 'Report an Issue...',
|
label: 'Report an Issue...',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
const shell = require('./shell')
|
||||||
shell.openExternal(config.GITHUB_URL_ISSUES)
|
shell.openExternal(config.GITHUB_URL_ISSUES)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Follow us on Twitter',
|
label: 'Follow us on Twitter',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
const shell = require('./shell')
|
||||||
shell.openExternal(config.TWITTER_PAGE_URL)
|
shell.openExternal(config.TWITTER_PAGE_URL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
// WebTorrent menu (Mac)
|
// WebTorrent menu (Mac)
|
||||||
template.unshift({
|
template.unshift({
|
||||||
@@ -411,8 +426,8 @@ function getMenuTemplate () {
|
|||||||
// File menu (Windows, Linux)
|
// File menu (Windows, Linux)
|
||||||
template[0].submenu.unshift({
|
template[0].submenu.unshift({
|
||||||
label: 'Create New Torrent from File...',
|
label: 'Create New Torrent from File...',
|
||||||
click: async () => {
|
click: () => {
|
||||||
const dialog = await import('./dialog')
|
const dialog = require('./dialog')
|
||||||
dialog.openSeedFile()
|
dialog.openSeedFile()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -445,26 +460,9 @@ function getMenuTemplate () {
|
|||||||
// File menu (Linux)
|
// File menu (Linux)
|
||||||
template[0].submenu.push({
|
template[0].submenu.push({
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
click: () => electron.app.quit()
|
click: () => app.quit()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
export { init }
|
|
||||||
export { togglePlaybackControls }
|
|
||||||
export { setWindowFocus }
|
|
||||||
export { setAllowNav }
|
|
||||||
export { onPlayerUpdate }
|
|
||||||
export { onToggleAlwaysOnTop }
|
|
||||||
export { onToggleFullScreen }
|
|
||||||
export default {
|
|
||||||
init,
|
|
||||||
togglePlaybackControls,
|
|
||||||
setWindowFocus,
|
|
||||||
setAllowNav,
|
|
||||||
onPlayerUpdate,
|
|
||||||
onToggleAlwaysOnTop,
|
|
||||||
onToggleFullScreen
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { powerSaveBlocker } from 'electron'
|
module.exports = {
|
||||||
import log from './log.js'
|
enable,
|
||||||
|
disable
|
||||||
|
}
|
||||||
|
|
||||||
|
const { powerSaveBlocker } = require('electron')
|
||||||
|
const log = require('./log')
|
||||||
|
|
||||||
let blockId = 0
|
let blockId = 0
|
||||||
|
|
||||||
@@ -7,7 +12,7 @@ let blockId = 0
|
|||||||
* Block the system from entering low-power (sleep) mode or turning off the
|
* Block the system from entering low-power (sleep) mode or turning off the
|
||||||
* display.
|
* display.
|
||||||
*/
|
*/
|
||||||
export function enable () {
|
function enable () {
|
||||||
if (powerSaveBlocker.isStarted(blockId)) {
|
if (powerSaveBlocker.isStarted(blockId)) {
|
||||||
// If a power saver block already exists, do nothing.
|
// If a power saver block already exists, do nothing.
|
||||||
return
|
return
|
||||||
@@ -19,7 +24,7 @@ export function enable () {
|
|||||||
/**
|
/**
|
||||||
* Stop blocking the system from entering low-power mode.
|
* Stop blocking the system from entering low-power mode.
|
||||||
*/
|
*/
|
||||||
export function disable () {
|
function disable () {
|
||||||
if (!powerSaveBlocker.isStarted(blockId)) {
|
if (!powerSaveBlocker.isStarted(blockId)) {
|
||||||
// If a power saver block does not exist, do nothing.
|
// If a power saver block does not exist, do nothing.
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import log from './log.js'
|
openExternal,
|
||||||
|
openPath,
|
||||||
|
showItemInFolder,
|
||||||
|
moveItemToTrash
|
||||||
|
}
|
||||||
|
|
||||||
const { shell } = electron
|
const { shell } = require('electron')
|
||||||
|
const log = require('./log')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the given external protocol URL in the desktop’s default manner.
|
* Open the given external protocol URL in the desktop’s default manner.
|
||||||
@@ -14,6 +19,7 @@ function openExternal (url) {
|
|||||||
/**
|
/**
|
||||||
* Open the given file in the desktop’s default manner.
|
* Open the given file in the desktop’s default manner.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function openPath (path) {
|
function openPath (path) {
|
||||||
log(`openPath: ${path}`)
|
log(`openPath: ${path}`)
|
||||||
shell.openPath(path)
|
shell.openPath(path)
|
||||||
@@ -34,10 +40,3 @@ function moveItemToTrash (path) {
|
|||||||
log(`moveItemToTrash: ${path}`)
|
log(`moveItemToTrash: ${path}`)
|
||||||
shell.trashItem(path)
|
shell.trashItem(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
openExternal,
|
|
||||||
openPath,
|
|
||||||
showItemInFolder,
|
|
||||||
moveItemToTrash
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
import { globalShortcut } from 'electron'
|
module.exports = {
|
||||||
import * as windows from './windows'
|
disable,
|
||||||
|
enable
|
||||||
|
}
|
||||||
|
|
||||||
export function enable () {
|
const { globalShortcut } = require('electron')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
|
function enable () {
|
||||||
// Register play/pause media key, available on some keyboards.
|
// Register play/pause media key, available on some keyboards.
|
||||||
globalShortcut.register(
|
globalShortcut.register(
|
||||||
'MediaPlayPause',
|
'MediaPlayPause',
|
||||||
@@ -17,7 +22,7 @@ export function enable () {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function disable () {
|
function disable () {
|
||||||
// Return the media key to the OS, so other apps can use it.
|
// Return the media key to the OS, so other apps can use it.
|
||||||
globalShortcut.unregister('MediaPlayPause')
|
globalShortcut.unregister('MediaPlayPause')
|
||||||
globalShortcut.unregister('MediaNextTrack')
|
globalShortcut.unregister('MediaNextTrack')
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import { app } from 'electron'
|
module.exports = {
|
||||||
import path from 'path'
|
handleEvent
|
||||||
import { spawn } from 'child_process'
|
}
|
||||||
import handlers from './handlers.js'
|
|
||||||
|
const { app } = require('electron')
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
const spawn = require('child_process').spawn
|
||||||
|
|
||||||
|
const handlers = require('./handlers')
|
||||||
|
|
||||||
const EXE_NAME = path.basename(process.execPath)
|
const EXE_NAME = path.basename(process.execPath)
|
||||||
const UPDATE_EXE = path.join(process.execPath, '..', '..', 'Update.exe')
|
const UPDATE_EXE = path.join(process.execPath, '..', '..', 'Update.exe')
|
||||||
|
|
||||||
const run = (args, done) => {
|
const run = (args, done) => {
|
||||||
spawn(UPDATE_EXE, args, { detached: true }).on('close', done)
|
spawn(UPDATE_EXE, args, { detached: true })
|
||||||
|
.on('close', done)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleEvent (cmd) {
|
function handleEvent (cmd) {
|
||||||
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
||||||
run([`--createShortcut=${EXE_NAME}`], app.quit)
|
run([`--createShortcut=${EXE_NAME}`], app.quit)
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import { APP_NAME } from '../config.js'
|
module.exports = {
|
||||||
import AutoLaunch from 'auto-launch'
|
install,
|
||||||
|
uninstall
|
||||||
|
}
|
||||||
|
|
||||||
|
const { APP_NAME } = require('../config')
|
||||||
|
const AutoLaunch = require('auto-launch')
|
||||||
|
|
||||||
const appLauncher = new AutoLaunch({
|
const appLauncher = new AutoLaunch({
|
||||||
name: APP_NAME,
|
name: APP_NAME,
|
||||||
isHidden: true
|
isHidden: true
|
||||||
})
|
})
|
||||||
|
|
||||||
export function install () {
|
function install () {
|
||||||
return appLauncher
|
return appLauncher
|
||||||
.isEnabled()
|
.isEnabled()
|
||||||
.then(enabled => {
|
.then(enabled => {
|
||||||
@@ -14,7 +19,7 @@ export function install () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uninstall () {
|
function uninstall () {
|
||||||
return appLauncher
|
return appLauncher
|
||||||
.isEnabled()
|
.isEnabled()
|
||||||
.then(enabled => {
|
.then(enabled => {
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
import path from 'path'
|
module.exports = {
|
||||||
import config from '../config.js'
|
disable,
|
||||||
import * as windows from './windows'
|
enable,
|
||||||
|
onPlayerPause,
|
||||||
|
onPlayerPlay,
|
||||||
|
onPlayerUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
const config = require('../config')
|
||||||
|
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
const PREV_ICON = path.join(config.STATIC_PATH, 'PreviousTrackThumbnailBarButton.png')
|
const PREV_ICON = path.join(config.STATIC_PATH, 'PreviousTrackThumbnailBarButton.png')
|
||||||
const PLAY_ICON = path.join(config.STATIC_PATH, 'PlayThumbnailBarButton.png')
|
const PLAY_ICON = path.join(config.STATIC_PATH, 'PlayThumbnailBarButton.png')
|
||||||
@@ -17,7 +32,7 @@ let buttons = []
|
|||||||
/**
|
/**
|
||||||
* Show the Windows thumbnail toolbar buttons.
|
* Show the Windows thumbnail toolbar buttons.
|
||||||
*/
|
*/
|
||||||
export function enable () {
|
function enable () {
|
||||||
buttons = [
|
buttons = [
|
||||||
{
|
{
|
||||||
tooltip: 'Previous Track',
|
tooltip: 'Previous Track',
|
||||||
@@ -41,26 +56,26 @@ export function enable () {
|
|||||||
/**
|
/**
|
||||||
* Hide the Windows thumbnail toolbar buttons.
|
* Hide the Windows thumbnail toolbar buttons.
|
||||||
*/
|
*/
|
||||||
export function disable () {
|
function disable () {
|
||||||
buttons = []
|
buttons = []
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onPlayerPause () {
|
function onPlayerPause () {
|
||||||
if (!isEnabled()) return
|
if (!isEnabled()) return
|
||||||
buttons[PLAY_PAUSE].tooltip = 'Play'
|
buttons[PLAY_PAUSE].tooltip = 'Play'
|
||||||
buttons[PLAY_PAUSE].icon = PLAY_ICON
|
buttons[PLAY_PAUSE].icon = PLAY_ICON
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onPlayerPlay () {
|
function onPlayerPlay () {
|
||||||
if (!isEnabled()) return
|
if (!isEnabled()) return
|
||||||
buttons[PLAY_PAUSE].tooltip = 'Pause'
|
buttons[PLAY_PAUSE].tooltip = 'Pause'
|
||||||
buttons[PLAY_PAUSE].icon = PAUSE_ICON
|
buttons[PLAY_PAUSE].icon = PAUSE_ICON
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onPlayerUpdate (state) {
|
function onPlayerUpdate (state) {
|
||||||
if (!isEnabled()) return
|
if (!isEnabled()) return
|
||||||
buttons[PREV].flags = [state.hasPrevious ? 'enabled' : 'disabled']
|
buttons[PREV].flags = [state.hasPrevious ? 'enabled' : 'disabled']
|
||||||
buttons[NEXT].flags = [state.hasNext ? 'enabled' : 'disabled']
|
buttons[NEXT].flags = [state.hasNext ? 'enabled' : 'disabled']
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
import { app, Tray, Menu } from 'electron'
|
module.exports = {
|
||||||
import config from '../config.js'
|
hasTray,
|
||||||
import * as windows from './windows'
|
init,
|
||||||
|
setWindowFocus
|
||||||
|
}
|
||||||
|
|
||||||
|
const { app, Tray, Menu } = require('electron')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
let tray
|
let tray
|
||||||
|
|
||||||
export function init () {
|
function init () {
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
initLinux()
|
initLinux()
|
||||||
}
|
}
|
||||||
@@ -17,11 +24,11 @@ export function init () {
|
|||||||
/**
|
/**
|
||||||
* Returns true if there a tray icon is active.
|
* Returns true if there a tray icon is active.
|
||||||
*/
|
*/
|
||||||
export function hasTray () {
|
function hasTray () {
|
||||||
return !!tray
|
return !!tray
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setWindowFocus (flag) {
|
function setWindowFocus (flag) {
|
||||||
if (!tray) return
|
if (!tray) return
|
||||||
updateTrayMenu()
|
updateTrayMenu()
|
||||||
}
|
}
|
||||||
@@ -39,8 +46,8 @@ function initWin32 () {
|
|||||||
/**
|
/**
|
||||||
* Check for libappindicator support before creating tray icon.
|
* Check for libappindicator support before creating tray icon.
|
||||||
*/
|
*/
|
||||||
async function checkLinuxTraySupport (cb) {
|
function checkLinuxTraySupport (cb) {
|
||||||
const cp = await import('child_process')
|
const cp = require('child_process')
|
||||||
|
|
||||||
// Check that libappindicator libraries are installed in system.
|
// Check that libappindicator libraries are installed in system.
|
||||||
cp.exec('ldconfig -p | grep libappindicator', (err, stdout) => {
|
cp.exec('ldconfig -p | grep libappindicator', (err, stdout) => {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import electron from '../../electron.cjs'
|
module.exports = {
|
||||||
import get from 'simple-get'
|
init
|
||||||
import config from '../config.js'
|
}
|
||||||
import log from './log.js'
|
|
||||||
import * as windows from './windows/index.js'
|
|
||||||
|
|
||||||
const { autoUpdater } = electron
|
const { autoUpdater } = require('electron')
|
||||||
|
const get = require('simple-get')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
const log = require('./log')
|
||||||
|
const windows = require('./windows')
|
||||||
|
|
||||||
const AUTO_UPDATE_URL = config.AUTO_UPDATE_URL +
|
const AUTO_UPDATE_URL = config.AUTO_UPDATE_URL +
|
||||||
'?version=' + config.APP_VERSION +
|
'?version=' + config.APP_VERSION +
|
||||||
@@ -19,8 +22,6 @@ function init () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { init }
|
|
||||||
|
|
||||||
// The Electron auto-updater does not support Linux yet, so manually check for
|
// The Electron auto-updater does not support Linux yet, so manually check for
|
||||||
// updates and show the user a modal notification.
|
// updates and show the user a modal notification.
|
||||||
function initLinux () {
|
function initLinux () {
|
||||||
@@ -48,7 +49,7 @@ function onResponse (err, res, data) {
|
|||||||
function initDarwinWin32 () {
|
function initDarwinWin32 () {
|
||||||
autoUpdater.on(
|
autoUpdater.on(
|
||||||
'error',
|
'error',
|
||||||
(err) => log(`Update error: ${err.message}`)
|
(err) => log.error(`Update error: ${err.message}`)
|
||||||
)
|
)
|
||||||
|
|
||||||
autoUpdater.on(
|
autoUpdater.on(
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { app } from 'electron'
|
module.exports = {
|
||||||
|
init
|
||||||
|
}
|
||||||
|
|
||||||
|
const { app } = require('electron')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user task menu to the app icon on right-click. (Windows)
|
* Add a user task menu to the app icon on right-click. (Windows)
|
||||||
*/
|
*/
|
||||||
export function init () {
|
function init () {
|
||||||
if (process.platform !== 'win32') return
|
if (process.platform !== 'win32') return
|
||||||
app.setUserTasks(getUserTasks())
|
app.setUserTasks(getUserTasks())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import config from '../../config.js'
|
const about = module.exports = {
|
||||||
import electron from '../../../electron.cjs'
|
|
||||||
import * as RemoteMain from '@electron/remote/main/index.js'
|
|
||||||
|
|
||||||
export const about = {
|
|
||||||
init,
|
init,
|
||||||
win: null
|
win: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
const { BrowserWindow } = require('electron')
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
if (about.win) {
|
if (about.win) {
|
||||||
return about.win.show()
|
return about.win.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
const win = about.win = new electron.BrowserWindow({
|
const win = about.win = new BrowserWindow({
|
||||||
backgroundColor: '#ECECEC',
|
backgroundColor: '#ECECEC',
|
||||||
center: true,
|
center: true,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
@@ -34,7 +33,8 @@ function init () {
|
|||||||
},
|
},
|
||||||
width: 300
|
width: 300
|
||||||
})
|
})
|
||||||
RemoteMain.enable(win.webContents)
|
require('@electron/remote/main').enable(win.webContents)
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_ABOUT)
|
win.loadURL(config.WINDOW_ABOUT)
|
||||||
|
|
||||||
win.once('ready-to-show', () => {
|
win.once('ready-to-show', () => {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export * from './about.js'
|
exports.about = require('./about')
|
||||||
export * from './main.js'
|
exports.main = require('./main')
|
||||||
export * from './webtorrent.js'
|
exports.webtorrent = require('./webtorrent')
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
import debounce from 'debounce'
|
const main = module.exports = {
|
||||||
import electron from '../../../electron.cjs'
|
|
||||||
import config from '../../config.js'
|
|
||||||
import log from '../log.js'
|
|
||||||
import menu from '../menu.js'
|
|
||||||
import * as RemoteMain from '@electron/remote/main/index.js'
|
|
||||||
|
|
||||||
const { app, BrowserWindow, screen } = electron
|
|
||||||
|
|
||||||
export const main = {
|
|
||||||
dispatch,
|
dispatch,
|
||||||
hide,
|
hide,
|
||||||
init,
|
init,
|
||||||
@@ -23,6 +14,13 @@ export const main = {
|
|||||||
win: null
|
win: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { app, BrowserWindow, screen } = require('electron')
|
||||||
|
const debounce = require('debounce')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
const log = require('../log')
|
||||||
|
const menu = require('../menu')
|
||||||
|
|
||||||
function init (state, options) {
|
function init (state, options) {
|
||||||
if (main.win) {
|
if (main.win) {
|
||||||
return main.win.show()
|
return main.win.show()
|
||||||
@@ -52,8 +50,8 @@ function init (state, options) {
|
|||||||
x: initialBounds.x,
|
x: initialBounds.x,
|
||||||
y: initialBounds.y
|
y: initialBounds.y
|
||||||
})
|
})
|
||||||
RemoteMain.enable(win.webContents)
|
require('@electron/remote/main').enable(win.webContents)
|
||||||
console.log(config.WINDOW_MAIN)
|
|
||||||
win.loadURL(config.WINDOW_MAIN)
|
win.loadURL(config.WINDOW_MAIN)
|
||||||
|
|
||||||
win.once('ready-to-show', () => {
|
win.once('ready-to-show', () => {
|
||||||
@@ -100,10 +98,10 @@ function init (state, options) {
|
|||||||
send('windowBoundsChanged', e.sender.getBounds())
|
send('windowBoundsChanged', e.sender.getBounds())
|
||||||
}, 1000))
|
}, 1000))
|
||||||
|
|
||||||
win.on('close', async e => {
|
win.on('close', e => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
const { hasTray } = await import('../tray.js')
|
const tray = require('../tray')
|
||||||
if (!hasTray()) {
|
if (!tray.hasTray()) {
|
||||||
app.quit()
|
app.quit()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import electron from '../../../electron.cjs'
|
const webtorrent = module.exports = {
|
||||||
import config from '../../config.js'
|
|
||||||
import * as RemoteMain from '@electron/remote/main/index.js'
|
|
||||||
|
|
||||||
export const webtorrent = {
|
|
||||||
init,
|
init,
|
||||||
send,
|
send,
|
||||||
show,
|
show,
|
||||||
@@ -10,8 +6,12 @@ export const webtorrent = {
|
|||||||
win: null
|
win: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { app, BrowserWindow } = require('electron')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
const win = webtorrent.win = new electron.BrowserWindow({
|
const win = webtorrent.win = new BrowserWindow({
|
||||||
backgroundColor: '#1E1E1E',
|
backgroundColor: '#1E1E1E',
|
||||||
center: true,
|
center: true,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
@@ -33,11 +33,13 @@ function init () {
|
|||||||
},
|
},
|
||||||
width: 150
|
width: 150
|
||||||
})
|
})
|
||||||
RemoteMain.enable(win.webContents)
|
require('@electron/remote/main').enable(win.webContents)
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_WEBTORRENT)
|
win.loadURL(config.WINDOW_WEBTORRENT)
|
||||||
|
|
||||||
// Prevent killing the WebTorrent process
|
// Prevent killing the WebTorrent process
|
||||||
win.on('close', e => {
|
win.on('close', e => {
|
||||||
if (electron.app.isQuitting) {
|
if (app.isQuitting) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import { dispatcher } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class CreateTorrentErrorPage extends React.Component {
|
const { dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class CreateTorrentErrorPage extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<div className='create-torrent'>
|
<div className='create-torrent'>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import ModalOKCancel from './modal-ok-cancel.js'
|
|
||||||
import { dispatch, dispatcher } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class DeleteAllTorrentsModal extends React.Component {
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class DeleteAllTorrentsModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const { state: { modal: { deleteData } } } = this.props
|
const { state: { modal: { deleteData } } } = this.props
|
||||||
const message = deleteData
|
const message = deleteData
|
||||||
@@ -15,6 +16,7 @@ export default class DeleteAllTorrentsModal extends React.Component {
|
|||||||
<p><strong>{message}</strong></p>
|
<p><strong>{message}</strong></p>
|
||||||
<ModalOKCancel
|
<ModalOKCancel
|
||||||
cancelText='CANCEL'
|
cancelText='CANCEL'
|
||||||
|
color='secondary'
|
||||||
onCancel={dispatcher('exitModal')}
|
onCancel={dispatcher('exitModal')}
|
||||||
okText={buttonText}
|
okText={buttonText}
|
||||||
onOK={handleRemove}
|
onOK={handleRemove}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import { dispatcher } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class Header extends React.Component {
|
const { dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
class Header extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const loc = this.props.state.location
|
const loc = this.props.state.location
|
||||||
return (
|
return (
|
||||||
@@ -10,6 +11,7 @@ export default class Header extends React.Component {
|
|||||||
onMouseMove={dispatcher('mediaMouseMoved')}
|
onMouseMove={dispatcher('mediaMouseMoved')}
|
||||||
onMouseEnter={dispatcher('mediaControlsMouseEnter')}
|
onMouseEnter={dispatcher('mediaControlsMouseEnter')}
|
||||||
onMouseLeave={dispatcher('mediaControlsMouseLeave')}
|
onMouseLeave={dispatcher('mediaControlsMouseLeave')}
|
||||||
|
role='navigation'
|
||||||
>
|
>
|
||||||
{this.getTitle()}
|
{this.getTitle()}
|
||||||
<div className='nav left float-left'>
|
<div className='nav left float-left'>
|
||||||
@@ -17,6 +19,9 @@ export default class Header extends React.Component {
|
|||||||
className={'icon back ' + (loc.hasBack() ? '' : 'disabled')}
|
className={'icon back ' + (loc.hasBack() ? '' : 'disabled')}
|
||||||
title='Back'
|
title='Back'
|
||||||
onClick={dispatcher('back')}
|
onClick={dispatcher('back')}
|
||||||
|
role='button'
|
||||||
|
aria-disabled={!loc.hasBack()}
|
||||||
|
aria-label='Back'
|
||||||
>
|
>
|
||||||
chevron_left
|
chevron_left
|
||||||
</i>
|
</i>
|
||||||
@@ -24,6 +29,9 @@ export default class Header extends React.Component {
|
|||||||
className={'icon forward ' + (loc.hasForward() ? '' : 'disabled')}
|
className={'icon forward ' + (loc.hasForward() ? '' : 'disabled')}
|
||||||
title='Forward'
|
title='Forward'
|
||||||
onClick={dispatcher('forward')}
|
onClick={dispatcher('forward')}
|
||||||
|
role='button'
|
||||||
|
aria-disabled={!loc.hasForward()}
|
||||||
|
aria-label='Forward'
|
||||||
>
|
>
|
||||||
chevron_right
|
chevron_right
|
||||||
</i>
|
</i>
|
||||||
@@ -49,9 +57,12 @@ export default class Header extends React.Component {
|
|||||||
className='icon add'
|
className='icon add'
|
||||||
title='Add torrent'
|
title='Add torrent'
|
||||||
onClick={dispatcher('openFiles')}
|
onClick={dispatcher('openFiles')}
|
||||||
|
role='button'
|
||||||
>
|
>
|
||||||
add
|
add
|
||||||
</i>
|
</i>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = Header
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import PropTypes from 'prop-types'
|
const PropTypes = require('prop-types')
|
||||||
import * as colors from 'material-ui/styles/colors'
|
|
||||||
|
|
||||||
export default class Heading extends React.Component {
|
const grey = require('@material-ui/core/colors/grey').default
|
||||||
|
|
||||||
|
class Heading extends React.Component {
|
||||||
static get propTypes () {
|
static get propTypes () {
|
||||||
return {
|
return {
|
||||||
level: PropTypes.number
|
level: PropTypes.number
|
||||||
@@ -18,7 +19,7 @@ export default class Heading extends React.Component {
|
|||||||
render () {
|
render () {
|
||||||
const HeadingTag = 'h' + this.props.level
|
const HeadingTag = 'h' + this.props.level
|
||||||
const style = {
|
const style = {
|
||||||
color: colors.grey100,
|
color: grey['100'],
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
marginBottom: 15,
|
marginBottom: 15,
|
||||||
marginTop: 30
|
marginTop: 30
|
||||||
@@ -30,3 +31,5 @@ export default class Heading extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = Heading
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import flatButton from 'material-ui/FlatButton'
|
const Button = require('@material-ui/core/Button').default
|
||||||
import raisedButton from 'material-ui/RaisedButton'
|
|
||||||
|
|
||||||
const FlatButton = flatButton.default
|
module.exports = class ModalOKCancel extends React.Component {
|
||||||
const RaisedButton = raisedButton.default
|
|
||||||
export default class ModalOKCancel extends React.Component {
|
|
||||||
render () {
|
render () {
|
||||||
const cancelStyle = { marginRight: 10, color: 'black' }
|
const cancelStyle = { marginRight: 10, color: 'black' }
|
||||||
const { cancelText, onCancel, okText, onOK } = this.props
|
const { cancelText, color = 'primary', onCancel, okText, onOK } = this.props
|
||||||
return (
|
return (
|
||||||
<div className='float-right'>
|
<div className='float-right'>
|
||||||
<FlatButton
|
<Button
|
||||||
className='control cancel'
|
className='control cancel'
|
||||||
style={cancelStyle}
|
|
||||||
label={cancelText}
|
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
/>
|
style={cancelStyle}
|
||||||
<RaisedButton
|
>
|
||||||
className='control ok'
|
{cancelText}
|
||||||
primary
|
</Button>
|
||||||
label={okText}
|
<Button
|
||||||
onClick={onOK}
|
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
className='control ok'
|
||||||
|
onClick={onOK}
|
||||||
|
color={color}
|
||||||
|
variant='contained'
|
||||||
|
>
|
||||||
|
{okText}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import textField from 'material-ui/TextField'
|
const TextField = require('@material-ui/core/TextField').default
|
||||||
import electron from 'electron'
|
const { clipboard } = require('electron')
|
||||||
import ModalOKCancel from './modal-ok-cancel.js'
|
|
||||||
import { dispatch, dispatcher } from '../lib/dispatcher.js'
|
|
||||||
import { isMagnetLink } from '../lib/torrent-player.js'
|
|
||||||
|
|
||||||
const TextField = textField.default
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
const { clipboard } = electron
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
const { isMagnetLink } = require('../lib/torrent-player')
|
||||||
|
|
||||||
export default class OpenTorrentAddressModal extends React.Component {
|
module.exports = class OpenTorrentAddressModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<div className='open-torrent-address-modal'>
|
<div className='open-torrent-address-modal'>
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import path from 'path'
|
const path = require('path')
|
||||||
import * as colors from 'material-ui/styles/colors'
|
|
||||||
import remote from '@electron/remote'
|
const remote = require('@electron/remote')
|
||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import PropTypes from 'prop-types'
|
const PropTypes = require('prop-types')
|
||||||
import raisedButton from 'material-ui/RaisedButton'
|
|
||||||
import textField from 'material-ui/TextField'
|
const Button = require('@material-ui/core/Button').default
|
||||||
|
const TextField = require('@material-ui/core/TextField').default
|
||||||
|
const grey = require('@material-ui/core/colors/grey').default
|
||||||
|
|
||||||
const RaisedButton = raisedButton.default
|
|
||||||
const TextField = textField.default
|
|
||||||
// Lets you pick a file or directory.
|
// Lets you pick a file or directory.
|
||||||
// Uses the system Open File dialog.
|
// Uses the system Open File dialog.
|
||||||
// You can't edit the text field directly.
|
// You can't edit the text field directly.
|
||||||
export default class PathSelector extends React.Component {
|
class PathSelector extends React.Component {
|
||||||
static propTypes () {
|
static propTypes () {
|
||||||
return {
|
return {
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
@@ -53,10 +53,8 @@ export default class PathSelector extends React.Component {
|
|||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
whiteSpace: 'nowrap'
|
whiteSpace: 'nowrap'
|
||||||
}
|
}
|
||||||
const textareaStyle = {
|
|
||||||
color: colors.grey50
|
|
||||||
}
|
|
||||||
const textFieldStyle = {
|
const textFieldStyle = {
|
||||||
|
color: grey['50'],
|
||||||
flex: '1'
|
flex: '1'
|
||||||
}
|
}
|
||||||
const text = this.props.value || ''
|
const text = this.props.value || ''
|
||||||
@@ -70,14 +68,23 @@ export default class PathSelector extends React.Component {
|
|||||||
{this.props.title}:
|
{this.props.title}:
|
||||||
</div>
|
</div>
|
||||||
<TextField
|
<TextField
|
||||||
className='control' disabled id={id} value={text}
|
className='control'
|
||||||
inputStyle={textareaStyle} style={textFieldStyle}
|
disabled
|
||||||
|
id={id}
|
||||||
|
style={textFieldStyle}
|
||||||
|
value={text}
|
||||||
/>
|
/>
|
||||||
<RaisedButton
|
<Button
|
||||||
className='control' label='Change' onClick={this.handleClick}
|
className='control'
|
||||||
|
onClick={this.handleClick}
|
||||||
style={buttonStyle}
|
style={buttonStyle}
|
||||||
/>
|
variant='contained'
|
||||||
|
>
|
||||||
|
Change
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = PathSelector
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import ModalOKCancel from './modal-ok-cancel.js'
|
|
||||||
import { dispatch, dispatcher } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class RemoveTorrentModal extends React.Component {
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class RemoveTorrentModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
const message = state.modal.deleteData
|
const message = state.modal.deleteData
|
||||||
@@ -15,6 +16,7 @@ export default class RemoveTorrentModal extends React.Component {
|
|||||||
<p><strong>{message}</strong></p>
|
<p><strong>{message}</strong></p>
|
||||||
<ModalOKCancel
|
<ModalOKCancel
|
||||||
cancelText='CANCEL'
|
cancelText='CANCEL'
|
||||||
|
color='secondary'
|
||||||
onCancel={dispatcher('exitModal')}
|
onCancel={dispatcher('exitModal')}
|
||||||
okText={buttonText}
|
okText={buttonText}
|
||||||
onOK={handleRemove}
|
onOK={handleRemove}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import PropTypes from 'prop-types'
|
const PropTypes = require('prop-types')
|
||||||
import raisedButton from 'material-ui/RaisedButton'
|
|
||||||
|
|
||||||
const RaisedButton = raisedButton.default
|
const Button = require('@material-ui/core/Button').default
|
||||||
|
|
||||||
export default class ShowMore extends React.Component {
|
class ShowMore extends React.Component {
|
||||||
static get propTypes () {
|
static get propTypes () {
|
||||||
return {
|
return {
|
||||||
defaultExpanded: PropTypes.bool,
|
defaultExpanded: PropTypes.bool,
|
||||||
@@ -22,9 +21,11 @@ export default class ShowMore extends React.Component {
|
|||||||
|
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
expanded: !!this.props.defaultExpanded
|
expanded: !!this.props.defaultExpanded
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleClick = this.handleClick.bind(this)
|
this.handleClick = this.handleClick.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,12 +42,16 @@ export default class ShowMore extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className='show-more' style={this.props.style}>
|
<div className='show-more' style={this.props.style}>
|
||||||
{this.state.expanded ? this.props.children : null}
|
{this.state.expanded ? this.props.children : null}
|
||||||
<RaisedButton
|
<Button
|
||||||
className='control'
|
className='control'
|
||||||
onClick={this.handleClick}
|
onClick={this.handleClick}
|
||||||
label={label}
|
variant='contained'
|
||||||
/>
|
>
|
||||||
|
{label}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = ShowMore
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import { shell } from 'electron'
|
const { shell } = require('electron')
|
||||||
import ModalOKCancel from './modal-ok-cancel.js'
|
|
||||||
import { dispatcher } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class UnsupportedMediaModal extends React.Component {
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
|
const { dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class UnsupportedMediaModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
const err = state.modal.error
|
const err = state.modal.error
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import { shell } from 'electron'
|
const { shell } = require('electron')
|
||||||
import ModalOKCancel from './modal-ok-cancel.js'
|
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class UpdateAvailableModal extends React.Component {
|
const ModalOKCancel = require('./modal-ok-cancel')
|
||||||
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class UpdateAvailableModal extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { dispatch } from '../lib/dispatcher.js'
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
|
||||||
export default class AudioTracksController {
|
module.exports = class AudioTracksController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
const { ipcRenderer } = require('electron')
|
||||||
|
|
||||||
export default class FolderWatcherController {
|
module.exports = class FolderWatcherController {
|
||||||
start () {
|
start () {
|
||||||
console.log('-- IPC: start folder watcher')
|
console.log('-- IPC: start folder watcher')
|
||||||
ipcRenderer.send('startFolderWatcher')
|
ipcRenderer.send('startFolderWatcher')
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
const { ipcRenderer } = require('electron')
|
||||||
import telemetry from '../lib/telemetry.js'
|
const telemetry = require('../lib/telemetry')
|
||||||
import Playlist from '../lib/playlist.js'
|
const Playlist = require('../lib/playlist')
|
||||||
|
|
||||||
export default class MediaController {
|
// Controls local play back: the <video>/<audio> tag and VLC
|
||||||
|
// Does not control remote casting (Chromecast etc)
|
||||||
|
module.exports = class MediaController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,19 @@
|
|||||||
import { ipcRenderer } from 'electron'
|
const { ipcRenderer } = require('electron')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import Cast from '../lib/cast.js'
|
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
const Cast = require('../lib/cast')
|
||||||
import telemetry from '../lib/telemetry.js'
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
import { UnplayableFileError, UnplayableTorrentError } from '../lib/errors.js'
|
const telemetry = require('../lib/telemetry')
|
||||||
import sound from '../lib/sound.js'
|
const { UnplayableFileError, UnplayableTorrentError } = require('../lib/errors')
|
||||||
import TorrentPlayer from '../lib/torrent-player.js'
|
const sound = require('../lib/sound')
|
||||||
import TorrentSummary from '../lib/torrent-summary.js'
|
const TorrentPlayer = require('../lib/torrent-player')
|
||||||
import Playlist from '../lib/playlist.js'
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
import State from '../lib/state.js'
|
const Playlist = require('../lib/playlist')
|
||||||
// Checks whether we are connected and already casting
|
const State = require('../lib/state')
|
||||||
// Returns false if we not casting (state.playing.location === 'local')
|
|
||||||
// or if we're trying to connect but haven't yet ('chromecast-pending', etc)
|
// Controls playback of torrents and files within torrents
|
||||||
function isCasting (state) {
|
// both local (<video>,<audio>,external player) and remote (cast)
|
||||||
return state.playing.location === 'chromecast' ||
|
module.exports = class PlaybackController {
|
||||||
state.playing.location === 'airplay' ||
|
|
||||||
state.playing.location === 'dlna'
|
|
||||||
}
|
|
||||||
function restoreBounds (state) {
|
|
||||||
ipcRenderer.send('setAspectRatio', 0)
|
|
||||||
if (state.window.bounds) {
|
|
||||||
ipcRenderer.send('setBounds', state.window.bounds, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default class PlaybackController {
|
|
||||||
constructor (state, config, update) {
|
constructor (state, config, update) {
|
||||||
this.state = state
|
this.state = state
|
||||||
this.config = config
|
this.config = config
|
||||||
@@ -36,10 +26,12 @@ export default class PlaybackController {
|
|||||||
// * If no file index is provided, restore the most recently viewed file or autoplay the first
|
// * If no file index is provided, restore the most recently viewed file or autoplay the first
|
||||||
playFile (infoHash, index /* optional */) {
|
playFile (infoHash, index /* optional */) {
|
||||||
this.pauseActiveTorrents(infoHash)
|
this.pauseActiveTorrents(infoHash)
|
||||||
|
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (state.location.url() === 'player') {
|
if (state.location.url() === 'player') {
|
||||||
this.updatePlayer(infoHash, index, false, (err) => {
|
this.updatePlayer(infoHash, index, false, (err) => {
|
||||||
if (err) { dispatch('error', err) } else { this.play() }
|
if (err) dispatch('error', err)
|
||||||
|
else this.play()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let initialized = false
|
let initialized = false
|
||||||
@@ -47,10 +39,13 @@ export default class PlaybackController {
|
|||||||
url: 'player',
|
url: 'player',
|
||||||
setup: (cb) => {
|
setup: (cb) => {
|
||||||
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
||||||
|
|
||||||
if (index === undefined || initialized) index = torrentSummary.mostRecentFileIndex
|
if (index === undefined || initialized) index = torrentSummary.mostRecentFileIndex
|
||||||
if (index === undefined) index = torrentSummary.files.findIndex(TorrentPlayer.isPlayable)
|
if (index === undefined) index = torrentSummary.files.findIndex(TorrentPlayer.isPlayable)
|
||||||
if (index === undefined) return cb(new UnplayableTorrentError())
|
if (index === undefined) return cb(new UnplayableTorrentError())
|
||||||
|
|
||||||
initialized = true
|
initialized = true
|
||||||
|
|
||||||
this.openPlayer(infoHash, index, (err) => {
|
this.openPlayer(infoHash, index, (err) => {
|
||||||
if (!err) this.play()
|
if (!err) this.play()
|
||||||
cb(err)
|
cb(err)
|
||||||
@@ -58,7 +53,7 @@ export default class PlaybackController {
|
|||||||
},
|
},
|
||||||
destroy: () => this.closePlayer()
|
destroy: () => this.closePlayer()
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err) { dispatch('error', err) }
|
if (err) dispatch('error', err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +61,9 @@ export default class PlaybackController {
|
|||||||
// Open a file in OS default app.
|
// Open a file in OS default app.
|
||||||
openPath (infoHash, index) {
|
openPath (infoHash, index) {
|
||||||
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
const filePath = path.join(torrentSummary.path, torrentSummary.files[index].path)
|
const filePath = path.join(
|
||||||
|
torrentSummary.path,
|
||||||
|
torrentSummary.files[index].path)
|
||||||
ipcRenderer.send('openPath', filePath)
|
ipcRenderer.send('openPath', filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,21 +71,27 @@ export default class PlaybackController {
|
|||||||
playPause () {
|
playPause () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (state.location.url() !== 'player') return
|
if (state.location.url() !== 'player') return
|
||||||
|
|
||||||
// force rerendering if window is hidden,
|
// force rerendering if window is hidden,
|
||||||
// in order to bypass `raf` and play/pause media immediately
|
// in order to bypass `raf` and play/pause media immediately
|
||||||
const mediaTag = document.querySelector('video,audio')
|
const mediaTag = document.querySelector('video,audio')
|
||||||
if (!state.window.isVisible && mediaTag) {
|
if (!state.window.isVisible && mediaTag) {
|
||||||
if (state.playing.isPaused) { mediaTag.play() } else { mediaTag.pause() }
|
if (state.playing.isPaused) mediaTag.play()
|
||||||
|
else mediaTag.pause()
|
||||||
}
|
}
|
||||||
if (state.playing.isPaused) { this.play() } else { this.pause() }
|
|
||||||
|
if (state.playing.isPaused) this.play()
|
||||||
|
else this.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
pauseActiveTorrents (infoHash) {
|
pauseActiveTorrents (infoHash) {
|
||||||
// Playback Priority: pause all active torrents if needed.
|
// Playback Priority: pause all active torrents if needed.
|
||||||
if (!this.state.saved.prefs.highestPlaybackPriority) return
|
if (!this.state.saved.prefs.highestPlaybackPriority) return
|
||||||
|
|
||||||
// Do not pause active torrents if playing a fully downloaded torrent.
|
// Do not pause active torrents if playing a fully downloaded torrent.
|
||||||
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
if (torrentSummary.status === 'seeding') return
|
if (torrentSummary.status === 'seeding') return
|
||||||
|
|
||||||
dispatch('prioritizeTorrent', infoHash)
|
dispatch('prioritizeTorrent', infoHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,9 +99,11 @@ export default class PlaybackController {
|
|||||||
nextTrack () {
|
nextTrack () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (Playlist.hasNext(state) && state.playing.location !== 'external') {
|
if (Playlist.hasNext(state) && state.playing.location !== 'external') {
|
||||||
this.updatePlayer(state.playing.infoHash, Playlist.getNextIndex(state), false, (err) => {
|
this.updatePlayer(
|
||||||
if (err) { dispatch('error', err) } else { this.play() }
|
state.playing.infoHash, Playlist.getNextIndex(state), false, (err) => {
|
||||||
})
|
if (err) dispatch('error', err)
|
||||||
|
else this.play()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,9 +111,11 @@ export default class PlaybackController {
|
|||||||
previousTrack () {
|
previousTrack () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (Playlist.hasPrevious(state) && state.playing.location !== 'external') {
|
if (Playlist.hasPrevious(state) && state.playing.location !== 'external') {
|
||||||
this.updatePlayer(state.playing.infoHash, Playlist.getPreviousIndex(state), false, (err) => {
|
this.updatePlayer(
|
||||||
if (err) { dispatch('error', err) } else { this.play() }
|
state.playing.infoHash, Playlist.getPreviousIndex(state), false, (err) => {
|
||||||
})
|
if (err) dispatch('error', err)
|
||||||
|
else this.play()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +152,8 @@ export default class PlaybackController {
|
|||||||
console.error('Tried to skip to a non-finite time ' + time)
|
console.error('Tried to skip to a non-finite time ' + time)
|
||||||
return console.trace()
|
return console.trace()
|
||||||
}
|
}
|
||||||
if (isCasting(this.state)) { Cast.seek(time) } else { this.state.playing.jumpToTime = time }
|
if (isCasting(this.state)) Cast.seek(time)
|
||||||
|
else this.state.playing.jumpToTime = time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show video preview
|
// Show video preview
|
||||||
@@ -197,6 +205,7 @@ export default class PlaybackController {
|
|||||||
setVolume (volume) {
|
setVolume (volume) {
|
||||||
// check if its in [0.0 - 1.0] range
|
// check if its in [0.0 - 1.0] range
|
||||||
volume = Math.max(0, Math.min(1, volume))
|
volume = Math.max(0, Math.min(1, volume))
|
||||||
|
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (isCasting(state)) {
|
if (isCasting(state)) {
|
||||||
Cast.setVolume(volume)
|
Cast.setVolume(volume)
|
||||||
@@ -213,6 +222,7 @@ export default class PlaybackController {
|
|||||||
showOrHidePlayerControls () {
|
showOrHidePlayerControls () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
const hideControls = state.shouldHidePlayerControls()
|
const hideControls = state.shouldHidePlayerControls()
|
||||||
|
|
||||||
if (hideControls !== state.playing.hideControls) {
|
if (hideControls !== state.playing.hideControls) {
|
||||||
state.playing.hideControls = hideControls
|
state.playing.hideControls = hideControls
|
||||||
return true
|
return true
|
||||||
@@ -224,10 +234,13 @@ export default class PlaybackController {
|
|||||||
openPlayer (infoHash, index, cb) {
|
openPlayer (infoHash, index, cb) {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
||||||
|
|
||||||
state.playing.infoHash = torrentSummary.infoHash
|
state.playing.infoHash = torrentSummary.infoHash
|
||||||
state.playing.isReady = false
|
state.playing.isReady = false
|
||||||
|
|
||||||
// update UI to show pending playback
|
// update UI to show pending playback
|
||||||
sound.play('PLAY')
|
sound.play('PLAY')
|
||||||
|
|
||||||
this.startServer(torrentSummary)
|
this.startServer(torrentSummary)
|
||||||
ipcRenderer.send('onPlayerOpen')
|
ipcRenderer.send('onPlayerOpen')
|
||||||
this.updatePlayer(infoHash, index, true, cb)
|
this.updatePlayer(infoHash, index, true, cb)
|
||||||
@@ -236,12 +249,15 @@ export default class PlaybackController {
|
|||||||
// Starts WebTorrent server for media streaming
|
// Starts WebTorrent server for media streaming
|
||||||
startServer (torrentSummary) {
|
startServer (torrentSummary) {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
|
|
||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
dispatch('startTorrentingSummary', torrentSummary.torrentKey)
|
dispatch('startTorrentingSummary', torrentSummary.torrentKey)
|
||||||
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash, () => onTorrentReady())
|
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash,
|
||||||
|
() => onTorrentReady())
|
||||||
} else {
|
} else {
|
||||||
onTorrentReady()
|
onTorrentReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTorrentReady () {
|
function onTorrentReady () {
|
||||||
ipcRenderer.send('wt-start-server', torrentSummary.infoHash)
|
ipcRenderer.send('wt-start-server', torrentSummary.infoHash)
|
||||||
ipcRenderer.once('wt-server-running', () => { state.playing.isReady = true })
|
ipcRenderer.once('wt-server-running', () => { state.playing.isReady = true })
|
||||||
@@ -251,13 +267,17 @@ export default class PlaybackController {
|
|||||||
// Called each time the current file changes
|
// Called each time the current file changes
|
||||||
updatePlayer (infoHash, index, resume, cb) {
|
updatePlayer (infoHash, index, resume, cb) {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
|
|
||||||
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(state, infoHash)
|
||||||
const fileSummary = torrentSummary.files[index]
|
const fileSummary = torrentSummary.files[index]
|
||||||
|
|
||||||
if (!TorrentPlayer.isPlayable(fileSummary)) {
|
if (!TorrentPlayer.isPlayable(fileSummary)) {
|
||||||
torrentSummary.mostRecentFileIndex = undefined
|
torrentSummary.mostRecentFileIndex = undefined
|
||||||
return cb(new UnplayableFileError())
|
return cb(new UnplayableFileError())
|
||||||
}
|
}
|
||||||
|
|
||||||
torrentSummary.mostRecentFileIndex = index
|
torrentSummary.mostRecentFileIndex = index
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
state.playing.infoHash = infoHash
|
state.playing.infoHash = infoHash
|
||||||
state.playing.fileIndex = index
|
state.playing.fileIndex = index
|
||||||
@@ -267,7 +287,8 @@ export default class PlaybackController {
|
|||||||
: TorrentPlayer.isAudio(fileSummary)
|
: TorrentPlayer.isAudio(fileSummary)
|
||||||
? 'audio'
|
? 'audio'
|
||||||
: 'other'
|
: 'other'
|
||||||
// pick up where we left off
|
|
||||||
|
// pick up where we left off
|
||||||
let jumpToTime = 0
|
let jumpToTime = 0
|
||||||
if (resume && fileSummary.currentTime) {
|
if (resume && fileSummary.currentTime) {
|
||||||
const fraction = fileSummary.currentTime / fileSummary.duration
|
const fraction = fileSummary.currentTime / fileSummary.duration
|
||||||
@@ -277,24 +298,30 @@ export default class PlaybackController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.playing.jumpToTime = jumpToTime
|
state.playing.jumpToTime = jumpToTime
|
||||||
|
|
||||||
// if it's audio, parse out the metadata (artist, title, etc)
|
// if it's audio, parse out the metadata (artist, title, etc)
|
||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash, getAudioMetadata)
|
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash, getAudioMetadata)
|
||||||
} else {
|
} else {
|
||||||
getAudioMetadata()
|
getAudioMetadata()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAudioMetadata () {
|
function getAudioMetadata () {
|
||||||
if (state.playing.type === 'audio') {
|
if (state.playing.type === 'audio') {
|
||||||
ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index)
|
ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it's video, check for subtitles files that are done downloading
|
// if it's video, check for subtitles files that are done downloading
|
||||||
dispatch('checkForSubtitles')
|
dispatch('checkForSubtitles')
|
||||||
|
|
||||||
// enable previously selected subtitle track
|
// enable previously selected subtitle track
|
||||||
if (fileSummary.selectedSubtitle) {
|
if (fileSummary.selectedSubtitle) {
|
||||||
dispatch('addSubtitles', [fileSummary.selectedSubtitle], true)
|
dispatch('addSubtitles', [fileSummary.selectedSubtitle], true)
|
||||||
}
|
}
|
||||||
|
|
||||||
state.window.title = fileSummary.name
|
state.window.title = fileSummary.name
|
||||||
|
|
||||||
// play in VLC if set as default player (Preferences / Playback / Play in VLC)
|
// play in VLC if set as default player (Preferences / Playback / Play in VLC)
|
||||||
if (this.state.saved.prefs.openExternalPlayer) {
|
if (this.state.saved.prefs.openExternalPlayer) {
|
||||||
dispatch('openExternalPlayer')
|
dispatch('openExternalPlayer')
|
||||||
@@ -302,8 +329,10 @@ export default class PlaybackController {
|
|||||||
cb()
|
cb()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, play the video
|
// otherwise, play the video
|
||||||
this.update()
|
this.update()
|
||||||
|
|
||||||
ipcRenderer.send('onPlayerUpdate', Playlist.hasNext(state), Playlist.hasPrevious(state))
|
ipcRenderer.send('onPlayerUpdate', Playlist.hasNext(state), Playlist.hasPrevious(state))
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
@@ -334,13 +363,33 @@ export default class PlaybackController {
|
|||||||
dispatch('toggleFullScreen', false)
|
dispatch('toggleFullScreen', false)
|
||||||
}
|
}
|
||||||
restoreBounds(state)
|
restoreBounds(state)
|
||||||
|
|
||||||
// Tell the WebTorrent process to kill the torrent-to-HTTP server
|
// Tell the WebTorrent process to kill the torrent-to-HTTP server
|
||||||
ipcRenderer.send('wt-stop-server')
|
ipcRenderer.send('wt-stop-server')
|
||||||
|
|
||||||
ipcRenderer.send('onPlayerClose')
|
ipcRenderer.send('onPlayerClose')
|
||||||
|
|
||||||
// Playback Priority: resume previously paused downloads.
|
// Playback Priority: resume previously paused downloads.
|
||||||
if (this.state.saved.prefs.highestPlaybackPriority) {
|
if (this.state.saved.prefs.highestPlaybackPriority) {
|
||||||
dispatch('resumePausedTorrents')
|
dispatch('resumePausedTorrents')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
function isCasting (state) {
|
||||||
|
return state.playing.location === 'chromecast' ||
|
||||||
|
state.playing.location === 'airplay' ||
|
||||||
|
state.playing.location === 'dlna'
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreBounds (state) {
|
||||||
|
ipcRenderer.send('setAspectRatio', 0)
|
||||||
|
if (state.window.bounds) {
|
||||||
|
ipcRenderer.send('setBounds', state.window.bounds, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { dispatch } from '../lib/dispatcher.js'
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
import { ipcRenderer } from 'electron'
|
const { ipcRenderer } = require('electron')
|
||||||
|
|
||||||
export default class PrefsController {
|
// Controls the Preferences screen
|
||||||
|
module.exports = class PrefsController {
|
||||||
constructor (state, config) {
|
constructor (state, config) {
|
||||||
this.state = state
|
this.state = state
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import remote from '@electron/remote'
|
const remote = require('@electron/remote')
|
||||||
import fs from 'fs'
|
const fs = require('fs')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import parallel from 'run-parallel'
|
const parallel = require('run-parallel')
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class SubtitlesController {
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class SubtitlesController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
@@ -81,11 +82,11 @@ export default class SubtitlesController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadSubtitle (file, cb) {
|
function loadSubtitle (file, cb) {
|
||||||
// Lazy load to keep startup fast
|
// Lazy load to keep startup fast
|
||||||
const concat = await import('simple-concat')
|
const concat = require('simple-concat')
|
||||||
const LanguageDetect = await import('languagedetect')
|
const LanguageDetect = require('languagedetect')
|
||||||
const srtToVtt = await import('srt-to-vtt')
|
const srtToVtt = require('srt-to-vtt')
|
||||||
|
|
||||||
// Read the .SRT or .VTT file, parse it, add subtitle track
|
// Read the .SRT or .VTT file, parse it, add subtitle track
|
||||||
const filePath = file.path || file
|
const filePath = file.path || file
|
||||||
@@ -114,8 +115,8 @@ async function loadSubtitle (file, cb) {
|
|||||||
|
|
||||||
// Checks whether a language name like 'English' or 'German' matches the system
|
// Checks whether a language name like 'English' or 'German' matches the system
|
||||||
// language, aka the current locale
|
// language, aka the current locale
|
||||||
async function isSystemLanguage (language) {
|
function isSystemLanguage (language) {
|
||||||
const iso639 = await import('iso-639-1')
|
const iso639 = require('iso-639-1')
|
||||||
const osLangISO = window.navigator.language.split('-')[0] // eg 'en'
|
const osLangISO = window.navigator.language.split('-')[0] // eg 'en'
|
||||||
const langIso = iso639.getCode(language) // eg 'de' if language is 'German'
|
const langIso = iso639.getCode(language) // eg 'de' if language is 'German'
|
||||||
return langIso === osLangISO
|
return langIso === osLangISO
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import path from 'path'
|
const path = require('path')
|
||||||
import { ipcRenderer } from 'electron'
|
const { ipcRenderer } = require('electron')
|
||||||
import TorrentSummary from '../lib/torrent-summary.js'
|
|
||||||
import sound from '../lib/sound.js'
|
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
|
||||||
|
|
||||||
export default class TorrentController {
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
|
const sound = require('../lib/sound')
|
||||||
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
|
||||||
|
module.exports = class TorrentController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import fs from 'fs'
|
const fs = require('fs')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import electron from 'electron'
|
const { ipcRenderer, clipboard } = require('electron')
|
||||||
import remote from '@electron/remote'
|
const remote = require('@electron/remote')
|
||||||
|
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
import { TorrentKeyNotFoundError } from '../lib/errors.js'
|
const { TorrentKeyNotFoundError } = require('../lib/errors')
|
||||||
import sound from '../lib/sound.js'
|
const sound = require('../lib/sound')
|
||||||
import TorrentSummary from '../lib/torrent-summary.js'
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
|
|
||||||
const { ipcRenderer, clipboard } = electron
|
|
||||||
|
|
||||||
const instantIoRegex = /^(https:\/\/)?instant\.io\/#/
|
const instantIoRegex = /^(https:\/\/)?instant\.io\/#/
|
||||||
|
|
||||||
export default class TorrentListController {
|
// Controls the torrent list: creating, adding, deleting, & manipulating torrents
|
||||||
|
module.exports = class TorrentListController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
@@ -114,6 +113,10 @@ export default class TorrentListController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGlobalTrackers (globalTrackers) {
|
||||||
|
ipcRenderer.send('wt-set-global-trackers', globalTrackers)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: use torrentKey, not infoHash
|
// TODO: use torrentKey, not infoHash
|
||||||
toggleTorrent (infoHash) {
|
toggleTorrent (infoHash) {
|
||||||
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { dispatch } from '../lib/dispatcher.js'
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
|
||||||
export default class UpdateController {
|
// Controls the UI checking for new versions of the app, prompting install
|
||||||
|
module.exports = class UpdateController {
|
||||||
constructor (state) {
|
constructor (state) {
|
||||||
this.state = state
|
this.state = state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,40 @@
|
|||||||
import http from 'http'
|
// The Cast module talks to Airplay and Chromecast
|
||||||
import config from '../src/config.js'
|
// * Modifies state when things change
|
||||||
import { CastingError } from './errors.js'
|
// * Starts and stops casting, provides remote video controls
|
||||||
|
module.exports = {
|
||||||
|
init,
|
||||||
|
toggleMenu,
|
||||||
|
selectDevice,
|
||||||
|
stop,
|
||||||
|
play,
|
||||||
|
pause,
|
||||||
|
seek,
|
||||||
|
setVolume,
|
||||||
|
setRate
|
||||||
|
}
|
||||||
|
|
||||||
|
const http = require('http')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
const { CastingError } = require('./errors')
|
||||||
|
|
||||||
// Lazy load these for a ~300ms improvement in startup time
|
// Lazy load these for a ~300ms improvement in startup time
|
||||||
let airplayer, chromecasts, dlnacasts
|
let airplayer, chromecasts, dlnacasts
|
||||||
|
|
||||||
// App state. Cast modifies state.playing and state.errors in response to events
|
// App state. Cast modifies state.playing and state.errors in response to events
|
||||||
let state
|
let state
|
||||||
|
|
||||||
// Callback to notify module users when state has changed
|
// Callback to notify module users when state has changed
|
||||||
let update
|
let update
|
||||||
|
|
||||||
// setInterval() for updating cast status
|
// setInterval() for updating cast status
|
||||||
let statusInterval = null
|
let statusInterval = null
|
||||||
|
|
||||||
// Start looking for cast devices on the local network
|
// Start looking for cast devices on the local network
|
||||||
function init (appState, callback) {
|
function init (appState, callback) {
|
||||||
state = appState
|
state = appState
|
||||||
update = callback
|
update = callback
|
||||||
|
|
||||||
// Don't actually cast during integration tests
|
// Don't actually cast during integration tests
|
||||||
// (Otherwise you'd need a physical Chromecast + AppleTV + DLNA TV to run them.)
|
// (Otherwise you'd need a physical Chromecast + AppleTV + DLNA TV to run them.)
|
||||||
if (config.IS_TEST) {
|
if (config.IS_TEST) {
|
||||||
@@ -21,26 +43,32 @@ function init (appState, callback) {
|
|||||||
state.devices.dlna = testPlayer('dlna')
|
state.devices.dlna = testPlayer('dlna')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load modules, scan the network for devices
|
// Load modules, scan the network for devices
|
||||||
airplayer = require('airplayer')()
|
airplayer = require('airplayer')()
|
||||||
chromecasts = require('chromecasts')()
|
chromecasts = require('chromecasts')()
|
||||||
dlnacasts = require('dlnacasts')()
|
dlnacasts = require('dlnacasts')()
|
||||||
|
|
||||||
state.devices.chromecast = chromecastPlayer()
|
state.devices.chromecast = chromecastPlayer()
|
||||||
state.devices.dlna = dlnaPlayer()
|
state.devices.dlna = dlnaPlayer()
|
||||||
state.devices.airplay = airplayPlayer()
|
state.devices.airplay = airplayPlayer()
|
||||||
|
|
||||||
// Listen for devices: Chromecast, DLNA and Airplay
|
// Listen for devices: Chromecast, DLNA and Airplay
|
||||||
chromecasts.on('update', device => {
|
chromecasts.on('update', device => {
|
||||||
// TODO: how do we tell if there are *no longer* any Chromecasts available?
|
// TODO: how do we tell if there are *no longer* any Chromecasts available?
|
||||||
// From looking at the code, chromecasts.players only grows, never shrinks
|
// From looking at the code, chromecasts.players only grows, never shrinks
|
||||||
state.devices.chromecast.addDevice(device)
|
state.devices.chromecast.addDevice(device)
|
||||||
})
|
})
|
||||||
|
|
||||||
dlnacasts.on('update', device => {
|
dlnacasts.on('update', device => {
|
||||||
state.devices.dlna.addDevice(device)
|
state.devices.dlna.addDevice(device)
|
||||||
})
|
})
|
||||||
|
|
||||||
airplayer.on('update', device => {
|
airplayer.on('update', device => {
|
||||||
state.devices.airplay.addDevice(device)
|
state.devices.airplay.addDevice(device)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// integration test player implementation
|
// integration test player implementation
|
||||||
function testPlayer (type) {
|
function testPlayer (type) {
|
||||||
return {
|
return {
|
||||||
@@ -53,17 +81,20 @@ function testPlayer (type) {
|
|||||||
seek,
|
seek,
|
||||||
volume
|
volume
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDevices () {
|
function getDevices () {
|
||||||
return [{ name: type + '-1' }, { name: type + '-2' }]
|
return [{ name: type + '-1' }, { name: type + '-2' }]
|
||||||
}
|
}
|
||||||
function open () { }
|
|
||||||
function play () { }
|
function open () {}
|
||||||
function pause () { }
|
function play () {}
|
||||||
function stop () { }
|
function pause () {}
|
||||||
function status () { }
|
function stop () {}
|
||||||
function seek () { }
|
function status () {}
|
||||||
function volume () { }
|
function seek () {}
|
||||||
|
function volume () {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// chromecast player implementation
|
// chromecast player implementation
|
||||||
function chromecastPlayer () {
|
function chromecastPlayer () {
|
||||||
const ret = {
|
const ret = {
|
||||||
@@ -79,9 +110,11 @@ function chromecastPlayer () {
|
|||||||
volume
|
volume
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
function getDevices () {
|
function getDevices () {
|
||||||
return chromecasts.players
|
return chromecasts.players
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDevice (device) {
|
function addDevice (device) {
|
||||||
device.on('error', err => {
|
device.on('error', err => {
|
||||||
if (device !== ret.device) return
|
if (device !== ret.device) return
|
||||||
@@ -98,6 +131,7 @@ function chromecastPlayer () {
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveSubtitles (callback) {
|
function serveSubtitles (callback) {
|
||||||
const subtitles = state.playing.subtitles
|
const subtitles = state.playing.subtitles
|
||||||
const selectedSubtitle = subtitles.tracks[subtitles.selectedIndex]
|
const selectedSubtitle = subtitles.tracks[subtitles.selectedIndex]
|
||||||
@@ -110,7 +144,7 @@ function chromecastPlayer () {
|
|||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
'Transfer-Encoding': 'chunked'
|
'Transfer-Encoding': 'chunked'
|
||||||
})
|
})
|
||||||
res.end(Buffer.from(selectedSubtitle.buffer.substr(21), 'base64'))
|
res.end(Buffer.from(selectedSubtitle.buffer.slice(21), 'base64'))
|
||||||
}).listen(0, () => {
|
}).listen(0, () => {
|
||||||
const port = ret.subServer.address().port
|
const port = ret.subServer.address().port
|
||||||
const subtitlesUrl = 'http://' + state.server.networkAddress + ':' + port + '/'
|
const subtitlesUrl = 'http://' + state.server.networkAddress + ':' + port + '/'
|
||||||
@@ -118,6 +152,7 @@ function chromecastPlayer () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function open () {
|
function open () {
|
||||||
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
||||||
serveSubtitles(subtitlesUrl => {
|
serveSubtitles(subtitlesUrl => {
|
||||||
@@ -140,28 +175,35 @@ function chromecastPlayer () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function play (callback) {
|
function play (callback) {
|
||||||
ret.device.play(null, null, callback)
|
ret.device.play(null, null, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause (callback) {
|
function pause (callback) {
|
||||||
ret.device.pause(callback)
|
ret.device.pause(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop (callback) {
|
function stop (callback) {
|
||||||
ret.device.stop(callback)
|
ret.device.stop(callback)
|
||||||
if (ret.subServer) {
|
if (ret.subServer) {
|
||||||
ret.subServer.close()
|
ret.subServer.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
ret.device.status(handleStatus)
|
ret.device.status(handleStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
function seek (time, callback) {
|
function seek (time, callback) {
|
||||||
ret.device.seek(time, callback)
|
ret.device.seek(time, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function volume (volume, callback) {
|
function volume (volume, callback) {
|
||||||
ret.device.volume(volume, callback)
|
ret.device.volume(volume, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// airplay player implementation
|
// airplay player implementation
|
||||||
function airplayPlayer () {
|
function airplayPlayer () {
|
||||||
const ret = {
|
const ret = {
|
||||||
@@ -177,6 +219,7 @@ function airplayPlayer () {
|
|||||||
volume
|
volume
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
function addDevice (player) {
|
function addDevice (player) {
|
||||||
player.on('event', event => {
|
player.on('event', event => {
|
||||||
switch (event.state) {
|
switch (event.state) {
|
||||||
@@ -194,9 +237,11 @@ function airplayPlayer () {
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDevices () {
|
function getDevices () {
|
||||||
return airplayer.players
|
return airplayer.players
|
||||||
}
|
}
|
||||||
|
|
||||||
function open () {
|
function open () {
|
||||||
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, (err, res) => {
|
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -211,15 +256,19 @@ function airplayPlayer () {
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function play (callback) {
|
function play (callback) {
|
||||||
ret.device.resume(callback)
|
ret.device.resume(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause (callback) {
|
function pause (callback) {
|
||||||
ret.device.pause(callback)
|
ret.device.pause(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop (callback) {
|
function stop (callback) {
|
||||||
ret.device.stop(callback)
|
ret.device.stop(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
ret.device.playbackInfo((err, res, status) => {
|
ret.device.playbackInfo((err, res, status) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -235,15 +284,18 @@ function airplayPlayer () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function seek (time, callback) {
|
function seek (time, callback) {
|
||||||
ret.device.scrub(time, callback)
|
ret.device.scrub(time, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function volume (volume, callback) {
|
function volume (volume, callback) {
|
||||||
// AirPlay doesn't support volume
|
// AirPlay doesn't support volume
|
||||||
// TODO: We should just disable the volume slider
|
// TODO: We should just disable the volume slider
|
||||||
state.playing.volume = volume
|
state.playing.volume = volume
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DLNA player implementation
|
// DLNA player implementation
|
||||||
function dlnaPlayer (player) {
|
function dlnaPlayer (player) {
|
||||||
const ret = {
|
const ret = {
|
||||||
@@ -259,9 +311,11 @@ function dlnaPlayer (player) {
|
|||||||
volume
|
volume
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
function getDevices () {
|
function getDevices () {
|
||||||
return dlnacasts.players
|
return dlnacasts.players
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDevice (device) {
|
function addDevice (device) {
|
||||||
device.on('error', err => {
|
device.on('error', err => {
|
||||||
if (device !== ret.device) return
|
if (device !== ret.device) return
|
||||||
@@ -278,6 +332,7 @@ function dlnaPlayer (player) {
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function open () {
|
function open () {
|
||||||
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
||||||
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, {
|
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, {
|
||||||
@@ -297,21 +352,27 @@ function dlnaPlayer (player) {
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function play (callback) {
|
function play (callback) {
|
||||||
ret.device.play(null, null, callback)
|
ret.device.play(null, null, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause (callback) {
|
function pause (callback) {
|
||||||
ret.device.pause(callback)
|
ret.device.pause(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop (callback) {
|
function stop (callback) {
|
||||||
ret.device.stop(callback)
|
ret.device.stop(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
ret.device.status(handleStatus)
|
ret.device.status(handleStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
function seek (time, callback) {
|
function seek (time, callback) {
|
||||||
ret.device.seek(time, callback)
|
ret.device.seek(time, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function volume (volume, callback) {
|
function volume (volume, callback) {
|
||||||
ret.device.volume(volume, err => {
|
ret.device.volume(volume, err => {
|
||||||
// quick volume update
|
// quick volume update
|
||||||
@@ -320,15 +381,19 @@ function dlnaPlayer (player) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleStatus (err, status) {
|
function handleStatus (err, status) {
|
||||||
if (err || !status) {
|
if (err || !status) {
|
||||||
return console.log('error getting %s status: %o', state.playing.location, err || 'missing response')
|
return console.log('error getting %s status: %o',
|
||||||
|
state.playing.location,
|
||||||
|
err || 'missing response')
|
||||||
}
|
}
|
||||||
state.playing.isPaused = status.playerState === 'PAUSED'
|
state.playing.isPaused = status.playerState === 'PAUSED'
|
||||||
state.playing.currentTime = status.currentTime
|
state.playing.currentTime = status.currentTime
|
||||||
state.playing.volume = status.volume.muted ? 0 : status.volume.level
|
state.playing.volume = status.volume.muted ? 0 : status.volume.level
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start polling cast device state, whenever we're connected
|
// Start polling cast device state, whenever we're connected
|
||||||
function startStatusInterval () {
|
function startStatusInterval () {
|
||||||
statusInterval = setInterval(() => {
|
statusInterval = setInterval(() => {
|
||||||
@@ -336,6 +401,7 @@ function startStatusInterval () {
|
|||||||
if (player) player.status()
|
if (player) player.status()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shows the device menu for a given cast type ('chromecast', 'airplay', etc)
|
* Shows the device menu for a given cast type ('chromecast', 'airplay', etc)
|
||||||
* The menu lists eg. all Chromecasts detected; the user can click one to cast.
|
* The menu lists eg. all Chromecasts detected; the user can click one to cast.
|
||||||
@@ -347,33 +413,43 @@ function toggleMenu (location) {
|
|||||||
state.devices.castMenu = null
|
state.devices.castMenu = null
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never cast to two devices at the same time
|
// Never cast to two devices at the same time
|
||||||
if (state.playing.location !== 'local') {
|
if (state.playing.location !== 'local') {
|
||||||
throw new CastingError(`You can't connect to ${location} when already connected to another device`)
|
throw new CastingError(
|
||||||
|
`You can't connect to ${location} when already connected to another device`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all cast devices of the given type
|
// Find all cast devices of the given type
|
||||||
const player = getPlayer(location)
|
const player = getPlayer(location)
|
||||||
const devices = player ? player.getDevices() : []
|
const devices = player ? player.getDevices() : []
|
||||||
if (devices.length === 0) {
|
if (devices.length === 0) {
|
||||||
throw new CastingError(`No ${location} devices available`)
|
throw new CastingError(`No ${location} devices available`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show a menu
|
// Show a menu
|
||||||
state.devices.castMenu = { location, devices }
|
state.devices.castMenu = { location, devices }
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectDevice (index) {
|
function selectDevice (index) {
|
||||||
const { location, devices } = state.devices.castMenu
|
const { location, devices } = state.devices.castMenu
|
||||||
|
|
||||||
// Start casting
|
// Start casting
|
||||||
const player = getPlayer(location)
|
const player = getPlayer(location)
|
||||||
player.device = devices[index]
|
player.device = devices[index]
|
||||||
player.open()
|
player.open()
|
||||||
|
|
||||||
// Poll the casting device's status every few seconds
|
// Poll the casting device's status every few seconds
|
||||||
startStatusInterval()
|
startStatusInterval()
|
||||||
|
|
||||||
// Show the Connecting... screen
|
// Show the Connecting... screen
|
||||||
state.devices.castMenu = null
|
state.devices.castMenu = null
|
||||||
state.playing.castName = devices[index].name
|
state.playing.castName = devices[index].name
|
||||||
state.playing.location = location + '-pending'
|
state.playing.location = location + '-pending'
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stops casting, move video back to local screen
|
// Stops casting, move video back to local screen
|
||||||
function stop () {
|
function stop () {
|
||||||
const player = getPlayer()
|
const player = getPlayer()
|
||||||
@@ -387,6 +463,7 @@ function stop () {
|
|||||||
stoppedCasting()
|
stoppedCasting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stoppedCasting () {
|
function stoppedCasting () {
|
||||||
state.playing.location = 'local'
|
state.playing.location = 'local'
|
||||||
state.playing.jumpToTime = Number.isFinite(state.playing.currentTime)
|
state.playing.jumpToTime = Number.isFinite(state.playing.currentTime)
|
||||||
@@ -394,6 +471,7 @@ function stoppedCasting () {
|
|||||||
: 0
|
: 0
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayer (location) {
|
function getPlayer (location) {
|
||||||
if (location) {
|
if (location) {
|
||||||
return state.devices[location]
|
return state.devices[location]
|
||||||
@@ -407,14 +485,17 @@ function getPlayer (location) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function play () {
|
function play () {
|
||||||
const player = getPlayer()
|
const player = getPlayer()
|
||||||
if (player) player.play(castCallback)
|
if (player) player.play(castCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause () {
|
function pause () {
|
||||||
const player = getPlayer()
|
const player = getPlayer()
|
||||||
if (player) player.pause(castCallback)
|
if (player) player.pause(castCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRate (rate) {
|
function setRate (rate) {
|
||||||
let player
|
let player
|
||||||
let result = true
|
let result = true
|
||||||
@@ -430,34 +511,17 @@ function setRate (rate) {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function seek (time) {
|
function seek (time) {
|
||||||
const player = getPlayer()
|
const player = getPlayer()
|
||||||
if (player) { player.seek(time, castCallback) }
|
if (player) player.seek(time, castCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setVolume (volume) {
|
function setVolume (volume) {
|
||||||
const player = getPlayer()
|
const player = getPlayer()
|
||||||
if (player) { player.volume(volume, castCallback) }
|
if (player) player.volume(volume, castCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function castCallback (...args) {
|
function castCallback (...args) {
|
||||||
console.log('%s callback: %o', state.playing.location, args)
|
console.log('%s callback: %o', state.playing.location, args)
|
||||||
}
|
}
|
||||||
export { init }
|
|
||||||
export { toggleMenu }
|
|
||||||
export { selectDevice }
|
|
||||||
export { stop }
|
|
||||||
export { play }
|
|
||||||
export { pause }
|
|
||||||
export { seek }
|
|
||||||
export { setVolume }
|
|
||||||
export { setRate }
|
|
||||||
export default {
|
|
||||||
init,
|
|
||||||
toggleMenu,
|
|
||||||
selectDevice,
|
|
||||||
stop,
|
|
||||||
play,
|
|
||||||
pause,
|
|
||||||
seek,
|
|
||||||
setVolume,
|
|
||||||
setRate
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
|
module.exports = {
|
||||||
|
dispatch,
|
||||||
|
dispatcher,
|
||||||
|
setDispatch
|
||||||
|
}
|
||||||
|
|
||||||
const dispatchers = {}
|
const dispatchers = {}
|
||||||
let _dispatch = () => { }
|
let _dispatch = () => {}
|
||||||
|
|
||||||
function setDispatch (dispatch) {
|
function setDispatch (dispatch) {
|
||||||
_dispatch = dispatch
|
_dispatch = dispatch
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatch (...args) {
|
function dispatch (...args) {
|
||||||
_dispatch(...args)
|
_dispatch(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Most DOM event handlers are trivial functions like `() => dispatch(<args>)`.
|
// Most DOM event handlers are trivial functions like `() => dispatch(<args>)`.
|
||||||
// For these, `dispatcher(<args>)` is preferred because it memoizes the handler
|
// For these, `dispatcher(<args>)` is preferred because it memoizes the handler
|
||||||
// function. This prevents React from updating the listener functions on
|
// function. This prevents React from updating the listener functions on
|
||||||
@@ -17,20 +26,14 @@ function dispatcher (...args) {
|
|||||||
handler = dispatchers[str] = e => {
|
handler = dispatchers[str] = e => {
|
||||||
// Do not propagate click to elements below the button
|
// Do not propagate click to elements below the button
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
if (e.currentTarget.classList.contains('disabled')) {
|
if (e.currentTarget.classList.contains('disabled')) {
|
||||||
// Ignore clicks on disabled elements
|
// Ignore clicks on disabled elements
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(...args)
|
dispatch(...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
export { dispatch }
|
|
||||||
export { dispatcher }
|
|
||||||
export { setDispatch }
|
|
||||||
export default {
|
|
||||||
dispatch,
|
|
||||||
dispatcher,
|
|
||||||
setDispatch
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,37 +1,35 @@
|
|||||||
import ExtendableError from 'es6-error'
|
const ExtendableError = require('es6-error')
|
||||||
|
|
||||||
/* Generic errors */
|
/* Generic errors */
|
||||||
class CastingError extends ExtendableError {
|
|
||||||
}
|
class CastingError extends ExtendableError {}
|
||||||
class PlaybackError extends ExtendableError {
|
class PlaybackError extends ExtendableError {}
|
||||||
}
|
class SoundError extends ExtendableError {}
|
||||||
class SoundError extends ExtendableError {
|
class TorrentError extends ExtendableError {}
|
||||||
}
|
|
||||||
class TorrentError extends ExtendableError {
|
|
||||||
}
|
|
||||||
/* Playback */
|
/* Playback */
|
||||||
|
|
||||||
class UnplayableTorrentError extends PlaybackError {
|
class UnplayableTorrentError extends PlaybackError {
|
||||||
constructor () { super('Can\'t play any files in torrent') }
|
constructor () { super('Can\'t play any files in torrent') }
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnplayableFileError extends PlaybackError {
|
class UnplayableFileError extends PlaybackError {
|
||||||
constructor () { super('Can\'t play that file') }
|
constructor () { super('Can\'t play that file') }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sound */
|
/* Sound */
|
||||||
|
|
||||||
class InvalidSoundNameError extends SoundError {
|
class InvalidSoundNameError extends SoundError {
|
||||||
constructor (name) { super(`Invalid sound name: ${name}`) }
|
constructor (name) { super(`Invalid sound name: ${name}`) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Torrent */
|
/* Torrent */
|
||||||
|
|
||||||
class TorrentKeyNotFoundError extends TorrentError {
|
class TorrentKeyNotFoundError extends TorrentError {
|
||||||
constructor (torrentKey) { super(`Can't resolve torrent key ${torrentKey}`) }
|
constructor (torrentKey) { super(`Can't resolve torrent key ${torrentKey}`) }
|
||||||
}
|
}
|
||||||
export { CastingError }
|
|
||||||
export { PlaybackError }
|
module.exports = {
|
||||||
export { SoundError }
|
|
||||||
export { TorrentError }
|
|
||||||
export { UnplayableTorrentError }
|
|
||||||
export { UnplayableFileError }
|
|
||||||
export { InvalidSoundNameError }
|
|
||||||
export { TorrentKeyNotFoundError }
|
|
||||||
export default {
|
|
||||||
CastingError,
|
CastingError,
|
||||||
PlaybackError,
|
PlaybackError,
|
||||||
SoundError,
|
SoundError,
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ const mediaExtensions = {
|
|||||||
audio: [
|
audio: [
|
||||||
'.aac', '.aif', '.aiff', '.asf', '.dff', '.dsf', '.flac', '.m2a',
|
'.aac', '.aif', '.aiff', '.asf', '.dff', '.dsf', '.flac', '.m2a',
|
||||||
'.m2a', '.m4a', '.mpc', '.m4b', '.mka', '.mp2', '.mp3', '.mpc', '.oga',
|
'.m2a', '.m4a', '.mpc', '.m4b', '.mka', '.mp2', '.mp3', '.mpc', '.oga',
|
||||||
'.ogg', '.opus', '.spx', '.wma', '.wav', '.wv', '.wvp'
|
'.ogg', '.opus', '.spx', '.wma', '.wav', '.wv', '.wvp'],
|
||||||
],
|
|
||||||
video: [
|
video: [
|
||||||
'.avi', '.mp4', '.m4v', '.webm', '.mov', '.mkv', '.mpg', '.mpeg',
|
'.avi', '.mp4', '.m4v', '.webm', '.mov', '.mkv', '.mpg', '.mpeg',
|
||||||
'.ogv', '.webm', '.wmv', '.m2ts'
|
'.ogv', '.webm', '.wmv', '.m2ts'],
|
||||||
],
|
|
||||||
image: ['.gif', '.jpg', '.jpeg', '.png']
|
image: ['.gif', '.jpg', '.jpeg', '.png']
|
||||||
}
|
}
|
||||||
export default mediaExtensions
|
|
||||||
|
module.exports = mediaExtensions
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import fs, { copyFileSync } from 'fs'
|
|
||||||
import path from 'path'
|
module.exports = {
|
||||||
import semver from 'semver'
|
run
|
||||||
import config from '../../config.js'
|
}
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const semver = require('semver')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
// Change `state.saved` (which will be saved back to config.json on exit) as
|
// Change `state.saved` (which will be saved back to config.json on exit) as
|
||||||
// needed, for example to deal with config.json format changes across versions
|
// needed, for example to deal with config.json format changes across versions
|
||||||
@@ -35,14 +41,17 @@ function run (state) {
|
|||||||
|
|
||||||
// Whenever the app is updated, re-install default handlers if the user has
|
// Whenever the app is updated, re-install default handlers if the user has
|
||||||
// enabled them.
|
// enabled them.
|
||||||
async function installHandlers (saved) {
|
function installHandlers (saved) {
|
||||||
if (saved.prefs.isFileHandler) {
|
if (saved.prefs.isFileHandler) {
|
||||||
const { ipcRenderer } = await import('electron')
|
const ipcRenderer = require('electron').ipcRenderer
|
||||||
ipcRenderer.send('setDefaultFileHandler', true)
|
ipcRenderer.send('setDefaultFileHandler', true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function migrate_0_7_0 (saved) {
|
function migrate_0_7_0 (saved) {
|
||||||
|
const { copyFileSync } = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
saved.torrents.forEach(ts => {
|
saved.torrents.forEach(ts => {
|
||||||
const infoHash = ts.infoHash
|
const infoHash = ts.infoHash
|
||||||
|
|
||||||
@@ -82,6 +91,7 @@ function migrate_0_7_0 (saved) {
|
|||||||
delete ts.posterURL
|
delete ts.posterURL
|
||||||
ts.posterFileName = infoHash + extension
|
ts.posterFileName = infoHash + extension
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix exception caused by incorrect file ordering.
|
// Fix exception caused by incorrect file ordering.
|
||||||
// https://github.com/webtorrent/webtorrent-desktop/pull/604#issuecomment-222805214
|
// https://github.com/webtorrent/webtorrent-desktop/pull/604#issuecomment-222805214
|
||||||
delete ts.defaultPlayFileIndex
|
delete ts.defaultPlayFileIndex
|
||||||
@@ -106,8 +116,8 @@ function migrate_0_11_0 (saved) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrate_0_12_0 (saved) {
|
function migrate_0_12_0 (saved) {
|
||||||
const TorrentSummary = await import('./torrent-summary')
|
const TorrentSummary = require('./torrent-summary')
|
||||||
|
|
||||||
if (saved.prefs.openExternalPlayer == null && saved.prefs.playInVlc != null) {
|
if (saved.prefs.openExternalPlayer == null && saved.prefs.playInVlc != null) {
|
||||||
saved.prefs.openExternalPlayer = saved.prefs.playInVlc
|
saved.prefs.openExternalPlayer = saved.prefs.playInVlc
|
||||||
@@ -159,6 +169,10 @@ function migrate_0_17_2 (saved) {
|
|||||||
// Remove the trailing dot (.) from the Wired CD torrent name, since
|
// Remove the trailing dot (.) from the Wired CD torrent name, since
|
||||||
// folders/files that end in a trailing dot (.) or space are not deletable from
|
// folders/files that end in a trailing dot (.) or space are not deletable from
|
||||||
// Windows Explorer. See: https://github.com/webtorrent/webtorrent-desktop/issues/905
|
// Windows Explorer. See: https://github.com/webtorrent/webtorrent-desktop/issues/905
|
||||||
|
|
||||||
|
const { copyFileSync } = require('fs')
|
||||||
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
const OLD_NAME = 'The WIRED CD - Rip. Sample. Mash. Share.'
|
const OLD_NAME = 'The WIRED CD - Rip. Sample. Mash. Share.'
|
||||||
const NEW_NAME = 'The WIRED CD - Rip. Sample. Mash. Share'
|
const NEW_NAME = 'The WIRED CD - Rip. Sample. Mash. Share'
|
||||||
|
|
||||||
@@ -188,7 +202,7 @@ function migrate_0_17_2 (saved) {
|
|||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
ts.posterFileName = NEW_HASH + '.jpg'
|
ts.posterFileName = NEW_HASH + '.jpg'
|
||||||
|
|
||||||
fs.rmdirSync(path.join(config.TORRENT_PATH, ts.torrentFileName))
|
rimraf.sync(path.join(config.TORRENT_PATH, ts.torrentFileName))
|
||||||
copyFileSync(
|
copyFileSync(
|
||||||
path.join(config.STATIC_PATH, 'wiredCd.torrent'),
|
path.join(config.STATIC_PATH, 'wiredCd.torrent'),
|
||||||
path.join(config.TORRENT_PATH, NEW_HASH + '.torrent')
|
path.join(config.TORRENT_PATH, NEW_HASH + '.torrent')
|
||||||
@@ -218,7 +232,3 @@ function migrate_0_22_0 (saved) {
|
|||||||
saved.prefs.externalPlayerPath = ''
|
saved.prefs.externalPlayerPath = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
run
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,36 +1,52 @@
|
|||||||
import TorrentSummary from './torrent-summary.js'
|
module.exports = {
|
||||||
import TorrentPlayer from './torrent-player.js'
|
hasNext,
|
||||||
|
getNextIndex,
|
||||||
|
hasPrevious,
|
||||||
|
getPreviousIndex,
|
||||||
|
getCurrentLocalURL
|
||||||
|
}
|
||||||
|
|
||||||
|
const TorrentSummary = require('./torrent-summary')
|
||||||
|
const TorrentPlayer = require('./torrent-player')
|
||||||
|
|
||||||
const cache = {
|
const cache = {
|
||||||
infoHash: null,
|
infoHash: null,
|
||||||
previousIndex: null,
|
previousIndex: null,
|
||||||
currentIndex: null,
|
currentIndex: null,
|
||||||
nextIndex: null
|
nextIndex: null
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNext (state) {
|
function hasNext (state) {
|
||||||
updateCache(state)
|
updateCache(state)
|
||||||
return cache.nextIndex !== null
|
return cache.nextIndex !== null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNextIndex (state) {
|
function getNextIndex (state) {
|
||||||
updateCache(state)
|
updateCache(state)
|
||||||
return cache.nextIndex
|
return cache.nextIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPrevious (state) {
|
function hasPrevious (state) {
|
||||||
updateCache(state)
|
updateCache(state)
|
||||||
return cache.previousIndex !== null
|
return cache.previousIndex !== null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreviousIndex (state) {
|
function getPreviousIndex (state) {
|
||||||
updateCache(state)
|
updateCache(state)
|
||||||
return cache.previousIndex
|
return cache.previousIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentLocalURL (state) {
|
function getCurrentLocalURL (state) {
|
||||||
return state.server
|
return state.server
|
||||||
? state.server.localURL + '/' + state.playing.fileIndex + '/' +
|
? state.server.localURL + '/' + state.playing.fileIndex + '/' +
|
||||||
encodeURIComponent(state.playing.fileName)
|
encodeURIComponent(state.playing.fileName)
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCache (state) {
|
function updateCache (state) {
|
||||||
const infoHash = state.playing.infoHash
|
const infoHash = state.playing.infoHash
|
||||||
const fileIndex = state.playing.fileIndex
|
const fileIndex = state.playing.fileIndex
|
||||||
|
|
||||||
if (infoHash === cache.infoHash) {
|
if (infoHash === cache.infoHash) {
|
||||||
switch (fileIndex) {
|
switch (fileIndex) {
|
||||||
case cache.currentIndex:
|
case cache.currentIndex:
|
||||||
@@ -49,10 +65,12 @@ function updateCache (state) {
|
|||||||
} else {
|
} else {
|
||||||
cache.infoHash = infoHash
|
cache.infoHash = infoHash
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.previousIndex = findPreviousIndex(state)
|
cache.previousIndex = findPreviousIndex(state)
|
||||||
cache.currentIndex = fileIndex
|
cache.currentIndex = fileIndex
|
||||||
cache.nextIndex = findNextIndex(state)
|
cache.nextIndex = findNextIndex(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
function findPreviousIndex (state) {
|
function findPreviousIndex (state) {
|
||||||
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
|
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
|
||||||
for (let i = state.playing.fileIndex - 1; i >= 0; i--) {
|
for (let i = state.playing.fileIndex - 1; i >= 0; i--) {
|
||||||
@@ -60,6 +78,7 @@ function findPreviousIndex (state) {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNextIndex (state) {
|
function findNextIndex (state) {
|
||||||
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
|
const files = TorrentSummary.getByKey(state, state.playing.infoHash).files
|
||||||
for (let i = state.playing.fileIndex + 1; i < files.length; i++) {
|
for (let i = state.playing.fileIndex + 1; i < files.length; i++) {
|
||||||
@@ -67,15 +86,3 @@ function findNextIndex (state) {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
export { hasNext }
|
|
||||||
export { getNextIndex }
|
|
||||||
export { hasPrevious }
|
|
||||||
export { getPreviousIndex }
|
|
||||||
export { getCurrentLocalURL }
|
|
||||||
export default {
|
|
||||||
hasNext,
|
|
||||||
getNextIndex,
|
|
||||||
hasPrevious,
|
|
||||||
getPreviousIndex,
|
|
||||||
getCurrentLocalURL
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
import config from '../src/config.js'
|
module.exports = {
|
||||||
import { InvalidSoundNameError } from './errors.js'
|
init,
|
||||||
import path from 'path'
|
play
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
const { InvalidSoundNameError } = require('./errors')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
const VOLUME = 0.25
|
const VOLUME = 0.25
|
||||||
|
|
||||||
// App state to access the soundNotifications preference
|
// App state to access the soundNotifications preference
|
||||||
let state
|
let state
|
||||||
|
|
||||||
/* Cache of Audio elements, for instant playback */
|
/* Cache of Audio elements, for instant playback */
|
||||||
const cache = {}
|
const cache = {}
|
||||||
|
|
||||||
const sounds = {
|
const sounds = {
|
||||||
ADD: {
|
ADD: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'add.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'add.wav'),
|
||||||
@@ -40,16 +49,20 @@ const sounds = {
|
|||||||
volume: VOLUME
|
volume: VOLUME
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init (appState) {
|
function init (appState) {
|
||||||
state = appState
|
state = appState
|
||||||
}
|
}
|
||||||
|
|
||||||
function play (name) {
|
function play (name) {
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.saved.prefs.soundNotifications) {
|
if (!state.saved.prefs.soundNotifications) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio = cache[name]
|
let audio = cache[name]
|
||||||
if (!audio) {
|
if (!audio) {
|
||||||
const sound = sounds[name]
|
const sound = sounds[name]
|
||||||
@@ -63,9 +76,3 @@ function play (name) {
|
|||||||
audio.currentTime = 0
|
audio.currentTime = 0
|
||||||
audio.play()
|
audio.play()
|
||||||
}
|
}
|
||||||
export { init }
|
|
||||||
export { play }
|
|
||||||
export default {
|
|
||||||
init,
|
|
||||||
play
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import applicationConfig from 'application-config'
|
const appConfig = require('application-config')('WebTorrent')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import { EventEmitter } from 'events'
|
const { EventEmitter } = require('events')
|
||||||
|
|
||||||
import config from '../../config.js'
|
const config = require('../../config')
|
||||||
|
const defaultAnnounceList = require('create-torrent').announceList.map((arr) => arr[0])
|
||||||
|
|
||||||
const appConfig = applicationConfig('WebTorrent')
|
|
||||||
const SAVE_DEBOUNCE_INTERVAL = 1000
|
const SAVE_DEBOUNCE_INTERVAL = 1000
|
||||||
|
|
||||||
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
||||||
|
|
||||||
const State = Object.assign(new EventEmitter(), {
|
const State = module.exports = Object.assign(new EventEmitter(), {
|
||||||
getDefaultPlayState,
|
getDefaultPlayState,
|
||||||
load,
|
load,
|
||||||
// state.save() calls are rate-limited. Use state.saveImmediate() to skip limit.
|
// state.save() calls are rate-limited. Use state.saveImmediate() to skip limit.
|
||||||
async save (...args) {
|
save (...args) {
|
||||||
// Perf optimization: Lazy-require debounce (and it's dependencies)
|
// Perf optimization: Lazy-require debounce (and it's dependencies)
|
||||||
const debounce = await import('debounce')
|
const debounce = require('debounce')
|
||||||
// After first State.save() invokation, future calls go straight to the
|
// After first State.save() invokation, future calls go straight to the
|
||||||
// debounced function
|
// debounced function
|
||||||
State.save = debounce(saveImmediate, SAVE_DEBOUNCE_INTERVAL)
|
State.save = debounce(saveImmediate, SAVE_DEBOUNCE_INTERVAL)
|
||||||
@@ -24,10 +24,8 @@ const State = Object.assign(new EventEmitter(), {
|
|||||||
saveImmediate
|
saveImmediate
|
||||||
})
|
})
|
||||||
|
|
||||||
export default State
|
function getDefaultState () {
|
||||||
|
const LocationHistory = require('location-history')
|
||||||
async function getDefaultState () {
|
|
||||||
const { default: LocationHistory } = await import('location-history')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/*
|
/*
|
||||||
@@ -82,6 +80,7 @@ async function getDefaultState () {
|
|||||||
getPlayingTorrentSummary,
|
getPlayingTorrentSummary,
|
||||||
getPlayingFileSummary,
|
getPlayingFileSummary,
|
||||||
getExternalPlayerName,
|
getExternalPlayerName,
|
||||||
|
getGlobalTrackers,
|
||||||
shouldHidePlayerControls
|
shouldHidePlayerControls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,9 +117,9 @@ function getDefaultPlayState () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If the saved state file doesn't exist yet, here's what we use instead */
|
/* If the saved state file doesn't exist yet, here's what we use instead */
|
||||||
async function setupStateSaved () {
|
function setupStateSaved () {
|
||||||
const { copyFileSync, mkdirSync, readFileSync } = await import('fs')
|
const { copyFileSync, mkdirSync, readFileSync } = require('fs')
|
||||||
const { default: parseTorrent } = await import('parse-torrent')
|
const parseTorrent = require('parse-torrent')
|
||||||
|
|
||||||
const saved = {
|
const saved = {
|
||||||
prefs: {
|
prefs: {
|
||||||
@@ -132,7 +131,8 @@ async function setupStateSaved () {
|
|||||||
soundNotifications: true,
|
soundNotifications: true,
|
||||||
autoAddTorrents: false,
|
autoAddTorrents: false,
|
||||||
torrentsFolderPath: '',
|
torrentsFolderPath: '',
|
||||||
highestPlaybackPriority: true
|
highestPlaybackPriority: true,
|
||||||
|
globalTrackers: defaultAnnounceList
|
||||||
},
|
},
|
||||||
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
||||||
torrentsToResume: [],
|
torrentsToResume: [],
|
||||||
@@ -201,18 +201,24 @@ function shouldHidePlayerControls () {
|
|||||||
new Date().getTime() - this.playing.mouseStationarySince > 2000 &&
|
new Date().getTime() - this.playing.mouseStationarySince > 2000 &&
|
||||||
!this.playing.mouseInControls &&
|
!this.playing.mouseInControls &&
|
||||||
!this.playing.isPaused &&
|
!this.playing.isPaused &&
|
||||||
this.playing.location === 'local' &&
|
this.playing.location === 'local'
|
||||||
this.playing.playbackRate === 1
|
}
|
||||||
|
|
||||||
|
function getGlobalTrackers () {
|
||||||
|
const trackers = this.saved.prefs.globalTrackers
|
||||||
|
if (!trackers) {
|
||||||
|
return defaultAnnounceList
|
||||||
|
}
|
||||||
|
return trackers
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load (cb) {
|
async function load (cb) {
|
||||||
console.log('state load')
|
|
||||||
let saved = await appConfig.read()
|
let saved = await appConfig.read()
|
||||||
|
|
||||||
if (!saved || !saved.version) {
|
if (!saved || !saved.version) {
|
||||||
console.log('Missing config file: Creating new one')
|
console.log('Missing config file: Creating new one')
|
||||||
try {
|
try {
|
||||||
saved = await setupStateSaved()
|
saved = setupStateSaved()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
onSavedState(err)
|
onSavedState(err)
|
||||||
return
|
return
|
||||||
@@ -221,9 +227,9 @@ async function load (cb) {
|
|||||||
|
|
||||||
onSavedState(null, saved)
|
onSavedState(null, saved)
|
||||||
|
|
||||||
async function onSavedState (err, saved) {
|
function onSavedState (err, saved) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
const state = await getDefaultState()
|
const state = getDefaultState()
|
||||||
state.saved = saved
|
state.saved = saved
|
||||||
|
|
||||||
if (process.type === 'renderer') {
|
if (process.type === 'renderer') {
|
||||||
@@ -232,7 +238,6 @@ async function load (cb) {
|
|||||||
migrations.run(state)
|
migrations.run(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('calling cb')
|
|
||||||
cb(null, state)
|
cb(null, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
import remote from '@electron/remote'
|
// Collects anonymous usage stats and uncaught errors
|
||||||
import config from '../../config.js'
|
// Reports back so that we can improve WebTorrent Desktop
|
||||||
|
module.exports = {
|
||||||
|
init,
|
||||||
|
send,
|
||||||
|
logUncaughtError,
|
||||||
|
logPlayAttempt
|
||||||
|
}
|
||||||
|
|
||||||
|
const remote = require('@electron/remote')
|
||||||
|
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
let telemetry
|
let telemetry
|
||||||
|
|
||||||
async function init (state) {
|
function init (state) {
|
||||||
telemetry = state.saved.telemetry
|
telemetry = state.saved.telemetry
|
||||||
|
|
||||||
// First app run
|
// First app run
|
||||||
if (!telemetry) {
|
if (!telemetry) {
|
||||||
const crypto = await import('crypto')
|
const crypto = require('crypto')
|
||||||
telemetry = state.saved.telemetry = {
|
telemetry = state.saved.telemetry = {
|
||||||
userID: crypto.randomBytes(32).toString('hex') // 256-bit random ID
|
userID: crypto.randomBytes(32).toString('hex') // 256-bit random ID
|
||||||
}
|
}
|
||||||
@@ -16,7 +26,7 @@ async function init (state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function send (state) {
|
function send (state) {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
telemetry.version = config.APP_VERSION
|
telemetry.version = config.APP_VERSION
|
||||||
telemetry.timestamp = now.toISOString()
|
telemetry.timestamp = now.toISOString()
|
||||||
@@ -32,7 +42,7 @@ async function send (state) {
|
|||||||
return reset()
|
return reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
const get = await import('simple-get')
|
const get = require('simple-get')
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
url: config.TELEMETRY_URL,
|
url: config.TELEMETRY_URL,
|
||||||
@@ -72,8 +82,8 @@ function getScreenInfo () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Track basic system info like OS version and amount of RAM
|
// Track basic system info like OS version and amount of RAM
|
||||||
async function getSystemInfo () {
|
function getSystemInfo () {
|
||||||
const os = await import('os')
|
const os = require('os')
|
||||||
return {
|
return {
|
||||||
osPlatform: process.platform,
|
osPlatform: process.platform,
|
||||||
osRelease: os.type() + ' ' + os.release(),
|
osRelease: os.type() + ' ' + os.release(),
|
||||||
@@ -210,14 +220,3 @@ function logPlayAttempt (result) {
|
|||||||
attempts.total = (attempts.total || 0) + 1
|
attempts.total = (attempts.total || 0) + 1
|
||||||
attempts[result] = (attempts[result] || 0) + 1
|
attempts[result] = (attempts[result] || 0) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export { init }
|
|
||||||
export { send }
|
|
||||||
export { logUncaughtError }
|
|
||||||
export { logPlayAttempt }
|
|
||||||
export default {
|
|
||||||
init,
|
|
||||||
send,
|
|
||||||
logUncaughtError,
|
|
||||||
logPlayAttempt
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
|
module.exports = {
|
||||||
|
calculateEta
|
||||||
|
}
|
||||||
|
|
||||||
function calculateEta (missing, downloadSpeed) {
|
function calculateEta (missing, downloadSpeed) {
|
||||||
if (downloadSpeed === 0 || missing === 0) return
|
if (downloadSpeed === 0 || missing === 0) return
|
||||||
|
|
||||||
const rawEta = missing / downloadSpeed
|
const rawEta = missing / downloadSpeed
|
||||||
const hours = Math.floor(rawEta / 3600) % 24
|
const hours = Math.floor(rawEta / 3600) % 24
|
||||||
const minutes = Math.floor(rawEta / 60) % 60
|
const minutes = Math.floor(rawEta / 60) % 60
|
||||||
const seconds = Math.floor(rawEta % 60)
|
const seconds = Math.floor(rawEta % 60)
|
||||||
|
|
||||||
// Only display hours and minutes if they are greater than 0 but always
|
// Only display hours and minutes if they are greater than 0 but always
|
||||||
// display minutes if hours is being displayed
|
// display minutes if hours is being displayed
|
||||||
const hoursStr = hours ? hours + ' h' : ''
|
const hoursStr = hours ? hours + ' h' : ''
|
||||||
const minutesStr = (hours || minutes) ? minutes + ' min' : ''
|
const minutesStr = (hours || minutes) ? minutes + ' min' : ''
|
||||||
const secondsStr = seconds + ' s'
|
const secondsStr = seconds + ' s'
|
||||||
|
|
||||||
return `${hoursStr} ${minutesStr} ${secondsStr} remaining`
|
return `${hoursStr} ${minutesStr} ${secondsStr} remaining`
|
||||||
}
|
}
|
||||||
export { calculateEta }
|
|
||||||
export default {
|
|
||||||
calculateEta
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,45 +1,4 @@
|
|||||||
import path from 'path'
|
module.exports = {
|
||||||
import mediaExtensions from './media-extensions.js'
|
|
||||||
// Checks whether a fileSummary or file path is audio/video that we can play,
|
|
||||||
// based on the file extension
|
|
||||||
function isPlayable (file) {
|
|
||||||
return isVideo(file) || isAudio(file)
|
|
||||||
}
|
|
||||||
// Checks whether a fileSummary or file path is playable video
|
|
||||||
function isVideo (file) {
|
|
||||||
return mediaExtensions.video.includes(getFileExtension(file))
|
|
||||||
}
|
|
||||||
// Checks whether a fileSummary or file path is playable audio
|
|
||||||
function isAudio (file) {
|
|
||||||
return mediaExtensions.audio.includes(getFileExtension(file))
|
|
||||||
}
|
|
||||||
// Checks if the argument is either:
|
|
||||||
// - a string that's a valid filename ending in .torrent
|
|
||||||
// - a file object where obj.name is ends in .torrent
|
|
||||||
// - a string that's a magnet link (magnet://...)
|
|
||||||
function isTorrent (file) {
|
|
||||||
return isTorrentFile(file) || isMagnetLink(file)
|
|
||||||
}
|
|
||||||
function isTorrentFile (file) {
|
|
||||||
return getFileExtension(file) === '.torrent'
|
|
||||||
}
|
|
||||||
function isMagnetLink (link) {
|
|
||||||
return typeof link === 'string' && /^(stream-)?magnet:/.test(link)
|
|
||||||
}
|
|
||||||
function getFileExtension (file) {
|
|
||||||
const name = typeof file === 'string' ? file : file.name
|
|
||||||
return path.extname(name).toLowerCase()
|
|
||||||
}
|
|
||||||
function isPlayableTorrentSummary (torrentSummary) {
|
|
||||||
return torrentSummary.files && torrentSummary.files.some(isPlayable)
|
|
||||||
}
|
|
||||||
export { isPlayable }
|
|
||||||
export { isVideo }
|
|
||||||
export { isAudio }
|
|
||||||
export { isTorrent }
|
|
||||||
export { isMagnetLink }
|
|
||||||
export { isPlayableTorrentSummary }
|
|
||||||
export default {
|
|
||||||
isPlayable,
|
isPlayable,
|
||||||
isVideo,
|
isVideo,
|
||||||
isAudio,
|
isAudio,
|
||||||
@@ -47,3 +6,48 @@ export default {
|
|||||||
isMagnetLink,
|
isMagnetLink,
|
||||||
isPlayableTorrentSummary
|
isPlayableTorrentSummary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const mediaExtensions = require('./media-extensions')
|
||||||
|
|
||||||
|
// Checks whether a fileSummary or file path is audio/video that we can play,
|
||||||
|
// based on the file extension
|
||||||
|
function isPlayable (file) {
|
||||||
|
return isVideo(file) || isAudio(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks whether a fileSummary or file path is playable video
|
||||||
|
function isVideo (file) {
|
||||||
|
return mediaExtensions.video.includes(getFileExtension(file))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks whether a fileSummary or file path is playable audio
|
||||||
|
function isAudio (file) {
|
||||||
|
return mediaExtensions.audio.includes(getFileExtension(file))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the argument is either:
|
||||||
|
// - a string that's a valid filename ending in .torrent
|
||||||
|
// - a file object where obj.name is ends in .torrent
|
||||||
|
// - a string that's a magnet link (magnet://...)
|
||||||
|
function isTorrent (file) {
|
||||||
|
return isTorrentFile(file) || isMagnetLink(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTorrentFile (file) {
|
||||||
|
return getFileExtension(file) === '.torrent'
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMagnetLink (link) {
|
||||||
|
return typeof link === 'string' && /^(stream-)?magnet:/.test(link)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileExtension (file) {
|
||||||
|
const name = typeof file === 'string' ? file : file.name
|
||||||
|
return path.extname(name).toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlayableTorrentSummary (torrentSummary) {
|
||||||
|
return torrentSummary.files && torrentSummary.files.some(isPlayable)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,20 +1,28 @@
|
|||||||
import captureFrame from 'capture-frame'
|
module.exports = torrentPoster
|
||||||
import path from 'path'
|
|
||||||
import mediaExtensions from './media-extensions.js'
|
const captureFrame = require('capture-frame')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const mediaExtensions = require('./media-extensions')
|
||||||
|
|
||||||
const msgNoSuitablePoster = 'Cannot generate a poster from any files in the torrent'
|
const msgNoSuitablePoster = 'Cannot generate a poster from any files in the torrent'
|
||||||
|
|
||||||
function torrentPoster (torrent, cb) {
|
function torrentPoster (torrent, cb) {
|
||||||
// First, try to use a poster image if available
|
// First, try to use a poster image if available
|
||||||
const posterFile = torrent.files.filter(file => /^poster\.(jpg|png|gif)$/.test(file.name))[0]
|
const posterFile = torrent.files.filter(file => /^poster\.(jpg|png|gif)$/.test(file.name))[0]
|
||||||
if (posterFile) return extractPoster(posterFile, cb)
|
if (posterFile) return extractPoster(posterFile, cb)
|
||||||
|
|
||||||
// 'score' each media type based on total size present in torrent
|
// 'score' each media type based on total size present in torrent
|
||||||
const bestScore = ['audio', 'video', 'image'].map(mediaType => ({
|
const bestScore = ['audio', 'video', 'image'].map(mediaType => ({
|
||||||
type: mediaType,
|
type: mediaType,
|
||||||
size: calculateDataLengthByExtension(torrent, mediaExtensions[mediaType])
|
size: calculateDataLengthByExtension(torrent, mediaExtensions[mediaType])
|
||||||
})).sort((a, b) => b.size - a.size)[0] // sort descending on size
|
})).sort((a, b) => b.size - a.size)[0] // sort descending on size
|
||||||
|
|
||||||
if (bestScore.size === 0) {
|
if (bestScore.size === 0) {
|
||||||
// Admit defeat, no video, audio or image had a significant presence
|
// Admit defeat, no video, audio or image had a significant presence
|
||||||
return cb(new Error(msgNoSuitablePoster))
|
return cb(new Error(msgNoSuitablePoster))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on which media type is dominant we select the corresponding poster function
|
// Based on which media type is dominant we select the corresponding poster function
|
||||||
switch (bestScore.type) {
|
switch (bestScore.type) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
@@ -25,6 +33,7 @@ function torrentPoster (torrent, cb) {
|
|||||||
return torrentPosterFromVideo(torrent, cb)
|
return torrentPosterFromVideo(torrent, cb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the total data size of file matching one of the provided extensions
|
* Calculate the total data size of file matching one of the provided extensions
|
||||||
* @param torrent
|
* @param torrent
|
||||||
@@ -38,6 +47,7 @@ function calculateDataLengthByExtension (torrent, extensions) {
|
|||||||
.map(file => file.length)
|
.map(file => file.length)
|
||||||
.reduce((a, b) => a + b)
|
.reduce((a, b) => a + b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the largest file of a given torrent, filtered by provided extension
|
* Get the largest file of a given torrent, filtered by provided extension
|
||||||
* @param torrent Torrent to search in
|
* @param torrent Torrent to search in
|
||||||
@@ -49,6 +59,7 @@ function getLargestFileByExtension (torrent, extensions) {
|
|||||||
if (files.length === 0) return undefined
|
if (files.length === 0) return undefined
|
||||||
return files.reduce((a, b) => a.length > b.length ? a : b)
|
return files.reduce((a, b) => a.length > b.length ? a : b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter file on a list extension, can be used to find al image files
|
* Filter file on a list extension, can be used to find al image files
|
||||||
* @param torrent Torrent to filter files from
|
* @param torrent Torrent to filter files from
|
||||||
@@ -61,6 +72,7 @@ function filterOnExtension (torrent, extensions) {
|
|||||||
return extensions.indexOf(extname) !== -1
|
return extensions.indexOf(extname) !== -1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a score how likely the file is suitable as a poster
|
* Returns a score how likely the file is suitable as a poster
|
||||||
* @param imgFile File object of an image
|
* @param imgFile File object of an image
|
||||||
@@ -76,6 +88,7 @@ function scoreAudioCoverFile (imgFile) {
|
|||||||
back: 20,
|
back: 20,
|
||||||
spectrogram: -80
|
spectrogram: -80
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const keyword in relevanceScore) {
|
for (const keyword in relevanceScore) {
|
||||||
if (fileName === keyword) {
|
if (fileName === keyword) {
|
||||||
return relevanceScore[keyword]
|
return relevanceScore[keyword]
|
||||||
@@ -86,9 +99,12 @@ function scoreAudioCoverFile (imgFile) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function torrentPosterFromAudio (torrent, cb) {
|
function torrentPosterFromAudio (torrent, cb) {
|
||||||
const imageFiles = filterOnExtension(torrent, mediaExtensions.image)
|
const imageFiles = filterOnExtension(torrent, mediaExtensions.image)
|
||||||
|
|
||||||
if (imageFiles.length === 0) return cb(new Error(msgNoSuitablePoster))
|
if (imageFiles.length === 0) return cb(new Error(msgNoSuitablePoster))
|
||||||
|
|
||||||
const bestCover = imageFiles.map(file => ({
|
const bestCover = imageFiles.map(file => ({
|
||||||
file,
|
file,
|
||||||
score: scoreAudioCoverFile(file)
|
score: scoreAudioCoverFile(file)
|
||||||
@@ -105,47 +121,62 @@ function torrentPosterFromAudio (torrent, cb) {
|
|||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
})
|
})
|
||||||
|
|
||||||
const extname = path.extname(bestCover.file.name)
|
const extname = path.extname(bestCover.file.name)
|
||||||
bestCover.file.getBuffer((err, buf) => cb(err, buf, extname))
|
bestCover.file.getBuffer((err, buf) => cb(err, buf, extname))
|
||||||
}
|
}
|
||||||
|
|
||||||
function torrentPosterFromVideo (torrent, cb) {
|
function torrentPosterFromVideo (torrent, cb) {
|
||||||
const file = getLargestFileByExtension(torrent, mediaExtensions.video)
|
const file = getLargestFileByExtension(torrent, mediaExtensions.video)
|
||||||
|
|
||||||
const index = torrent.files.indexOf(file)
|
const index = torrent.files.indexOf(file)
|
||||||
|
|
||||||
const server = torrent.createServer(0)
|
const server = torrent.createServer(0)
|
||||||
server.listen(0, onListening)
|
server.listen(0, onListening)
|
||||||
|
|
||||||
function onListening () {
|
function onListening () {
|
||||||
const port = server.address().port
|
const port = server.address().port
|
||||||
const url = 'http://localhost:' + port + '/' + index
|
const url = 'http://localhost:' + port + '/' + index
|
||||||
const video = document.createElement('video')
|
const video = document.createElement('video')
|
||||||
video.addEventListener('canplay', onCanPlay)
|
video.addEventListener('canplay', onCanPlay)
|
||||||
|
|
||||||
video.volume = 0
|
video.volume = 0
|
||||||
video.src = url
|
video.src = url
|
||||||
video.play()
|
video.play()
|
||||||
|
|
||||||
function onCanPlay () {
|
function onCanPlay () {
|
||||||
video.removeEventListener('canplay', onCanPlay)
|
video.removeEventListener('canplay', onCanPlay)
|
||||||
video.addEventListener('seeked', onSeeked)
|
video.addEventListener('seeked', onSeeked)
|
||||||
|
|
||||||
video.currentTime = Math.min((video.duration || 600) * 0.03, 60)
|
video.currentTime = Math.min((video.duration || 600) * 0.03, 60)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSeeked () {
|
function onSeeked () {
|
||||||
video.removeEventListener('seeked', onSeeked)
|
video.removeEventListener('seeked', onSeeked)
|
||||||
|
|
||||||
const frame = captureFrame(video)
|
const frame = captureFrame(video)
|
||||||
const buf = frame && frame.image
|
const buf = frame && frame.image
|
||||||
|
|
||||||
// unload video element
|
// unload video element
|
||||||
video.pause()
|
video.pause()
|
||||||
video.src = ''
|
video.src = ''
|
||||||
video.load()
|
video.load()
|
||||||
|
|
||||||
server.destroy()
|
server.destroy()
|
||||||
|
|
||||||
if (buf.length === 0) return cb(new Error(msgNoSuitablePoster))
|
if (buf.length === 0) return cb(new Error(msgNoSuitablePoster))
|
||||||
|
|
||||||
cb(null, buf, '.jpg')
|
cb(null, buf, '.jpg')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function torrentPosterFromImage (torrent, cb) {
|
function torrentPosterFromImage (torrent, cb) {
|
||||||
const file = getLargestFileByExtension(torrent, mediaExtensions.image)
|
const file = getLargestFileByExtension(torrent, mediaExtensions.image)
|
||||||
extractPoster(file, cb)
|
extractPoster(file, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractPoster (file, cb) {
|
function extractPoster (file, cb) {
|
||||||
const extname = path.extname(file.name)
|
const extname = path.extname(file.name)
|
||||||
file.getBuffer((err, buf) => cb(err, buf, extname))
|
file.getBuffer((err, buf) => cb(err, buf, extname))
|
||||||
}
|
}
|
||||||
export default torrentPoster
|
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
import path from 'path'
|
module.exports = {
|
||||||
import config from '../src/config.js'
|
getPosterPath,
|
||||||
|
getTorrentPath,
|
||||||
|
getByKey,
|
||||||
|
getTorrentId,
|
||||||
|
getFileOrFolder
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = require('path')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
// Expects a torrentSummary
|
// Expects a torrentSummary
|
||||||
// Returns an absolute path to the torrent file, or null if unavailable
|
// Returns an absolute path to the torrent file, or null if unavailable
|
||||||
function getTorrentPath (torrentSummary) {
|
function getTorrentPath (torrentSummary) {
|
||||||
if (!torrentSummary || !torrentSummary.torrentFileName) return null
|
if (!torrentSummary || !torrentSummary.torrentFileName) return null
|
||||||
return path.join(config.TORRENT_PATH, torrentSummary.torrentFileName)
|
return path.join(config.TORRENT_PATH, torrentSummary.torrentFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expects a torrentSummary
|
// Expects a torrentSummary
|
||||||
// Returns an absolute path to the poster image, or null if unavailable
|
// Returns an absolute path to the poster image, or null if unavailable
|
||||||
function getPosterPath (torrentSummary) {
|
function getPosterPath (torrentSummary) {
|
||||||
@@ -15,6 +25,7 @@ function getPosterPath (torrentSummary) {
|
|||||||
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
// Backslashes in URLS in CSS cause bizarre string encoding issues
|
||||||
return posterPath.replace(/\\/g, '/')
|
return posterPath.replace(/\\/g, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expects a torrentSummary
|
// Expects a torrentSummary
|
||||||
// Returns a torrentID: filename, magnet URI, or infohash
|
// Returns a torrentID: filename, magnet URI, or infohash
|
||||||
function getTorrentId (torrentSummary) {
|
function getTorrentId (torrentSummary) {
|
||||||
@@ -25,12 +36,15 @@ function getTorrentId (torrentSummary) {
|
|||||||
return s.magnetURI || s.infoHash
|
return s.magnetURI || s.infoHash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expects a torrentKey or infoHash
|
// Expects a torrentKey or infoHash
|
||||||
// Returns the corresponding torrentSummary, or undefined
|
// Returns the corresponding torrentSummary, or undefined
|
||||||
function getByKey (state, torrentKey) {
|
function getByKey (state, torrentKey) {
|
||||||
if (!torrentKey) return undefined
|
if (!torrentKey) return undefined
|
||||||
return state.saved.torrents.find((x) => x.torrentKey === torrentKey || x.infoHash === torrentKey)
|
return state.saved.torrents.find((x) =>
|
||||||
|
x.torrentKey === torrentKey || x.infoHash === torrentKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the path to either the file (in a single-file torrent) or the root
|
// Returns the path to either the file (in a single-file torrent) or the root
|
||||||
// folder (in multi-file torrent)
|
// folder (in multi-file torrent)
|
||||||
// WARNING: assumes that multi-file torrents consist of a SINGLE folder.
|
// WARNING: assumes that multi-file torrents consist of a SINGLE folder.
|
||||||
@@ -42,15 +56,3 @@ function getFileOrFolder (torrentSummary) {
|
|||||||
const dirname = ts.files[0].path.split(path.sep)[0]
|
const dirname = ts.files[0].path.split(path.sep)[0]
|
||||||
return path.join(ts.path, dirname)
|
return path.join(ts.path, dirname)
|
||||||
}
|
}
|
||||||
export { getPosterPath }
|
|
||||||
export { getTorrentPath }
|
|
||||||
export { getByKey }
|
|
||||||
export { getTorrentId }
|
|
||||||
export { getFileOrFolder }
|
|
||||||
export default {
|
|
||||||
getPosterPath,
|
|
||||||
getTorrentPath,
|
|
||||||
getByKey,
|
|
||||||
getTorrentId,
|
|
||||||
getFileOrFolder
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,43 +1,51 @@
|
|||||||
/* eslint-disable import/first */
|
/**
|
||||||
|
* Perf optimization: Hook into require() to modify how certain modules load:
|
||||||
|
*
|
||||||
|
* - `inline-style-prefixer` (used by `material-ui`) takes ~40ms. It is not
|
||||||
|
* actually used because auto-prefixing is disabled with
|
||||||
|
* `darkBaseTheme.userAgent = false`. Return a fake object.
|
||||||
|
*/
|
||||||
|
const Module = require('module')
|
||||||
|
const _require = Module.prototype.require
|
||||||
|
Module.prototype.require = function (id) {
|
||||||
|
if (id === 'inline-style-prefixer') return {}
|
||||||
|
return _require.apply(this, arguments)
|
||||||
|
}
|
||||||
|
|
||||||
console.time('init')
|
console.time('init')
|
||||||
|
|
||||||
// Perf optimization: Start asynchronously read on config file before all the
|
// Perf optimization: Start asynchronously read on config file before all the
|
||||||
// blocking import() calls below.
|
// blocking require() calls below.
|
||||||
|
|
||||||
import State from './lib/state'
|
const State = require('./lib/state')
|
||||||
State.load(onState)
|
State.load(onState)
|
||||||
|
|
||||||
import createGetter from 'fn-getter'
|
const createGetter = require('fn-getter')
|
||||||
import remote from '@electron/remote'
|
const debounce = require('debounce')
|
||||||
import debounce from 'debounce'
|
const dragDrop = require('drag-drop')
|
||||||
import dragDrop from 'drag-drop'
|
const electron = require('electron')
|
||||||
import electron from 'electron'
|
const fs = require('fs')
|
||||||
import fs from 'fs'
|
const React = require('react')
|
||||||
import * as React from 'react'
|
const ReactDOM = require('react-dom')
|
||||||
import * as ReactDOM from 'react-dom'
|
|
||||||
|
|
||||||
import config from '../config.js'
|
const config = require('../config')
|
||||||
import telemetry from './lib/telemetry.js'
|
const telemetry = require('./lib/telemetry')
|
||||||
import sound from './lib/sound.js'
|
const sound = require('./lib/sound')
|
||||||
import TorrentPlayer from './lib/torrent-player.js'
|
const TorrentPlayer = require('./lib/torrent-player')
|
||||||
import App from './pages/app.js'
|
|
||||||
import { setDispatch } from './lib/dispatcher.js'
|
|
||||||
|
|
||||||
import TorrentController from './controllers/torrent-controller.js'
|
// Perf optimization: Needed immediately, so do not lazy load it below
|
||||||
import AudioTracksController from './controllers/audio-tracks-controller.js'
|
const TorrentListController = require('./controllers/torrent-list-controller')
|
||||||
import SubtitlesController from './controllers/subtitles-controller.js'
|
|
||||||
import PrefsController from './controllers/prefs-controller.js'
|
|
||||||
import PlaybackController from './controllers/playback-controller.js'
|
|
||||||
import MediaController from './controllers/media-controller.js'
|
|
||||||
import TorrentListController from './controllers/torrent-list-controller.js'
|
|
||||||
import UpdateController from './controllers/update-controller.js'
|
|
||||||
import FolderWatcherController from './controllers/folder-watcher-controller.js'
|
|
||||||
|
|
||||||
const { clipboard, ipcRenderer } = electron
|
const App = require('./pages/app')
|
||||||
|
|
||||||
|
// 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
|
||||||
|
const ipcRenderer = electron.ipcRenderer
|
||||||
|
|
||||||
// Yo-yo pattern: state object lives here and percolates down thru all the views.
|
// Yo-yo pattern: state object lives here and percolates down thru all the views.
|
||||||
// Events come back up from the views via dispatch(...)
|
// Events come back up from the views via dispatch(...)
|
||||||
setDispatch(dispatch)
|
require('./lib/dispatcher').setDispatch(dispatch)
|
||||||
|
|
||||||
// From dispatch(...), events are sent to one of the controllers
|
// From dispatch(...), events are sent to one of the controllers
|
||||||
let controllers = null
|
let controllers = null
|
||||||
@@ -72,15 +80,39 @@ function onState (err, _state) {
|
|||||||
|
|
||||||
// Create controllers
|
// Create controllers
|
||||||
controllers = {
|
controllers = {
|
||||||
media: createGetter(() => new MediaController(state)),
|
media: createGetter(() => {
|
||||||
playback: createGetter(() => new PlaybackController(state, config, update)),
|
const MediaController = require('./controllers/media-controller')
|
||||||
prefs: createGetter(() => new PrefsController(state, config)),
|
return new MediaController(state)
|
||||||
subtitles: createGetter(() => new SubtitlesController(state)),
|
}),
|
||||||
audioTracks: createGetter(() => new AudioTracksController(state)),
|
playback: createGetter(() => {
|
||||||
torrent: createGetter(() => new TorrentController(state)),
|
const PlaybackController = require('./controllers/playback-controller')
|
||||||
|
return new PlaybackController(state, config, update)
|
||||||
|
}),
|
||||||
|
prefs: createGetter(() => {
|
||||||
|
const PrefsController = require('./controllers/prefs-controller')
|
||||||
|
return new PrefsController(state, config)
|
||||||
|
}),
|
||||||
|
subtitles: createGetter(() => {
|
||||||
|
const SubtitlesController = require('./controllers/subtitles-controller')
|
||||||
|
return new SubtitlesController(state)
|
||||||
|
}),
|
||||||
|
audioTracks: createGetter(() => {
|
||||||
|
const AudioTracksController = require('./controllers/audio-tracks-controller')
|
||||||
|
return new AudioTracksController(state)
|
||||||
|
}),
|
||||||
|
torrent: createGetter(() => {
|
||||||
|
const TorrentController = require('./controllers/torrent-controller')
|
||||||
|
return new TorrentController(state)
|
||||||
|
}),
|
||||||
torrentList: createGetter(() => new TorrentListController(state)),
|
torrentList: createGetter(() => new TorrentListController(state)),
|
||||||
update: createGetter(() => new UpdateController(state)),
|
update: createGetter(() => {
|
||||||
folderWatcher: createGetter(() => new FolderWatcherController())
|
const UpdateController = require('./controllers/update-controller')
|
||||||
|
return new UpdateController(state)
|
||||||
|
}),
|
||||||
|
folderWatcher: createGetter(() => {
|
||||||
|
const FolderWatcherController = require('./controllers/folder-watcher-controller')
|
||||||
|
return new FolderWatcherController()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add first page to location history
|
// Add first page to location history
|
||||||
@@ -92,6 +124,9 @@ function onState (err, _state) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Give global trackers
|
||||||
|
setGlobalTrackers()
|
||||||
|
|
||||||
// Restart everything we were torrenting last time the app ran
|
// Restart everything we were torrenting last time the app ran
|
||||||
resumeTorrents()
|
resumeTorrents()
|
||||||
|
|
||||||
@@ -137,7 +172,7 @@ function onState (err, _state) {
|
|||||||
window.addEventListener('focus', onFocus)
|
window.addEventListener('focus', onFocus)
|
||||||
window.addEventListener('blur', onBlur)
|
window.addEventListener('blur', onBlur)
|
||||||
|
|
||||||
if (remote.getCurrentWindow().isVisible()) {
|
if (electron.remote.getCurrentWindow().isVisible()) {
|
||||||
sound.play('STARTUP')
|
sound.play('STARTUP')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,9 +202,9 @@ function delayedInit () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lazily loads Chromecast and Airplay support
|
// Lazily loads Chromecast and Airplay support
|
||||||
async function lazyLoadCast () {
|
function lazyLoadCast () {
|
||||||
if (!Cast) {
|
if (!Cast) {
|
||||||
Cast = (await import('./lib/cast')).default
|
Cast = require('./lib/cast')
|
||||||
Cast.init(state, update) // Search the local network for Chromecast and Airplays
|
Cast.init(state, update) // Search the local network for Chromecast and Airplays
|
||||||
}
|
}
|
||||||
return Cast
|
return Cast
|
||||||
@@ -282,6 +317,7 @@ 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,
|
||||||
|
updateGlobalTrackers: (trackers) => setGlobalTrackers(trackers),
|
||||||
startFolderWatcher: () => controllers.folderWatcher().start(),
|
startFolderWatcher: () => controllers.folderWatcher().start(),
|
||||||
stopFolderWatcher: () => controllers.folderWatcher().stop(),
|
stopFolderWatcher: () => controllers.folderWatcher().stop(),
|
||||||
|
|
||||||
@@ -384,6 +420,10 @@ function escapeBack () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setGlobalTrackers () {
|
||||||
|
controllers.torrentList().setGlobalTrackers(state.getGlobalTrackers())
|
||||||
|
}
|
||||||
|
|
||||||
// Starts all torrents that aren't paused on program startup
|
// Starts all torrents that aren't paused on program startup
|
||||||
function resumeTorrents () {
|
function resumeTorrents () {
|
||||||
state.saved.torrents
|
state.saved.torrents
|
||||||
@@ -400,7 +440,7 @@ function resumeTorrents () {
|
|||||||
// Set window dimensions to match video dimensions or fill the screen
|
// Set window dimensions to match video dimensions or fill the screen
|
||||||
function setDimensions (dimensions) {
|
function setDimensions (dimensions) {
|
||||||
// Don't modify the window size if it's already maximized
|
// Don't modify the window size if it's already maximized
|
||||||
if (remote.getCurrentWindow().isMaximized()) {
|
if (electron.remote.getCurrentWindow().isMaximized()) {
|
||||||
state.window.bounds = null
|
state.window.bounds = null
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -412,7 +452,7 @@ function setDimensions (dimensions) {
|
|||||||
width: window.outerWidth,
|
width: window.outerWidth,
|
||||||
height: window.outerHeight
|
height: window.outerHeight
|
||||||
}
|
}
|
||||||
state.window.wasMaximized = remote.getCurrentWindow().isMaximized
|
state.window.wasMaximized = electron.remote.getCurrentWindow().isMaximized
|
||||||
|
|
||||||
// Limit window size to screen size
|
// Limit window size to screen size
|
||||||
const screenWidth = window.screen.width
|
const screenWidth = window.screen.width
|
||||||
@@ -487,7 +527,7 @@ const editableHtmlTags = new Set(['input', 'textarea'])
|
|||||||
|
|
||||||
function onPaste (e) {
|
function onPaste (e) {
|
||||||
if (e && editableHtmlTags.has(e.target.tagName.toLowerCase())) return
|
if (e && editableHtmlTags.has(e.target.tagName.toLowerCase())) return
|
||||||
controllers.torrentList().addTorrent(clipboard.readText())
|
controllers.torrentList().addTorrent(electron.clipboard.readText())
|
||||||
|
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1,41 @@
|
|||||||
import * as colors from 'material-ui/styles/colors'
|
const createGetter = require('fn-getter')
|
||||||
import createGetter from 'fn-getter'
|
const React = require('react')
|
||||||
import * as React from 'react'
|
|
||||||
import darkBaseTheme$0 from 'material-ui/styles/baseThemes/darkBaseTheme'
|
const { ThemeProvider, createTheme } = require('@material-ui/core/styles')
|
||||||
import getMuiTheme$0 from 'material-ui/styles/getMuiTheme'
|
const grey = require('@material-ui/core/colors/grey').default
|
||||||
import muiThemeProvider from 'material-ui/styles/MuiThemeProvider'
|
const red = require('@material-ui/core/colors/red').default
|
||||||
import Header from '../components/header.js'
|
|
||||||
import TorrentListPage from './torrent-list-page.js'
|
const Header = require('../components/header')
|
||||||
import playerPage from './player-page.js'
|
|
||||||
import createTorrentPage from './create-torrent-page.js'
|
// Perf optimization: Needed immediately, so do not lazy load it below
|
||||||
import preferencesPage from './preferences-page.js'
|
const TorrentListPage = require('./torrent-list-page')
|
||||||
import openTorrentAddressModal from '../components/open-torrent-address-modal.js'
|
|
||||||
import removeTorrentModal from '../components/remove-torrent-modal.js'
|
|
||||||
import updateAvailableModal from '../components/update-available-modal.js'
|
|
||||||
import unsupportedMediaModal from '../components/unsupported-media-modal.js'
|
|
||||||
import deleteAllTorrentsModal from '../components/delete-all-torrents-modal.js'
|
|
||||||
const darkBaseTheme = { default: darkBaseTheme$0 }.default
|
|
||||||
const getMuiTheme = getMuiTheme$0.default
|
|
||||||
const MuiThemeProvider = muiThemeProvider.default
|
|
||||||
const Views = {
|
const Views = {
|
||||||
home: createGetter(() => TorrentListPage),
|
home: createGetter(() => TorrentListPage),
|
||||||
player: createGetter(() => playerPage),
|
player: createGetter(() => require('./player-page')),
|
||||||
'create-torrent': createGetter(() => createTorrentPage),
|
'create-torrent': createGetter(() => require('./create-torrent-page')),
|
||||||
preferences: createGetter(() => preferencesPage)
|
preferences: createGetter(() => require('./preferences-page'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const Modals = {
|
const Modals = {
|
||||||
'open-torrent-address-modal': createGetter(() => openTorrentAddressModal),
|
'open-torrent-address-modal': createGetter(
|
||||||
'remove-torrent-modal': createGetter(() => removeTorrentModal),
|
() => require('../components/open-torrent-address-modal')
|
||||||
'update-available-modal': createGetter(() => updateAvailableModal),
|
),
|
||||||
'unsupported-media-modal': createGetter(() => unsupportedMediaModal),
|
'remove-torrent-modal': createGetter(() => require('../components/remove-torrent-modal')),
|
||||||
'delete-all-torrents-modal': createGetter(() => deleteAllTorrentsModal)
|
'update-available-modal': createGetter(() => require('../components/update-available-modal')),
|
||||||
|
'unsupported-media-modal': createGetter(() => require('../components/unsupported-media-modal')),
|
||||||
|
'delete-all-torrents-modal':
|
||||||
|
createGetter(() => require('../components/delete-all-torrents-modal'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fontFamily = process.platform === 'win32'
|
const fontFamily = process.platform === 'win32'
|
||||||
? '"Segoe UI", sans-serif'
|
? '"Segoe UI", sans-serif'
|
||||||
: 'BlinkMacSystemFont, "Helvetica Neue", Helvetica, sans-serif'
|
: 'BlinkMacSystemFont, "Helvetica Neue", Helvetica, sans-serif'
|
||||||
|
|
||||||
darkBaseTheme.fontFamily = fontFamily
|
let darkTheme
|
||||||
darkBaseTheme.userAgent = false
|
let lightTheme
|
||||||
darkBaseTheme.palette.primary1Color = colors.grey50
|
|
||||||
darkBaseTheme.palette.primary2Color = colors.grey50
|
|
||||||
darkBaseTheme.palette.primary3Color = colors.grey600
|
|
||||||
darkBaseTheme.palette.accent1Color = colors.redA200
|
|
||||||
darkBaseTheme.palette.accent2Color = colors.redA400
|
|
||||||
darkBaseTheme.palette.accent3Color = colors.redA100
|
|
||||||
|
|
||||||
let darkMuiTheme
|
class App extends React.Component {
|
||||||
let lightMuiTheme
|
|
||||||
|
|
||||||
export default class App extends React.Component {
|
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
|
|
||||||
@@ -67,19 +54,66 @@ export default class App extends React.Component {
|
|||||||
if (state.window.isFocused) cls.push('is-focused')
|
if (state.window.isFocused) cls.push('is-focused')
|
||||||
if (hideControls) cls.push('hide-video-controls')
|
if (hideControls) cls.push('hide-video-controls')
|
||||||
|
|
||||||
if (!darkMuiTheme) {
|
if (!darkTheme) {
|
||||||
darkMuiTheme = getMuiTheme(darkBaseTheme)
|
darkTheme = createTheme({
|
||||||
|
overrides: {
|
||||||
|
MuiButton: {
|
||||||
|
contained: {
|
||||||
|
backgroundColor: '#303030',
|
||||||
|
color: 'white',
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: '#414141',
|
||||||
|
// Reset on touch devices, it doesn't add specificity
|
||||||
|
'@media (hover: none)': {
|
||||||
|
backgroundColor: '#303030',
|
||||||
|
color: 'white'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MuiCheckbox: {
|
||||||
|
root: {
|
||||||
|
padding: '0px',
|
||||||
|
marginRight: '16px'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MuiFormControlLabel: {
|
||||||
|
label: {
|
||||||
|
color: 'white',
|
||||||
|
fontSize: '0.875rem'
|
||||||
|
},
|
||||||
|
root: {
|
||||||
|
marginLeft: '0px',
|
||||||
|
marginRight: '0px'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
palette: {
|
||||||
|
primary: {
|
||||||
|
main: grey['50']
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
main: grey['50']
|
||||||
|
},
|
||||||
|
type: 'dark'
|
||||||
|
},
|
||||||
|
typography: {
|
||||||
|
fontFamily
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
userAgent: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MuiThemeProvider muiTheme={darkMuiTheme}>
|
<ThemeProvider theme={darkTheme}>
|
||||||
<div className={'app ' + cls.join(' ')}>
|
<div className={'app ' + cls.join(' ')}>
|
||||||
<Header state={state} />
|
<Header state={state} />
|
||||||
{this.getErrorPopover()}
|
{this.getErrorPopover()}
|
||||||
<div key='content' className='content'>{this.getView()}</div>
|
<div key='content' className='content'>{this.getView()}</div>
|
||||||
{this.getModal()}
|
{this.getModal()}
|
||||||
</div>
|
</div>
|
||||||
</MuiThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,27 +135,36 @@ export default class App extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getModal () {
|
getModal () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
if (!state.modal) return
|
if (!state.modal) return
|
||||||
|
|
||||||
if (!lightMuiTheme) {
|
if (!lightTheme) {
|
||||||
const lightBaseTheme = (await import('material-ui/styles/baseThemes/lightBaseTheme')).default
|
lightTheme = createTheme({
|
||||||
lightBaseTheme.fontFamily = fontFamily
|
palette: {
|
||||||
lightBaseTheme.userAgent = false
|
secondary: {
|
||||||
lightMuiTheme = getMuiTheme(lightBaseTheme)
|
main: red.A200
|
||||||
|
},
|
||||||
|
type: 'light'
|
||||||
|
},
|
||||||
|
typography: {
|
||||||
|
fontFamily
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
userAgent: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModalContents = Modals[state.modal.id]()
|
const ModalContents = Modals[state.modal.id]()
|
||||||
return (
|
return (
|
||||||
<MuiThemeProvider muiTheme={lightMuiTheme}>
|
<ThemeProvider theme={lightTheme}>
|
||||||
<div key='modal' className='modal'>
|
<div key='modal' className='modal'>
|
||||||
<div key='modal-background' className='modal-background' />
|
<div key='modal-background' className='modal-background' />
|
||||||
<div key='modal-content' className='modal-content'>
|
<div key='modal-content' className='modal-content'>
|
||||||
<ModalContents state={state} />
|
<ModalContents state={state} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</MuiThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,3 +174,5 @@ export default class App extends React.Component {
|
|||||||
return (<View state={state} />)
|
return (<View state={state} />)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = App
|
||||||
|
|||||||
@@ -1,25 +1,21 @@
|
|||||||
import createTorrent from 'create-torrent'
|
const createTorrent = require('create-torrent')
|
||||||
import path from 'path'
|
const path = require('path')
|
||||||
import prettyBytes from 'prettier-bytes'
|
const prettyBytes = require('prettier-bytes')
|
||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import flatButton from 'material-ui/FlatButton'
|
|
||||||
import raisedButton from 'material-ui/RaisedButton'
|
|
||||||
import textField from 'material-ui/TextField'
|
|
||||||
import checkbox from 'material-ui/Checkbox'
|
|
||||||
|
|
||||||
import { dispatch, dispatcher } from '../lib/dispatcher.js'
|
const Button = require('@material-ui/core/Button').default
|
||||||
import CreateTorrentErrorPage from '../components/create-torrent-error-page.js'
|
const TextField = require('@material-ui/core/TextField').default
|
||||||
import Heading from '../components/heading.js'
|
const Checkbox = require('@material-ui/core/Checkbox').default
|
||||||
import ShowMore from '../components/show-more.js'
|
|
||||||
|
|
||||||
const FlatButton = flatButton.default
|
const CreateTorrentErrorPage = require('../components/create-torrent-error-page')
|
||||||
const RaisedButton = raisedButton.default
|
const Heading = require('../components/heading')
|
||||||
const TextField = textField.default
|
const ShowMore = require('../components/show-more')
|
||||||
const Checkbox = checkbox.default
|
|
||||||
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
|
||||||
// Shows a basic UI to create a torrent, from an already-selected file or folder.
|
// Shows a basic UI to create a torrent, from an already-selected file or folder.
|
||||||
// Includes a "Show Advanced..." button and more advanced UI.
|
// Includes a "Show Advanced..." button and more advanced UI.
|
||||||
export default class CreateTorrentPage extends React.Component {
|
class CreateTorrentPage extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
@@ -102,20 +98,23 @@ export default class CreateTorrentPage extends React.Component {
|
|||||||
{this.renderAdvanced()}
|
{this.renderAdvanced()}
|
||||||
</ShowMore>
|
</ShowMore>
|
||||||
<div className='float-right'>
|
<div className='float-right'>
|
||||||
<FlatButton
|
<Button
|
||||||
className='control cancel'
|
className='control cancel'
|
||||||
label='Cancel'
|
onClick={dispatcher('cancel')}
|
||||||
style={{
|
style={{
|
||||||
marginRight: 10
|
marginRight: 10
|
||||||
}}
|
}}
|
||||||
onClick={dispatcher('cancel')}
|
>
|
||||||
/>
|
Cancel
|
||||||
<RaisedButton
|
</Button>
|
||||||
|
<Button
|
||||||
className='control create-torrent-button'
|
className='control create-torrent-button'
|
||||||
label='Create Torrent'
|
|
||||||
primary
|
|
||||||
onClick={this.handleSubmit}
|
onClick={this.handleSubmit}
|
||||||
/>
|
color='primary'
|
||||||
|
variant='contained'
|
||||||
|
>
|
||||||
|
Create Torrent
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -137,10 +136,6 @@ export default class CreateTorrentPage extends React.Component {
|
|||||||
fileElems.push(<div key='more'>+ {files.length - maxFileElems} more</div>)
|
fileElems.push(<div key='more'>+ {files.length - maxFileElems} more</div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align the text fields
|
|
||||||
const textFieldStyle = { width: '' }
|
|
||||||
const textareaStyle = { margin: 0 }
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key='advanced' className='create-torrent-advanced'>
|
<div key='advanced' className='create-torrent-advanced'>
|
||||||
<div key='private' className='torrent-attribute'>
|
<div key='private' className='torrent-attribute'>
|
||||||
@@ -149,34 +144,32 @@ export default class CreateTorrentPage extends React.Component {
|
|||||||
className='torrent-is-private control'
|
className='torrent-is-private control'
|
||||||
style={{ display: '' }}
|
style={{ display: '' }}
|
||||||
checked={this.state.isPrivate}
|
checked={this.state.isPrivate}
|
||||||
onCheck={this.handleSetIsPrivate}
|
onChange={this.handleSetIsPrivate}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div key='trackers' className='torrent-attribute'>
|
<div key='trackers' className='torrent-attribute'>
|
||||||
<label>Trackers:</label>
|
<label>Trackers:</label>
|
||||||
<TextField
|
<TextField
|
||||||
className='torrent-trackers control'
|
className='torrent-trackers control'
|
||||||
style={textFieldStyle}
|
fullWidth
|
||||||
textareaStyle={textareaStyle}
|
maxRows={10}
|
||||||
multiLine
|
minRows={2}
|
||||||
rows={2}
|
multiline
|
||||||
rowsMax={10}
|
|
||||||
value={this.state.trackers}
|
|
||||||
onChange={this.handleSetTrackers}
|
onChange={this.handleSetTrackers}
|
||||||
|
value={this.state.trackers}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div key='comment' className='torrent-attribute'>
|
<div key='comment' className='torrent-attribute'>
|
||||||
<label>Comment:</label>
|
<label>Comment:</label>
|
||||||
<TextField
|
<TextField
|
||||||
className='torrent-comment control'
|
className='torrent-comment control'
|
||||||
style={textFieldStyle}
|
fullWidth
|
||||||
textareaStyle={textareaStyle}
|
maxRows={10}
|
||||||
hintText='Optionally describe your torrent...'
|
minRows={2}
|
||||||
multiLine
|
multiline
|
||||||
rows={2}
|
|
||||||
rowsMax={10}
|
|
||||||
value={this.state.comment}
|
|
||||||
onChange={this.handleSetComment}
|
onChange={this.handleSetComment}
|
||||||
|
placeholder='Optionally describe your torrent...'
|
||||||
|
value={this.state.comment}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div key='files' className='torrent-attribute'>
|
<div key='files' className='torrent-attribute'>
|
||||||
@@ -226,3 +219,5 @@ function containsDots (path, pathPrefix) {
|
|||||||
const suffix = path.substring(pathPrefix.length).replace(/\\/g, '/')
|
const suffix = path.substring(pathPrefix.length).replace(/\\/g, '/')
|
||||||
return ('/' + suffix).includes('/.')
|
return ('/' + suffix).includes('/.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = CreateTorrentPage
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import * as React from 'react'
|
/* globals MediaMetadata */
|
||||||
import bitfield from 'bitfield'
|
|
||||||
import prettyBytes from 'prettier-bytes'
|
|
||||||
|
|
||||||
import TorrentSummary from '../lib/torrent-summary.js'
|
const React = require('react')
|
||||||
import Playlist from '../lib/playlist.js'
|
const BitField = require('bitfield').default
|
||||||
import { dispatch, dispatcher } from '../lib/dispatcher.js'
|
const prettyBytes = require('prettier-bytes')
|
||||||
import config from '../../config.js'
|
|
||||||
import { calculateEta } from '../lib/time.js'
|
|
||||||
|
|
||||||
const BitField = bitfield.default
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
|
const Playlist = require('../lib/playlist')
|
||||||
|
const { dispatch, dispatcher } = require('../lib/dispatcher')
|
||||||
|
const config = require('../../config')
|
||||||
|
const { calculateEta } = require('../lib/time')
|
||||||
|
|
||||||
export default class Player extends React.Component {
|
// Shows a streaming video player. Standard features + Chromecast + Airplay
|
||||||
|
module.exports = class Player extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
// Show the video as large as will fit in the window, play immediately
|
// Show the video as large as will fit in the window, play immediately
|
||||||
// If the video is on Chromecast or Airplay, show a title screen instead
|
// If the video is on Chromecast or Airplay, show a title screen instead
|
||||||
@@ -36,6 +37,7 @@ export default class Player extends React.Component {
|
|||||||
tag.pause()
|
tag.pause()
|
||||||
tag.src = ''
|
tag.src = ''
|
||||||
tag.load()
|
tag.load()
|
||||||
|
navigator.mediaSession.metadata = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +54,28 @@ function renderMedia (state) {
|
|||||||
// Get the <video> or <audio> tag
|
// Get the <video> or <audio> tag
|
||||||
const mediaElement = document.querySelector(state.playing.type)
|
const mediaElement = document.querySelector(state.playing.type)
|
||||||
if (mediaElement !== null) {
|
if (mediaElement !== null) {
|
||||||
|
if (navigator.mediaSession.metadata === null && mediaElement.played.length !== 0) {
|
||||||
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
|
title: state.playing.fileName
|
||||||
|
})
|
||||||
|
navigator.mediaSession.setActionHandler('pause', () => {
|
||||||
|
dispatch('playPause')
|
||||||
|
})
|
||||||
|
navigator.mediaSession.setActionHandler('play', () => {
|
||||||
|
dispatch('playPause')
|
||||||
|
})
|
||||||
|
if (Playlist.hasNext(state)) {
|
||||||
|
navigator.mediaSession.setActionHandler('nexttrack', () => {
|
||||||
|
dispatch('nextTrack')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (Playlist.hasPrevious(state)) {
|
||||||
|
navigator.mediaSession.setActionHandler('previoustrack', () => {
|
||||||
|
dispatch('previousTrack')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state.playing.isPaused && !mediaElement.paused) {
|
if (state.playing.isPaused && !mediaElement.paused) {
|
||||||
mediaElement.pause()
|
mediaElement.pause()
|
||||||
} else if (!state.playing.isPaused && mediaElement.paused) {
|
} else if (!state.playing.isPaused && mediaElement.paused) {
|
||||||
@@ -611,6 +635,8 @@ function renderPlayerControls (state) {
|
|||||||
key='skip-previous'
|
key='skip-previous'
|
||||||
className={'icon skip-previous float-left ' + prevClass}
|
className={'icon skip-previous float-left ' + prevClass}
|
||||||
onClick={dispatcher('previousTrack')}
|
onClick={dispatcher('previousTrack')}
|
||||||
|
role='button'
|
||||||
|
aria-label='Previous track'
|
||||||
>
|
>
|
||||||
skip_previous
|
skip_previous
|
||||||
</i>,
|
</i>,
|
||||||
@@ -619,6 +645,8 @@ function renderPlayerControls (state) {
|
|||||||
key='play'
|
key='play'
|
||||||
className='icon play-pause float-left'
|
className='icon play-pause float-left'
|
||||||
onClick={dispatcher('playPause')}
|
onClick={dispatcher('playPause')}
|
||||||
|
role='button'
|
||||||
|
aria-label={state.playing.isPaused ? 'Play' : 'Pause'}
|
||||||
>
|
>
|
||||||
{state.playing.isPaused ? 'play_arrow' : 'pause'}
|
{state.playing.isPaused ? 'play_arrow' : 'pause'}
|
||||||
</i>,
|
</i>,
|
||||||
@@ -627,6 +655,8 @@ function renderPlayerControls (state) {
|
|||||||
key='skip-next'
|
key='skip-next'
|
||||||
className={'icon skip-next float-left ' + nextClass}
|
className={'icon skip-next float-left ' + nextClass}
|
||||||
onClick={dispatcher('nextTrack')}
|
onClick={dispatcher('nextTrack')}
|
||||||
|
role='button'
|
||||||
|
aria-label='Next track'
|
||||||
>
|
>
|
||||||
skip_next
|
skip_next
|
||||||
</i>,
|
</i>,
|
||||||
@@ -635,6 +665,8 @@ function renderPlayerControls (state) {
|
|||||||
key='fullscreen'
|
key='fullscreen'
|
||||||
className='icon fullscreen float-right'
|
className='icon fullscreen float-right'
|
||||||
onClick={dispatcher('toggleFullScreen')}
|
onClick={dispatcher('toggleFullScreen')}
|
||||||
|
role='button'
|
||||||
|
aria-label={state.window.isFullScreen ? 'Exit full screen' : 'Enter full screen'}
|
||||||
>
|
>
|
||||||
{state.window.isFullScreen ? 'fullscreen_exit' : 'fullscreen'}
|
{state.window.isFullScreen ? 'fullscreen_exit' : 'fullscreen'}
|
||||||
</i>
|
</i>
|
||||||
@@ -647,6 +679,8 @@ function renderPlayerControls (state) {
|
|||||||
key='subtitles'
|
key='subtitles'
|
||||||
className={'icon closed-caption float-right ' + captionsClass}
|
className={'icon closed-caption float-right ' + captionsClass}
|
||||||
onClick={handleSubtitles}
|
onClick={handleSubtitles}
|
||||||
|
role='button'
|
||||||
|
aria-label='Closed captions'
|
||||||
>
|
>
|
||||||
closed_caption
|
closed_caption
|
||||||
</i>
|
</i>
|
||||||
@@ -728,6 +762,8 @@ function renderPlayerControls (state) {
|
|||||||
<i
|
<i
|
||||||
className='icon volume-icon float-left'
|
className='icon volume-icon float-left'
|
||||||
onMouseDown={handleVolumeMute}
|
onMouseDown={handleVolumeMute}
|
||||||
|
role='button'
|
||||||
|
aria-label='Mute'
|
||||||
>
|
>
|
||||||
{volumeIcon}
|
{volumeIcon}
|
||||||
</i>
|
</i>
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import PropTypes from 'prop-types'
|
const PropTypes = require('prop-types')
|
||||||
import * as colors from 'material-ui/styles/colors'
|
|
||||||
import checkbox from 'material-ui/Checkbox'
|
|
||||||
import raisedButton from 'material-ui/RaisedButton'
|
|
||||||
|
|
||||||
import Heading from '../components/heading.js'
|
const Button = require('@material-ui/core/Button').default
|
||||||
import PathSelector from '../components/path-selector.js'
|
const Checkbox = require('@material-ui/core/Checkbox').default
|
||||||
import { dispatch } from '../lib/dispatcher.js'
|
const FormControlLabel = require('@material-ui/core/FormControlLabel').default
|
||||||
import config from '../../config.js'
|
const TextField = require('@material-ui/core/TextField').default
|
||||||
|
const grey = require('@material-ui/core/colors/grey').default
|
||||||
|
|
||||||
const Checkbox = checkbox.default
|
const Heading = require('../components/heading')
|
||||||
const RaisedButton = raisedButton.default
|
const PathSelector = require('../components/path-selector')
|
||||||
|
|
||||||
export default class PreferencesPage extends React.Component {
|
const { dispatch } = require('../lib/dispatcher')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
|
class PreferencesPage extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
@@ -30,6 +31,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
|
|
||||||
this.handleSoundNotificationsChange =
|
this.handleSoundNotificationsChange =
|
||||||
this.handleSoundNotificationsChange.bind(this)
|
this.handleSoundNotificationsChange.bind(this)
|
||||||
|
|
||||||
|
this.handleSetGlobalTrackers =
|
||||||
|
this.handleSetGlobalTrackers.bind(this)
|
||||||
|
|
||||||
|
const globalTrackers = this.props.state.getGlobalTrackers().join('\n')
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
globalTrackers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadPathSelector () {
|
downloadPathSelector () {
|
||||||
@@ -55,11 +65,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
openExternalPlayerCheckbox () {
|
openExternalPlayerCheckbox () {
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
className='control'
|
control={
|
||||||
checked={!this.props.state.saved.prefs.openExternalPlayer}
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={!this.props.state.saved.prefs.openExternalPlayer}
|
||||||
|
onChange={this.handleOpenExternalPlayerChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
label='Play torrent media files using WebTorrent'
|
label='Play torrent media files using WebTorrent'
|
||||||
onCheck={this.handleOpenExternalPlayerChange}
|
|
||||||
/>
|
/>
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
@@ -72,11 +86,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
highestPlaybackPriorityCheckbox () {
|
highestPlaybackPriorityCheckbox () {
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
className='control'
|
control={
|
||||||
checked={this.props.state.saved.prefs.highestPlaybackPriority}
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.saved.prefs.highestPlaybackPriority}
|
||||||
|
onChange={this.handleHighestPlaybackPriorityChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
label='Highest Playback Priority'
|
label='Highest Playback Priority'
|
||||||
onCheck={this.handleHighestPlaybackPriorityChange}
|
|
||||||
/>
|
/>
|
||||||
<p>Pauses all active torrents to allow playback to use all of the available bandwidth.</p>
|
<p>Pauses all active torrents to allow playback to use all of the available bandwidth.</p>
|
||||||
</Preference>
|
</Preference>
|
||||||
@@ -118,11 +136,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
autoAddTorrentsCheckbox () {
|
autoAddTorrentsCheckbox () {
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
className='control'
|
control={
|
||||||
checked={this.props.state.saved.prefs.autoAddTorrents}
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.saved.prefs.autoAddTorrents}
|
||||||
|
onChange={(e, value) => { this.handleAutoAddTorrentsChange(e, value) }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
label='Watch for new .torrent files and add them immediately'
|
label='Watch for new .torrent files and add them immediately'
|
||||||
onCheck={(e, value) => { this.handleAutoAddTorrentsChange(e, value) }}
|
|
||||||
/>
|
/>
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
@@ -180,11 +202,13 @@ export default class PreferencesPage extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<p>WebTorrent is not currently the default torrent app.</p>
|
<p>WebTorrent is not currently the default torrent app.</p>
|
||||||
<RaisedButton
|
<Button
|
||||||
className='control'
|
className='control'
|
||||||
onClick={this.handleSetDefaultApp}
|
onClick={this.handleSetDefaultApp}
|
||||||
label='Make WebTorrent the default'
|
variant='contained'
|
||||||
/>
|
>
|
||||||
|
Make WebTorrent the default
|
||||||
|
</Button>
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -200,11 +224,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
className='control'
|
control={
|
||||||
checked={this.props.state.saved.prefs.startup}
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.saved.prefs.startup}
|
||||||
|
onChange={this.handleStartupChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
label='Open WebTorrent on startup'
|
label='Open WebTorrent on startup'
|
||||||
onCheck={this.handleStartupChange}
|
|
||||||
/>
|
/>
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
@@ -213,11 +241,15 @@ export default class PreferencesPage extends React.Component {
|
|||||||
soundNotificationsCheckbox () {
|
soundNotificationsCheckbox () {
|
||||||
return (
|
return (
|
||||||
<Preference>
|
<Preference>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
className='control'
|
control={
|
||||||
checked={this.props.state.saved.prefs.soundNotifications}
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.saved.prefs.soundNotifications}
|
||||||
|
onChange={this.handleSoundNotificationsChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
label='Enable sounds'
|
label='Enable sounds'
|
||||||
onCheck={this.handleSoundNotificationsChange}
|
|
||||||
/>
|
/>
|
||||||
</Preference>
|
</Preference>
|
||||||
)
|
)
|
||||||
@@ -231,9 +263,37 @@ export default class PreferencesPage extends React.Component {
|
|||||||
dispatch('updatePreferences', 'isFileHandler', true)
|
dispatch('updatePreferences', 'isFileHandler', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGlobalTrackers () {
|
||||||
|
return (
|
||||||
|
<Preference>
|
||||||
|
<TextField
|
||||||
|
className='torrent-trackers control'
|
||||||
|
fullWidth
|
||||||
|
maxRows={10}
|
||||||
|
minRows={2}
|
||||||
|
multiline
|
||||||
|
onChange={this.handleSetGlobalTrackers}
|
||||||
|
value={this.state.globalTrackers}
|
||||||
|
/>
|
||||||
|
</Preference>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSetGlobalTrackers (e, globalTrackers) {
|
||||||
|
this.setState({ globalTrackers })
|
||||||
|
|
||||||
|
const announceList = globalTrackers
|
||||||
|
.split('\n')
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.filter((s) => s !== '')
|
||||||
|
|
||||||
|
dispatch('updatePreferences', 'globalTrackers', announceList)
|
||||||
|
dispatch('updateGlobalTrackers', announceList)
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const style = {
|
const style = {
|
||||||
color: colors.grey400,
|
color: grey['400'],
|
||||||
marginLeft: 25,
|
marginLeft: 25,
|
||||||
marginRight: 25
|
marginRight: 25
|
||||||
}
|
}
|
||||||
@@ -256,6 +316,9 @@ export default class PreferencesPage extends React.Component {
|
|||||||
{this.setStartupCheckbox()}
|
{this.setStartupCheckbox()}
|
||||||
{this.soundNotificationsCheckbox()}
|
{this.soundNotificationsCheckbox()}
|
||||||
</PreferencesSection>
|
</PreferencesSection>
|
||||||
|
<PreferencesSection title='Trackers'>
|
||||||
|
{this.setGlobalTrackers()}
|
||||||
|
</PreferencesSection>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -288,3 +351,5 @@ class Preference extends React.Component {
|
|||||||
return (<div style={style}>{this.props.children}</div>)
|
return (<div style={style}>{this.props.children}</div>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = PreferencesPage
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import * as React from 'react'
|
const React = require('react')
|
||||||
import prettyBytes from 'prettier-bytes'
|
const prettyBytes = require('prettier-bytes')
|
||||||
import checkbox from 'material-ui/Checkbox'
|
|
||||||
import linearProgress from 'material-ui/LinearProgress'
|
|
||||||
|
|
||||||
import TorrentSummary from '../lib/torrent-summary.js'
|
const Checkbox = require('@material-ui/core/Checkbox').default
|
||||||
import TorrentPlayer from '../lib/torrent-player.js'
|
const LinearProgress = require('@material-ui/core/LinearProgress').default
|
||||||
import { dispatcher } from '../lib/dispatcher.js'
|
|
||||||
import { calculateEta } from '../lib/time.js'
|
|
||||||
|
|
||||||
const Checkbox = checkbox.default
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
const LinearProgress = linearProgress.default
|
const TorrentPlayer = require('../lib/torrent-player')
|
||||||
|
const { dispatcher } = require('../lib/dispatcher')
|
||||||
|
const { calculateEta } = require('../lib/time')
|
||||||
|
|
||||||
export default class TorrentList extends React.Component {
|
module.exports = class TorrentList extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
|
|
||||||
@@ -126,19 +124,19 @@ export default class TorrentList extends React.Component {
|
|||||||
const isActive = ['downloading', 'seeding'].includes(torrentSummary.status)
|
const isActive = ['downloading', 'seeding'].includes(torrentSummary.status)
|
||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
key='download-button'
|
checked={isActive}
|
||||||
className={'control download ' + torrentSummary.status}
|
className={'control download ' + torrentSummary.status}
|
||||||
|
key='download-button'
|
||||||
|
onChange={dispatcher('toggleTorrent', infoHash)}
|
||||||
|
onClick={stopPropagation}
|
||||||
style={{
|
style={{
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
width: 32
|
marginRight: '12px',
|
||||||
|
'& .MuiSvgIconRoot': {
|
||||||
|
width: '20px',
|
||||||
|
height: '20px'
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
iconStyle={{
|
|
||||||
width: 20,
|
|
||||||
height: 20
|
|
||||||
}}
|
|
||||||
checked={isActive}
|
|
||||||
onClick={stopPropagation}
|
|
||||||
onCheck={dispatcher('toggleTorrent', infoHash)}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -157,7 +155,7 @@ export default class TorrentList extends React.Component {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div key='progress-bar' style={styles.wrapper}>
|
<div key='progress-bar' style={styles.wrapper}>
|
||||||
<LinearProgress style={styles.progress} mode='determinate' value={progress} />
|
<LinearProgress style={styles.progress} value={progress} variant='determinate' />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,24 @@
|
|||||||
/* eslint-disable import/first */
|
|
||||||
// To keep the UI snappy, we run WebTorrent in its own hidden window, a separate
|
// To keep the UI snappy, we run WebTorrent in its own hidden window, a separate
|
||||||
// process from the main window.
|
// process from the main window.
|
||||||
console.time('init')
|
console.time('init')
|
||||||
|
|
||||||
import crypto from 'crypto'
|
const crypto = require('crypto')
|
||||||
import util from 'util'
|
const util = require('util')
|
||||||
import { announceList as defaultAnnounceList } from 'create-torrent'
|
const { ipcRenderer } = require('electron')
|
||||||
import electron from 'electron'
|
const fs = require('fs')
|
||||||
import fs from 'fs'
|
const mm = require('music-metadata')
|
||||||
import * as mm from 'music-metadata'
|
const networkAddress = require('network-address')
|
||||||
import networkAddress from 'network-address'
|
const path = require('path')
|
||||||
import path from 'path'
|
const WebTorrent = require('webtorrent')
|
||||||
import WebTorrent from 'webtorrent'
|
|
||||||
|
|
||||||
import config from '../config.js'
|
const config = require('../config')
|
||||||
import { TorrentKeyNotFoundError } from './lib/errors.js'
|
const { TorrentKeyNotFoundError } = require('./lib/errors')
|
||||||
import torrentPoster from './lib/torrent-poster.js'
|
const torrentPoster = require('./lib/torrent-poster')
|
||||||
|
|
||||||
const { ipcRenderer } = electron
|
|
||||||
|
|
||||||
// Force use of webtorrent trackers on all torrents
|
|
||||||
globalThis.WEBTORRENT_ANNOUNCE = defaultAnnounceList
|
|
||||||
.map((arr) => arr[0])
|
|
||||||
.filter((url) => url.indexOf('wss://') === 0 || url.indexOf('ws://') === 0)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebTorrent version.
|
* WebTorrent version.
|
||||||
*/
|
*/
|
||||||
const VERSION = JSON.parse(fs.readFileSync('package.json').toString()).version
|
const VERSION = require('../../package.json').version
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version number in Azureus-style. Generated from major and minor semver version.
|
* Version number in Azureus-style. Generated from major and minor semver version.
|
||||||
@@ -68,6 +59,8 @@ init()
|
|||||||
function init () {
|
function init () {
|
||||||
listenToClientEvents()
|
listenToClientEvents()
|
||||||
|
|
||||||
|
ipcRenderer.on('wt-set-global-trackers', (e, globalTrackers) =>
|
||||||
|
setGlobalTrackers(globalTrackers))
|
||||||
ipcRenderer.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
|
ipcRenderer.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
|
||||||
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
|
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
|
||||||
ipcRenderer.on('wt-stop-torrenting', (e, infoHash) =>
|
ipcRenderer.on('wt-stop-torrenting', (e, infoHash) =>
|
||||||
@@ -102,6 +95,11 @@ function listenToClientEvents () {
|
|||||||
client.on('error', (err) => ipcRenderer.send('wt-error', null, err.message))
|
client.on('error', (err) => ipcRenderer.send('wt-error', null, err.message))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the default trackers
|
||||||
|
function setGlobalTrackers (globalTrackers) {
|
||||||
|
globalThis.WEBTORRENT_ANNOUNCE = globalTrackers
|
||||||
|
}
|
||||||
|
|
||||||
// Starts a given TorrentID, which can be an infohash, magnet URI, etc.
|
// Starts a given TorrentID, which can be an infohash, magnet URI, etc.
|
||||||
// Returns a WebTorrent object. See https://git.io/vik9M
|
// Returns a WebTorrent object. See https://git.io/vik9M
|
||||||
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
|
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ textarea,
|
|||||||
text-shadow: rgba(0, 0, 0, 0.5) 0 0 4px;
|
text-shadow: rgba(0, 0, 0, 0.5) 0 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.torrent .metadata span:not(:last-child)::after {
|
.torrent .metadata .ellipsis > span:not(:last-child):not(.control)::after {
|
||||||
content: ' • ';
|
content: ' • ';
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id='body'></div>
|
<div id='body'></div>
|
||||||
<script type="module" src="../build/renderer/main.js"></script>
|
<script>require('../build/renderer/main.js')</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user