Compare commits
125 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2c3c182d0 | ||
|
|
687038560c | ||
|
|
09d00c6383 | ||
|
|
957c5b64e9 | ||
|
|
a82498ba16 | ||
|
|
3b05b52e57 | ||
|
|
cdfb907c75 | ||
|
|
c2abb50e9e | ||
|
|
99f4fc96bf | ||
|
|
043f81996e | ||
|
|
213f2f124d | ||
|
|
96e7e83e20 | ||
|
|
e5fccd93a8 | ||
|
|
78e46f5576 | ||
|
|
69ce07fbf7 | ||
|
|
827131e136 | ||
|
|
c764bf4884 | ||
|
|
972203d675 | ||
|
|
2c382e14b5 | ||
|
|
c298950d34 | ||
|
|
00f2e5ccd6 | ||
|
|
8d86cffabd | ||
|
|
568fede67e | ||
|
|
944eb8b8b0 | ||
|
|
c3cdda354e | ||
|
|
25ed12ba3c | ||
|
|
830312842b | ||
|
|
95d6ec5fdd | ||
|
|
9fbee6cfeb | ||
|
|
9892f88530 | ||
|
|
10ad990f97 | ||
|
|
0ee7e80fd2 | ||
|
|
7d1520f858 | ||
|
|
77ba258fbf | ||
|
|
06366529cc | ||
|
|
d1c263f1b0 | ||
|
|
d7a031a457 | ||
|
|
b7201f424d | ||
|
|
89f2785244 | ||
|
|
cffe416f50 | ||
|
|
d0eea34e9b | ||
|
|
4e82718788 | ||
|
|
293ca60e72 | ||
|
|
af4a6a5960 | ||
|
|
e01c0b6f43 | ||
|
|
086d8bf00a | ||
|
|
50c100130a | ||
|
|
edcea2661a | ||
|
|
efc984f1dd | ||
|
|
a046db40d2 | ||
|
|
9068909b4d | ||
|
|
4bb2056bc9 | ||
|
|
ed0f05abc4 | ||
|
|
0c44e10ca7 | ||
|
|
d8c9014471 | ||
|
|
7cf1d96a80 | ||
|
|
ffd9fbda57 | ||
|
|
d8904aaf6e | ||
|
|
de2db211cc | ||
|
|
e8ab172d1b | ||
|
|
32f96c03dd | ||
|
|
5158606740 | ||
|
|
0de80165ed | ||
|
|
dcaa99d2bf | ||
|
|
1a1a4cd5d0 | ||
|
|
4cbad1fccd | ||
|
|
f818564dd1 | ||
|
|
8be690a26e | ||
|
|
8081d42477 | ||
|
|
b0b6069fe2 | ||
|
|
994aed9af7 | ||
|
|
852fc86cbd | ||
|
|
8801a87a58 | ||
|
|
1e10f0083c | ||
|
|
bb40f0f11a | ||
|
|
78d7243a08 | ||
|
|
09724dddd9 | ||
|
|
59286ff3cb | ||
|
|
3f79c90868 | ||
|
|
33c48d4dfb | ||
|
|
48fbcd7303 | ||
|
|
cdb7b6eb44 | ||
|
|
90b72523b7 | ||
|
|
a1fd30f4f5 | ||
|
|
fcae064dbb | ||
|
|
5815d8efe7 | ||
|
|
0be8a73621 | ||
|
|
76e1d7777c | ||
|
|
e10a84b294 | ||
|
|
5ff2d893b9 | ||
|
|
02f5dbb63f | ||
|
|
d4cfc32c8d | ||
|
|
d5820063a1 | ||
|
|
21de048738 | ||
|
|
06cdac8121 | ||
|
|
f1aa1bdd59 | ||
|
|
44f621b4de | ||
|
|
fd1a1f0f7e | ||
|
|
a38b5220ac | ||
|
|
428a07101a | ||
|
|
f1ef9daa8f | ||
|
|
46d5c9c9e9 | ||
|
|
ecd877551e | ||
|
|
76e071e965 | ||
|
|
5623c1024e | ||
|
|
1a20155f66 | ||
|
|
9a17313a0c | ||
|
|
b3ec61ddd8 | ||
|
|
7dcddf90e9 | ||
|
|
a94fdcae61 | ||
|
|
f9bb83815f | ||
|
|
dccaf16a02 | ||
|
|
f4ee831319 | ||
|
|
5bcf1c6379 | ||
|
|
d2eb87e821 | ||
|
|
be08925eb4 | ||
|
|
5698c22e75 | ||
|
|
2114532f62 | ||
|
|
815ba00a6b | ||
|
|
bcd9f046fb | ||
|
|
44a0f760de | ||
|
|
1e5ac1df9c | ||
|
|
4cdc3085ff | ||
|
|
e483263d70 | ||
|
|
bd41bd4db8 |
2
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
<!-- DO NOT POST LINKS OR REFERENCES TO COPYRIGHTED CONTENT IN YOUR ISSUE. -->
|
||||||
|
|
||||||
**What version of WebTorrent Desktop?** (See the 'About WebTorrent' menu)
|
**What version of WebTorrent Desktop?** (See the 'About WebTorrent' menu)
|
||||||
|
|
||||||
**What operating system and version?**
|
**What operating system and version?**
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
build/
|
|
||||||
dist/
|
|
||||||
@@ -34,5 +34,8 @@
|
|||||||
- PurgingPanda (t3ch0wn3r@gmail.com)
|
- PurgingPanda (t3ch0wn3r@gmail.com)
|
||||||
- Kai Curtis (morecode@kcurtis.com)
|
- Kai Curtis (morecode@kcurtis.com)
|
||||||
- Omri Litov (omrilitov@gmail.com)
|
- Omri Litov (omrilitov@gmail.com)
|
||||||
|
- Alexey Romanov (romanalexey@gmail.com)
|
||||||
|
- Karan Thakkar (karanjthakkar@gmail.com)
|
||||||
|
- Nuno Campos (nuno.campos@me.com)
|
||||||
|
|
||||||
#### Generated by bin/update-authors.sh.
|
#### Generated by bin/update-authors.sh.
|
||||||
|
|||||||
96
CHANGELOG.md
@@ -1,5 +1,51 @@
|
|||||||
# WebTorrent Desktop Version History
|
# WebTorrent Desktop Version History
|
||||||
|
|
||||||
|
## v0.18.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add a new "Transfers" menu for pausing or resuming all torrents (#1027)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Update Electron to 1.4.15
|
||||||
|
- Windows 32-bit: App can use 4GB of memory instead of just 2GB
|
||||||
|
- Fix "Portable App" writing crash reports to "%APPDATA%\Temp" (Windows)
|
||||||
|
- Updated WebTorrent engine to 0.98.5
|
||||||
|
- Fix issue where http web seeds would sometimes stall
|
||||||
|
- Don't send 'completed' event to tracker again if torrent is already complete
|
||||||
|
- Add more peer ID entropy
|
||||||
|
- Set user-agent header for tracker http requests
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix paste shortcut in tracker list on Create Torrent page (#1112)
|
||||||
|
- Auto-focus the 'OK' button in modal dialogs (#1058)
|
||||||
|
- Fix formatting issue in the speed stats on the Player page (#1039)
|
||||||
|
|
||||||
|
## v0.17.2 - 2016-10-10
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Windows: Fix impossible-to-delete "Wired CD" default torrent
|
||||||
|
- Throttle browser-window 'move' and 'resize' events
|
||||||
|
- Fix crash ("Cannot read property 'files' of null" error)
|
||||||
|
- Fix crash ("TypeError: Cannot read property 'startPiece' of undefined")
|
||||||
|
|
||||||
|
## v0.17.1 - 2016-10-03
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Faster startup (improved by ~25%)
|
||||||
|
- Update Electron to 1.4.2
|
||||||
|
- Remove support for pasting multiple newline-separated magnet links
|
||||||
|
- Reduce UX sound volume
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix external player (VLC, etc.) opening before HTTP server was ready
|
||||||
|
- Windows (Portable App): Fix "Portable App" mode
|
||||||
|
- Write application support files to the "Portable Settings" folder
|
||||||
|
- Stop writing Electron "single instance" lock file to "%APPDATA%\Roaming\WebTorrent"
|
||||||
|
- Some temp data is still written to "%APPDATA%\Temp" (will be fixed in future version)
|
||||||
|
- Don't show pointer cursor on torrent list checkbox
|
||||||
|
- Trim extra whitespace from magnet links pasted into "Open Torrent Address" dialog
|
||||||
|
- Fix weird outline on 'Create Torrent' button
|
||||||
|
|
||||||
## v0.17.0 - 2016-09-23
|
## v0.17.0 - 2016-09-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -21,7 +67,7 @@
|
|||||||
## v0.16.0 - 2016-09-18
|
## v0.16.0 - 2016-09-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- **Windows 64-bit support!** ([#931](https://github.com/feross/webtorrent-desktop/pull/931))
|
- **Windows 64-bit support!** ([#931](https://github.com/webtorrent/webtorrent-desktop/pull/931))
|
||||||
- Existing 32-bit users will update to 64-bit automatically in next release
|
- Existing 32-bit users will update to 64-bit automatically in next release
|
||||||
- 64-bit reduces likelihood of out-of-memory errors by increasing the address space
|
- 64-bit reduces likelihood of out-of-memory errors by increasing the address space
|
||||||
|
|
||||||
@@ -81,16 +127,13 @@
|
|||||||
## v0.12.0 - 2016-08-23
|
## v0.12.0 - 2016-08-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Custom external media player
|
- Custom external media player
|
||||||
- Linux: add system-wide launcher and icons for Debian, including Ubuntu
|
- Linux: add system-wide launcher and icons for Debian, including Ubuntu
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Telemetry improvements: redact stacktraces, log app version
|
- Telemetry improvements: redact stacktraces, log app version
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix playback and download of default torrents ("missing path" error) (#804)
|
- Fix playback and download of default torrents ("missing path" error) (#804)
|
||||||
- Fix Delete Torrent + Data for newly added magnet links
|
- Fix Delete Torrent + Data for newly added magnet links
|
||||||
- Fix jumpToTime error (#804)
|
- Fix jumpToTime error (#804)
|
||||||
@@ -103,13 +146,11 @@
|
|||||||
- Check for missing default download path and torrent folders on start up (#776)
|
- Check for missing default download path and torrent folders on start up (#776)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Do not automatically set WebTorrent as the default handler for torrents (#771)
|
- Do not automatically set WebTorrent as the default handler for torrents (#771)
|
||||||
- Torrents can only be created from the home screen (#770)
|
- Torrents can only be created from the home screen (#770)
|
||||||
- Update Electron to 1.3.3 (#772)
|
- Update Electron to 1.3.3 (#772)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Allow modifying the default tracker list on the Create Torrent page (#775)
|
- Allow modifying the default tracker list on the Create Torrent page (#775)
|
||||||
- Prevent opening multiple stacked Preference windows or Create Torrent windows (#770)
|
- Prevent opening multiple stacked Preference windows or Create Torrent windows (#770)
|
||||||
- Windows: Player window auto-resize does not match video aspect ratio (#565)
|
- Windows: Player window auto-resize does not match video aspect ratio (#565)
|
||||||
@@ -118,13 +159,11 @@
|
|||||||
## v0.10.0 - 2016-08-05
|
## v0.10.0 - 2016-08-05
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Drag-and-drop magnet links (selected text) is now supported (#284)
|
- Drag-and-drop magnet links (selected text) is now supported (#284)
|
||||||
- Windows: Add "User Tasks" shortcuts to app icon in Start Menu (#114)
|
- Windows: Add "User Tasks" shortcuts to app icon in Start Menu (#114)
|
||||||
- Linux: Show badge count for completed torrent downloads
|
- Linux: Show badge count for completed torrent downloads
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Change WebTorrent Desktop peer ID prefix to 'WD' to distinguish from WebTorrent in the browser, 'WW' (#688)
|
- Change WebTorrent Desktop peer ID prefix to 'WD' to distinguish from WebTorrent in the browser, 'WW' (#688)
|
||||||
- Switch UI to React to improve UI rendering speed (#729)
|
- Switch UI to React to improve UI rendering speed (#729)
|
||||||
- The primary bottleneck was actually `hyperx`, not `virtual-dom`.
|
- The primary bottleneck was actually `hyperx`, not `virtual-dom`.
|
||||||
@@ -141,7 +180,6 @@
|
|||||||
- Location history abstraction released independently as [`location-history`](https://www.npmjs.com/package/location-history)
|
- Location history abstraction released independently as [`location-history`](https://www.npmjs.com/package/location-history)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- When streaming to VLC, set VLC window title to torrent file name (#746)
|
- When streaming to VLC, set VLC window title to torrent file name (#746)
|
||||||
- Fix "Cannot read property 'numPiecesPresent' of undefined" exception (#695)
|
- Fix "Cannot read property 'numPiecesPresent' of undefined" exception (#695)
|
||||||
- Fix rare case where config file could not be completely written (#733)
|
- Fix rare case where config file could not be completely written (#733)
|
||||||
@@ -149,35 +187,29 @@
|
|||||||
## v0.9.0 - 2016-07-20
|
## v0.9.0 - 2016-07-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Save selected subtitles
|
- Save selected subtitles
|
||||||
- Ask for confirmation before deleting torrents
|
- Ask for confirmation before deleting torrents
|
||||||
- Support Debian Jessie
|
- Support Debian Jessie
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Only send telemetry in production
|
- Only send telemetry in production
|
||||||
- Clean up the code. Split main.js, refactor lots of things
|
- Clean up the code. Split main.js, refactor lots of things
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix state.playing.jumpToTime behavior
|
- Fix state.playing.jumpToTime behavior
|
||||||
- Remove torrent file and poster image when deleting a torrent
|
- Remove torrent file and poster image when deleting a torrent
|
||||||
|
|
||||||
## v0.8.1 - 2016-06-24
|
## v0.8.1 - 2016-06-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- New URI handler: stream-magnet
|
- New URI handler: stream-magnet
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- DLNA crashing bug
|
- DLNA crashing bug
|
||||||
|
|
||||||
## v0.8.0 - 2016-06-23
|
## v0.8.0 - 2016-06-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Cast menu: choose which Chromecast, Airplay, or DLNA device you want to use
|
- Cast menu: choose which Chromecast, Airplay, or DLNA device you want to use
|
||||||
- Telemetry: send basic data, plus stats on how often the play button works
|
- Telemetry: send basic data, plus stats on how often the play button works
|
||||||
- Make posters from jpeg files, not just jpg
|
- Make posters from jpeg files, not just jpg
|
||||||
@@ -185,17 +217,14 @@
|
|||||||
- Windows thumbnail bar with a play/pause button
|
- Windows thumbnail bar with a play/pause button
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Nicer modal styles
|
- Nicer modal styles
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Windows tray icon now stays in the right state
|
- Windows tray icon now stays in the right state
|
||||||
|
|
||||||
## v0.7.2 - 2016-06-02
|
## v0.7.2 - 2016-06-02
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix exception that affects users upgrading from v0.5.1 or older
|
- Fix exception that affects users upgrading from v0.5.1 or older
|
||||||
- Ensure `state.saved.prefs` configuration exists
|
- Ensure `state.saved.prefs` configuration exists
|
||||||
- Fix window title on "About WebTorrent" window
|
- Fix window title on "About WebTorrent" window
|
||||||
@@ -203,23 +232,19 @@
|
|||||||
## v0.7.1 - 2016-06-02
|
## v0.7.1 - 2016-06-02
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Change "Step Forward" keyboard shortcut to `Alt+Left` (Windows)
|
- Change "Step Forward" keyboard shortcut to `Alt+Left` (Windows)
|
||||||
- Change "Step Backward" keyboard shortcut to to `Alt+Right` (Windows)
|
- Change "Step Backward" keyboard shortcut to to `Alt+Right` (Windows)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- First time startup bug -- invalid torrent/poster paths
|
- First time startup bug -- invalid torrent/poster paths
|
||||||
|
|
||||||
## v0.7.0 - 2016-06-02
|
## v0.7.0 - 2016-06-02
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Improved AirPlay support -- using the new [`airplayer`](https://www.npmjs.com/package/airplayer) package
|
- Improved AirPlay support -- using the new [`airplayer`](https://www.npmjs.com/package/airplayer) package
|
||||||
- Remember volume setting in player, for as long as the app is open
|
- Remember volume setting in player, for as long as the app is open
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Add (+) button now also accepts non .torrent files and creates a torrent from
|
- Add (+) button now also accepts non .torrent files and creates a torrent from
|
||||||
those files
|
those files
|
||||||
- Show prompt text in title bar for open dialogs (OS X)
|
- Show prompt text in title bar for open dialogs (OS X)
|
||||||
@@ -229,7 +254,6 @@
|
|||||||
- Fix crash reporter not working (Windows)
|
- Fix crash reporter not working (Windows)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Re-enable WebRTC (web peers)! (OS X, Windows)
|
- Re-enable WebRTC (web peers)! (OS X, Windows)
|
||||||
- Windows support was disabled in v0.6.1 to work around a bug in Electron
|
- Windows support was disabled in v0.6.1 to work around a bug in Electron
|
||||||
- OS X support was disabled in v0.4.0 to work around a 100% CPU bug
|
- OS X support was disabled in v0.4.0 to work around a 100% CPU bug
|
||||||
@@ -240,7 +264,6 @@
|
|||||||
- Fix torrent loading message UI misalignment
|
- Fix torrent loading message UI misalignment
|
||||||
|
|
||||||
### Known issues
|
### Known issues
|
||||||
|
|
||||||
- When upgrading to WebTorrent Desktop v0.7.0, some torrent metadata (file list,
|
- When upgrading to WebTorrent Desktop v0.7.0, some torrent metadata (file list,
|
||||||
selected files, whether torrent is streamable) will be cleared. Just start the
|
selected files, whether torrent is streamable) will be cleared. Just start the
|
||||||
torrent to re-populate the metadata.
|
torrent to re-populate the metadata.
|
||||||
@@ -248,7 +271,6 @@
|
|||||||
## v0.6.1 - 2016-05-26
|
## v0.6.1 - 2016-05-26
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Disable WebRTC to work around Electron crash (Windows)
|
- Disable WebRTC to work around Electron crash (Windows)
|
||||||
- Will be re-enabled in the next version of WebTorrent, which will be based on
|
- Will be re-enabled in the next version of WebTorrent, which will be based on
|
||||||
the next version of Electron, where the bug is fixed.
|
the next version of Electron, where the bug is fixed.
|
||||||
@@ -260,7 +282,6 @@
|
|||||||
## v0.6.0 - 2016-05-24
|
## v0.6.0 - 2016-05-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added Preferences page to set Download folder
|
- Added Preferences page to set Download folder
|
||||||
- Save video position, resume playback from saved position
|
- Save video position, resume playback from saved position
|
||||||
- Add additional video player keyboard shortcuts (#275)
|
- Add additional video player keyboard shortcuts (#275)
|
||||||
@@ -270,7 +291,6 @@
|
|||||||
- Add announcement feature
|
- Add announcement feature
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Nicer player UI
|
- Nicer player UI
|
||||||
- Reduce startup jank, improve startup time (#568)
|
- Reduce startup jank, improve startup time (#568)
|
||||||
- Cleanup unsupported codec detection (#569, #570)
|
- Cleanup unsupported codec detection (#569, #570)
|
||||||
@@ -278,7 +298,6 @@
|
|||||||
- Improve subtitle positioning (#551)
|
- Improve subtitle positioning (#551)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix Uncaught TypeError: Cannot read property 'update' of undefined (#567)
|
- Fix Uncaught TypeError: Cannot read property 'update' of undefined (#567)
|
||||||
- Fix bugs in LocationHistory
|
- Fix bugs in LocationHistory
|
||||||
- When player is active, and magnet link is pasted, go back to list
|
- When player is active, and magnet link is pasted, go back to list
|
||||||
@@ -289,23 +308,19 @@
|
|||||||
## v0.5.1 - 2016-05-18
|
## v0.5.1 - 2016-05-18
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix auto-updater (OS X, Windows).
|
- Fix auto-updater (OS X, Windows).
|
||||||
|
|
||||||
## v0.5.0 - 2016-05-17
|
## v0.5.0 - 2016-05-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Select/deselect individual files to torrent.
|
- Select/deselect individual files to torrent.
|
||||||
- Automatically include subtitle files (.srt, .vtt) from torrent in the subtitles menu.
|
- Automatically include subtitle files (.srt, .vtt) from torrent in the subtitles menu.
|
||||||
- "Add Subtitle File..." menu item.
|
- "Add Subtitle File..." menu item.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- When manually adding subtitle track(s), always switch to the new track.
|
- When manually adding subtitle track(s), always switch to the new track.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Magnet links throw exception on app launch. (OS X)
|
- Magnet links throw exception on app launch. (OS X)
|
||||||
- Multi-file torrents would not seed in-place, were copied to Downloads folder.
|
- Multi-file torrents would not seed in-place, were copied to Downloads folder.
|
||||||
- Missing 'About WebTorrent' menu item. (Windows)
|
- Missing 'About WebTorrent' menu item. (Windows)
|
||||||
@@ -314,7 +329,6 @@
|
|||||||
## v0.4.0 - 2016-05-13
|
## v0.4.0 - 2016-05-13
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Better Windows support!
|
- Better Windows support!
|
||||||
- Windows 32-bit build.
|
- Windows 32-bit build.
|
||||||
- Windows Portable App build.
|
- Windows Portable App build.
|
||||||
@@ -337,7 +351,6 @@
|
|||||||
- New default torrent on first launch: The WIRED CD.
|
- New default torrent on first launch: The WIRED CD.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improve app startup time by 40%.
|
- Improve app startup time by 40%.
|
||||||
- UI tweaks: Reduce font size, reduce torrent list item height.
|
- UI tweaks: Reduce font size, reduce torrent list item height.
|
||||||
- Add Playback menu for playback-related functionality.
|
- Add Playback menu for playback-related functionality.
|
||||||
@@ -348,7 +361,6 @@
|
|||||||
- Remove "Add Fake Airplay/Chromecast" menu items.
|
- Remove "Add Fake Airplay/Chromecast" menu items.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Disable WebRTC to fix 100% CPU usage/crashes caused by Chromium issue. This is
|
- Disable WebRTC to fix 100% CPU usage/crashes caused by Chromium issue. This is
|
||||||
temporary. (OS X)
|
temporary. (OS X)
|
||||||
- When fullscreen, make controls use the full window. (OS X)
|
- When fullscreen, make controls use the full window. (OS X)
|
||||||
@@ -373,24 +385,20 @@ to this release!
|
|||||||
## v0.3.3 - 2016-04-07
|
## v0.3.3 - 2016-04-07
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- App icon was incorrect (OS X)
|
- App icon was incorrect (OS X)
|
||||||
|
|
||||||
## v0.3.2 - 2016-04-07
|
## v0.3.2 - 2016-04-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Register WebTorrent as default handler for magnet links (OS X)
|
- Register WebTorrent as default handler for magnet links (OS X)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Faster startup time (50ms)
|
- Faster startup time (50ms)
|
||||||
- Update Electron to 0.37.5
|
- Update Electron to 0.37.5
|
||||||
- Remove the white flash when loading pages and resizing the window
|
- Remove the white flash when loading pages and resizing the window
|
||||||
- Fix crash when sending IPC messages
|
- Fix crash when sending IPC messages
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix installation bugs with .deb file (Linux)
|
- Fix installation bugs with .deb file (Linux)
|
||||||
- Pause audio reliably when closing the window
|
- Pause audio reliably when closing the window
|
||||||
- Enforce minimimum window size when resizing player (for audio-only .mov files, which are 0x0)
|
- Enforce minimimum window size when resizing player (for audio-only .mov files, which are 0x0)
|
||||||
@@ -398,17 +406,14 @@ to this release!
|
|||||||
## v0.3.1 - 2016-04-06
|
## v0.3.1 - 2016-04-06
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Add crash reporter to torrent engine process
|
- Add crash reporter to torrent engine process
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix cast screen background: cover, don't tile
|
- Fix cast screen background: cover, don't tile
|
||||||
|
|
||||||
## v0.3.0 - 2016-04-06
|
## v0.3.0 - 2016-04-06
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- **Ubuntu/Debian support!** (.deb installer)
|
- **Ubuntu/Debian support!** (.deb installer)
|
||||||
- **DLNA streaming support**
|
- **DLNA streaming support**
|
||||||
- Add "File > Quit" menu item (Linux)
|
- Add "File > Quit" menu item (Linux)
|
||||||
@@ -416,14 +421,12 @@ to this release!
|
|||||||
- Crash reporting
|
- Crash reporting
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- On startup, do not re-verify files when timestamps are unchanged
|
- On startup, do not re-verify files when timestamps are unchanged
|
||||||
- Moved torrent engine to an independent process, for better UI performance
|
- Moved torrent engine to an independent process, for better UI performance
|
||||||
- Removed media queries (UI resizing based on window width)
|
- Removed media queries (UI resizing based on window width)
|
||||||
- Improved Chromecast icon, when connected
|
- Improved Chromecast icon, when connected
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- "Download Complete" notification shows consistently
|
- "Download Complete" notification shows consistently
|
||||||
- Create new torrents and seed them without copying to temporary folder
|
- Create new torrents and seed them without copying to temporary folder
|
||||||
- Clicking the "Download Complete" notification will always activate app
|
- Clicking the "Download Complete" notification will always activate app
|
||||||
@@ -442,7 +445,6 @@ Thanks to @dcposch, @grunjol, and @feross for contributing to this release.
|
|||||||
## v0.2.0 - 2016-03-29
|
## v0.2.0 - 2016-03-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Minimise to tray (Windows, Linux)
|
- Minimise to tray (Windows, Linux)
|
||||||
- Show spinner and download speed when player is stalled waiting for data
|
- Show spinner and download speed when player is stalled waiting for data
|
||||||
- Highlight window on drag-and-drop
|
- Highlight window on drag-and-drop
|
||||||
@@ -451,12 +453,10 @@ Thanks to @dcposch, @grunjol, and @feross for contributing to this release.
|
|||||||
Linux users need to download new versions manually.
|
Linux users need to download new versions manually.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Renamed WebTorrent.app to WebTorrent Desktop
|
- Renamed WebTorrent.app to WebTorrent Desktop
|
||||||
- Add Cosmos Laundromat as a default torrent
|
- Add Cosmos Laundromat as a default torrent
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Only capture media keys when player is active
|
- Only capture media keys when player is active
|
||||||
- Update WebTorrent to 0.88.1 for performance improvements
|
- Update WebTorrent to 0.88.1 for performance improvements
|
||||||
- When seeding, do not proactively connect to new peers
|
- When seeding, do not proactively connect to new peers
|
||||||
@@ -516,7 +516,7 @@ Windows, and Linux. For now, we're only releasing binaries for OS X.
|
|||||||
|
|
||||||
WebTorrent Desktop is in ALPHA and under very active development – expect lots more polish in
|
WebTorrent Desktop is in ALPHA and under very active development – expect lots more polish in
|
||||||
the coming weeks! If you know JavaScript and want to help us out, there's
|
the coming weeks! If you know JavaScript and want to help us out, there's
|
||||||
[lots to do](https://github.com/feross/webtorrent-desktop/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+contribution%22)!
|
[lots to do](https://github.com/webtorrent/webtorrent-desktop/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+contribution%22)!
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ and to avoid style arguments. `npm test` runs `standard` automatically, so you d
|
|||||||
to!
|
to!
|
||||||
|
|
||||||
[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
|
[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
|
||||||
[standard-url]: https://github.com/feross/standard
|
[standard-url]: https://standardjs.com
|
||||||
|
|
||||||
## Project Governance
|
## Project Governance
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ standard guarded open source project.
|
|||||||
|
|
||||||
There are a few basic ground-rules for contributors:
|
There are a few basic ground-rules for contributors:
|
||||||
|
|
||||||
1. **No `--force` pushes** or modifying the Git history in any way.
|
1. **No `--force` pushes to master** or modifying history in any way. Rebasing and force pushing your own PR branch is fine.
|
||||||
2. **Non-master branches** should be used for ongoing work.
|
2. **Non-master branches** should be used for ongoing work.
|
||||||
3. **Significant modifications** like API changes should be subject to a **pull request**
|
3. **Significant modifications** like API changes should be subject to a **pull request**
|
||||||
to solicit feedback from other contributors.
|
to solicit feedback from other contributors.
|
||||||
@@ -74,6 +74,99 @@ By making a contribution to this project, I certify that:
|
|||||||
including my sign-off) is maintained indefinitely and may be redistributed consistent
|
including my sign-off) is maintained indefinitely and may be redistributed consistent
|
||||||
with this project or the open source license(s) involved.
|
with this project or the open source license(s) involved.
|
||||||
|
|
||||||
|
## Release Procedure
|
||||||
|
|
||||||
|
### 1. Create a new version
|
||||||
|
|
||||||
|
- Update `AUTHORS`
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run update-authors
|
||||||
|
```
|
||||||
|
|
||||||
|
Commit if necessary. The commit message should be "authors".
|
||||||
|
|
||||||
|
- Write the changelog
|
||||||
|
|
||||||
|
You can use `git log --oneline <last version tag>..HEAD` to get a list of changes.
|
||||||
|
|
||||||
|
Summarize them concisely in `CHANGELOG.md`. The commit message should be "changelog".
|
||||||
|
|
||||||
|
- Update the version
|
||||||
|
|
||||||
|
```
|
||||||
|
npm version [major|minor|patch]
|
||||||
|
```
|
||||||
|
|
||||||
|
This creates both a commit and a git tag.
|
||||||
|
|
||||||
|
- Make a PR
|
||||||
|
|
||||||
|
Once the PR is reviewed, merge it:
|
||||||
|
|
||||||
|
```
|
||||||
|
git push origin <branch-name>:master
|
||||||
|
```
|
||||||
|
|
||||||
|
This makes it so that the commit hash on master matches the commit hash of the version tag.
|
||||||
|
|
||||||
|
Finally, run:
|
||||||
|
|
||||||
|
```
|
||||||
|
git push --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Create the release binaries
|
||||||
|
|
||||||
|
- On a Mac:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run package -- darwin --sign
|
||||||
|
npm run package -- linux --sign
|
||||||
|
```
|
||||||
|
|
||||||
|
- On Windows, or in a Windows VM:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run package -- win32 --sign
|
||||||
|
```
|
||||||
|
|
||||||
|
- Then, upload the release binaries to Github:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run gh-release
|
||||||
|
```
|
||||||
|
|
||||||
|
Follow the URL to a newly created Github release page. Manually upload the binaries from
|
||||||
|
`webtorrent-desktop/dist/`. Open the previous release in another tab, and make sure that you
|
||||||
|
are uploading the same set of files, no more, no less.
|
||||||
|
|
||||||
|
### 3. Test it
|
||||||
|
|
||||||
|
**This is the most important part.**
|
||||||
|
|
||||||
|
- Manually download the binaries for each platform from Github.
|
||||||
|
|
||||||
|
**Do not use your locally built binaries.** Modern OSs treat executables differently if they've
|
||||||
|
been downloaded, even though the files are byte for byte identical. This ensures that the
|
||||||
|
codesigning worked and is valid.
|
||||||
|
|
||||||
|
- Smoke test WebTorrent Desktop on each platform.
|
||||||
|
|
||||||
|
See Smoke Tests below for details. Open DevTools
|
||||||
|
on Windows and Mac, and ensure that the auto updater is running. If the auto updater does not
|
||||||
|
run, users will successfully auto update to this new version, and then be stuck there forever.
|
||||||
|
|
||||||
|
### 4. Ship it
|
||||||
|
|
||||||
|
- Update the website
|
||||||
|
|
||||||
|
Create a pull request in [webtorrent.io](https://github.com/webtorrent/webtorrent.io). Update
|
||||||
|
`config.js`, updating the desktop app version.
|
||||||
|
|
||||||
|
As soon as this PR is merged, Jenkins will automatically redeploy the WebTorrent website, and
|
||||||
|
hundreds of thousands of users around the world will start auto updating. **Merge with care.**
|
||||||
|
|
||||||
## Smoke Tests
|
## Smoke Tests
|
||||||
|
|
||||||
Before a release, check that the following basic use cases work correctly:
|
Before a release, check that the following basic use cases work correctly:
|
||||||
|
|||||||
41
README.md
@@ -1,6 +1,8 @@
|
|||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<br>
|
<br>
|
||||||
<a href="https://webtorrent.io"><img src="https://webtorrent.io/img/WebTorrent.png" alt="WebTorrent" width="200"></a>
|
<a href="https://webtorrent.io">
|
||||||
|
<img src="https://webtorrent.io/img/WebTorrent.png" alt="WebTorrent" width="200">
|
||||||
|
</a>
|
||||||
<br>
|
<br>
|
||||||
WebTorrent Desktop
|
WebTorrent Desktop
|
||||||
<br>
|
<br>
|
||||||
@@ -10,16 +12,17 @@
|
|||||||
<h4 align="center">The streaming torrent app. For Mac, Windows, and Linux.</h4>
|
<h4 align="center">The streaming torrent app. For Mac, Windows, and Linux.</h4>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://gitter.im/feross/webtorrent"><img src="https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg" alt="Gitter"></a>
|
<a href="https://gitter.im/webtorrent/webtorrent"><img src="https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg" alt="gitter"></a>
|
||||||
<a href="https://travis-ci.org/feross/webtorrent-desktop"><img src="https://img.shields.io/travis/feross/webtorrent-desktop/master.svg" alt="Travis"></a>
|
<a href="https://github.com/webtorrent/webtorrent-desktop/releases"><img src="https://img.shields.io/github/release/webtorrent/webtorrent-desktop.svg" alt="github release"></a>
|
||||||
<a href="https://github.com/feross/webtorrent-desktop/releases"><img src="https://img.shields.io/github/release/feross/webtorrent-desktop.svg" alt="Release"></a>
|
<a href="https://travis-ci.org/webtorrent/webtorrent-desktop"><img src="https://img.shields.io/travis/webtorrent/webtorrent-desktop/master.svg" alt="travis"></a>
|
||||||
|
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard - JavaScript Style Guide"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Download the latest version of WebTorrent Desktop from
|
Download the latest version of WebTorrent Desktop from
|
||||||
[the official website](https://webtorrent.io/desktop/) or the
|
[the official website](https://webtorrent.io/desktop/) or the
|
||||||
[GitHub releases](https://github.com/feross/webtorrent-desktop/releases) page.
|
[GitHub releases](https://github.com/webtorrent/webtorrent-desktop/releases) page.
|
||||||
|
|
||||||
**WebTorrent Desktop** is under very active development. You can try out the
|
**WebTorrent Desktop** is under very active development. You can try out the
|
||||||
current (unstable) development version by cloning the Git repo. See the
|
current (unstable) development version by cloning the Git repo. See the
|
||||||
@@ -37,7 +40,7 @@ instructions below in the ["How to Contribute"](#how-to-contribute) section.
|
|||||||
### Get the code
|
### Get the code
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone https://github.com/feross/webtorrent-desktop.git
|
$ git clone https://github.com/webtorrent/webtorrent-desktop.git
|
||||||
$ cd webtorrent-desktop
|
$ cd webtorrent-desktop
|
||||||
$ npm install
|
$ npm install
|
||||||
```
|
```
|
||||||
@@ -65,22 +68,28 @@ $ npm test
|
|||||||
### Run integration tests
|
### Run integration tests
|
||||||
|
|
||||||
```
|
```
|
||||||
$ npm run integration-test
|
$ npm run test-integration
|
||||||
```
|
```
|
||||||
|
|
||||||
The integration tests use Spectron and Tape. They click through the app, taking screenshots and comparing each one to a reference. Why screenshots?
|
The integration tests use Spectron and Tape. They click through the app, taking screenshots and
|
||||||
|
comparing each one to a reference. Why screenshots?
|
||||||
|
|
||||||
* Ad-hoc checking makes the tests a lot more work to write
|
* Ad-hoc checking makes the tests a lot more work to write
|
||||||
* Even diffing the whole HTML is not as thorough as screenshot diffing. For example, it wouldn't catch an bug where hitting ESC from a video doesn't correctly restore window size.
|
* Even diffing the whole HTML is not as thorough as screenshot diffing. For example, it wouldn't
|
||||||
|
catch an bug where hitting ESC from a video doesn't correctly restore window size.
|
||||||
* Chrome's own integration tests use screenshot diffing iirc
|
* Chrome's own integration tests use screenshot diffing iirc
|
||||||
* Small UI changes will break a few tests, but the fix is as easy as deleting the offending screenshots and running the tests, which will recreate them with the new look.
|
* Small UI changes will break a few tests, but the fix is as easy as deleting the offending
|
||||||
* The resulting Github PR will then show, pixel by pixel, the exact UI changes that were made! Ses https://github.com/blog/817-behold-image-view-modes
|
screenshots and running the tests, which will recreate them with the new look.
|
||||||
|
* The resulting Github PR will then show, pixel by pixel, the exact UI changes that were made! See
|
||||||
|
https://github.com/blog/817-behold-image-view-modes
|
||||||
|
|
||||||
For MacOS, you'll need a Retina screen for the integration tests to pass. Your screen should have the same resolution as a 2016 12" Macbook.
|
For MacOS, you'll need a Retina screen for the integration tests to pass. Your screen should have
|
||||||
|
the same resolution as a 2016 12" Macbook.
|
||||||
|
|
||||||
For Windows, you'll need Windows 10 with a 1366x768 screen.
|
For Windows, you'll need Windows 10 with a 1366x768 screen.
|
||||||
|
|
||||||
When running integration tests, keep the mouse on the edge of the screen and don't touch the mouse or keyboard while the tests are running.
|
When running integration tests, keep the mouse on the edge of the screen and don't touch the mouse
|
||||||
|
or keyboard while the tests are running.
|
||||||
|
|
||||||
### Package the app
|
### Package the app
|
||||||
|
|
||||||
@@ -110,7 +119,7 @@ The following optional arguments are available:
|
|||||||
- `all` - All platforms (default)
|
- `all` - All platforms (default)
|
||||||
|
|
||||||
Note: Even with the `--package` option, the auto-update files (.nupkg for Windows,
|
Note: Even with the `--package` option, the auto-update files (.nupkg for Windows,
|
||||||
*-darwin.zip for Mac) will always be produced.
|
-darwin.zip for Mac) will always be produced.
|
||||||
|
|
||||||
#### Windows build notes
|
#### Windows build notes
|
||||||
|
|
||||||
@@ -145,10 +154,6 @@ Time out? Show a missing codec error?
|
|||||||
The app never sends any personally identifying information, nor does it track which
|
The app never sends any personally identifying information, nor does it track which
|
||||||
torrents you add.
|
torrents you add.
|
||||||
|
|
||||||
### Code Style
|
|
||||||
|
|
||||||
[](https://github.com/feross/standard)
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT. Copyright (c) [WebTorrent, LLC](https://webtorrent.io).
|
MIT. Copyright (c) [WebTorrent, LLC](https://webtorrent.io).
|
||||||
|
|||||||
16
bin/clean.js
@@ -5,13 +5,13 @@
|
|||||||
* Useful for developers.
|
* Useful for developers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var fs = require('fs')
|
const fs = require('fs')
|
||||||
var os = require('os')
|
const os = require('os')
|
||||||
var path = require('path')
|
const path = require('path')
|
||||||
var rimraf = require('rimraf')
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
var config = require('../src/config')
|
const config = require('../src/config')
|
||||||
var handlers = require('../src/main/handlers')
|
const handlers = require('../src/main/handlers')
|
||||||
|
|
||||||
// First, remove generated files
|
// First, remove generated files
|
||||||
rimraf.sync('build/')
|
rimraf.sync('build/')
|
||||||
@@ -21,11 +21,11 @@ rimraf.sync('dist/')
|
|||||||
rimraf.sync(config.CONFIG_PATH)
|
rimraf.sync(config.CONFIG_PATH)
|
||||||
|
|
||||||
// Remove any temporary files
|
// Remove any temporary files
|
||||||
var tmpPath
|
let tmpPath
|
||||||
try {
|
try {
|
||||||
tmpPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent')
|
tmpPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
tmpPath = path.join(os.tmpDir(), 'webtorrent')
|
tmpPath = path.join(os.tmpdir(), 'webtorrent')
|
||||||
}
|
}
|
||||||
rimraf.sync(tmpPath)
|
rimraf.sync(tmpPath)
|
||||||
|
|
||||||
|
|||||||
10
bin/cmd.js
@@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var electron = require('electron')
|
|
||||||
var cp = require('child_process')
|
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
var child = cp.spawn(electron, [path.join(__dirname, '..')], {stdio: 'inherit'})
|
|
||||||
child.on('close', function (code) {
|
|
||||||
process.exitCode = code
|
|
||||||
})
|
|
||||||
@@ -7,16 +7,16 @@ const path = require('path')
|
|||||||
let hasErrors = false
|
let hasErrors = false
|
||||||
|
|
||||||
// Find all Javascript source files
|
// Find all Javascript source files
|
||||||
var files = walkSync('src', {globs: ['**/*.js']})
|
const files = walkSync('src', {globs: ['**/*.js']})
|
||||||
console.log('Running extra-lint on ' + files.length + ' files...')
|
console.log('Running extra-lint on ' + files.length + ' files...')
|
||||||
|
|
||||||
// Read each file, line by line
|
// Read each file, line by line
|
||||||
files.forEach(function (file) {
|
files.forEach(function (file) {
|
||||||
var filepath = path.join('src', file)
|
const filepath = path.join('src', file)
|
||||||
var lines = fs.readFileSync(filepath, 'utf8').split('\n')
|
const lines = fs.readFileSync(filepath, 'utf8').split('\n')
|
||||||
|
|
||||||
lines.forEach(function (line, i) {
|
lines.forEach(function (line, i) {
|
||||||
var error
|
let error
|
||||||
|
|
||||||
// Consistent JSX tag closing
|
// Consistent JSX tag closing
|
||||||
if (line.match(/' {2}\/> *$/) ||
|
if (line.match(/' {2}\/> *$/) ||
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var config = require('../src/config')
|
const config = require('../src/config')
|
||||||
var open = require('open')
|
const open = require('open')
|
||||||
|
|
||||||
open(config.CONFIG_PATH)
|
open(config.CONFIG_PATH)
|
||||||
|
|||||||
154
bin/package.js
@@ -1,28 +1,29 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds app binaries for Mac, Linux, and Windows.
|
* Builds app binaries for Mac, Windows, and Linux.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var cp = require('child_process')
|
const cp = require('child_process')
|
||||||
var electronPackager = require('electron-packager')
|
const electronPackager = require('electron-packager')
|
||||||
var fs = require('fs')
|
const fs = require('fs')
|
||||||
var minimist = require('minimist')
|
const minimist = require('minimist')
|
||||||
var mkdirp = require('mkdirp')
|
const mkdirp = require('mkdirp')
|
||||||
var os = require('os')
|
const os = require('os')
|
||||||
var path = require('path')
|
const path = require('path')
|
||||||
var rimraf = require('rimraf')
|
const rimraf = require('rimraf')
|
||||||
var series = require('run-series')
|
const series = require('run-series')
|
||||||
var zip = require('cross-zip')
|
const zip = require('cross-zip')
|
||||||
|
|
||||||
var config = require('../src/config')
|
const config = require('../src/config')
|
||||||
var pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
|
|
||||||
var BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION
|
const BUILD_NAME = config.APP_NAME + '-v' + config.APP_VERSION
|
||||||
var BUILD_PATH = path.join(config.ROOT_PATH, 'build')
|
const BUILD_PATH = path.join(config.ROOT_PATH, 'build')
|
||||||
var DIST_PATH = path.join(config.ROOT_PATH, 'dist')
|
const DIST_PATH = path.join(config.ROOT_PATH, 'dist')
|
||||||
|
const NODE_MODULES_PATH = path.join(config.ROOT_PATH, 'node_modules')
|
||||||
|
|
||||||
var argv = minimist(process.argv.slice(2), {
|
const argv = minimist(process.argv.slice(2), {
|
||||||
boolean: [
|
boolean: [
|
||||||
'sign'
|
'sign'
|
||||||
],
|
],
|
||||||
@@ -36,6 +37,12 @@ var argv = minimist(process.argv.slice(2), {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function build () {
|
function build () {
|
||||||
|
console.log('Reinstalling node_modules...')
|
||||||
|
rimraf.sync(NODE_MODULES_PATH)
|
||||||
|
cp.execSync('npm install', { stdio: 'inherit' })
|
||||||
|
cp.execSync('npm dedupe', { stdio: 'inherit' })
|
||||||
|
|
||||||
|
console.log('Nuking dist/ and build/...')
|
||||||
rimraf.sync(DIST_PATH)
|
rimraf.sync(DIST_PATH)
|
||||||
rimraf.sync(BUILD_PATH)
|
rimraf.sync(BUILD_PATH)
|
||||||
|
|
||||||
@@ -43,7 +50,7 @@ function build () {
|
|||||||
cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' })
|
cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' })
|
||||||
console.log('Build: Transpiled to ES5.')
|
console.log('Build: Transpiled to ES5.')
|
||||||
|
|
||||||
var platform = argv._[0]
|
const platform = argv._[0]
|
||||||
if (platform === 'darwin') {
|
if (platform === 'darwin') {
|
||||||
buildDarwin(printDone)
|
buildDarwin(printDone)
|
||||||
} else if (platform === 'win32') {
|
} else if (platform === 'win32') {
|
||||||
@@ -61,7 +68,7 @@ function build () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var all = {
|
const all = {
|
||||||
// The human-readable copyright line for the app. Maps to the `LegalCopyright` metadata
|
// The human-readable copyright line for the app. Maps to the `LegalCopyright` metadata
|
||||||
// property on Windows, and `NSHumanReadableCopyright` on Mac.
|
// property on Windows, and `NSHumanReadableCopyright` on Mac.
|
||||||
'app-copyright': config.APP_COPYRIGHT,
|
'app-copyright': config.APP_COPYRIGHT,
|
||||||
@@ -89,7 +96,7 @@ var all = {
|
|||||||
|
|
||||||
// Pattern which specifies which files to ignore when copying files to create the
|
// Pattern which specifies which files to ignore when copying files to create the
|
||||||
// package(s).
|
// package(s).
|
||||||
ignore: /^\/src|^\/dist|\/(appveyor.yml|\.appveyor.yml|\.github|appdmg|AUTHORS|CONTRIBUTORS|bench|benchmark|benchmark\.js|bin|bower\.json|component\.json|coverage|doc|docs|docs\.mli|dragdrop\.min\.js|example|examples|example\.html|example\.js|externs|ipaddr\.min\.js|Makefile|min|minimist|perf|rusha|simplepeer\.min\.js|simplewebsocket\.min\.js|static\/screenshot\.png|test|tests|test\.js|tests\.js|webtorrent\.min\.js|\.[^\/]*|.*\.md|.*\.markdown)$/,
|
ignore: /^\/src|^\/dist|\/(appveyor.yml|\.appveyor.yml|\.github|appdmg|AUTHORS|CONTRIBUTORS|bench|benchmark|benchmark\.js|bin|bower\.json|component\.json|coverage|doc|docs|docs\.mli|dragdrop\.min\.js|example|examples|example\.html|example\.js|externs|ipaddr\.min\.js|Makefile|min|minimist|perf|rusha|simplepeer\.min\.js|simplewebsocket\.min\.js|static\/screenshot\.png|test|tests|test\.js|tests\.js|webtorrent\.min\.js|\.[^/]*|.*\.md|.*\.markdown)$/,
|
||||||
|
|
||||||
// The application name.
|
// The application name.
|
||||||
name: config.APP_NAME,
|
name: config.APP_NAME,
|
||||||
@@ -104,11 +111,11 @@ var all = {
|
|||||||
// "devDependencies" before starting to package the app.
|
// "devDependencies" before starting to package the app.
|
||||||
prune: true,
|
prune: true,
|
||||||
|
|
||||||
// The Electron version with which the app is built (without the leading 'v')
|
// The Electron version that the app is built with (without the leading 'v')
|
||||||
version: require('electron/package.json').version
|
electronVersion: require('electron/package.json').version
|
||||||
}
|
}
|
||||||
|
|
||||||
var darwin = {
|
const darwin = {
|
||||||
// Build for Mac
|
// Build for Mac
|
||||||
platform: 'darwin',
|
platform: 'darwin',
|
||||||
|
|
||||||
@@ -129,12 +136,12 @@ var darwin = {
|
|||||||
icon: config.APP_ICON + '.icns'
|
icon: config.APP_ICON + '.icns'
|
||||||
}
|
}
|
||||||
|
|
||||||
var win32 = {
|
const win32 = {
|
||||||
// Build for Windows.
|
// Build for Windows.
|
||||||
platform: 'win32',
|
platform: 'win32',
|
||||||
|
|
||||||
// Build ia32 and x64 binaries.
|
// Build ia32 and x64 binaries.
|
||||||
arch: 'all',
|
arch: ['ia32', 'x64'],
|
||||||
|
|
||||||
// Object hash of application metadata to embed into the executable (Windows only)
|
// Object hash of application metadata to embed into the executable (Windows only)
|
||||||
win32metadata: {
|
win32metadata: {
|
||||||
@@ -163,12 +170,12 @@ var win32 = {
|
|||||||
icon: config.APP_ICON + '.ico'
|
icon: config.APP_ICON + '.ico'
|
||||||
}
|
}
|
||||||
|
|
||||||
var linux = {
|
const linux = {
|
||||||
// Build for Linux.
|
// Build for Linux.
|
||||||
platform: 'linux',
|
platform: 'linux',
|
||||||
|
|
||||||
// Build ia32 and x64 binaries.
|
// Build ia32 and x64 binaries.
|
||||||
arch: 'all'
|
arch: ['ia32', 'x64']
|
||||||
|
|
||||||
// Note: Application icon for Linux is specified via the BrowserWindow `icon` option.
|
// Note: Application icon for Linux is specified via the BrowserWindow `icon` option.
|
||||||
}
|
}
|
||||||
@@ -176,18 +183,18 @@ var linux = {
|
|||||||
build()
|
build()
|
||||||
|
|
||||||
function buildDarwin (cb) {
|
function buildDarwin (cb) {
|
||||||
var plist = require('plist')
|
const plist = require('plist')
|
||||||
|
|
||||||
console.log('Mac: Packaging electron...')
|
console.log('Mac: Packaging electron...')
|
||||||
electronPackager(Object.assign({}, all, darwin), function (err, buildPath) {
|
electronPackager(Object.assign({}, all, darwin), function (err, buildPath) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
console.log('Mac: Packaged electron. ' + buildPath)
|
console.log('Mac: Packaged electron. ' + buildPath)
|
||||||
|
|
||||||
var appPath = path.join(buildPath[0], config.APP_NAME + '.app')
|
const appPath = path.join(buildPath[0], config.APP_NAME + '.app')
|
||||||
var contentsPath = path.join(appPath, 'Contents')
|
const contentsPath = path.join(appPath, 'Contents')
|
||||||
var resourcesPath = path.join(contentsPath, 'Resources')
|
const resourcesPath = path.join(contentsPath, 'Resources')
|
||||||
var infoPlistPath = path.join(contentsPath, 'Info.plist')
|
const infoPlistPath = path.join(contentsPath, 'Info.plist')
|
||||||
var infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'))
|
const infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'))
|
||||||
|
|
||||||
infoPlist.CFBundleDocumentTypes = [
|
infoPlist.CFBundleDocumentTypes = [
|
||||||
{
|
{
|
||||||
@@ -261,7 +268,7 @@ function buildDarwin (cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function signApp (cb) {
|
function signApp (cb) {
|
||||||
var sign = require('electron-osx-sign')
|
const sign = require('electron-osx-sign')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons:
|
* Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons:
|
||||||
@@ -276,7 +283,7 @@ function buildDarwin (cb) {
|
|||||||
* - Xcode Command Line Tools (xcode-select --install)
|
* - Xcode Command Line Tools (xcode-select --install)
|
||||||
* - Membership in the Apple Developer Program
|
* - Membership in the Apple Developer Program
|
||||||
*/
|
*/
|
||||||
var signOpts = {
|
const signOpts = {
|
||||||
app: appPath,
|
app: appPath,
|
||||||
platform: 'darwin',
|
platform: 'darwin',
|
||||||
verbose: true
|
verbose: true
|
||||||
@@ -302,8 +309,8 @@ function buildDarwin (cb) {
|
|||||||
// Create .zip file (used by the auto-updater)
|
// Create .zip file (used by the auto-updater)
|
||||||
console.log('Mac: Creating zip...')
|
console.log('Mac: Creating zip...')
|
||||||
|
|
||||||
var inPath = path.join(buildPath[0], config.APP_NAME + '.app')
|
const inPath = path.join(buildPath[0], config.APP_NAME + '.app')
|
||||||
var outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip')
|
const outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip')
|
||||||
zip.zipSync(inPath, outPath)
|
zip.zipSync(inPath, outPath)
|
||||||
|
|
||||||
console.log('Mac: Created zip.')
|
console.log('Mac: Created zip.')
|
||||||
@@ -312,13 +319,13 @@ function buildDarwin (cb) {
|
|||||||
function packageDmg (cb) {
|
function packageDmg (cb) {
|
||||||
console.log('Mac: Creating dmg...')
|
console.log('Mac: Creating dmg...')
|
||||||
|
|
||||||
var appDmg = require('appdmg')
|
const appDmg = require('appdmg')
|
||||||
|
|
||||||
var targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg')
|
const targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg')
|
||||||
rimraf.sync(targetPath)
|
rimraf.sync(targetPath)
|
||||||
|
|
||||||
// Create a .dmg (Mac disk image) file, for easy user installation.
|
// Create a .dmg (Mac disk image) file, for easy user installation.
|
||||||
var dmgOpts = {
|
const dmgOpts = {
|
||||||
basepath: config.ROOT_PATH,
|
basepath: config.ROOT_PATH,
|
||||||
target: targetPath,
|
target: targetPath,
|
||||||
specification: {
|
specification: {
|
||||||
@@ -339,7 +346,7 @@ function buildDarwin (cb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dmg = appDmg(dmgOpts)
|
const dmg = appDmg(dmgOpts)
|
||||||
dmg.once('error', cb)
|
dmg.once('error', cb)
|
||||||
dmg.on('progress', function (info) {
|
dmg.on('progress', function (info) {
|
||||||
if (info.type === 'step-begin') console.log(info.title + '...')
|
if (info.type === 'step-begin') console.log(info.title + '...')
|
||||||
@@ -353,7 +360,7 @@ function buildDarwin (cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildWin32 (cb) {
|
function buildWin32 (cb) {
|
||||||
var installer = require('electron-winstaller')
|
const installer = require('electron-winstaller')
|
||||||
console.log('Windows: Packaging electron...')
|
console.log('Windows: Packaging electron...')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -361,7 +368,7 @@ function buildWin32 (cb) {
|
|||||||
* - Windows Authenticode private key and cert (authenticode.p12)
|
* - Windows Authenticode private key and cert (authenticode.p12)
|
||||||
* - Windows Authenticode password file (authenticode.txt)
|
* - Windows Authenticode password file (authenticode.txt)
|
||||||
*/
|
*/
|
||||||
var CERT_PATH
|
let CERT_PATH
|
||||||
try {
|
try {
|
||||||
fs.accessSync('D:')
|
fs.accessSync('D:')
|
||||||
CERT_PATH = 'D:'
|
CERT_PATH = 'D:'
|
||||||
@@ -373,12 +380,12 @@ function buildWin32 (cb) {
|
|||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
console.log('Windows: Packaged electron. ' + buildPath)
|
console.log('Windows: Packaged electron. ' + buildPath)
|
||||||
|
|
||||||
var signWithParams
|
let signWithParams
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
if (argv.sign) {
|
if (argv.sign) {
|
||||||
var certificateFile = path.join(CERT_PATH, 'authenticode.p12')
|
const certificateFile = path.join(CERT_PATH, 'authenticode.p12')
|
||||||
var certificatePassword = fs.readFileSync(path.join(CERT_PATH, 'authenticode.txt'), 'utf8')
|
const certificatePassword = fs.readFileSync(path.join(CERT_PATH, 'authenticode.txt'), 'utf8')
|
||||||
var timestampServer = 'http://timestamp.comodoca.com'
|
const timestampServer = 'http://timestamp.comodoca.com'
|
||||||
signWithParams = `/a /f "${certificateFile}" /p "${certificatePassword}" /tr "${timestampServer}" /td sha256`
|
signWithParams = `/a /f "${certificateFile}" /p "${certificatePassword}" /tr "${timestampServer}" /td sha256`
|
||||||
} else {
|
} else {
|
||||||
printWarning()
|
printWarning()
|
||||||
@@ -387,9 +394,9 @@ function buildWin32 (cb) {
|
|||||||
printWarning()
|
printWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
var tasks = []
|
const tasks = []
|
||||||
buildPath.forEach(function (filesPath) {
|
buildPath.forEach(function (filesPath) {
|
||||||
var destArch = filesPath.split('-').pop()
|
const destArch = filesPath.split('-').pop()
|
||||||
|
|
||||||
if (argv.package === 'exe' || argv.package === 'all') {
|
if (argv.package === 'exe' || argv.package === 'all') {
|
||||||
tasks.push((cb) => packageInstaller(filesPath, destArch, cb))
|
tasks.push((cb) => packageInstaller(filesPath, destArch, cb))
|
||||||
@@ -403,7 +410,7 @@ function buildWin32 (cb) {
|
|||||||
function packageInstaller (filesPath, destArch, cb) {
|
function packageInstaller (filesPath, destArch, cb) {
|
||||||
console.log(`Windows: Creating ${destArch} installer...`)
|
console.log(`Windows: Creating ${destArch} installer...`)
|
||||||
|
|
||||||
var archStr = destArch === 'ia32' ? '-ia32' : ''
|
const archStr = destArch === 'ia32' ? '-ia32' : ''
|
||||||
|
|
||||||
installer.createWindowsInstaller({
|
installer.createWindowsInstaller({
|
||||||
appDirectory: filesPath,
|
appDirectory: filesPath,
|
||||||
@@ -423,13 +430,18 @@ function buildWin32 (cb) {
|
|||||||
* names (i.e. RELEASES-ia32 instead of RELEASES) and so Squirrel won't
|
* names (i.e. RELEASES-ia32 instead of RELEASES) and so Squirrel won't
|
||||||
* find them unless we proxy the requests.
|
* find them unless we proxy the requests.
|
||||||
*/
|
*/
|
||||||
remoteReleases: destArch === 'x64'
|
// TODO: Re-enable Windows 64-bit delta updates when we confirm that they
|
||||||
? config.GITHUB_URL
|
// work correctly in the presence of the "ia32" .nupkg files. I
|
||||||
: undefined,
|
// (feross) noticed them listed in the 64-bit RELEASES file and
|
||||||
|
// manually edited them out for the v0.17 release. Shipping only
|
||||||
|
// full updates for now will work fine, with no ill-effects.
|
||||||
|
// remoteReleases: destArch === 'x64'
|
||||||
|
// ? config.GITHUB_URL
|
||||||
|
// : undefined,
|
||||||
/**
|
/**
|
||||||
* If you hit a "GitHub API rate limit exceeded" error, set this token!
|
* If you hit a "GitHub API rate limit exceeded" error, set this token!
|
||||||
*/
|
*/
|
||||||
remoteToken: process.env.WEBTORRENT_GITHUB_API_TOKEN,
|
// remoteToken: process.env.WEBTORRENT_GITHUB_API_TOKEN,
|
||||||
setupExe: config.APP_NAME + 'Setup-v' + config.APP_VERSION + archStr + '.exe',
|
setupExe: config.APP_NAME + 'Setup-v' + config.APP_VERSION + archStr + '.exe',
|
||||||
setupIcon: config.APP_ICON + '.ico',
|
setupIcon: config.APP_ICON + '.ico',
|
||||||
signWithParams: signWithParams,
|
signWithParams: signWithParams,
|
||||||
@@ -454,7 +466,7 @@ function buildWin32 (cb) {
|
|||||||
console.log('Windows: Renaming ia32 installer files...')
|
console.log('Windows: Renaming ia32 installer files...')
|
||||||
|
|
||||||
// RELEASES -> RELEASES-ia32
|
// RELEASES -> RELEASES-ia32
|
||||||
var relPath = path.join(DIST_PATH, 'RELEASES-ia32')
|
const relPath = path.join(DIST_PATH, 'RELEASES-ia32')
|
||||||
fs.renameSync(
|
fs.renameSync(
|
||||||
path.join(DIST_PATH, 'RELEASES'),
|
path.join(DIST_PATH, 'RELEASES'),
|
||||||
relPath
|
relPath
|
||||||
@@ -467,8 +479,8 @@ function buildWin32 (cb) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Change file name inside RELEASES-ia32 to match renamed file
|
// Change file name inside RELEASES-ia32 to match renamed file
|
||||||
var relContent = fs.readFileSync(relPath, 'utf8')
|
const relContent = fs.readFileSync(relPath, 'utf8')
|
||||||
var relContent32 = relContent.replace('full.nupkg', 'ia32-full.nupkg')
|
const relContent32 = relContent.replace('full.nupkg', 'ia32-full.nupkg')
|
||||||
fs.writeFileSync(relPath, relContent32)
|
fs.writeFileSync(relPath, relContent32)
|
||||||
|
|
||||||
if (relContent === relContent32) {
|
if (relContent === relContent32) {
|
||||||
@@ -487,13 +499,19 @@ function buildWin32 (cb) {
|
|||||||
function packagePortable (filesPath, destArch, cb) {
|
function packagePortable (filesPath, destArch, cb) {
|
||||||
console.log(`Windows: Creating ${destArch} portable app...`)
|
console.log(`Windows: Creating ${destArch} portable app...`)
|
||||||
|
|
||||||
var portablePath = path.join(filesPath, 'Portable Settings')
|
const portablePath = path.join(filesPath, 'Portable Settings')
|
||||||
mkdirp.sync(portablePath)
|
mkdirp.sync(portablePath)
|
||||||
|
|
||||||
var archStr = destArch === 'ia32' ? '-ia32' : ''
|
const downloadsPath = path.join(portablePath, 'Downloads')
|
||||||
|
mkdirp.sync(downloadsPath)
|
||||||
|
|
||||||
var inPath = path.join(DIST_PATH, path.basename(filesPath))
|
const tempPath = path.join(portablePath, 'Temp')
|
||||||
var outPath = path.join(DIST_PATH, BUILD_NAME + '-win' + archStr + '.zip')
|
mkdirp.sync(tempPath)
|
||||||
|
|
||||||
|
const archStr = destArch === 'ia32' ? '-ia32' : ''
|
||||||
|
|
||||||
|
const inPath = path.join(DIST_PATH, path.basename(filesPath))
|
||||||
|
const outPath = path.join(DIST_PATH, BUILD_NAME + '-win' + archStr + '.zip')
|
||||||
zip.zipSync(inPath, outPath)
|
zip.zipSync(inPath, outPath)
|
||||||
|
|
||||||
console.log(`Windows: Created ${destArch} portable app.`)
|
console.log(`Windows: Created ${destArch} portable app.`)
|
||||||
@@ -508,9 +526,9 @@ function buildLinux (cb) {
|
|||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
console.log('Linux: Packaged electron. ' + buildPath)
|
console.log('Linux: Packaged electron. ' + buildPath)
|
||||||
|
|
||||||
var tasks = []
|
const tasks = []
|
||||||
buildPath.forEach(function (filesPath) {
|
buildPath.forEach(function (filesPath) {
|
||||||
var destArch = filesPath.split('-').pop()
|
const destArch = filesPath.split('-').pop()
|
||||||
|
|
||||||
if (argv.package === 'deb' || argv.package === 'all') {
|
if (argv.package === 'deb' || argv.package === 'all') {
|
||||||
tasks.push((cb) => packageDeb(filesPath, destArch, cb))
|
tasks.push((cb) => packageDeb(filesPath, destArch, cb))
|
||||||
@@ -526,8 +544,8 @@ function buildLinux (cb) {
|
|||||||
// Create .deb file for Debian-based platforms
|
// Create .deb file for Debian-based platforms
|
||||||
console.log(`Linux: Creating ${destArch} deb...`)
|
console.log(`Linux: Creating ${destArch} deb...`)
|
||||||
|
|
||||||
var deb = require('nobin-debian-installer')()
|
const deb = require('nobin-debian-installer')()
|
||||||
var destPath = path.join('/opt', pkg.name)
|
const destPath = path.join('/opt', pkg.name)
|
||||||
|
|
||||||
deb.pack({
|
deb.pack({
|
||||||
package: pkg,
|
package: pkg,
|
||||||
@@ -561,10 +579,10 @@ function buildLinux (cb) {
|
|||||||
// Create .zip file for Linux
|
// Create .zip file for Linux
|
||||||
console.log(`Linux: Creating ${destArch} zip...`)
|
console.log(`Linux: Creating ${destArch} zip...`)
|
||||||
|
|
||||||
var archStr = destArch === 'ia32' ? '-ia32' : ''
|
const archStr = destArch === 'ia32' ? '-ia32' : ''
|
||||||
|
|
||||||
var inPath = path.join(DIST_PATH, path.basename(filesPath))
|
const inPath = path.join(DIST_PATH, path.basename(filesPath))
|
||||||
var outPath = path.join(DIST_PATH, BUILD_NAME + '-linux' + archStr + '.zip')
|
const outPath = path.join(DIST_PATH, BUILD_NAME + '-linux' + archStr + '.zip')
|
||||||
zip.zipSync(inPath, outPath)
|
zip.zipSync(inPath, outPath)
|
||||||
|
|
||||||
console.log(`Linux: Created ${destArch} zip.`)
|
console.log(`Linux: Created ${destArch} zip.`)
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
npm run update-authors
|
|
||||||
git diff --exit-code
|
|
||||||
npm run package -- --sign
|
|
||||||
git push
|
|
||||||
git push --tags
|
|
||||||
npm publish
|
|
||||||
npm run gh-release
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
|
|
||||||
git pull
|
|
||||||
rm -rf node_modules/
|
|
||||||
npm install
|
|
||||||
npm dedupe
|
|
||||||
npm test
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
BIN=`dirname $0`
|
|
||||||
|
|
||||||
$BIN/release-_pre.sh
|
|
||||||
npm version major
|
|
||||||
$BIN/release-_post.sh
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
BIN=`dirname $0`
|
|
||||||
|
|
||||||
$BIN/release-_pre.sh
|
|
||||||
npm version minor
|
|
||||||
$BIN/release-_post.sh
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
BIN=`dirname $0`
|
|
||||||
|
|
||||||
$BIN/release-_pre.sh
|
|
||||||
npm version patch
|
|
||||||
$BIN/release-_post.sh
|
|
||||||
49
package.json
@@ -1,17 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "webtorrent-desktop",
|
"name": "webtorrent-desktop",
|
||||||
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
"description": "WebTorrent, the streaming torrent client. For Mac, Windows, and Linux.",
|
||||||
"version": "0.17.0",
|
"version": "0.18.0",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "WebTorrent, LLC",
|
"name": "WebTorrent, LLC",
|
||||||
"email": "feross@webtorrent.io",
|
"email": "feross@webtorrent.io",
|
||||||
"url": "https://webtorrent.io"
|
"url": "https://webtorrent.io"
|
||||||
},
|
},
|
||||||
"bin": {
|
|
||||||
"webtorrent-desktop": "./bin/cmd.js"
|
|
||||||
},
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/feross/webtorrent-desktop/issues"
|
"url": "https://github.com/webtorrent/webtorrent-desktop/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"airplayer": "^2.0.0",
|
"airplayer": "^2.0.0",
|
||||||
@@ -21,27 +18,33 @@
|
|||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
"capture-frame": "^1.0.0",
|
"capture-frame": "^1.0.0",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
|
"cp-file": "^4.0.1",
|
||||||
"create-torrent": "^3.24.5",
|
"create-torrent": "^3.24.5",
|
||||||
"debounce": "^1.0.0",
|
"debounce": "^1.0.0",
|
||||||
"deep-equal": "^1.0.1",
|
"deep-equal": "^1.0.1",
|
||||||
"dlnacasts": "^0.1.0",
|
"dlnacasts": "^0.1.0",
|
||||||
"drag-drop": "^2.12.1",
|
"drag-drop": "^2.12.1",
|
||||||
"electron": "1.4.1",
|
"es6-error": "^4.0.0",
|
||||||
"es6-error": "^3.0.1",
|
"fn-getter": "^1.0.0",
|
||||||
"fs-extra": "^0.30.0",
|
"gaze": "^1.1.2",
|
||||||
"iso-639-1": "^1.2.1",
|
"iso-639-1": "^1.2.1",
|
||||||
"languagedetect": "^1.1.1",
|
"languagedetect": "^1.1.1",
|
||||||
"location-history": "^1.0.0",
|
"location-history": "^1.0.0",
|
||||||
"material-ui": "^0.15.4",
|
"material-ui": "^0.17.0",
|
||||||
|
"mkdirp": "^0.5.1",
|
||||||
|
"ms": "^0.7.2",
|
||||||
"musicmetadata": "^2.0.2",
|
"musicmetadata": "^2.0.2",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
|
"node-notifier": "^5.0.2",
|
||||||
"parse-torrent": "^5.7.3",
|
"parse-torrent": "^5.7.3",
|
||||||
"prettier-bytes": "^1.0.1",
|
"prettier-bytes": "^1.0.1",
|
||||||
"react": "^15.2.1",
|
"react": "^15.4.2",
|
||||||
"react-dom": "^15.2.1",
|
"react-dom": "^15.4.2",
|
||||||
"react-tap-event-plugin": "^1.0.0",
|
"react-tap-event-plugin": "^2.0.1",
|
||||||
|
"rimraf": "^2.5.2",
|
||||||
"run-parallel": "^1.1.6",
|
"run-parallel": "^1.1.6",
|
||||||
"semver": "^5.1.0",
|
"semver": "^5.1.0",
|
||||||
|
"shell-env": "^0.3.0",
|
||||||
"simple-concat": "^1.0.0",
|
"simple-concat": "^1.0.0",
|
||||||
"simple-get": "^2.0.0",
|
"simple-get": "^2.0.0",
|
||||||
"srt-to-vtt": "^1.1.1",
|
"srt-to-vtt": "^1.1.1",
|
||||||
@@ -51,21 +54,20 @@
|
|||||||
"zero-fill": "^2.2.3"
|
"zero-fill": "^2.2.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"buble": "^0.14.0",
|
"buble": "^0.15.2",
|
||||||
"cross-zip": "^2.0.1",
|
"cross-zip": "^2.0.1",
|
||||||
"depcheck": "^0.6.4",
|
"depcheck": "^0.6.4",
|
||||||
"electron-osx-sign": "^0.3.0",
|
"electron": "1.6.0",
|
||||||
"electron-packager": "^8.0.0",
|
"electron-osx-sign": "0.4.3",
|
||||||
"electron-winstaller": "^2.3.0",
|
"electron-packager": "~8.5.1",
|
||||||
|
"electron-winstaller": "~2.5.2",
|
||||||
"gh-release": "^2.0.3",
|
"gh-release": "^2.0.3",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"mkdirp": "^0.5.1",
|
"nobin-debian-installer": "0.0.10",
|
||||||
"nobin-debian-installer": "^0.0.10",
|
|
||||||
"nodemon": "^1.10.2",
|
"nodemon": "^1.10.2",
|
||||||
"open": "0.0.5",
|
"open": "0.0.5",
|
||||||
"plist": "^2.0.1",
|
"plist": "^2.0.1",
|
||||||
"pngjs": "^3.0.0",
|
"pngjs": "^3.0.0",
|
||||||
"rimraf": "^2.5.2",
|
|
||||||
"run-series": "^1.1.4",
|
"run-series": "^1.1.4",
|
||||||
"spectron": "^3.3.0",
|
"spectron": "^3.3.0",
|
||||||
"standard": "*",
|
"standard": "*",
|
||||||
@@ -91,22 +93,23 @@
|
|||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"appdmg": "^0.4.3"
|
"appdmg": "^0.4.3"
|
||||||
},
|
},
|
||||||
|
"private": true,
|
||||||
"productName": "WebTorrent",
|
"productName": "WebTorrent",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/feross/webtorrent-desktop.git"
|
"url": "git://github.com/webtorrent/webtorrent-desktop.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "buble src --output build",
|
"build": "buble src --output build",
|
||||||
"clean": "node ./bin/clean.js",
|
"clean": "node ./bin/clean.js",
|
||||||
|
"gh-release": "gh-release",
|
||||||
"open-config": "node ./bin/open-config.js",
|
"open-config": "node ./bin/open-config.js",
|
||||||
"package": "node ./bin/package.js",
|
"package": "node ./bin/package.js",
|
||||||
"prepublish": "npm run build",
|
"prepublish": "npm run build",
|
||||||
"start": "npm run build && electron .",
|
"start": "npm run build && electron .",
|
||||||
"integration-test": "npm run build && node ./test",
|
|
||||||
"test": "standard && depcheck --ignores=buble,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js",
|
"test": "standard && depcheck --ignores=buble,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js",
|
||||||
"gh-release": "gh-release",
|
"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,pug,css"
|
"watch": "nodemon --exec \"npm run start\" --ext js,css --ignore build/ --ignore dist/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const fs = require('fs')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const arch = require('arch')
|
const arch = require('arch')
|
||||||
|
const gaze = require('gaze')
|
||||||
|
|
||||||
const APP_NAME = 'WebTorrent'
|
const APP_NAME = 'WebTorrent'
|
||||||
const APP_TEAM = 'WebTorrent, LLC'
|
const APP_TEAM = 'WebTorrent, LLC'
|
||||||
@@ -12,23 +13,19 @@ 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')
|
||||||
: path.join(path.dirname(process.execPath), 'Portable Settings')
|
: path.join(path.dirname(process.execPath), 'Portable Settings')
|
||||||
const IS_PORTABLE = isPortable()
|
|
||||||
const IS_PRODUCTION = isProduction()
|
const IS_PRODUCTION = isProduction()
|
||||||
|
const IS_PORTABLE = isPortable()
|
||||||
|
|
||||||
const UI_HEADER_HEIGHT = 38
|
const UI_HEADER_HEIGHT = 38
|
||||||
const UI_TORRENT_HEIGHT = 100
|
const UI_TORRENT_HEIGHT = 100
|
||||||
|
|
||||||
console.log('Production: %s portable: %s test: %s',
|
const exports = module.exports = {
|
||||||
IS_PRODUCTION, IS_PORTABLE, IS_TEST)
|
|
||||||
if (IS_PORTABLE) console.log('Portable path: %s', PORTABLE_PATH)
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement',
|
||||||
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update',
|
||||||
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report',
|
||||||
TELEMETRY_URL: 'https://webtorrent.io/desktop/telemetry',
|
TELEMETRY_URL: 'https://webtorrent.io/desktop/telemetry',
|
||||||
|
|
||||||
APP_COPYRIGHT: 'Copyright © 2014-2016 ' + APP_TEAM,
|
APP_COPYRIGHT: 'Copyright © 2014-2017 ' + APP_TEAM,
|
||||||
APP_FILE_ICON: path.join(__dirname, '..', 'static', 'WebTorrentFile'),
|
APP_FILE_ICON: path.join(__dirname, '..', 'static', 'WebTorrentFile'),
|
||||||
APP_ICON: path.join(__dirname, '..', 'static', 'WebTorrent'),
|
APP_ICON: path.join(__dirname, '..', 'static', 'WebTorrent'),
|
||||||
APP_NAME: APP_NAME,
|
APP_NAME: APP_NAME,
|
||||||
@@ -65,7 +62,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
testID: 'wired',
|
testID: 'wired',
|
||||||
name: 'The WIRED CD - Rip. Sample. Mash. Share.',
|
name: 'The WIRED CD - Rip. Sample. Mash. Share',
|
||||||
posterFileName: 'wiredCd.jpg',
|
posterFileName: 'wiredCd.jpg',
|
||||||
torrentFileName: 'wiredCd.torrent'
|
torrentFileName: 'wiredCd.torrent'
|
||||||
}
|
}
|
||||||
@@ -75,9 +72,9 @@ module.exports = {
|
|||||||
|
|
||||||
DEFAULT_DOWNLOAD_PATH: getDefaultDownloadPath(),
|
DEFAULT_DOWNLOAD_PATH: getDefaultDownloadPath(),
|
||||||
|
|
||||||
GITHUB_URL: 'https://github.com/feross/webtorrent-desktop',
|
GITHUB_URL: 'https://github.com/webtorrent/webtorrent-desktop',
|
||||||
GITHUB_URL_ISSUES: 'https://github.com/feross/webtorrent-desktop/issues',
|
GITHUB_URL_ISSUES: 'https://github.com/webtorrent/webtorrent-desktop/issues',
|
||||||
GITHUB_URL_RAW: 'https://raw.githubusercontent.com/feross/webtorrent-desktop/master',
|
GITHUB_URL_RAW: 'https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/master',
|
||||||
|
|
||||||
HOME_PAGE_URL: 'https://webtorrent.io',
|
HOME_PAGE_URL: 'https://webtorrent.io',
|
||||||
|
|
||||||
@@ -107,6 +104,62 @@ module.exports = {
|
|||||||
UI_TORRENT_HEIGHT: UI_TORRENT_HEIGHT
|
UI_TORRENT_HEIGHT: UI_TORRENT_HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const configFile = appConfig.filePath
|
||||||
|
let config = getConfig()
|
||||||
|
const watchers = []
|
||||||
|
|
||||||
|
function updateConfig () {
|
||||||
|
config = JSON.parse(fs.readFileSync(configFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
function watch () {
|
||||||
|
gaze(configFile, function (err) {
|
||||||
|
if (err) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
this.on('changed', () => {
|
||||||
|
try {
|
||||||
|
updateConfig()
|
||||||
|
console.log('WebTorrent configuration reloaded!')
|
||||||
|
watchers.forEach(fn => fn())
|
||||||
|
} catch (err) {
|
||||||
|
// TODO: display notification
|
||||||
|
console.log(`An error occurred loading your configuration (${configFile}): ${err.message}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.on('error', () => {
|
||||||
|
// Ignore file watching errors
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// start watching for config changes
|
||||||
|
watch()
|
||||||
|
|
||||||
|
exports.subscribe = function (fn) {
|
||||||
|
watchers.push(fn)
|
||||||
|
return () => {
|
||||||
|
watchers.splice(watchers.indexOf(fn), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlugins () {
|
||||||
|
return config.plugins || {}
|
||||||
|
}
|
||||||
|
exports.getPlugins = getPlugins
|
||||||
|
|
||||||
|
exports.getConfigPath = getConfigPath
|
||||||
|
exports.getConfig = getConfig
|
||||||
|
|
||||||
|
function getConfig () {
|
||||||
|
const config = {}
|
||||||
|
try {
|
||||||
|
return require(configFile)
|
||||||
|
} catch (e) {
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getConfigPath () {
|
function getConfigPath () {
|
||||||
if (IS_PORTABLE) {
|
if (IS_PORTABLE) {
|
||||||
return PORTABLE_PATH
|
return PORTABLE_PATH
|
||||||
@@ -116,9 +169,7 @@ function getConfigPath () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultDownloadPath () {
|
function getDefaultDownloadPath () {
|
||||||
if (!process || !process.type) {
|
if (IS_PORTABLE) {
|
||||||
return ''
|
|
||||||
} else if (IS_PORTABLE) {
|
|
||||||
return path.join(getConfigPath(), 'Downloads')
|
return path.join(getConfigPath(), 'Downloads')
|
||||||
} else {
|
} else {
|
||||||
return getPath('downloads')
|
return getPath('downloads')
|
||||||
@@ -126,9 +177,14 @@ function getDefaultDownloadPath () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPath (key) {
|
function getPath (key) {
|
||||||
if (process.type === 'renderer') {
|
if (!process.versions.electron) {
|
||||||
|
// Node.js process
|
||||||
|
return ''
|
||||||
|
} else if (process.type === 'renderer') {
|
||||||
|
// Electron renderer process
|
||||||
return electron.remote.app.getPath(key)
|
return electron.remote.app.getPath(key)
|
||||||
} else {
|
} else {
|
||||||
|
// Electron main process
|
||||||
return electron.app.getPath(key)
|
return electron.app.getPath(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,8 +197,17 @@ function isPortable () {
|
|||||||
if (IS_TEST) {
|
if (IS_TEST) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.platform !== 'win32' || !IS_PRODUCTION) {
|
||||||
|
// Fast path: Non-Windows platforms should not check for path on disk
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return process.platform === 'win32' && IS_PRODUCTION && !!fs.statSync(PORTABLE_PATH)
|
// This line throws if the "Portable Settings" folder does not exist, and does
|
||||||
|
// nothing otherwise.
|
||||||
|
fs.accessSync(PORTABLE_PATH, fs.constants.R_OK | fs.constants.W_OK)
|
||||||
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -150,6 +215,7 @@ function isPortable () {
|
|||||||
|
|
||||||
function isProduction () {
|
function isProduction () {
|
||||||
if (!process.versions.electron) {
|
if (!process.versions.electron) {
|
||||||
|
// Node.js process
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ module.exports = {
|
|||||||
init
|
init
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = require('./config')
|
|
||||||
const electron = require('electron')
|
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
|
const config = require('./config')
|
||||||
|
const electron = require('electron')
|
||||||
|
|
||||||
electron.crashReporter.start({
|
electron.crashReporter.start({
|
||||||
companyName: config.APP_NAME,
|
companyName: config.APP_NAME,
|
||||||
productName: config.APP_NAME,
|
productName: config.APP_NAME,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function downloadFinished (path) {
|
|||||||
*/
|
*/
|
||||||
function setBadge (count) {
|
function setBadge (count) {
|
||||||
if (process.platform === 'darwin' ||
|
if (process.platform === 'darwin' ||
|
||||||
process.platform === 'linux' && app.isUnityRunning()) {
|
(process.platform === 'linux' && app.isUnityRunning())) {
|
||||||
log(`setBadge: ${count}`)
|
log(`setBadge: ${count}`)
|
||||||
app.setBadgeCount(Number(count))
|
app.setBadgeCount(Number(count))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ let proc = null
|
|||||||
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 == null) return vlcCommand((err) => cb(!err))
|
if (playerPath == null) return vlcCommand(cb)
|
||||||
process.nextTick(() => cb(true))
|
process.nextTick(() => cb(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawn (playerPath, url, title) {
|
function spawn (playerPath, url, title) {
|
||||||
@@ -48,7 +48,7 @@ function kill () {
|
|||||||
function spawnExternal (playerPath, args) {
|
function spawnExternal (playerPath, args) {
|
||||||
log('Running external media player:', playerPath + ' ' + args.join(' '))
|
log('Running external media player:', playerPath + ' ' + args.join(' '))
|
||||||
|
|
||||||
if (path.extname(playerPath) === '.app') {
|
if (process.platform === 'darwin' && path.extname(playerPath) === '.app') {
|
||||||
// Mac: Use executable in packaged .app bundle
|
// Mac: Use executable in packaged .app bundle
|
||||||
playerPath += '/Contents/MacOS/' + path.basename(playerPath, '.app')
|
playerPath += '/Contents/MacOS/' + path.basename(playerPath, '.app')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ function commandToArgs (command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function installLinux () {
|
function installLinux () {
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
@@ -326,6 +326,8 @@ function installLinux () {
|
|||||||
function writeIconFile (err, iconFile) {
|
function writeIconFile (err, iconFile) {
|
||||||
if (err) return log.error(err.message)
|
if (err) return log.error(err.message)
|
||||||
|
|
||||||
|
const mkdirp = require('mkdirp')
|
||||||
|
|
||||||
const iconFilePath = path.join(
|
const iconFilePath = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
'.local',
|
'.local',
|
||||||
@@ -333,9 +335,11 @@ function installLinux () {
|
|||||||
'icons',
|
'icons',
|
||||||
'webtorrent-desktop.png'
|
'webtorrent-desktop.png'
|
||||||
)
|
)
|
||||||
fs.mkdirp(path.dirname(iconFilePath))
|
mkdirp(path.dirname(iconFilePath), (err) => {
|
||||||
fs.writeFile(iconFilePath, iconFile, function (err) {
|
|
||||||
if (err) return log.error(err.message)
|
if (err) return log.error(err.message)
|
||||||
|
fs.writeFile(iconFilePath, iconFile, (err) => {
|
||||||
|
if (err) log.error(err.message)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,7 +347,7 @@ function installLinux () {
|
|||||||
function uninstallLinux () {
|
function uninstallLinux () {
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs-extra')
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
const desktopFilePath = path.join(
|
const desktopFilePath = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
@@ -352,7 +356,7 @@ function uninstallLinux () {
|
|||||||
'applications',
|
'applications',
|
||||||
'webtorrent-desktop.desktop'
|
'webtorrent-desktop.desktop'
|
||||||
)
|
)
|
||||||
fs.removeSync(desktopFilePath)
|
rimraf(desktopFilePath)
|
||||||
|
|
||||||
const iconFilePath = path.join(
|
const iconFilePath = path.join(
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
@@ -361,5 +365,5 @@ function uninstallLinux () {
|
|||||||
'icons',
|
'icons',
|
||||||
'webtorrent-desktop.png'
|
'webtorrent-desktop.png'
|
||||||
)
|
)
|
||||||
fs.removeSync(iconFilePath)
|
rimraf(iconFilePath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ const log = require('./log')
|
|||||||
const menu = require('./menu')
|
const menu = require('./menu')
|
||||||
const State = require('../renderer/lib/state')
|
const State = require('../renderer/lib/state')
|
||||||
const windows = require('./windows')
|
const windows = require('./windows')
|
||||||
|
const Plugins = require('./plugins')
|
||||||
|
const plugins = new Plugins()
|
||||||
|
|
||||||
let shouldQuit = false
|
let shouldQuit = false
|
||||||
let argv = sliceArgv(process.argv)
|
let argv = sliceArgv(process.argv)
|
||||||
@@ -33,9 +35,11 @@ if (process.platform === 'win32') {
|
|||||||
argv = argv.filter((arg) => !arg.includes('--squirrel'))
|
argv = argv.filter((arg) => !arg.includes('--squirrel'))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shouldQuit) {
|
if (!shouldQuit && !config.IS_PORTABLE) {
|
||||||
// Prevent multiple instances of app from running at same time. New instances
|
// Prevent multiple instances of app from running at same time. New instances
|
||||||
// signal this instance and quit.
|
// signal this instance and quit. Note: This feature creates a lock file in
|
||||||
|
// %APPDATA%\Roaming\WebTorrent so we do not do it for the Portable App since
|
||||||
|
// we want to be "silent" as well as "portable".
|
||||||
shouldQuit = app.makeSingleInstance(onAppOpen)
|
shouldQuit = app.makeSingleInstance(onAppOpen)
|
||||||
if (shouldQuit) {
|
if (shouldQuit) {
|
||||||
app.quit()
|
app.quit()
|
||||||
@@ -48,7 +52,11 @@ if (!shouldQuit) {
|
|||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
if (config.IS_PORTABLE) {
|
if (config.IS_PORTABLE) {
|
||||||
|
const path = require('path')
|
||||||
|
// 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
|
||||||
|
app.setPath('temp', path.join(config.CONFIG_PATH, 'Temp'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const ipcMain = electron.ipcMain
|
const ipcMain = electron.ipcMain
|
||||||
@@ -66,10 +74,17 @@ function init () {
|
|||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
isReady = true
|
isReady = true
|
||||||
|
const state = results.state
|
||||||
|
|
||||||
windows.main.init(results.state, {hidden: hidden})
|
// init new plugins then notify user
|
||||||
windows.webtorrent.init()
|
plugins.subscribe(() => {
|
||||||
menu.init()
|
// update menu and windows
|
||||||
|
// passing thru new plugin decorators
|
||||||
|
initApp(state)
|
||||||
|
})
|
||||||
|
|
||||||
|
plugins.init(state)
|
||||||
|
initApp(state)
|
||||||
|
|
||||||
// To keep app startup fast, some code is delayed.
|
// To keep app startup fast, some code is delayed.
|
||||||
setTimeout(delayedInit, config.DELAYED_INIT)
|
setTimeout(delayedInit, config.DELAYED_INIT)
|
||||||
@@ -82,6 +97,26 @@ function init () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initApp (state) {
|
||||||
|
// decorate app
|
||||||
|
plugins.onApp(app)
|
||||||
|
|
||||||
|
// init decorate menu
|
||||||
|
menu.init((tpl) => plugins.decorateMenu(tpl))
|
||||||
|
|
||||||
|
// init and decorate window
|
||||||
|
windows.main.init(
|
||||||
|
state,
|
||||||
|
{hidden: hidden},
|
||||||
|
(options) => plugins.decorateWindow(options)
|
||||||
|
)
|
||||||
|
windows.webtorrent.init((options) => plugins.decorateWindow(options))
|
||||||
|
plugins.onWindow([
|
||||||
|
windows.main.win,
|
||||||
|
windows.webtorrent.win
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
app.on('open-file', onOpen)
|
app.on('open-file', onOpen)
|
||||||
app.on('open-url', onOpen)
|
app.on('open-url', onOpen)
|
||||||
|
|
||||||
@@ -116,17 +151,25 @@ function init () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function delayedInit () {
|
function delayedInit () {
|
||||||
|
if (app.isQuitting) return
|
||||||
|
|
||||||
const announcement = require('./announcement')
|
const announcement = require('./announcement')
|
||||||
const dock = require('./dock')
|
const dock = require('./dock')
|
||||||
const tray = require('./tray')
|
|
||||||
const updater = require('./updater')
|
const updater = require('./updater')
|
||||||
const userTasks = require('./user-tasks')
|
|
||||||
|
|
||||||
announcement.init()
|
announcement.init()
|
||||||
dock.init()
|
dock.init()
|
||||||
tray.init()
|
|
||||||
updater.init()
|
updater.init()
|
||||||
userTasks.init()
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const userTasks = require('./user-tasks')
|
||||||
|
userTasks.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
const tray = require('./tray')
|
||||||
|
tray.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onOpen (e, torrentId) {
|
function onOpen (e, torrentId) {
|
||||||
@@ -184,7 +227,7 @@ function processArgv (argv) {
|
|||||||
// Ignore hidden argument, already being handled
|
// Ignore hidden argument, already being handled
|
||||||
} else if (arg.startsWith('-psn')) {
|
} else if (arg.startsWith('-psn')) {
|
||||||
// Ignore Mac launchd "process serial number" argument
|
// Ignore Mac launchd "process serial number" argument
|
||||||
// Issue: https://github.com/feross/webtorrent-desktop/issues/214
|
// Issue: https://github.com/webtorrent/webtorrent-desktop/issues/214
|
||||||
} else if (arg.startsWith('--')) {
|
} else if (arg.startsWith('--')) {
|
||||||
// Ignore Spectron flags
|
// Ignore Spectron flags
|
||||||
} else if (arg === 'data:,') {
|
} else if (arg === 'data:,') {
|
||||||
|
|||||||
@@ -166,8 +166,8 @@ function init () {
|
|||||||
ipc.on('checkForExternalPlayer', function (e, path) {
|
ipc.on('checkForExternalPlayer', function (e, path) {
|
||||||
const externalPlayer = require('./external-player')
|
const externalPlayer = require('./external-player')
|
||||||
|
|
||||||
externalPlayer.checkInstall(path, function (isInstalled) {
|
externalPlayer.checkInstall(path, function (err) {
|
||||||
windows.main.send('checkForExternalPlayer', isInstalled)
|
windows.main.send('checkForExternalPlayer', !err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,11 @@ const windows = require('./windows')
|
|||||||
|
|
||||||
let menu = null
|
let menu = null
|
||||||
|
|
||||||
function init () {
|
function init (decorate) {
|
||||||
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
|
let template = getMenuTemplate()
|
||||||
|
if (decorate) template = decorate(template)
|
||||||
|
|
||||||
|
menu = electron.Menu.buildFromTemplate(template)
|
||||||
electron.Menu.setApplicationMenu(menu)
|
electron.Menu.setApplicationMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,6 +281,19 @@ function getMenuTemplate () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Transfers',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Pause All',
|
||||||
|
click: () => windows.main.dispatch('pauseAllTorrents')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Resume All',
|
||||||
|
click: () => windows.main.dispatch('resumeAllTorrents')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Help',
|
label: 'Help',
|
||||||
role: 'help',
|
role: 'help',
|
||||||
@@ -311,7 +327,7 @@ function getMenuTemplate () {
|
|||||||
]
|
]
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
// Add WebTorrent app menu (Mac)
|
// WebTorrent menu (Mac)
|
||||||
template.unshift({
|
template.unshift({
|
||||||
label: config.APP_NAME,
|
label: config.APP_NAME,
|
||||||
submenu: [
|
submenu: [
|
||||||
@@ -354,8 +370,26 @@ function getMenuTemplate () {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add Window menu (Mac)
|
// Edit menu (Mac)
|
||||||
template.splice(5, 0, {
|
template[2].submenu.push(
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Speech',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
role: 'startspeaking'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'stopspeaking'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Window menu (Mac)
|
||||||
|
template.splice(6, 0, {
|
||||||
role: 'window',
|
role: 'window',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
@@ -395,7 +429,7 @@ function getMenuTemplate () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Help menu (Windows, Linux)
|
// Help menu (Windows, Linux)
|
||||||
template[4].submenu.push(
|
template[5].submenu.push(
|
||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
|
|||||||
424
src/main/plugins.js
Normal file
@@ -0,0 +1,424 @@
|
|||||||
|
const {exec} = require('child_process')
|
||||||
|
const {resolve, basename} = require('path')
|
||||||
|
const {writeFileSync} = require('fs')
|
||||||
|
const State = require('../renderer/lib/state')
|
||||||
|
const notifier = require('node-notifier')
|
||||||
|
const {app} = require('electron')
|
||||||
|
|
||||||
|
const {sync: mkdirpSync} = require('mkdirp')
|
||||||
|
const ms = require('ms')
|
||||||
|
const shellEnv = require('shell-env')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
|
||||||
|
module.exports = class Plugins {
|
||||||
|
constructor () {
|
||||||
|
// modules path
|
||||||
|
this.path = resolve(config.getConfigPath(), 'plugins')
|
||||||
|
log('Path: ', this.path)
|
||||||
|
this.availableExtensions = new Set([
|
||||||
|
'onApp', 'onWindow', 'decorateMenu', 'decorateWindow', 'decorateConfig'
|
||||||
|
])
|
||||||
|
|
||||||
|
this.forceUpdate = false
|
||||||
|
this.updating = false
|
||||||
|
this.watchers = []
|
||||||
|
}
|
||||||
|
|
||||||
|
init (state) {
|
||||||
|
this.state = state
|
||||||
|
|
||||||
|
// initialize state
|
||||||
|
this.state.saved = Object.assign(this.state.saved || {})
|
||||||
|
|
||||||
|
// init plugin directories if not present
|
||||||
|
mkdirpSync(this.path)
|
||||||
|
|
||||||
|
// caches
|
||||||
|
this.plugins = config.getPlugins()
|
||||||
|
this.paths = this.getPaths(this.plugins)
|
||||||
|
this.id = this.getId(this.plugins)
|
||||||
|
this.modules = this.requirePlugins()
|
||||||
|
|
||||||
|
// we listen on configuration updates to trigger
|
||||||
|
// plugin installation
|
||||||
|
config.subscribe(() => {
|
||||||
|
const plugins = config.getPlugins()
|
||||||
|
if (plugins !== this.plugins) {
|
||||||
|
const id = this.getId(plugins)
|
||||||
|
if (this.id !== id) {
|
||||||
|
this.alert('Installing plugins...')
|
||||||
|
log('UPDATING...')
|
||||||
|
this.id = id
|
||||||
|
this.plugins = plugins
|
||||||
|
this.paths = this.getPaths(this.plugins)
|
||||||
|
this.updatePlugins()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// schedule the initial plugins update
|
||||||
|
// a bit after the user launches the app
|
||||||
|
// to prevent slowness
|
||||||
|
if (this.needsUpdate()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.updatePlugins()
|
||||||
|
}, 5000)
|
||||||
|
log('Installation scheduled')
|
||||||
|
}
|
||||||
|
|
||||||
|
// update plugins every 5 hours
|
||||||
|
setInterval(() => {
|
||||||
|
this.updatePlugins()
|
||||||
|
}, ms('5h'))
|
||||||
|
}
|
||||||
|
|
||||||
|
on (action, params) {
|
||||||
|
log(`ON ${action}:`, params)
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
const actionName = this.capitalizeFirstLetter(action)
|
||||||
|
const methodName = `on${actionName}`
|
||||||
|
if (typeof plugin[methodName] === 'function') {
|
||||||
|
plugin[methodName](params)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
capitalizeFirstLetter (string) {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
didPluginsChange () {
|
||||||
|
return this.state.saved.installedPlugins !== this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPlugins () {
|
||||||
|
return !this.isEmptyObject(this.plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
isFirstInstall () {
|
||||||
|
return (!this.state.saved.installedPlugins && this.hasPlugins())
|
||||||
|
}
|
||||||
|
|
||||||
|
needsUpdate () {
|
||||||
|
return (this.didPluginsChange() || this.isFirstInstall())
|
||||||
|
}
|
||||||
|
|
||||||
|
getId (plugins) {
|
||||||
|
const hash = crypto.createHash('sha256')
|
||||||
|
hash.update(JSON.stringify(plugins))
|
||||||
|
return hash.digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePlugins (forceUpdate = false) {
|
||||||
|
this.forceUpdate = forceUpdate
|
||||||
|
if (this.updating) {
|
||||||
|
// TODO
|
||||||
|
// return notify('Plugin update in progress')
|
||||||
|
}
|
||||||
|
this.updating = true
|
||||||
|
this.syncPackageJSON()
|
||||||
|
this.installPackages((err) => this.loadPlugins(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPlugins (err, localOnly = false) {
|
||||||
|
this.updating = false
|
||||||
|
|
||||||
|
// handle errors first
|
||||||
|
if (err) {
|
||||||
|
console.error(err.stack)
|
||||||
|
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
||||||
|
this.alert(
|
||||||
|
'Error updating plugins: We could not find the "npm" command. Make sure it\'s in $PATH'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.alert(`Error updating plugins: Check '${this.path}/npm-debug.log' for more information.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// update state with latest plugins
|
||||||
|
this.state.saved.plugins = this.plugins
|
||||||
|
|
||||||
|
// cache modules
|
||||||
|
this.modules = this.requirePlugins()
|
||||||
|
|
||||||
|
// clear require cache
|
||||||
|
this.clearCache()
|
||||||
|
|
||||||
|
// we're done with local plugins
|
||||||
|
if (localOnly) return
|
||||||
|
|
||||||
|
// OK, no errors
|
||||||
|
// flag successful plugin update
|
||||||
|
this.state.saved.installedPlugins = this.id
|
||||||
|
|
||||||
|
// check if package based plugins were updated
|
||||||
|
const loaded = this.modules.length
|
||||||
|
const total = this.paths.plugins.length
|
||||||
|
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
||||||
|
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
||||||
|
this.state.saved.installedPluginVersions = pluginVersions
|
||||||
|
|
||||||
|
// notify watchers
|
||||||
|
if (this.forceUpdate || changed) {
|
||||||
|
this.watchers.forEach(fn => fn(err, {forceUpdate: this.forceUpdate}))
|
||||||
|
this.alert('Installation completed')
|
||||||
|
log('Installation completed')
|
||||||
|
}
|
||||||
|
|
||||||
|
// save state
|
||||||
|
State.save(this.state)
|
||||||
|
}
|
||||||
|
|
||||||
|
getPluginVersions () {
|
||||||
|
const paths_ = this.paths.plugins
|
||||||
|
return paths_.map(path => {
|
||||||
|
let version = null
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require
|
||||||
|
version = require(resolve(path, 'package.json')).version
|
||||||
|
} catch (err) { }
|
||||||
|
return [
|
||||||
|
basename(path),
|
||||||
|
version
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
clearCache () {
|
||||||
|
// trigger unload hooks
|
||||||
|
this.modules.forEach(mod => {
|
||||||
|
if (mod.onUnload) {
|
||||||
|
mod.onUnload(app)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// clear require cache
|
||||||
|
for (const entry in require.cache) {
|
||||||
|
if (entry.indexOf(this.path) === 0) {
|
||||||
|
delete require.cache[entry]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmptyObject (obj) {
|
||||||
|
return (Object.keys(obj).length === 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
syncPackageJSON () {
|
||||||
|
const dependencies = this.toDependencies(this.plugins)
|
||||||
|
const pkg = {
|
||||||
|
name: 'webtorrent-plugins',
|
||||||
|
description: 'Auto-generated from WebTorrent config.',
|
||||||
|
private: true,
|
||||||
|
version: '0.0.1',
|
||||||
|
repository: 'feross/webtorrent-desktop',
|
||||||
|
license: 'MIT',
|
||||||
|
homepage: 'https://webtorrent.io',
|
||||||
|
dependencies
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = resolve(this.path, 'package.json')
|
||||||
|
try {
|
||||||
|
writeFileSync(file, JSON.stringify(pkg, null, 2))
|
||||||
|
return true
|
||||||
|
} catch (err) {
|
||||||
|
this.alert(`An error occurred writing to ${file}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alert (message) {
|
||||||
|
notifier.notify({
|
||||||
|
title: 'WebTorrent Plugins',
|
||||||
|
// icon: config.icon, // TODO: save icon in webtorrent local folder and set config.icon
|
||||||
|
message: message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
isLocalPath (string) {
|
||||||
|
// matches unix and windows local paths
|
||||||
|
return string.match(/^(\/|[a-z]:\/)/i)
|
||||||
|
}
|
||||||
|
|
||||||
|
toDependencies (plugins) {
|
||||||
|
const obj = {}
|
||||||
|
const pluginNames = Object.keys(plugins)
|
||||||
|
|
||||||
|
pluginNames.forEach(name => {
|
||||||
|
let url = plugins[name]
|
||||||
|
if (this.isLocalPath(url)) return
|
||||||
|
obj[name] = url
|
||||||
|
})
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
installPackages (fn) {
|
||||||
|
const {shell = '', npmRegistry} = config
|
||||||
|
|
||||||
|
shellEnv(shell).then(env => {
|
||||||
|
if (npmRegistry) {
|
||||||
|
env.NPM_CONFIG_REGISTRY = npmRegistry
|
||||||
|
}
|
||||||
|
/* eslint-disable camelcase */
|
||||||
|
env.npm_config_runtime = 'electron'
|
||||||
|
env.npm_config_target = process.versions.electron
|
||||||
|
env.npm_config_disturl = 'https://atom.io/download/atom-shell'
|
||||||
|
/* eslint-enable camelcase */
|
||||||
|
// Shell-specific installation commands
|
||||||
|
const installCommands = {
|
||||||
|
fish: 'npm prune; and npm install --production',
|
||||||
|
posix: 'npm prune && npm install --production'
|
||||||
|
}
|
||||||
|
// determine the shell we're running in
|
||||||
|
const whichShell = shell.match(/fish/) ? 'fish' : 'posix'
|
||||||
|
|
||||||
|
// Use the install command that is appropriate for our shell
|
||||||
|
exec(installCommands[whichShell], {
|
||||||
|
cwd: this.path
|
||||||
|
}, err => {
|
||||||
|
if (err) return fn(err)
|
||||||
|
fn(null)
|
||||||
|
})
|
||||||
|
}).catch(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribe (fn) {
|
||||||
|
this.watchers.push(fn)
|
||||||
|
return () => {
|
||||||
|
this.watchers.splice(this.watchers.indexOf(fn), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getPaths (plugins) {
|
||||||
|
const pluginNames = Object.keys(plugins)
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: pluginNames.map(name => {
|
||||||
|
let url = plugins[name]
|
||||||
|
|
||||||
|
// plugin is already on a local folder
|
||||||
|
// directly load it from its current location
|
||||||
|
if (this.isLocalPath(url)) return url
|
||||||
|
|
||||||
|
// plugin will be installed with npm install from a remote url
|
||||||
|
return resolve(this.path, 'node_modules', name.split('#')[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requirePlugins () {
|
||||||
|
const {plugins} = this.paths
|
||||||
|
let installNeeded = false
|
||||||
|
|
||||||
|
const load = (path) => {
|
||||||
|
if (!path.match(/\/$/)) {
|
||||||
|
path += '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainPath = `${path}main.js`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const Plugin = require(mainPath) // eslint-disable import/no-dynamic-require
|
||||||
|
const plugin = new Plugin()
|
||||||
|
|
||||||
|
const exposed = plugin && Object.keys(plugin).some(key => this.availableExtensions.has(key))
|
||||||
|
if (!exposed) return
|
||||||
|
|
||||||
|
// populate the name for internal errors here
|
||||||
|
plugin._name = basename(mainPath)
|
||||||
|
|
||||||
|
return plugin
|
||||||
|
} catch (err) {
|
||||||
|
log('Require plugins ERROR:', err)
|
||||||
|
this.alert(`Error loading plugin: ${mainPath}`)
|
||||||
|
// plugin not installed
|
||||||
|
// node_modules removed? did a manual plugin uninstall?
|
||||||
|
// try installing and then loading if successfull
|
||||||
|
installNeeded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin installation happens on the MAIN process.
|
||||||
|
// If plugins haven't finished installing, wait for them.
|
||||||
|
if (installNeeded) {
|
||||||
|
log('Plugins install needed, wait...')
|
||||||
|
setTimeout(() => {
|
||||||
|
this.requirePlugins()
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
return plugins.map(load).filter(v => Boolean(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
onApp (app) {
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
if (plugin.onApp) {
|
||||||
|
plugin.onApp(app)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindow (win) {
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
if (plugin.onWindow) {
|
||||||
|
plugin.onWindow(win)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// decorates the base object by calling plugin[key]
|
||||||
|
// for all the available plugins
|
||||||
|
decorateObject (base, key) {
|
||||||
|
let decorated = base
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
if (plugin[key]) {
|
||||||
|
const res = plugin[key](decorated)
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
decorated = res
|
||||||
|
} else {
|
||||||
|
this.alert(`Plugin error: "${plugin._name}": invalid return type for \`${key}\``)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return decorated
|
||||||
|
}
|
||||||
|
|
||||||
|
decorateMenu (tpl) {
|
||||||
|
return this.decorateObject(tpl, 'decorateMenu')
|
||||||
|
}
|
||||||
|
|
||||||
|
decorateWindow (options) {
|
||||||
|
return this.decorateObject(options, 'decorateWindow')
|
||||||
|
}
|
||||||
|
|
||||||
|
getDecoratedEnv (baseEnv) {
|
||||||
|
return this.decorateObject(baseEnv, 'decorateEnv')
|
||||||
|
}
|
||||||
|
|
||||||
|
getDecoratedConfig () {
|
||||||
|
const baseConfig = config.getConfig()
|
||||||
|
return this.decorateObject(baseConfig, 'decorateConfig')
|
||||||
|
}
|
||||||
|
|
||||||
|
getDecoratedBrowserOptions (defaults) {
|
||||||
|
return this.decorateObject(defaults, 'decorateBrowserOptions')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs passed arguments to console using a prefix.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function log () {
|
||||||
|
const prefix = '[ PLUGINS.Main ]-->'
|
||||||
|
const args = [prefix]
|
||||||
|
|
||||||
|
for (var i = 0; i < arguments.length; ++i) {
|
||||||
|
args.push(arguments[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log.apply(console, args)
|
||||||
|
}
|
||||||
@@ -36,8 +36,8 @@ function setWindowFocus (flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initLinux () {
|
function initLinux () {
|
||||||
checkLinuxTraySupport(function (supportsTray) {
|
checkLinuxTraySupport(function (err) {
|
||||||
if (supportsTray) createTray()
|
if (!err) createTray()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,10 +55,14 @@ function checkLinuxTraySupport (cb) {
|
|||||||
// libappindicator1. If WebTorrent was installed from the deb file, we should
|
// libappindicator1. If WebTorrent was installed from the deb file, we should
|
||||||
// always have it. If it was installed from the zip file, we might not.
|
// always have it. If it was installed from the zip file, we might not.
|
||||||
cp.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
|
cp.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
|
||||||
if (err) return cb(false)
|
if (err) return cb(err)
|
||||||
// Unfortunately there's no cleaner way, as far as I can tell, to check
|
// Unfortunately there's no cleaner way, as far as I can tell, to check
|
||||||
// whether a debian package is installed:
|
// whether a debian package is installed:
|
||||||
cb(stdout.endsWith('\tinstall\n'))
|
if (stdout.endsWith('\tinstall\n')) {
|
||||||
|
cb(null)
|
||||||
|
} else {
|
||||||
|
cb(new Error('debian package not installed'))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const main = module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
|
const debounce = require('debounce')
|
||||||
|
|
||||||
const app = electron.app
|
const app = electron.app
|
||||||
|
|
||||||
@@ -22,41 +23,53 @@ const config = require('../../config')
|
|||||||
const log = require('../log')
|
const log = require('../log')
|
||||||
const menu = require('../menu')
|
const menu = require('../menu')
|
||||||
|
|
||||||
function init (state, options) {
|
function init (state, options, decorate) {
|
||||||
if (main.win) {
|
if (main.win) {
|
||||||
return main.win.show()
|
return main.win.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
|
const initialBounds = Object.assign(config.WINDOW_INITIAL_BOUNDS, state.saved.bounds)
|
||||||
|
|
||||||
const win = main.win = new electron.BrowserWindow({
|
let windowOptions = {
|
||||||
backgroundColor: '#282828',
|
backgroundColor: '#282828',
|
||||||
|
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
||||||
darkTheme: true, // Forces dark theme (GTK+3)
|
darkTheme: true, // Forces dark theme (GTK+3)
|
||||||
|
height: initialBounds.height,
|
||||||
icon: getIconPath(), // Window icon (Windows, Linux)
|
icon: getIconPath(), // Window icon (Windows, Linux)
|
||||||
minWidth: config.WINDOW_MIN_WIDTH,
|
|
||||||
minHeight: config.WINDOW_MIN_HEIGHT,
|
minHeight: config.WINDOW_MIN_HEIGHT,
|
||||||
|
minWidth: config.WINDOW_MIN_WIDTH,
|
||||||
|
show: false,
|
||||||
title: config.APP_WINDOW_TITLE,
|
title: config.APP_WINDOW_TITLE,
|
||||||
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
||||||
useContentSize: true, // Specify web page size without OS chrome
|
useContentSize: true, // Specify web page size without OS chrome
|
||||||
show: false,
|
|
||||||
width: initialBounds.width,
|
width: initialBounds.width,
|
||||||
height: initialBounds.height,
|
|
||||||
x: initialBounds.x,
|
x: initialBounds.x,
|
||||||
y: initialBounds.y
|
y: initialBounds.y
|
||||||
})
|
}
|
||||||
|
if (decorate) windowOptions = decorate(windowOptions)
|
||||||
|
|
||||||
win.once('ready-to-show', function () {
|
const win = main.win = new electron.BrowserWindow(windowOptions)
|
||||||
if (!options.hidden) win.show()
|
|
||||||
})
|
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_MAIN)
|
win.loadURL(config.WINDOW_MAIN)
|
||||||
|
|
||||||
if (win.setSheetOffset) win.setSheetOffset(config.UI_HEADER_HEIGHT)
|
win.once('ready-to-show', () => {
|
||||||
|
if (!options.hidden) win.show()
|
||||||
|
})
|
||||||
|
|
||||||
|
if (win.setSheetOffset) {
|
||||||
|
win.setSheetOffset(config.UI_HEADER_HEIGHT)
|
||||||
|
}
|
||||||
|
|
||||||
win.webContents.on('dom-ready', function () {
|
win.webContents.on('dom-ready', function () {
|
||||||
menu.onToggleFullScreen(main.win.isFullScreen())
|
menu.onToggleFullScreen(main.win.isFullScreen())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
win.webContents.on('will-navigate', (e, url) => {
|
||||||
|
// Prevent drag-and-drop from navigating the Electron window, which can happen
|
||||||
|
// before our drag-and-drop handlers have been initialized.
|
||||||
|
e.preventDefault()
|
||||||
|
})
|
||||||
|
|
||||||
win.on('blur', onWindowBlur)
|
win.on('blur', onWindowBlur)
|
||||||
win.on('focus', onWindowFocus)
|
win.on('focus', onWindowFocus)
|
||||||
|
|
||||||
@@ -75,20 +88,23 @@ function init (state, options) {
|
|||||||
win.setMenuBarVisibility(true)
|
win.setMenuBarVisibility(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
win.on('move', function (e) {
|
win.on('move', debounce(function (e) {
|
||||||
send('windowBoundsChanged', e.sender.getBounds())
|
send('windowBoundsChanged', e.sender.getBounds())
|
||||||
})
|
}, 1000))
|
||||||
|
|
||||||
win.on('resize', function (e) {
|
win.on('resize', debounce(function (e) {
|
||||||
send('windowBoundsChanged', e.sender.getBounds())
|
send('windowBoundsChanged', e.sender.getBounds())
|
||||||
})
|
}, 1000))
|
||||||
|
|
||||||
win.on('close', function (e) {
|
win.on('close', function (e) {
|
||||||
const tray = require('../tray')
|
if (process.platform !== 'darwin') {
|
||||||
|
const tray = require('../tray')
|
||||||
if (process.platform !== 'darwin' && !tray.hasTray()) {
|
if (!tray.hasTray()) {
|
||||||
app.quit()
|
app.quit()
|
||||||
} else if (!app.isQuitting) {
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!app.isQuitting) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
hide()
|
hide()
|
||||||
}
|
}
|
||||||
@@ -101,7 +117,7 @@ function dispatch (...args) {
|
|||||||
|
|
||||||
function hide () {
|
function hide () {
|
||||||
if (!main.win) return
|
if (!main.win) return
|
||||||
main.win.send('dispatch', 'backToList')
|
dispatch('backToList')
|
||||||
main.win.hide()
|
main.win.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +169,8 @@ function setBounds (bounds, maximize) {
|
|||||||
if (bounds.x === null && bounds.y === null) {
|
if (bounds.x === null && bounds.y === null) {
|
||||||
// X and Y not specified? By default, center on current screen
|
// X and Y not specified? By default, center on current screen
|
||||||
const scr = electron.screen.getDisplayMatching(main.win.getBounds())
|
const scr = electron.screen.getDisplayMatching(main.win.getBounds())
|
||||||
bounds.x = Math.round(scr.bounds.x + scr.bounds.width / 2 - bounds.width / 2)
|
bounds.x = Math.round(scr.bounds.x + (scr.bounds.width / 2) - (bounds.width / 2))
|
||||||
bounds.y = Math.round(scr.bounds.y + scr.bounds.height / 2 - bounds.height / 2)
|
bounds.y = Math.round(scr.bounds.y + (scr.bounds.height / 2) - (bounds.height / 2))
|
||||||
log('setBounds: centered to ' + JSON.stringify(bounds))
|
log('setBounds: centered to ' + JSON.stringify(bounds))
|
||||||
}
|
}
|
||||||
// Resize the window's content area (so window border doesn't need to be taken
|
// Resize the window's content area (so window border doesn't need to be taken
|
||||||
@@ -226,17 +242,21 @@ function toggleFullScreen (flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onWindowBlur () {
|
function onWindowBlur () {
|
||||||
const tray = require('../tray')
|
|
||||||
|
|
||||||
menu.setWindowFocus(false)
|
menu.setWindowFocus(false)
|
||||||
tray.setWindowFocus(false)
|
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
const tray = require('../tray')
|
||||||
|
tray.setWindowFocus(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onWindowFocus () {
|
function onWindowFocus () {
|
||||||
const tray = require('../tray')
|
|
||||||
|
|
||||||
menu.setWindowFocus(true)
|
menu.setWindowFocus(true)
|
||||||
tray.setWindowFocus(true)
|
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
const tray = require('../tray')
|
||||||
|
tray.setWindowFocus(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIconPath () {
|
function getIconPath () {
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ const webtorrent = module.exports = {
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
const log = require('../log')
|
|
||||||
|
|
||||||
function init () {
|
function init (decorate) {
|
||||||
const win = webtorrent.win = new electron.BrowserWindow({
|
let options = {
|
||||||
backgroundColor: '#1E1E1E',
|
backgroundColor: '#1E1E1E',
|
||||||
|
backgroundThrottling: false, // do not throttle animations/timers when page is background
|
||||||
center: true,
|
center: true,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
@@ -26,7 +26,9 @@ function init () {
|
|||||||
title: 'webtorrent-hidden-window',
|
title: 'webtorrent-hidden-window',
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
width: 150
|
width: 150
|
||||||
})
|
}
|
||||||
|
if (decorate) options = decorate(options)
|
||||||
|
const win = webtorrent.win = new electron.BrowserWindow(options)
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_WEBTORRENT)
|
win.loadURL(config.WINDOW_WEBTORRENT)
|
||||||
|
|
||||||
@@ -52,7 +54,6 @@ function send (...args) {
|
|||||||
|
|
||||||
function toggleDevTools () {
|
function toggleDevTools () {
|
||||||
if (!webtorrent.win) return
|
if (!webtorrent.win) return
|
||||||
log('toggleDevTools')
|
|
||||||
if (webtorrent.win.webContents.isDevToolsOpened()) {
|
if (webtorrent.win.webContents.isDevToolsOpened()) {
|
||||||
webtorrent.win.webContents.closeDevTools()
|
webtorrent.win.webContents.closeDevTools()
|
||||||
webtorrent.win.hide()
|
webtorrent.win.hide()
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ module.exports = class ModalOKCancel extends React.Component {
|
|||||||
className='control ok'
|
className='control ok'
|
||||||
primary
|
primary
|
||||||
label={okText}
|
label={okText}
|
||||||
onClick={onOK} />
|
onClick={onOK}
|
||||||
|
autoFocus />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ module.exports = class UpdateAvailableModal extends React.Component {
|
|||||||
)
|
)
|
||||||
|
|
||||||
function handleShow () {
|
function handleShow () {
|
||||||
electron.shell.openExternal('https://github.com/feross/webtorrent-desktop/releases')
|
// TODO: use the GitHub urls from config.js
|
||||||
|
electron.shell.openExternal('https://github.com/webtorrent/webtorrent-desktop/releases')
|
||||||
dispatch('exitModal')
|
dispatch('exitModal')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
const electron = require('electron')
|
const {ipcRenderer} = require('electron')
|
||||||
|
const telemetry = require('../lib/telemetry')
|
||||||
const ipcRenderer = electron.ipcRenderer
|
|
||||||
|
|
||||||
const Playlist = require('../lib/playlist')
|
const Playlist = require('../lib/playlist')
|
||||||
|
|
||||||
// Controls local play back: the <video>/<audio> tag and VLC
|
// Controls local play back: the <video>/<audio> tag and VLC
|
||||||
@@ -12,7 +10,7 @@ module.exports = class MediaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mediaSuccess () {
|
mediaSuccess () {
|
||||||
this.state.playing.result = 'success'
|
telemetry.logPlayAttempt('success')
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaStalled () {
|
mediaStalled () {
|
||||||
@@ -22,7 +20,7 @@ module.exports = class MediaController {
|
|||||||
mediaError (error) {
|
mediaError (error) {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
if (state.location.url() === 'player') {
|
if (state.location.url() === 'player') {
|
||||||
state.playing.result = 'error'
|
telemetry.logPlayAttempt('error')
|
||||||
state.playing.location = 'error'
|
state.playing.location = 'error'
|
||||||
ipcRenderer.send('checkForExternalPlayer', state.saved.prefs.externalPlayerPath)
|
ipcRenderer.send('checkForExternalPlayer', state.saved.prefs.externalPlayerPath)
|
||||||
ipcRenderer.once('checkForExternalPlayer', function (e, isInstalled) {
|
ipcRenderer.once('checkForExternalPlayer', function (e, isInstalled) {
|
||||||
@@ -56,12 +54,21 @@ module.exports = class MediaController {
|
|||||||
|
|
||||||
openExternalPlayer () {
|
openExternalPlayer () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
const mediaURL = Playlist.getCurrentLocalURL(this.state)
|
|
||||||
ipcRenderer.send('openExternalPlayer',
|
|
||||||
state.saved.prefs.externalPlayerPath,
|
|
||||||
mediaURL,
|
|
||||||
state.window.title)
|
|
||||||
state.playing.location = 'external'
|
state.playing.location = 'external'
|
||||||
|
|
||||||
|
const onServerRunning = function () {
|
||||||
|
state.playing.isReady = true
|
||||||
|
telemetry.logPlayAttempt('external')
|
||||||
|
|
||||||
|
const mediaURL = Playlist.getCurrentLocalURL(state)
|
||||||
|
ipcRenderer.send('openExternalPlayer',
|
||||||
|
state.saved.prefs.externalPlayerPath,
|
||||||
|
mediaURL,
|
||||||
|
state.window.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.server != null) onServerRunning()
|
||||||
|
else ipcRenderer.once('wt-server-running', onServerRunning)
|
||||||
}
|
}
|
||||||
|
|
||||||
externalPlayerNotFound () {
|
externalPlayerNotFound () {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ module.exports = class PlaybackController {
|
|||||||
// * Stream, if not already fully downloaded
|
// * Stream, if not already fully downloaded
|
||||||
// * 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)
|
||||||
|
|
||||||
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) => {
|
||||||
@@ -84,6 +86,17 @@ module.exports = class PlaybackController {
|
|||||||
else this.pause()
|
else this.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pauseActiveTorrents (infoHash) {
|
||||||
|
// Playback Priority: pause all active torrents if needed.
|
||||||
|
if (!this.state.saved.prefs.highestPlaybackPriority) return
|
||||||
|
|
||||||
|
// Do not pause active torrents if playing a fully downloaded torrent.
|
||||||
|
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
|
if (torrentSummary.status === 'seeding') return
|
||||||
|
|
||||||
|
dispatch('prioritizeTorrent', infoHash)
|
||||||
|
}
|
||||||
|
|
||||||
// Play next file in list (if any)
|
// Play next file in list (if any)
|
||||||
nextTrack () {
|
nextTrack () {
|
||||||
const state = this.state
|
const state = this.state
|
||||||
@@ -211,6 +224,7 @@ module.exports = class PlaybackController {
|
|||||||
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
|
||||||
|
|
||||||
// update UI to show pending playback
|
// update UI to show pending playback
|
||||||
sound.play('PLAY')
|
sound.play('PLAY')
|
||||||
@@ -222,6 +236,8 @@ module.exports = class PlaybackController {
|
|||||||
|
|
||||||
// Starts WebTorrent server for media streaming
|
// Starts WebTorrent server for media streaming
|
||||||
startServer (torrentSummary) {
|
startServer (torrentSummary) {
|
||||||
|
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,
|
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash,
|
||||||
@@ -232,6 +248,7 @@ module.exports = class PlaybackController {
|
|||||||
|
|
||||||
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 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +285,16 @@ module.exports = 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 (state.playing.type === 'audio' && !fileSummary.audioInfo) {
|
if (torrentSummary.status === 'paused') {
|
||||||
ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index)
|
ipcRenderer.once('wt-ready-' + torrentSummary.infoHash, getAudioMetadata)
|
||||||
|
} else {
|
||||||
|
getAudioMetadata()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAudioMetadata () {
|
||||||
|
if (state.playing.type === 'audio' && !fileSummary.audioInfo) {
|
||||||
|
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
|
||||||
@@ -312,12 +337,7 @@ module.exports = class PlaybackController {
|
|||||||
// Save volume (this session only, not in state.saved)
|
// Save volume (this session only, not in state.saved)
|
||||||
state.previousVolume = state.playing.volume
|
state.previousVolume = state.playing.volume
|
||||||
|
|
||||||
// Telemetry: track what happens after the user clicks play
|
if (!state.playing.isReady) telemetry.logPlayAttempt('abandoned') // user gave up waiting
|
||||||
const result = state.playing.result // 'success' or 'error'
|
|
||||||
if (result === 'success') telemetry.logPlayAttempt('success') // first frame displayed
|
|
||||||
else if (result === 'error') telemetry.logPlayAttempt('error') // codec missing, etc
|
|
||||||
else if (result === undefined) telemetry.logPlayAttempt('abandoned') // user gave up waiting
|
|
||||||
else console.error('Unknown state.playing.result', state.playing.result)
|
|
||||||
|
|
||||||
// Reset the window contents back to the home screen
|
// Reset the window contents back to the home screen
|
||||||
state.playing = State.getDefaultPlayState()
|
state.playing = State.getDefaultPlayState()
|
||||||
@@ -334,6 +354,11 @@ module.exports = class PlaybackController {
|
|||||||
|
|
||||||
ipcRenderer.send('onPlayerClose')
|
ipcRenderer.send('onPlayerClose')
|
||||||
|
|
||||||
|
// Playback Priority: resume previously paused downloads.
|
||||||
|
if (this.state.saved.prefs.highestPlaybackPriority) {
|
||||||
|
dispatch('resumePausedTorrents')
|
||||||
|
}
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const parallel = require('run-parallel')
|
const parallel = require('run-parallel')
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ module.exports = class TorrentListController {
|
|||||||
torrentId = torrentId.path
|
torrentId = torrentId.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trim extra spaces off pasted magnet links
|
||||||
|
if (typeof torrentId === 'string') {
|
||||||
|
torrentId = torrentId.trim()
|
||||||
|
}
|
||||||
|
|
||||||
// Allow a instant.io link to be pasted
|
// Allow a instant.io link to be pasted
|
||||||
if (typeof torrentId === 'string' && instantIoRegex.test(torrentId)) {
|
if (typeof torrentId === 'string' && instantIoRegex.test(torrentId)) {
|
||||||
torrentId = torrentId.slice(torrentId.indexOf('#') + 1)
|
torrentId = torrentId.slice(torrentId.indexOf('#') + 1)
|
||||||
@@ -93,6 +98,7 @@ module.exports = class TorrentListController {
|
|||||||
fs.stat(fileOrFolder, function (err) {
|
fs.stat(fileOrFolder, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
s.error = 'path-missing'
|
s.error = 'path-missing'
|
||||||
|
dispatch('backToList')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
start()
|
start()
|
||||||
@@ -101,7 +107,7 @@ module.exports = class TorrentListController {
|
|||||||
function start () {
|
function start () {
|
||||||
ipcRenderer.send('wt-start-torrenting',
|
ipcRenderer.send('wt-start-torrenting',
|
||||||
s.torrentKey,
|
s.torrentKey,
|
||||||
TorrentSummary.getTorrentID(s),
|
TorrentSummary.getTorrentId(s),
|
||||||
s.path,
|
s.path,
|
||||||
s.fileModtimes,
|
s.fileModtimes,
|
||||||
s.selections)
|
s.selections)
|
||||||
@@ -115,11 +121,65 @@ module.exports = class TorrentListController {
|
|||||||
torrentSummary.status = 'new'
|
torrentSummary.status = 'new'
|
||||||
this.startTorrentingSummary(torrentSummary.torrentKey)
|
this.startTorrentingSummary(torrentSummary.torrentKey)
|
||||||
sound.play('ENABLE')
|
sound.play('ENABLE')
|
||||||
} else {
|
return
|
||||||
torrentSummary.status = 'paused'
|
|
||||||
ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash)
|
|
||||||
sound.play('DISABLE')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.pauseTorrent(torrentSummary, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
pauseAllTorrents () {
|
||||||
|
this.state.saved.torrents.forEach((torrentSummary) => {
|
||||||
|
if (torrentSummary.status === 'downloading' ||
|
||||||
|
torrentSummary.status === 'seeding') {
|
||||||
|
torrentSummary.status = 'paused'
|
||||||
|
ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
sound.play('DISABLE')
|
||||||
|
}
|
||||||
|
|
||||||
|
resumeAllTorrents () {
|
||||||
|
this.state.saved.torrents.forEach((torrentSummary) => {
|
||||||
|
if (torrentSummary.status === 'paused') {
|
||||||
|
torrentSummary.status = 'downloading'
|
||||||
|
this.startTorrentingSummary(torrentSummary.torrentKey)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
sound.play('ENABLE')
|
||||||
|
}
|
||||||
|
|
||||||
|
pauseTorrent (torrentSummary, playSound) {
|
||||||
|
torrentSummary.status = 'paused'
|
||||||
|
ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash)
|
||||||
|
|
||||||
|
if (playSound) sound.play('DISABLE')
|
||||||
|
}
|
||||||
|
|
||||||
|
prioritizeTorrent (infoHash) {
|
||||||
|
this.state.saved.torrents
|
||||||
|
.filter((torrent) => { // We're interested in active torrents only.
|
||||||
|
return (['downloading', 'seeding'].indexOf(torrent.status) !== -1)
|
||||||
|
})
|
||||||
|
.map((torrent) => { // Pause all active torrents except the one that started playing.
|
||||||
|
if (infoHash === torrent.infoHash) return
|
||||||
|
|
||||||
|
// Pause torrent without playing sounds.
|
||||||
|
this.pauseTorrent(torrent, false)
|
||||||
|
|
||||||
|
this.state.saved.torrentsToResume.push(torrent.infoHash)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('Playback Priority: paused torrents: ', this.state.saved.torrentsToResume)
|
||||||
|
}
|
||||||
|
|
||||||
|
resumePausedTorrents () {
|
||||||
|
console.log('Playback Priority: resuming paused torrents')
|
||||||
|
this.state.saved.torrentsToResume.map((infoHash) => {
|
||||||
|
this.toggleTorrent(infoHash)
|
||||||
|
})
|
||||||
|
|
||||||
|
// reset paused torrents
|
||||||
|
this.state.saved.torrentsToResume = []
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleTorrentFile (infoHash, index) {
|
toggleTorrentFile (infoHash, index) {
|
||||||
@@ -214,7 +274,8 @@ module.exports = class TorrentListController {
|
|||||||
|
|
||||||
menu.append(new electron.remote.MenuItem({
|
menu.append(new electron.remote.MenuItem({
|
||||||
label: 'Save Torrent File As...',
|
label: 'Save Torrent File As...',
|
||||||
click: () => dispatch('saveTorrentFileAs', torrentSummary.torrentKey)
|
click: () => dispatch('saveTorrentFileAs', torrentSummary.torrentKey),
|
||||||
|
enabled: torrentSummary.torrentFileName != null
|
||||||
}))
|
}))
|
||||||
|
|
||||||
menu.popup(electron.remote.getCurrentWindow())
|
menu.popup(electron.remote.getCurrentWindow())
|
||||||
@@ -253,7 +314,7 @@ module.exports = class TorrentListController {
|
|||||||
|
|
||||||
// Recursively finds {name, path, size} for all files in a folder
|
// Recursively finds {name, path, size} for all files in a folder
|
||||||
// Calls `cb` on success, calls `onError` on failure
|
// Calls `cb` on success, calls `onError` on failure
|
||||||
function findFilesRecursive (paths, cb) {
|
function findFilesRecursive (paths, cb_) {
|
||||||
if (paths.length > 1) {
|
if (paths.length > 1) {
|
||||||
let numComplete = 0
|
let numComplete = 0
|
||||||
let ret = []
|
let ret = []
|
||||||
@@ -262,7 +323,7 @@ function findFilesRecursive (paths, cb) {
|
|||||||
ret.push(...fileObjs)
|
ret.push(...fileObjs)
|
||||||
if (++numComplete === paths.length) {
|
if (++numComplete === paths.length) {
|
||||||
ret.sort((a, b) => a.path < b.path ? -1 : a.path > b.path)
|
ret.sort((a, b) => a.path < b.path ? -1 : a.path > b.path)
|
||||||
cb(ret)
|
cb_(ret)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -276,7 +337,7 @@ function findFilesRecursive (paths, cb) {
|
|||||||
// Files: return name, path, and size
|
// Files: return name, path, and size
|
||||||
if (!stat.isDirectory()) {
|
if (!stat.isDirectory()) {
|
||||||
const filePath = fileOrFolder
|
const filePath = fileOrFolder
|
||||||
return cb([{
|
return cb_([{
|
||||||
name: path.basename(filePath),
|
name: path.basename(filePath),
|
||||||
path: filePath,
|
path: filePath,
|
||||||
size: stat.size
|
size: stat.size
|
||||||
@@ -288,7 +349,7 @@ function findFilesRecursive (paths, cb) {
|
|||||||
fs.readdir(folderPath, function (err, fileNames) {
|
fs.readdir(folderPath, function (err, fileNames) {
|
||||||
if (err) return dispatch('error', err)
|
if (err) return dispatch('error', err)
|
||||||
const paths = fileNames.map((fileName) => path.join(folderPath, fileName))
|
const paths = fileNames.map((fileName) => path.join(folderPath, fileName))
|
||||||
findFilesRecursive(paths, cb)
|
findFilesRecursive(paths, cb_)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,7 +388,8 @@ function toggleMenu (location) {
|
|||||||
if (state.playing.location !== 'local') {
|
if (state.playing.location !== 'local') {
|
||||||
throw new CastingError(
|
throw new CastingError(
|
||||||
`You can't connect to ${location} when already connected to another device`
|
`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)
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ class TorrentKeyNotFoundError extends TorrentError {
|
|||||||
constructor (torrentKey) { super(`Can't resolve torrent key ${torrentKey}`) }
|
constructor (torrentKey) { super(`Can't resolve torrent key ${torrentKey}`) }
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidTorrentError extends TorrentError {}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
CastingError,
|
CastingError,
|
||||||
PlaybackError,
|
PlaybackError,
|
||||||
@@ -39,6 +37,5 @@ module.exports = {
|
|||||||
UnplayableTorrentError,
|
UnplayableTorrentError,
|
||||||
UnplayableFileError,
|
UnplayableFileError,
|
||||||
InvalidSoundNameError,
|
InvalidSoundNameError,
|
||||||
TorrentKeyNotFoundError,
|
TorrentKeyNotFoundError
|
||||||
InvalidTorrentError
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
@@ -18,37 +19,22 @@ function run (state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const version = state.saved.version
|
const version = state.saved.version
|
||||||
|
const saved = state.saved
|
||||||
|
|
||||||
if (semver.lt(version, '0.7.0')) {
|
if (semver.lt(version, '0.7.0')) migrate_0_7_0(saved)
|
||||||
migrate_0_7_0(state.saved)
|
if (semver.lt(version, '0.7.2')) migrate_0_7_2(saved)
|
||||||
}
|
if (semver.lt(version, '0.11.0')) migrate_0_11_0(saved)
|
||||||
|
if (semver.lt(version, '0.12.0')) migrate_0_12_0(saved)
|
||||||
if (semver.lt(version, '0.7.2')) {
|
if (semver.lt(version, '0.14.0')) migrate_0_14_0(saved)
|
||||||
migrate_0_7_2(state.saved)
|
if (semver.lt(version, '0.17.0')) migrate_0_17_0(saved)
|
||||||
}
|
if (semver.lt(version, '0.17.2')) migrate_0_17_2(saved)
|
||||||
|
|
||||||
if (semver.lt(version, '0.11.0')) {
|
|
||||||
migrate_0_11_0(state.saved)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (semver.lt(version, '0.12.0')) {
|
|
||||||
migrate_0_12_0(state.saved)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (semver.lt(version, '0.14.0')) {
|
|
||||||
migrate_0_14_0(state.saved)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (semver.lt(version, '0.17.0')) {
|
|
||||||
migrate_0_17_0(state.saved)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config is now on the new version
|
// Config is now on the new version
|
||||||
state.saved.version = config.APP_VERSION
|
state.saved.version = config.APP_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
function migrate_0_7_0 (saved) {
|
function migrate_0_7_0 (saved) {
|
||||||
const fs = require('fs-extra')
|
const cpFile = require('cp-file')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
saved.torrents.forEach(function (ts) {
|
saved.torrents.forEach(function (ts) {
|
||||||
@@ -70,7 +56,7 @@ function migrate_0_7_0 (saved) {
|
|||||||
dst = path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
dst = path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
||||||
// Synchronous FS calls aren't ideal, but probably OK in a migration
|
// Synchronous FS calls aren't ideal, but probably OK in a migration
|
||||||
// that only runs once
|
// that only runs once
|
||||||
if (src !== dst) fs.copySync(src, dst)
|
if (src !== dst) cpFile.sync(src, dst)
|
||||||
|
|
||||||
delete ts.torrentPath
|
delete ts.torrentPath
|
||||||
ts.torrentFileName = infoHash + '.torrent'
|
ts.torrentFileName = infoHash + '.torrent'
|
||||||
@@ -85,14 +71,14 @@ function migrate_0_7_0 (saved) {
|
|||||||
dst = path.join(config.POSTER_PATH, infoHash + extension)
|
dst = path.join(config.POSTER_PATH, infoHash + extension)
|
||||||
// Synchronous FS calls aren't ideal, but probably OK in a migration
|
// Synchronous FS calls aren't ideal, but probably OK in a migration
|
||||||
// that only runs once
|
// that only runs once
|
||||||
if (src !== dst) fs.copySync(src, dst)
|
if (src !== dst) cpFile.sync(src, dst)
|
||||||
|
|
||||||
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/feross/webtorrent-desktop/pull/604#issuecomment-222805214
|
// https://github.com/webtorrent/webtorrent-desktop/pull/604#issuecomment-222805214
|
||||||
delete ts.defaultPlayFileIndex
|
delete ts.defaultPlayFileIndex
|
||||||
delete ts.files
|
delete ts.files
|
||||||
delete ts.selections
|
delete ts.selections
|
||||||
@@ -125,7 +111,7 @@ function migrate_0_12_0 (saved) {
|
|||||||
|
|
||||||
// Undo a terrible bug where clicking Play on a default torrent on a fresh
|
// Undo a terrible bug where clicking Play on a default torrent on a fresh
|
||||||
// install results in a "path missing" error
|
// install results in a "path missing" error
|
||||||
// See https://github.com/feross/webtorrent-desktop/pull/806
|
// See https://github.com/webtorrent/webtorrent-desktop/pull/806
|
||||||
const defaultTorrentFiles = [
|
const defaultTorrentFiles = [
|
||||||
'6a9759bffd5c0af65319979fb7832189f4f3c35d.torrent',
|
'6a9759bffd5c0af65319979fb7832189f4f3c35d.torrent',
|
||||||
'88594aaacbde40ef3e2510c47374ec0aa396c08e.torrent',
|
'88594aaacbde40ef3e2510c47374ec0aa396c08e.torrent',
|
||||||
@@ -139,7 +125,7 @@ function migrate_0_12_0 (saved) {
|
|||||||
if (!fileOrFolder) return
|
if (!fileOrFolder) return
|
||||||
try {
|
try {
|
||||||
fs.statSync(fileOrFolder)
|
fs.statSync(fileOrFolder)
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
// Default torrent with "missing path" error. Clear path.
|
// Default torrent with "missing path" error. Clear path.
|
||||||
delete torrentSummary.path
|
delete torrentSummary.path
|
||||||
}
|
}
|
||||||
@@ -163,3 +149,60 @@ function migrate_0_17_0 (saved) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function migrate_0_17_2 (saved) {
|
||||||
|
// 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
|
||||||
|
// Windows Explorer. See: https://github.com/webtorrent/webtorrent-desktop/issues/905
|
||||||
|
|
||||||
|
const cpFile = require('cp-file')
|
||||||
|
const rimraf = require('rimraf')
|
||||||
|
|
||||||
|
const OLD_NAME = 'The WIRED CD - Rip. Sample. Mash. Share.'
|
||||||
|
const NEW_NAME = 'The WIRED CD - Rip. Sample. Mash. Share'
|
||||||
|
|
||||||
|
const OLD_HASH = '3ba219a8634bf7bae3d848192b2da75ae995589d'
|
||||||
|
const NEW_HASH = 'a88fda5954e89178c372716a6a78b8180ed4dad3'
|
||||||
|
|
||||||
|
const ts = saved.torrents.find((ts) => {
|
||||||
|
return ts.infoHash === OLD_HASH
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!ts) return // Wired CD torrent does not exist
|
||||||
|
|
||||||
|
// New versions of WebTorrent ship with a fixed torrent file. Let's fix up the
|
||||||
|
// name in existing versions of WebTorrent.
|
||||||
|
ts.name = ts.displayName = NEW_NAME
|
||||||
|
ts.files.forEach((file) => {
|
||||||
|
file.path = file.path.replace(OLD_NAME, NEW_NAME)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Changing the torrent name causes the info hash to change
|
||||||
|
ts.infoHash = NEW_HASH
|
||||||
|
ts.magnetURI = ts.magnetURI.replace(OLD_HASH, NEW_HASH)
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.renameSync(
|
||||||
|
path.join(config.POSTER_PATH, ts.posterFileName),
|
||||||
|
path.join(config.POSTER_PATH, NEW_HASH + '.jpg')
|
||||||
|
)
|
||||||
|
} catch (err) {}
|
||||||
|
ts.posterFileName = NEW_HASH + '.jpg'
|
||||||
|
|
||||||
|
rimraf.sync(path.join(config.TORRENT_PATH, ts.torrentFileName))
|
||||||
|
cpFile.sync(
|
||||||
|
path.join(config.STATIC_PATH, 'wiredCd.torrent'),
|
||||||
|
path.join(config.TORRENT_PATH, NEW_HASH + '.torrent')
|
||||||
|
)
|
||||||
|
ts.torrentFileName = NEW_HASH + '.torrent'
|
||||||
|
|
||||||
|
if (ts.path) {
|
||||||
|
// If torrent folder already exists on disk, try to rename it
|
||||||
|
try {
|
||||||
|
fs.renameSync(
|
||||||
|
path.join(ts.path, OLD_NAME),
|
||||||
|
path.join(ts.path, NEW_NAME)
|
||||||
|
)
|
||||||
|
} catch (err) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ function updateCache (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 (var i = state.playing.fileIndex - 1; i >= 0; i--) {
|
for (let i = state.playing.fileIndex - 1; i >= 0; i--) {
|
||||||
if (TorrentPlayer.isPlayable(files[i])) return i
|
if (TorrentPlayer.isPlayable(files[i])) return i
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
@@ -80,7 +80,7 @@ function findPreviousIndex (state) {
|
|||||||
|
|
||||||
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 (var i = state.playing.fileIndex + 1; i < files.length; i++) {
|
for (let i = state.playing.fileIndex + 1; i < files.length; i++) {
|
||||||
if (TorrentPlayer.isPlayable(files[i])) return i
|
if (TorrentPlayer.isPlayable(files[i])) return i
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
preload,
|
|
||||||
play
|
play
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,7 +6,7 @@ const config = require('../../config')
|
|||||||
const {InvalidSoundNameError} = require('./errors')
|
const {InvalidSoundNameError} = require('./errors')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const VOLUME = 0.3
|
const VOLUME = 0.25
|
||||||
|
|
||||||
/* Cache of Audio elements, for instant playback */
|
/* Cache of Audio elements, for instant playback */
|
||||||
const cache = {}
|
const cache = {}
|
||||||
@@ -23,7 +22,7 @@ const sounds = {
|
|||||||
},
|
},
|
||||||
DISABLE: {
|
DISABLE: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'disable.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'disable.wav'),
|
||||||
volume: VOLUME
|
volume: VOLUME * 0.5
|
||||||
},
|
},
|
||||||
DONE: {
|
DONE: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'done.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'done.wav'),
|
||||||
@@ -31,7 +30,7 @@ const sounds = {
|
|||||||
},
|
},
|
||||||
ENABLE: {
|
ENABLE: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'enable.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'enable.wav'),
|
||||||
volume: VOLUME
|
volume: VOLUME * 0.5
|
||||||
},
|
},
|
||||||
ERROR: {
|
ERROR: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'error.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'error.wav'),
|
||||||
@@ -39,7 +38,7 @@ const sounds = {
|
|||||||
},
|
},
|
||||||
PLAY: {
|
PLAY: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'play.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'play.wav'),
|
||||||
volume: VOLUME * 1.25
|
volume: VOLUME
|
||||||
},
|
},
|
||||||
STARTUP: {
|
STARTUP: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'startup.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'startup.wav'),
|
||||||
@@ -47,17 +46,6 @@ const sounds = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function preload () {
|
|
||||||
for (let name in sounds) {
|
|
||||||
if (!cache[name]) {
|
|
||||||
const sound = sounds[name]
|
|
||||||
const audio = cache[name] = new window.Audio()
|
|
||||||
audio.volume = sound.volume
|
|
||||||
audio.src = sound.url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function play (name) {
|
function play (name) {
|
||||||
let audio = cache[name]
|
let audio = cache[name]
|
||||||
if (!audio) {
|
if (!audio) {
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
const appConfig = require('application-config')('WebTorrent')
|
const appConfig = require('application-config')('WebTorrent')
|
||||||
const debounce = require('debounce')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
const migrations = require('./migrations')
|
|
||||||
|
|
||||||
const SAVE_DEBOUNCE_INTERVAL = 1000
|
const SAVE_DEBOUNCE_INTERVAL = 1000
|
||||||
|
|
||||||
|
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
||||||
|
|
||||||
const State = module.exports = 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.
|
||||||
save: debounce(saveImmediate, SAVE_DEBOUNCE_INTERVAL),
|
save: function () {
|
||||||
|
// Perf optimization: Lazy-require debounce (and it's dependencies)
|
||||||
|
const debounce = require('debounce')
|
||||||
|
// After first State.save() invokation, future calls go straight to the
|
||||||
|
// debounced function
|
||||||
|
State.save = debounce(saveImmediate, SAVE_DEBOUNCE_INTERVAL)
|
||||||
|
State.save(...arguments)
|
||||||
|
},
|
||||||
saveImmediate
|
saveImmediate
|
||||||
})
|
})
|
||||||
|
|
||||||
appConfig.filePath = path.join(config.CONFIG_PATH, 'config.json')
|
|
||||||
|
|
||||||
function getDefaultState () {
|
function getDefaultState () {
|
||||||
const LocationHistory = require('location-history')
|
const LocationHistory = require('location-history')
|
||||||
|
|
||||||
@@ -87,6 +92,7 @@ function getDefaultPlayState () {
|
|||||||
type: null, /* 'audio' or 'video', could be 'other' if ever support eg streaming to VLC */
|
type: null, /* 'audio' or 'video', could be 'other' if ever support eg streaming to VLC */
|
||||||
currentTime: 0, /* seconds */
|
currentTime: 0, /* seconds */
|
||||||
duration: 1, /* seconds */
|
duration: 1, /* seconds */
|
||||||
|
isReady: false,
|
||||||
isPaused: true,
|
isPaused: true,
|
||||||
isStalled: false,
|
isStalled: false,
|
||||||
lastTimeUpdate: 0, /* Unix time in ms */
|
lastTimeUpdate: 0, /* Unix time in ms */
|
||||||
@@ -104,7 +110,8 @@ 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 */
|
||||||
function setupStateSaved (cb) {
|
function setupStateSaved (cb) {
|
||||||
const fs = require('fs-extra')
|
const cpFile = require('cp-file')
|
||||||
|
const fs = require('fs')
|
||||||
const parseTorrent = require('parse-torrent')
|
const parseTorrent = require('parse-torrent')
|
||||||
const parallel = require('run-parallel')
|
const parallel = require('run-parallel')
|
||||||
|
|
||||||
@@ -117,6 +124,7 @@ function setupStateSaved (cb) {
|
|||||||
startup: false
|
startup: false
|
||||||
},
|
},
|
||||||
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
||||||
|
torrentsToResume: [],
|
||||||
version: config.APP_VERSION /* make sure we can upgrade gracefully later */
|
version: config.APP_VERSION /* make sure we can upgrade gracefully later */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,18 +133,16 @@ function setupStateSaved (cb) {
|
|||||||
config.DEFAULT_TORRENTS.map(function (t, i) {
|
config.DEFAULT_TORRENTS.map(function (t, i) {
|
||||||
const infoHash = saved.torrents[i].infoHash
|
const infoHash = saved.torrents[i].infoHash
|
||||||
tasks.push(function (cb) {
|
tasks.push(function (cb) {
|
||||||
fs.copy(
|
cpFile(
|
||||||
path.join(config.STATIC_PATH, t.posterFileName),
|
path.join(config.STATIC_PATH, t.posterFileName),
|
||||||
path.join(config.POSTER_PATH, infoHash + path.extname(t.posterFileName)),
|
path.join(config.POSTER_PATH, infoHash + path.extname(t.posterFileName))
|
||||||
cb
|
).then(cb).catch(cb)
|
||||||
)
|
|
||||||
})
|
})
|
||||||
tasks.push(function (cb) {
|
tasks.push(function (cb) {
|
||||||
fs.copy(
|
cpFile(
|
||||||
path.join(config.STATIC_PATH, t.torrentFileName),
|
path.join(config.STATIC_PATH, t.torrentFileName),
|
||||||
path.join(config.TORRENT_PATH, infoHash + '.torrent'),
|
path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
||||||
cb
|
).then(cb).catch(cb)
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -146,6 +152,7 @@ function setupStateSaved (cb) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function createTorrentObject (t) {
|
function createTorrentObject (t) {
|
||||||
|
// TODO: Doing several fs.readFileSync calls during first startup is not ideal
|
||||||
const torrent = fs.readFileSync(path.join(config.STATIC_PATH, t.torrentFileName))
|
const torrent = fs.readFileSync(path.join(config.STATIC_PATH, t.torrentFileName))
|
||||||
const parsedTorrent = parseTorrent(torrent)
|
const parsedTorrent = parseTorrent(torrent)
|
||||||
|
|
||||||
@@ -205,7 +212,13 @@ function load (cb) {
|
|||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
const state = getDefaultState()
|
const state = getDefaultState()
|
||||||
state.saved = saved
|
state.saved = saved
|
||||||
migrations.run(state)
|
|
||||||
|
if (process.type === 'renderer') {
|
||||||
|
// Perf optimization: Save require() calls in the main process
|
||||||
|
const migrations = require('./migrations')
|
||||||
|
migrations.run(state)
|
||||||
|
}
|
||||||
|
|
||||||
cb(null, state)
|
cb(null, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,12 @@
|
|||||||
// Reports back so that we can improve WebTorrent Desktop
|
// Reports back so that we can improve WebTorrent Desktop
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init,
|
init,
|
||||||
|
send,
|
||||||
logUncaughtError,
|
logUncaughtError,
|
||||||
logPlayAttempt
|
logPlayAttempt
|
||||||
}
|
}
|
||||||
|
|
||||||
const crypto = require('crypto')
|
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const https = require('https')
|
|
||||||
const os = require('os')
|
|
||||||
const url = require('url')
|
|
||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
|
|
||||||
@@ -18,11 +15,18 @@ let telemetry
|
|||||||
|
|
||||||
function init (state) {
|
function init (state) {
|
||||||
telemetry = state.saved.telemetry
|
telemetry = state.saved.telemetry
|
||||||
|
|
||||||
|
// First app run
|
||||||
if (!telemetry) {
|
if (!telemetry) {
|
||||||
telemetry = state.saved.telemetry = createSummary()
|
const crypto = require('crypto')
|
||||||
|
telemetry = state.saved.telemetry = {
|
||||||
|
userID: crypto.randomBytes(32).toString('hex') // 256-bit random ID
|
||||||
|
}
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,15 +36,28 @@ function init (state) {
|
|||||||
telemetry.torrentStats = getTorrentStats(state)
|
telemetry.torrentStats = getTorrentStats(state)
|
||||||
telemetry.approxNumTorrents = telemetry.torrentStats.approxCount
|
telemetry.approxNumTorrents = telemetry.torrentStats.approxCount
|
||||||
|
|
||||||
if (config.IS_PRODUCTION) {
|
if (!config.IS_PRODUCTION) {
|
||||||
postToServer()
|
|
||||||
// If the user keeps WebTorrent running for a long time, post every 12h
|
|
||||||
setInterval(postToServer, 12 * 3600 * 1000)
|
|
||||||
} else {
|
|
||||||
// Development: telemetry used only for local debugging
|
// Development: telemetry used only for local debugging
|
||||||
// Empty uncaught errors, etc at the start of every run
|
// Empty uncaught errors, etc at the start of every run
|
||||||
reset()
|
return reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const get = require('simple-get')
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
url: config.TELEMETRY_URL,
|
||||||
|
body: telemetry,
|
||||||
|
json: true
|
||||||
|
}
|
||||||
|
|
||||||
|
get.post(opts, function (err, res) {
|
||||||
|
if (err) return console.error('Error sending telemetry', err)
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
return console.error(`Error sending telemetry, status code: ${res.statusCode}`)
|
||||||
|
}
|
||||||
|
console.log('Sent telemetry')
|
||||||
|
reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset () {
|
function reset () {
|
||||||
@@ -49,47 +66,12 @@ function reset () {
|
|||||||
minVersion: config.APP_VERSION,
|
minVersion: config.APP_VERSION,
|
||||||
total: 0,
|
total: 0,
|
||||||
success: 0,
|
success: 0,
|
||||||
timeout: 0,
|
|
||||||
error: 0,
|
error: 0,
|
||||||
|
external: 0,
|
||||||
abandoned: 0
|
abandoned: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function postToServer () {
|
|
||||||
// Serialize the telemetry summary
|
|
||||||
const payload = new Buffer(JSON.stringify(telemetry), 'utf8')
|
|
||||||
|
|
||||||
// POST to our server
|
|
||||||
const options = url.parse(config.TELEMETRY_URL)
|
|
||||||
options.method = 'POST'
|
|
||||||
options.headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Content-Length': payload.length
|
|
||||||
}
|
|
||||||
|
|
||||||
const req = https.request(options, function (res) {
|
|
||||||
if (res.statusCode === 200) {
|
|
||||||
console.log('Successfully posted telemetry summary')
|
|
||||||
reset()
|
|
||||||
} else {
|
|
||||||
console.error('Couldn\'t post telemetry summary, got HTTP ' + res.statusCode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
req.on('error', function (e) {
|
|
||||||
console.error('Couldn\'t post telemetry summary', e)
|
|
||||||
})
|
|
||||||
req.write(payload)
|
|
||||||
req.end()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new telemetry summary. Gives the user a unique ID,
|
|
||||||
// collects screen resolution, etc
|
|
||||||
function createSummary () {
|
|
||||||
// Make a 256-bit random unique ID
|
|
||||||
const userID = crypto.randomBytes(32).toString('hex')
|
|
||||||
return { userID }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track screen resolution
|
// Track screen resolution
|
||||||
function getScreenInfo () {
|
function getScreenInfo () {
|
||||||
return electron.screen.getAllDisplays().map((screen) => ({
|
return electron.screen.getAllDisplays().map((screen) => ({
|
||||||
@@ -101,6 +83,7 @@ function getScreenInfo () {
|
|||||||
|
|
||||||
// Track basic system info like OS version and amount of RAM
|
// Track basic system info like OS version and amount of RAM
|
||||||
function getSystemInfo () {
|
function getSystemInfo () {
|
||||||
|
const os = require('os')
|
||||||
return {
|
return {
|
||||||
osPlatform: process.platform,
|
osPlatform: process.platform,
|
||||||
osRelease: os.type() + ' ' + os.release(),
|
osRelease: os.type() + ' ' + os.release(),
|
||||||
@@ -223,14 +206,14 @@ function getElemString (elem) {
|
|||||||
let ret = elem.tagName
|
let ret = elem.tagName
|
||||||
try {
|
try {
|
||||||
ret += '.' + Array.from(elem.classList).join('.')
|
ret += '.' + Array.from(elem.classList).join('.')
|
||||||
} catch (e) {}
|
} catch (err) {}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user pressed play. It either worked, timed out, or showed the
|
// The user pressed play. Did it work, display an error,
|
||||||
// 'Play in VLC' codec error
|
// open an external player or did user abandon the attempt?
|
||||||
function logPlayAttempt (result) {
|
function logPlayAttempt (result) {
|
||||||
if (!['success', 'timeout', 'error', 'abandoned'].includes(result)) {
|
if (!['success', 'error', 'external', 'abandoned'].includes(result)) {
|
||||||
return console.error('Unknown play attempt result', result)
|
return console.error('Unknown play attempt result', result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ function isAudio (file) {
|
|||||||
'.mp3',
|
'.mp3',
|
||||||
'.ogg',
|
'.ogg',
|
||||||
'.wav',
|
'.wav',
|
||||||
|
'.flac',
|
||||||
'.m4a'
|
'.m4a'
|
||||||
].includes(getFileExtension(file))
|
].includes(getFileExtension(file))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module.exports = {
|
|||||||
getPosterPath,
|
getPosterPath,
|
||||||
getTorrentPath,
|
getTorrentPath,
|
||||||
getByKey,
|
getByKey,
|
||||||
getTorrentID,
|
getTorrentId,
|
||||||
getFileOrFolder
|
getFileOrFolder
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ function getPosterPath (torrentSummary) {
|
|||||||
|
|
||||||
// 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) {
|
||||||
const s = torrentSummary
|
const s = torrentSummary
|
||||||
if (s.torrentFileName) { // Load torrent file from disk
|
if (s.torrentFileName) { // Load torrent file from disk
|
||||||
return getTorrentPath(s)
|
return getTorrentPath(s)
|
||||||
|
|||||||
@@ -1,8 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
let 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')
|
||||||
|
|
||||||
const crashReporter = require('../crash-reporter')
|
const crashReporter = require('../crash-reporter')
|
||||||
crashReporter.init()
|
crashReporter.init()
|
||||||
|
|
||||||
|
// Perf optimization: Start asynchronously read on config file before all the
|
||||||
|
// blocking require() calls below.
|
||||||
|
|
||||||
|
const State = require('./lib/state')
|
||||||
|
State.load(onState)
|
||||||
|
|
||||||
|
const createGetter = require('fn-getter')
|
||||||
|
const debounce = require('debounce')
|
||||||
const dragDrop = require('drag-drop')
|
const dragDrop = require('drag-drop')
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
@@ -12,22 +34,19 @@ const ReactDOM = require('react-dom')
|
|||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
const telemetry = require('./lib/telemetry')
|
const telemetry = require('./lib/telemetry')
|
||||||
const sound = require('./lib/sound')
|
const sound = require('./lib/sound')
|
||||||
const State = require('./lib/state')
|
|
||||||
const TorrentPlayer = require('./lib/torrent-player')
|
const TorrentPlayer = require('./lib/torrent-player')
|
||||||
|
|
||||||
|
const Plugins = require('./plugins')
|
||||||
|
const plugins = new Plugins()
|
||||||
|
|
||||||
|
// Perf optimization: Needed immediately, so do not lazy load it below
|
||||||
|
const TorrentListController = require('./controllers/torrent-list-controller')
|
||||||
|
|
||||||
// Required by Material UI -- adds `onTouchTap` event
|
// Required by Material UI -- adds `onTouchTap` event
|
||||||
require('react-tap-event-plugin')()
|
require('react-tap-event-plugin')()
|
||||||
|
|
||||||
const App = require('./pages/app')
|
const App = require('./pages/app')
|
||||||
|
|
||||||
const MediaController = require('./controllers/media-controller')
|
|
||||||
const UpdateController = require('./controllers/update-controller')
|
|
||||||
const PrefsController = require('./controllers/prefs-controller')
|
|
||||||
const PlaybackController = require('./controllers/playback-controller')
|
|
||||||
const SubtitlesController = require('./controllers/subtitles-controller')
|
|
||||||
const TorrentListController = require('./controllers/torrent-list-controller')
|
|
||||||
const TorrentController = require('./controllers/torrent-controller')
|
|
||||||
|
|
||||||
// Electron apps have two processes: a main process (node) runs first and starts
|
// 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,
|
// 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
|
// and this IPC channel receives from and sends messages to the main process
|
||||||
@@ -50,34 +69,56 @@ let state
|
|||||||
// Root React component
|
// Root React component
|
||||||
let app
|
let app
|
||||||
|
|
||||||
State.load(onState)
|
|
||||||
|
|
||||||
// Called once when the application loads. (Not once per window.)
|
// Called once when the application loads. (Not once per window.)
|
||||||
// Connects to the torrent networks, sets up the UI and OS integrations like
|
// Connects to the torrent networks, sets up the UI and OS integrations like
|
||||||
// the dock icon and drag+drop.
|
// the dock icon and drag+drop.
|
||||||
function onState (err, _state) {
|
function onState (err, _state) {
|
||||||
if (err) return onError(err)
|
if (err) return onError(err)
|
||||||
state = window.state = _state // Make available for easier debugging
|
|
||||||
|
// Make available for easier debugging
|
||||||
|
state = window.state = _state
|
||||||
window.dispatch = dispatch
|
window.dispatch = dispatch
|
||||||
|
|
||||||
telemetry.init(state)
|
telemetry.init(state)
|
||||||
|
|
||||||
// Log uncaught JS errors
|
// Log uncaught JS errors
|
||||||
window.addEventListener('error',
|
window.addEventListener(
|
||||||
(e) => telemetry.logUncaughtError('window', e),
|
'error', (e) => telemetry.logUncaughtError('window', e), true /* capture */
|
||||||
true /* capture */)
|
)
|
||||||
|
|
||||||
// Create controllers
|
// Create controllers
|
||||||
controllers = {
|
controllers = {
|
||||||
media: new MediaController(state),
|
media: createGetter(() => {
|
||||||
update: new UpdateController(state),
|
const MediaController = require('./controllers/media-controller')
|
||||||
prefs: new PrefsController(state, config),
|
return new MediaController(state)
|
||||||
playback: new PlaybackController(state, config, update),
|
}),
|
||||||
subtitles: new SubtitlesController(state),
|
playback: createGetter(() => {
|
||||||
torrentList: new TorrentListController(state),
|
const PlaybackController = require('./controllers/playback-controller')
|
||||||
torrent: new TorrentController(state)
|
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)
|
||||||
|
}),
|
||||||
|
torrent: createGetter(() => {
|
||||||
|
const TorrentController = require('./controllers/torrent-controller')
|
||||||
|
return new TorrentController(state)
|
||||||
|
}),
|
||||||
|
torrentList: createGetter(() => {
|
||||||
|
return new TorrentListController(state)
|
||||||
|
}),
|
||||||
|
update: createGetter(() => {
|
||||||
|
const UpdateController = require('./controllers/update-controller')
|
||||||
|
return new UpdateController(state)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins.init({dispatch, state})
|
||||||
|
|
||||||
// Add first page to location history
|
// Add first page to location history
|
||||||
state.location.go({
|
state.location.go({
|
||||||
url: 'home',
|
url: 'home',
|
||||||
@@ -90,23 +131,18 @@ function onState (err, _state) {
|
|||||||
// Restart everything we were torrenting last time the app ran
|
// Restart everything we were torrenting last time the app ran
|
||||||
resumeTorrents()
|
resumeTorrents()
|
||||||
|
|
||||||
|
// Initialize ReactDOM
|
||||||
|
app = ReactDOM.render(<App state={state} />, document.querySelector('#body'))
|
||||||
|
|
||||||
// Calling update() updates the UI given the current state
|
// Calling update() updates the UI given the current state
|
||||||
// Do this at least once a second to give every file in every torrentSummary
|
// Do this at least once a second to give every file in every torrentSummary
|
||||||
// a progress bar and to keep the cursor in sync when playing a video
|
// a progress bar and to keep the cursor in sync when playing a video
|
||||||
setInterval(update, 1000)
|
setInterval(update, 1000)
|
||||||
app = ReactDOM.render(<App state={state} />, document.querySelector('#body'))
|
|
||||||
|
|
||||||
// Lazy-load other stuff, like the AppleTV module, later to keep startup fast
|
|
||||||
window.setTimeout(delayedInit, config.DELAYED_INIT)
|
|
||||||
|
|
||||||
// Listen for messages from the main process
|
// Listen for messages from the main process
|
||||||
setupIpc()
|
setupIpc()
|
||||||
|
|
||||||
// Warn if the download dir is gone, eg b/c an external drive is unplugged
|
// Drag and drop files/text to start torrenting or seeding
|
||||||
checkDownloadPath()
|
|
||||||
|
|
||||||
// OS integrations:
|
|
||||||
// ...drag and drop files/text to start torrenting or seeding
|
|
||||||
dragDrop('body', {
|
dragDrop('body', {
|
||||||
onDrop: onOpen,
|
onDrop: onOpen,
|
||||||
onDropText: onOpen
|
onDropText: onOpen
|
||||||
@@ -115,24 +151,49 @@ function onState (err, _state) {
|
|||||||
// ...same thing if you paste a torrent
|
// ...same thing if you paste a torrent
|
||||||
document.addEventListener('paste', onPaste)
|
document.addEventListener('paste', onPaste)
|
||||||
|
|
||||||
|
const debouncedFullscreenToggle = debounce(function () {
|
||||||
|
dispatch('toggleFullScreen')
|
||||||
|
}, 1000, true)
|
||||||
|
|
||||||
|
document.addEventListener('wheel', function (event) {
|
||||||
|
// ctrlKey detects pinch to zoom, http://crbug.com/289887
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
event.preventDefault()
|
||||||
|
debouncedFullscreenToggle()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// ...focus and blur. Needed to show correct dock icon text ('badge') in OSX
|
// ...focus and blur. Needed to show correct dock icon text ('badge') in OSX
|
||||||
window.addEventListener('focus', onFocus)
|
window.addEventListener('focus', onFocus)
|
||||||
window.addEventListener('blur', onBlur)
|
window.addEventListener('blur', onBlur)
|
||||||
|
|
||||||
// ...window visibility state.
|
|
||||||
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
|
||||||
|
|
||||||
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
|
||||||
if (electron.remote.getCurrentWindow().isVisible()) {
|
if (electron.remote.getCurrentWindow().isVisible()) {
|
||||||
sound.play('STARTUP')
|
sound.play('STARTUP')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To keep app startup fast, some code is delayed.
|
||||||
|
window.setTimeout(delayedInit, config.DELAYED_INIT)
|
||||||
|
|
||||||
|
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
||||||
console.timeEnd('init')
|
console.timeEnd('init')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs a few seconds after the app loads, to avoid slowing down startup time
|
// Runs a few seconds after the app loads, to avoid slowing down startup time
|
||||||
function delayedInit () {
|
function delayedInit () {
|
||||||
|
telemetry.send(state)
|
||||||
|
|
||||||
|
// Send telemetry data every 12 hours, for users who keep the app running
|
||||||
|
// for extended periods of time
|
||||||
|
setInterval(() => telemetry.send(state), 12 * 3600 * 1000)
|
||||||
|
|
||||||
|
// Warn if the download dir is gone, eg b/c an external drive is unplugged
|
||||||
|
checkDownloadPath()
|
||||||
|
|
||||||
|
// ...window visibility state.
|
||||||
|
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
||||||
|
onVisibilityChange()
|
||||||
|
|
||||||
lazyLoadCast()
|
lazyLoadCast()
|
||||||
sound.preload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lazily loads Chromecast and Airplay support
|
// Lazily loads Chromecast and Airplay support
|
||||||
@@ -150,7 +211,7 @@ function lazyLoadCast () {
|
|||||||
// 3. dispatch - the event handler calls dispatch(), main.js sends it to a controller
|
// 3. dispatch - the event handler calls dispatch(), main.js sends it to a controller
|
||||||
// 4. controller - the controller handles the event, changing the state object
|
// 4. controller - the controller handles the event, changing the state object
|
||||||
function update () {
|
function update () {
|
||||||
controllers.playback.showOrHidePlayerControls()
|
controllers.playback().showOrHidePlayerControls()
|
||||||
app.setState(state)
|
app.setState(state)
|
||||||
updateElectron()
|
updateElectron()
|
||||||
}
|
}
|
||||||
@@ -178,54 +239,58 @@ const dispatchHandlers = {
|
|||||||
'openFiles': () => ipcRenderer.send('openFiles'), /* shows the open file dialog */
|
'openFiles': () => ipcRenderer.send('openFiles'), /* shows the open file dialog */
|
||||||
'openTorrentAddress': () => { state.modal = { id: 'open-torrent-address-modal' } },
|
'openTorrentAddress': () => { state.modal = { id: 'open-torrent-address-modal' } },
|
||||||
|
|
||||||
'addTorrent': (torrentId) => controllers.torrentList.addTorrent(torrentId),
|
'addTorrent': (torrentId) => controllers.torrentList().addTorrent(torrentId),
|
||||||
'showCreateTorrent': (paths) => controllers.torrentList.showCreateTorrent(paths),
|
'showCreateTorrent': (paths) => controllers.torrentList().showCreateTorrent(paths),
|
||||||
'createTorrent': (options) => controllers.torrentList.createTorrent(options),
|
'createTorrent': (options) => controllers.torrentList().createTorrent(options),
|
||||||
'toggleTorrent': (infoHash) => controllers.torrentList.toggleTorrent(infoHash),
|
'toggleTorrent': (infoHash) => controllers.torrentList().toggleTorrent(infoHash),
|
||||||
|
'pauseAllTorrents': () => controllers.torrentList().pauseAllTorrents(),
|
||||||
|
'resumeAllTorrents': () => controllers.torrentList().resumeAllTorrents(),
|
||||||
'toggleTorrentFile': (infoHash, index) =>
|
'toggleTorrentFile': (infoHash, index) =>
|
||||||
controllers.torrentList.toggleTorrentFile(infoHash, index),
|
controllers.torrentList().toggleTorrentFile(infoHash, index),
|
||||||
'confirmDeleteTorrent': (infoHash, deleteData) =>
|
'confirmDeleteTorrent': (infoHash, deleteData) =>
|
||||||
controllers.torrentList.confirmDeleteTorrent(infoHash, deleteData),
|
controllers.torrentList().confirmDeleteTorrent(infoHash, deleteData),
|
||||||
'deleteTorrent': (infoHash, deleteData) =>
|
'deleteTorrent': (infoHash, deleteData) =>
|
||||||
controllers.torrentList.deleteTorrent(infoHash, deleteData),
|
controllers.torrentList().deleteTorrent(infoHash, deleteData),
|
||||||
'toggleSelectTorrent': (infoHash) =>
|
'toggleSelectTorrent': (infoHash) =>
|
||||||
controllers.torrentList.toggleSelectTorrent(infoHash),
|
controllers.torrentList().toggleSelectTorrent(infoHash),
|
||||||
'openTorrentContextMenu': (infoHash) =>
|
'openTorrentContextMenu': (infoHash) =>
|
||||||
controllers.torrentList.openTorrentContextMenu(infoHash),
|
controllers.torrentList().openTorrentContextMenu(infoHash),
|
||||||
'startTorrentingSummary': (torrentKey) =>
|
'startTorrentingSummary': (torrentKey) =>
|
||||||
controllers.torrentList.startTorrentingSummary(torrentKey),
|
controllers.torrentList().startTorrentingSummary(torrentKey),
|
||||||
'saveTorrentFileAs': (torrentKey) =>
|
'saveTorrentFileAs': (torrentKey) =>
|
||||||
controllers.torrentList.saveTorrentFileAs(torrentKey),
|
controllers.torrentList().saveTorrentFileAs(torrentKey),
|
||||||
|
'prioritizeTorrent': (infoHash) => controllers.torrentList().prioritizeTorrent(infoHash),
|
||||||
|
'resumePausedTorrents': () => controllers.torrentList().resumePausedTorrents(),
|
||||||
|
|
||||||
// Playback
|
// Playback
|
||||||
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
|
'playFile': (infoHash, index) => controllers.playback().playFile(infoHash, index),
|
||||||
'playPause': () => controllers.playback.playPause(),
|
'playPause': () => controllers.playback().playPause(),
|
||||||
'nextTrack': () => controllers.playback.nextTrack(),
|
'nextTrack': () => controllers.playback().nextTrack(),
|
||||||
'previousTrack': () => controllers.playback.previousTrack(),
|
'previousTrack': () => controllers.playback().previousTrack(),
|
||||||
'skip': (time) => controllers.playback.skip(time),
|
'skip': (time) => controllers.playback().skip(time),
|
||||||
'skipTo': (time) => controllers.playback.skipTo(time),
|
'skipTo': (time) => controllers.playback().skipTo(time),
|
||||||
'changePlaybackRate': (dir) => controllers.playback.changePlaybackRate(dir),
|
'changePlaybackRate': (dir) => controllers.playback().changePlaybackRate(dir),
|
||||||
'changeVolume': (delta) => controllers.playback.changeVolume(delta),
|
'changeVolume': (delta) => controllers.playback().changeVolume(delta),
|
||||||
'setVolume': (vol) => controllers.playback.setVolume(vol),
|
'setVolume': (vol) => controllers.playback().setVolume(vol),
|
||||||
'openItem': (infoHash, index) => controllers.playback.openItem(infoHash, index),
|
'openItem': (infoHash, index) => controllers.playback().openItem(infoHash, index),
|
||||||
|
|
||||||
// Subtitles
|
// Subtitles
|
||||||
'openSubtitles': () => controllers.subtitles.openSubtitles(),
|
'openSubtitles': () => controllers.subtitles().openSubtitles(),
|
||||||
'selectSubtitle': (index) => controllers.subtitles.selectSubtitle(index),
|
'selectSubtitle': (index) => controllers.subtitles().selectSubtitle(index),
|
||||||
'toggleSubtitlesMenu': () => controllers.subtitles.toggleSubtitlesMenu(),
|
'toggleSubtitlesMenu': () => controllers.subtitles().toggleSubtitlesMenu(),
|
||||||
'checkForSubtitles': () => controllers.subtitles.checkForSubtitles(),
|
'checkForSubtitles': () => controllers.subtitles().checkForSubtitles(),
|
||||||
'addSubtitles': (files, autoSelect) => controllers.subtitles.addSubtitles(files, autoSelect),
|
'addSubtitles': (files, autoSelect) => controllers.subtitles().addSubtitles(files, autoSelect),
|
||||||
|
|
||||||
// Local media: <video>, <audio>, external players
|
// Local media: <video>, <audio>, external players
|
||||||
'mediaStalled': () => controllers.media.mediaStalled(),
|
'mediaStalled': () => controllers.media().mediaStalled(),
|
||||||
'mediaError': (err) => controllers.media.mediaError(err),
|
'mediaError': (err) => controllers.media().mediaError(err),
|
||||||
'mediaSuccess': () => controllers.media.mediaSuccess(),
|
'mediaSuccess': () => controllers.media().mediaSuccess(),
|
||||||
'mediaTimeUpdate': () => controllers.media.mediaTimeUpdate(),
|
'mediaTimeUpdate': () => controllers.media().mediaTimeUpdate(),
|
||||||
'mediaMouseMoved': () => controllers.media.mediaMouseMoved(),
|
'mediaMouseMoved': () => controllers.media().mediaMouseMoved(),
|
||||||
'mediaControlsMouseEnter': () => controllers.media.controlsMouseEnter(),
|
'mediaControlsMouseEnter': () => controllers.media().controlsMouseEnter(),
|
||||||
'mediaControlsMouseLeave': () => controllers.media.controlsMouseLeave(),
|
'mediaControlsMouseLeave': () => controllers.media().controlsMouseLeave(),
|
||||||
'openExternalPlayer': () => controllers.media.openExternalPlayer(),
|
'openExternalPlayer': () => controllers.media().openExternalPlayer(),
|
||||||
'externalPlayerNotFound': () => controllers.media.externalPlayerNotFound(),
|
'externalPlayerNotFound': () => controllers.media().externalPlayerNotFound(),
|
||||||
|
|
||||||
// Remote casting: Chromecast, Airplay, etc
|
// Remote casting: Chromecast, Airplay, etc
|
||||||
'toggleCastMenu': (deviceType) => lazyLoadCast().toggleMenu(deviceType),
|
'toggleCastMenu': (deviceType) => lazyLoadCast().toggleMenu(deviceType),
|
||||||
@@ -233,13 +298,13 @@ const dispatchHandlers = {
|
|||||||
'stopCasting': () => lazyLoadCast().stop(),
|
'stopCasting': () => lazyLoadCast().stop(),
|
||||||
|
|
||||||
// Preferences screen
|
// Preferences screen
|
||||||
'preferences': () => controllers.prefs.show(),
|
'preferences': () => controllers.prefs().show(),
|
||||||
'updatePreferences': (key, value) => controllers.prefs.update(key, value),
|
'updatePreferences': (key, value) => controllers.prefs().update(key, value),
|
||||||
'checkDownloadPath': checkDownloadPath,
|
'checkDownloadPath': checkDownloadPath,
|
||||||
|
|
||||||
// Update (check for new versions on Linux, where there's no auto updater)
|
// Update (check for new versions on Linux, where there's no auto updater)
|
||||||
'updateAvailable': (version) => controllers.update.updateAvailable(version),
|
'updateAvailable': (version) => controllers.update().updateAvailable(version),
|
||||||
'skipVersion': (version) => controllers.update.skipVersion(version),
|
'skipVersion': (version) => controllers.update().skipVersion(version),
|
||||||
|
|
||||||
// Navigation between screens (back, forward, ESC, etc)
|
// Navigation between screens (back, forward, ESC, etc)
|
||||||
'exitModal': () => { state.modal = null },
|
'exitModal': () => { state.modal = null },
|
||||||
@@ -272,12 +337,13 @@ function dispatch (action, ...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handler = dispatchHandlers[action]
|
const handler = dispatchHandlers[action]
|
||||||
|
plugins.on(action, args)
|
||||||
if (handler) handler(...args)
|
if (handler) handler(...args)
|
||||||
else console.error('Missing dispatch handler: ' + action)
|
else console.error('Missing dispatch handler: ' + action)
|
||||||
|
|
||||||
// Update the virtual DOM, unless it's just a mouse move event
|
// Update the virtual DOM, unless it's just a mouse move event
|
||||||
if (action !== 'mediaMouseMoved' ||
|
if (action !== 'mediaMouseMoved' ||
|
||||||
controllers.playback.showOrHidePlayerControls()) {
|
controllers.playback().showOrHidePlayerControls()) {
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,10 +358,11 @@ function setupIpc () {
|
|||||||
ipcRenderer.on('fullscreenChanged', onFullscreenChanged)
|
ipcRenderer.on('fullscreenChanged', onFullscreenChanged)
|
||||||
ipcRenderer.on('windowBoundsChanged', onWindowBoundsChanged)
|
ipcRenderer.on('windowBoundsChanged', onWindowBoundsChanged)
|
||||||
|
|
||||||
const tc = controllers.torrent
|
const tc = controllers.torrent()
|
||||||
ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args))
|
ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args))
|
||||||
ipcRenderer.on('wt-metadata', (e, ...args) => tc.torrentMetadata(...args))
|
ipcRenderer.on('wt-metadata', (e, ...args) => tc.torrentMetadata(...args))
|
||||||
ipcRenderer.on('wt-done', (e, ...args) => tc.torrentDone(...args))
|
ipcRenderer.on('wt-done', (e, ...args) => tc.torrentDone(...args))
|
||||||
|
ipcRenderer.on('wt-done', () => controllers.torrentList().resumePausedTorrents())
|
||||||
ipcRenderer.on('wt-warning', (e, ...args) => tc.torrentWarning(...args))
|
ipcRenderer.on('wt-warning', (e, ...args) => tc.torrentWarning(...args))
|
||||||
ipcRenderer.on('wt-error', (e, ...args) => tc.torrentError(...args))
|
ipcRenderer.on('wt-error', (e, ...args) => tc.torrentError(...args))
|
||||||
|
|
||||||
@@ -345,7 +412,7 @@ function resumeTorrents () {
|
|||||||
return torrentSummary
|
return torrentSummary
|
||||||
})
|
})
|
||||||
.filter((s) => s.status !== 'paused')
|
.filter((s) => s.status !== 'paused')
|
||||||
.forEach((s) => controllers.torrentList.startTorrentingSummary(s.torrentKey))
|
.forEach((s) => controllers.torrentList().startTorrentingSummary(s.torrentKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set window dimensions to match video dimensions or fill the screen
|
// Set window dimensions to match video dimensions or fill the screen
|
||||||
@@ -394,20 +461,20 @@ function onOpen (files) {
|
|||||||
|
|
||||||
const url = state.location.url()
|
const url = state.location.url()
|
||||||
const allTorrents = files.every(TorrentPlayer.isTorrent)
|
const allTorrents = files.every(TorrentPlayer.isTorrent)
|
||||||
const allSubtitles = files.every(controllers.subtitles.isSubtitle)
|
const allSubtitles = files.every(controllers.subtitles().isSubtitle)
|
||||||
|
|
||||||
if (allTorrents) {
|
if (allTorrents) {
|
||||||
// Drop torrents onto the app: go to home screen, add torrents, no matter what
|
// Drop torrents onto the app: go to home screen, add torrents, no matter what
|
||||||
dispatch('backToList')
|
dispatch('backToList')
|
||||||
// All .torrent files? Add them.
|
// All .torrent files? Add them.
|
||||||
files.forEach((file) => controllers.torrentList.addTorrent(file))
|
files.forEach((file) => controllers.torrentList().addTorrent(file))
|
||||||
} else if (url === 'player' && allSubtitles) {
|
} else if (url === 'player' && allSubtitles) {
|
||||||
// Drop subtitles onto a playing video: add subtitles
|
// Drop subtitles onto a playing video: add subtitles
|
||||||
controllers.subtitles.addSubtitles(files, true)
|
controllers.subtitles().addSubtitles(files, true)
|
||||||
} else if (url === 'home') {
|
} else if (url === 'home') {
|
||||||
// Drop files onto home screen: show Create Torrent
|
// Drop files onto home screen: show Create Torrent
|
||||||
state.modal = null
|
state.modal = null
|
||||||
controllers.torrentList.showCreateTorrent(files)
|
controllers.torrentList().showCreateTorrent(files)
|
||||||
} else {
|
} else {
|
||||||
// Drop files onto any other screen: show error
|
// Drop files onto any other screen: show error
|
||||||
return onError('Please go back to the torrent list before creating a new torrent.')
|
return onError('Please go back to the torrent list before creating a new torrent.')
|
||||||
@@ -427,15 +494,11 @@ function onError (err) {
|
|||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPaste (e) {
|
const editableHtmlTags = new Set(['input', 'textarea'])
|
||||||
if (e.target.tagName.toLowerCase() === 'input') return
|
|
||||||
|
|
||||||
const torrentIds = electron.clipboard.readText().split('\n')
|
function onPaste (e) {
|
||||||
torrentIds.forEach(function (torrentId) {
|
if (editableHtmlTags.has(e.target.tagName.toLowerCase())) return
|
||||||
torrentId = torrentId.trim()
|
controllers.torrentList().addTorrent(electron.clipboard.readText())
|
||||||
if (torrentId.length === 0) return
|
|
||||||
controllers.torrentList.addTorrent(torrentId)
|
|
||||||
})
|
|
||||||
|
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,38 @@
|
|||||||
const colors = require('material-ui/styles/colors')
|
const colors = require('material-ui/styles/colors')
|
||||||
|
const createGetter = require('fn-getter')
|
||||||
const React = require('react')
|
const React = require('react')
|
||||||
|
|
||||||
const darkBaseTheme = require('material-ui/styles/baseThemes/darkBaseTheme').default
|
const darkBaseTheme = require('material-ui/styles/baseThemes/darkBaseTheme').default
|
||||||
const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default
|
|
||||||
const getMuiTheme = require('material-ui/styles/getMuiTheme').default
|
const getMuiTheme = require('material-ui/styles/getMuiTheme').default
|
||||||
const MuiThemeProvider = require('material-ui/styles/MuiThemeProvider').default
|
const MuiThemeProvider = require('material-ui/styles/MuiThemeProvider').default
|
||||||
|
|
||||||
const Header = require('../components/header')
|
const Header = require('../components/header')
|
||||||
|
|
||||||
|
// Perf optimization: Needed immediately, so do not lazy load it below
|
||||||
|
const TorrentListPage = require('./torrent-list-page')
|
||||||
|
|
||||||
const Views = {
|
const Views = {
|
||||||
'home': require('./torrent-list-page'),
|
'home': createGetter(() => TorrentListPage),
|
||||||
'player': require('./player-page'),
|
'player': createGetter(() => require('./player-page')),
|
||||||
'create-torrent': require('./create-torrent-page'),
|
'create-torrent': createGetter(() => require('./create-torrent-page')),
|
||||||
'preferences': require('./preferences-page')
|
'preferences': createGetter(() => require('./preferences-page'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const Modals = {
|
const Modals = {
|
||||||
'open-torrent-address-modal': require('../components/open-torrent-address-modal'),
|
'open-torrent-address-modal': createGetter(
|
||||||
'remove-torrent-modal': require('../components/remove-torrent-modal'),
|
() => require('../components/open-torrent-address-modal')
|
||||||
'update-available-modal': require('../components/update-available-modal'),
|
),
|
||||||
'unsupported-media-modal': require('../components/unsupported-media-modal')
|
'remove-torrent-modal': createGetter(() => require('../components/remove-torrent-modal')),
|
||||||
|
'update-available-modal': createGetter(() => require('../components/update-available-modal')),
|
||||||
|
'unsupported-media-modal': createGetter(() => require('../components/unsupported-media-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'
|
||||||
lightBaseTheme.fontFamily = fontFamily
|
|
||||||
darkBaseTheme.fontFamily = fontFamily
|
darkBaseTheme.fontFamily = fontFamily
|
||||||
|
darkBaseTheme.userAgent = false
|
||||||
darkBaseTheme.palette.primary1Color = colors.grey50
|
darkBaseTheme.palette.primary1Color = colors.grey50
|
||||||
darkBaseTheme.palette.primary2Color = colors.grey50
|
darkBaseTheme.palette.primary2Color = colors.grey50
|
||||||
darkBaseTheme.palette.primary3Color = colors.grey600
|
darkBaseTheme.palette.primary3Color = colors.grey600
|
||||||
@@ -34,6 +40,9 @@ darkBaseTheme.palette.accent1Color = colors.redA200
|
|||||||
darkBaseTheme.palette.accent2Color = colors.redA400
|
darkBaseTheme.palette.accent2Color = colors.redA400
|
||||||
darkBaseTheme.palette.accent3Color = colors.redA100
|
darkBaseTheme.palette.accent3Color = colors.redA100
|
||||||
|
|
||||||
|
let darkMuiTheme
|
||||||
|
let lightMuiTheme
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
@@ -53,8 +62,12 @@ 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')
|
||||||
|
|
||||||
const vdom = (
|
if (!darkMuiTheme) {
|
||||||
<MuiThemeProvider muiTheme={getMuiTheme(darkBaseTheme)}>
|
darkMuiTheme = getMuiTheme(darkBaseTheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MuiThemeProvider muiTheme={darkMuiTheme}>
|
||||||
<div className={'app ' + cls.join(' ')}>
|
<div className={'app ' + cls.join(' ')}>
|
||||||
<Header state={state} />
|
<Header state={state} />
|
||||||
{this.getErrorPopover()}
|
{this.getErrorPopover()}
|
||||||
@@ -63,8 +76,6 @@ class App extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
)
|
)
|
||||||
|
|
||||||
return vdom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getErrorPopover () {
|
getErrorPopover () {
|
||||||
@@ -88,9 +99,17 @@ class App extends React.Component {
|
|||||||
getModal () {
|
getModal () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
if (!state.modal) return
|
if (!state.modal) return
|
||||||
const ModalContents = Modals[state.modal.id]
|
|
||||||
|
if (!lightMuiTheme) {
|
||||||
|
const lightBaseTheme = require('material-ui/styles/baseThemes/lightBaseTheme').default
|
||||||
|
lightBaseTheme.fontFamily = fontFamily
|
||||||
|
lightBaseTheme.userAgent = false
|
||||||
|
lightMuiTheme = getMuiTheme(lightBaseTheme)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ModalContents = Modals[state.modal.id]()
|
||||||
return (
|
return (
|
||||||
<MuiThemeProvider muiTheme={getMuiTheme(lightBaseTheme)}>
|
<MuiThemeProvider muiTheme={lightMuiTheme}>
|
||||||
<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'>
|
||||||
@@ -103,7 +122,7 @@ class App extends React.Component {
|
|||||||
|
|
||||||
getView () {
|
getView () {
|
||||||
const state = this.props.state
|
const state = this.props.state
|
||||||
const View = Views[state.location.url()]
|
const View = Views[state.location.url()]()
|
||||||
return (<View state={state} />)
|
return (<View state={state} />)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class CreateTorrentPage extends React.Component {
|
|||||||
}}
|
}}
|
||||||
onClick={dispatcher('cancel')} />
|
onClick={dispatcher('cancel')} />
|
||||||
<RaisedButton
|
<RaisedButton
|
||||||
className='control create-torrent'
|
className='control create-torrent-button'
|
||||||
label='Create Torrent'
|
label='Create Torrent'
|
||||||
primary
|
primary
|
||||||
onClick={this.handleSubmit} />
|
onClick={this.handleSubmit} />
|
||||||
|
|||||||
@@ -275,9 +275,9 @@ function renderLoadingSpinner (state) {
|
|||||||
<div key='loading' className='media-stalled'>
|
<div key='loading' className='media-stalled'>
|
||||||
<div key='loading-spinner' className='loading-spinner'> </div>
|
<div key='loading-spinner' className='loading-spinner'> </div>
|
||||||
<div key='loading-progress' className='loading-status ellipsis'>
|
<div key='loading-progress' className='loading-status ellipsis'>
|
||||||
<span className='progress'>{fileProgress}%</span> downloaded,
|
<span className='progress'>{fileProgress}%</span> downloaded
|
||||||
<span>↓ {prettyBytes(prog.downloadSpeed || 0)}/s</span>
|
<span> ↓ {prettyBytes(prog.downloadSpeed || 0)}/s</span>
|
||||||
<span>↑ {prettyBytes(prog.uploadSpeed || 0)}/s</span>
|
<span> ↑ {prettyBytes(prog.uploadSpeed || 0)}/s</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -599,12 +599,15 @@ function renderLoadingBar (state) {
|
|||||||
|
|
||||||
const torrentSummary = state.getPlayingTorrentSummary()
|
const torrentSummary = state.getPlayingTorrentSummary()
|
||||||
if (!torrentSummary.progress) {
|
if (!torrentSummary.progress) {
|
||||||
return []
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all contiguous parts of the torrent which are loaded
|
// Find all contiguous parts of the torrent which are loaded
|
||||||
const prog = torrentSummary.progress
|
const prog = torrentSummary.progress
|
||||||
const fileProg = prog.files[state.playing.fileIndex]
|
const fileProg = prog.files[state.playing.fileIndex]
|
||||||
|
|
||||||
|
if (!fileProg) return null
|
||||||
|
|
||||||
const parts = []
|
const parts = []
|
||||||
let lastPiecePresent = false
|
let lastPiecePresent = false
|
||||||
for (let i = fileProg.startPiece; i <= fileProg.endPiece; i++) {
|
for (let i = fileProg.startPiece; i <= fileProg.endPiece; i++) {
|
||||||
@@ -626,6 +629,7 @@ function renderLoadingBar (state) {
|
|||||||
|
|
||||||
return (<div key={i} className='loading-bar-part' style={style} />)
|
return (<div key={i} className='loading-bar-part' style={style} />)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (<div key='loading-bar' className='loading-bar'>{loadingBarElems}</div>)
|
return (<div key='loading-bar' className='loading-bar'>{loadingBarElems}</div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,24 @@ class PreferencesPage extends React.Component {
|
|||||||
dispatch('updatePreferences', 'openExternalPlayer', !isChecked)
|
dispatch('updatePreferences', 'openExternalPlayer', !isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highestPlaybackPriorityCheckbox () {
|
||||||
|
return (
|
||||||
|
<Preference>
|
||||||
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.unsaved.prefs.highestPlaybackPriority}
|
||||||
|
label={'Highest Playback Priority'}
|
||||||
|
onCheck={this.handleHighestPlaybackPriorityChange}
|
||||||
|
/>
|
||||||
|
<p>Pauses all active torrents to allow playback to use all of the available bandwidth.</p>
|
||||||
|
</Preference>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
handleHighestPlaybackPriorityChange (e, isChecked) {
|
||||||
|
dispatch('updatePreferences', 'highestPlaybackPriority', isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
externalPlayerPathSelector () {
|
externalPlayerPathSelector () {
|
||||||
const playerPath = this.props.state.unsaved.prefs.externalPlayerPath
|
const playerPath = this.props.state.unsaved.prefs.externalPlayerPath
|
||||||
const playerName = this.props.state.getExternalPlayerName()
|
const playerName = this.props.state.getExternalPlayerName()
|
||||||
@@ -151,6 +169,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<PreferencesSection title='Playback'>
|
<PreferencesSection title='Playback'>
|
||||||
{this.openExternalPlayerCheckbox()}
|
{this.openExternalPlayerCheckbox()}
|
||||||
{this.externalPlayerPathSelector()}
|
{this.externalPlayerPathSelector()}
|
||||||
|
{this.highestPlaybackPriorityCheckbox()}
|
||||||
</PreferencesSection>
|
</PreferencesSection>
|
||||||
<PreferencesSection title='Default torrent app'>
|
<PreferencesSection title='Default torrent app'>
|
||||||
{this.setDefaultAppButton()}
|
{this.setDefaultAppButton()}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
const React = require('react')
|
const React = require('react')
|
||||||
const prettyBytes = require('prettier-bytes')
|
const prettyBytes = require('prettier-bytes')
|
||||||
|
|
||||||
const Checkbox = require('material-ui/Checkbox').default
|
const Checkbox = require('material-ui/Checkbox').default
|
||||||
const LinearProgress = require('material-ui/LinearProgress').default
|
const LinearProgress = require('material-ui/LinearProgress').default
|
||||||
|
|
||||||
const TorrentSummary = require('../lib/torrent-summary')
|
const TorrentSummary = require('../lib/torrent-summary')
|
||||||
const TorrentPlayer = require('../lib/torrent-player')
|
const TorrentPlayer = require('../lib/torrent-player')
|
||||||
const {dispatcher} = require('../lib/dispatcher')
|
const {dispatcher} = require('../lib/dispatcher')
|
||||||
const {InvalidTorrentError} = require('../lib/errors')
|
|
||||||
|
|
||||||
module.exports = class TorrentList extends React.Component {
|
module.exports = class TorrentList extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
@@ -59,7 +59,7 @@ module.exports = class TorrentList extends React.Component {
|
|||||||
const classes = ['torrent']
|
const classes = ['torrent']
|
||||||
if (isSelected) classes.push('selected')
|
if (isSelected) classes.push('selected')
|
||||||
if (!infoHash) classes.push('disabled')
|
if (!infoHash) classes.push('disabled')
|
||||||
if (!torrentSummary.torrentKey) throw new InvalidTorrentError('Missing torrentKey')
|
if (!torrentSummary.torrentKey) throw new Error('Missing torrentKey')
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id={torrentSummary.testID && ('torrent-' + torrentSummary.testID)}
|
id={torrentSummary.testID && ('torrent-' + torrentSummary.testID)}
|
||||||
@@ -119,9 +119,15 @@ module.exports = class TorrentList extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
key='download-button'
|
key='download-button'
|
||||||
className={'download ' + torrentSummary.status}
|
className={'control download ' + torrentSummary.status}
|
||||||
style={{display: 'inline-block', width: '32px'}}
|
style={{
|
||||||
iconStyle={{width: '20px', height: '20px'}}
|
display: 'inline-block',
|
||||||
|
width: 32
|
||||||
|
}}
|
||||||
|
iconStyle={{
|
||||||
|
width: 20,
|
||||||
|
height: 20
|
||||||
|
}}
|
||||||
checked={isActive}
|
checked={isActive}
|
||||||
onClick={stopPropagation}
|
onClick={stopPropagation}
|
||||||
onCheck={dispatcher('toggleTorrent', infoHash)} />
|
onCheck={dispatcher('toggleTorrent', infoHash)} />
|
||||||
@@ -133,11 +139,11 @@ module.exports = class TorrentList extends React.Component {
|
|||||||
const styles = {
|
const styles = {
|
||||||
wrapper: {
|
wrapper: {
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
marginRight: '8px'
|
marginRight: 8
|
||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
height: '8px',
|
height: 8,
|
||||||
width: '30px'
|
width: 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|||||||
287
src/renderer/plugins.js
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
const {resolve, basename} = require('path')
|
||||||
|
const notifier = require('node-notifier')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
|
||||||
|
module.exports = class Plugins {
|
||||||
|
constructor () {
|
||||||
|
// modules path
|
||||||
|
this.path = resolve(config.getConfigPath(), 'plugins')
|
||||||
|
log('Path: ', this.path)
|
||||||
|
this.availableExtensions = [
|
||||||
|
'onCheckForSubtitles'
|
||||||
|
]
|
||||||
|
|
||||||
|
this.forceUpdate = false
|
||||||
|
this.updating = false
|
||||||
|
this.watchers = []
|
||||||
|
this.state = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
init (params) {
|
||||||
|
this.state = params.state
|
||||||
|
|
||||||
|
// initialize state
|
||||||
|
this.state.saved = Object.assign(this.state.saved || {})
|
||||||
|
|
||||||
|
// caches
|
||||||
|
this.plugins = config.getPlugins()
|
||||||
|
this.paths = this.getPaths(this.plugins)
|
||||||
|
this.id = this.getId(this.plugins)
|
||||||
|
this.modules = this.requirePlugins()
|
||||||
|
|
||||||
|
// TODO: fire an event when plugins finish updating and listen to that.
|
||||||
|
// Listen to plugin changes on config.
|
||||||
|
// New plugins added, plugins removed or updated.
|
||||||
|
// The actual plugin update action will take place in the MAIN process.
|
||||||
|
config.subscribe(() => {
|
||||||
|
const plugins = config.getPlugins()
|
||||||
|
if (plugins !== this.plugins) {
|
||||||
|
const id = this.getId(plugins)
|
||||||
|
if (this.id !== id) {
|
||||||
|
log('UPDATING...')
|
||||||
|
this.id = id
|
||||||
|
this.plugins = plugins
|
||||||
|
this.paths = this.getPaths(this.plugins)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Plugins will be updated on the MAIN process after 5s.
|
||||||
|
if (this.needsUpdate()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.init(params)
|
||||||
|
}, 6000)
|
||||||
|
log('Plugins need update, init scheduled')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadPlugins()
|
||||||
|
this.initPlugins(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
initPlugins (params) {
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
if (plugin.init) {
|
||||||
|
plugin.init(params)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
on (action, params) {
|
||||||
|
log(`ON ${action}:`, params)
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
const actionName = this.capitalizeFirstLetter(action)
|
||||||
|
const methodName = `on${actionName}`
|
||||||
|
if (typeof plugin[methodName] === 'function') {
|
||||||
|
plugin[methodName](params)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
capitalizeFirstLetter (string) {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
didPluginsChange () {
|
||||||
|
return this.state.saved.installedPlugins !== this.id
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPlugins () {
|
||||||
|
return !this.isEmptyObject(this.plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
isFirstInstall () {
|
||||||
|
return (!this.state.saved.installedPlugins && this.hasPlugins())
|
||||||
|
}
|
||||||
|
|
||||||
|
needsUpdate () {
|
||||||
|
return (this.didPluginsChange() || this.isFirstInstall())
|
||||||
|
}
|
||||||
|
|
||||||
|
getId (plugins) {
|
||||||
|
const hash = crypto.createHash('sha256')
|
||||||
|
hash.update(JSON.stringify(plugins))
|
||||||
|
return hash.digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPlugins (err, localOnly = false) {
|
||||||
|
this.updating = false
|
||||||
|
|
||||||
|
// handle errors first
|
||||||
|
if (err) {
|
||||||
|
console.error(err.stack)
|
||||||
|
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
||||||
|
this.alert(
|
||||||
|
'Error updating plugins: We could not find the "npm" command. Make sure it\'s in $PATH'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.alert(`Error updating plugins: Check '${this.path}/npm-debug.log' for more information.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// update state with latest plugins
|
||||||
|
this.state.saved.plugins = this.plugins
|
||||||
|
|
||||||
|
// cache modules
|
||||||
|
this.modules = this.requirePlugins()
|
||||||
|
|
||||||
|
// clear require cache
|
||||||
|
this.clearCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
getPluginVersions () {
|
||||||
|
const paths_ = this.paths.plugins
|
||||||
|
return paths_.map(path => {
|
||||||
|
let version = null
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require
|
||||||
|
version = require(resolve(path, 'package.json')).version
|
||||||
|
} catch (err) { }
|
||||||
|
return [
|
||||||
|
basename(path),
|
||||||
|
version
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
clearCache () {
|
||||||
|
// clear require cache
|
||||||
|
for (const entry in require.cache) {
|
||||||
|
if (entry.indexOf(this.path) === 0) {
|
||||||
|
delete require.cache[entry]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmptyObject (obj) {
|
||||||
|
return (Object.keys(obj).length === 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
alert (message) {
|
||||||
|
notifier.notify({
|
||||||
|
title: 'WebTorrent Plugins',
|
||||||
|
// icon: config.icon, // TODO: save icon in webtorrent local folder and set config.icon
|
||||||
|
message: message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribe (fn) {
|
||||||
|
this.watchers.push(fn)
|
||||||
|
return () => {
|
||||||
|
this.watchers.splice(this.watchers.indexOf(fn), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isLocalPath (string) {
|
||||||
|
// matches unix and windows local paths
|
||||||
|
return string.match(/^(\/|[a-z]:\/)/i)
|
||||||
|
}
|
||||||
|
|
||||||
|
getPaths (plugins) {
|
||||||
|
const pluginNames = Object.keys(plugins)
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: pluginNames.map(name => {
|
||||||
|
let url = plugins[name]
|
||||||
|
|
||||||
|
// plugin is already on a local folder
|
||||||
|
// directly load it from its current location
|
||||||
|
if (this.isLocalPath(url)) return url
|
||||||
|
|
||||||
|
// plugin will be installed with npm install from a remote url
|
||||||
|
return resolve(this.path, 'node_modules', name.split('#')[0])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exposesSupportedApi (plugin) {
|
||||||
|
if (!plugin) return false
|
||||||
|
|
||||||
|
return this.availableExtensions.some((methodName) => {
|
||||||
|
return (typeof plugin[methodName] === 'function')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
requirePlugins () {
|
||||||
|
const {plugins} = this.paths
|
||||||
|
let installNeeded = false
|
||||||
|
|
||||||
|
const load = (path) => {
|
||||||
|
if (!path.match(/\/$/)) {
|
||||||
|
path += '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
const rendererPath = `${path}renderer.js`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const Plugin = require(rendererPath) // eslint-disable import/no-dynamic-require
|
||||||
|
const plugin = new Plugin()
|
||||||
|
|
||||||
|
const exposed = this.exposesSupportedApi(plugin)
|
||||||
|
if (!exposed) {
|
||||||
|
log('Plugin not exposing any available extensions.', rendererPath, Object.keys(plugin))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// populate the name for internal errors here
|
||||||
|
plugin._name = basename(rendererPath)
|
||||||
|
|
||||||
|
return plugin
|
||||||
|
} catch (err) {
|
||||||
|
log('Require plugins ERROR:', err)
|
||||||
|
this.alert(`Error loading plugin: ${rendererPath}`)
|
||||||
|
// plugin not installed
|
||||||
|
// node_modules removed? did a manual plugin uninstall?
|
||||||
|
// try installing and then loading if successfull
|
||||||
|
installNeeded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugin installation happens on the MAIN process.
|
||||||
|
// If plugins haven't finished installing, wait for them.
|
||||||
|
if (installNeeded) {
|
||||||
|
log('Plugins install needed, wait...')
|
||||||
|
setTimeout(() => {
|
||||||
|
this.requirePlugins()
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
return plugins.map(load).filter(v => Boolean(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// decorates the base object by calling plugin[key]
|
||||||
|
// for all the available plugins
|
||||||
|
decorateObject (base, key) {
|
||||||
|
let decorated = base
|
||||||
|
this.modules.forEach(plugin => {
|
||||||
|
if (plugin[key]) {
|
||||||
|
const res = plugin[key](decorated)
|
||||||
|
if (res && typeof res === 'object') {
|
||||||
|
decorated = res
|
||||||
|
} else {
|
||||||
|
this.alert(`Plugin error: "${plugin._name}": invalid return type for \`${key}\``)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return decorated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs passed arguments to console using a prefix.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function log () {
|
||||||
|
const prefix = '[ PLUGINS.Renderer ]-->'
|
||||||
|
const args = [prefix]
|
||||||
|
|
||||||
|
for (var i = 0; i < arguments.length; ++i) {
|
||||||
|
args.push(arguments[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log.apply(console, args)
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@ const crypto = require('crypto')
|
|||||||
const deepEqual = require('deep-equal')
|
const deepEqual = require('deep-equal')
|
||||||
const defaultAnnounceList = require('create-torrent').announceList
|
const defaultAnnounceList = require('create-torrent').announceList
|
||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs')
|
||||||
|
const mkdirp = require('mkdirp')
|
||||||
const musicmetadata = require('musicmetadata')
|
const musicmetadata = require('musicmetadata')
|
||||||
const networkAddress = require('network-address')
|
const networkAddress = require('network-address')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
@@ -124,11 +125,10 @@ function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections)
|
|||||||
|
|
||||||
// Only download the files the user wants, not necessarily all files
|
// Only download the files the user wants, not necessarily all files
|
||||||
torrent.once('ready', () => selectFiles(torrent, selections))
|
torrent.once('ready', () => selectFiles(torrent, selections))
|
||||||
|
|
||||||
return torrent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopTorrenting (infoHash) {
|
function stopTorrenting (infoHash) {
|
||||||
|
console.log('--- STOP TORRENTING: ', infoHash)
|
||||||
const torrent = client.get(infoHash)
|
const torrent = client.get(infoHash)
|
||||||
if (torrent) torrent.destroy()
|
if (torrent) torrent.destroy()
|
||||||
}
|
}
|
||||||
@@ -203,19 +203,22 @@ function getTorrentFileInfo (file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every time we resolve a magnet URI, save the torrent file so that we never
|
// Every time we resolve a magnet URI, save the torrent file so that we can use
|
||||||
// have to download it again. Never ask the DHT the same question twice.
|
// it on next startup. Starting with the full torrent metadata will be faster
|
||||||
|
// than re-fetching it from peers using ut_metadata.
|
||||||
function saveTorrentFile (torrentKey) {
|
function saveTorrentFile (torrentKey) {
|
||||||
const torrent = getTorrent(torrentKey)
|
const torrent = getTorrent(torrentKey)
|
||||||
checkIfTorrentFileExists(torrent.infoHash, function (torrentPath, exists) {
|
const torrentPath = path.join(config.TORRENT_PATH, torrent.infoHash + '.torrent')
|
||||||
|
|
||||||
|
fs.access(torrentPath, fs.constants.R_OK, function (err) {
|
||||||
const fileName = torrent.infoHash + '.torrent'
|
const fileName = torrent.infoHash + '.torrent'
|
||||||
if (exists) {
|
if (!err) {
|
||||||
// We've already saved the file
|
// We've already saved the file
|
||||||
return ipc.send('wt-file-saved', torrentKey, fileName)
|
return ipc.send('wt-file-saved', torrentKey, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, save the .torrent file, under the app config folder
|
// Otherwise, save the .torrent file, under the app config folder
|
||||||
fs.mkdir(config.TORRENT_PATH, function (_) {
|
mkdirp(config.TORRENT_PATH, function (_) {
|
||||||
fs.writeFile(torrentPath, torrent.torrentFile, function (err) {
|
fs.writeFile(torrentPath, torrent.torrentFile, function (err) {
|
||||||
if (err) return console.log('error saving torrent file %s: %o', torrentPath, err)
|
if (err) return console.log('error saving torrent file %s: %o', torrentPath, err)
|
||||||
console.log('saved torrent file %s', torrentPath)
|
console.log('saved torrent file %s', torrentPath)
|
||||||
@@ -225,15 +228,6 @@ function saveTorrentFile (torrentKey) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks whether we've already resolved a given infohash to a torrent file
|
|
||||||
// Calls back with (torrentPath, exists). Logs, does not call back on error
|
|
||||||
function checkIfTorrentFileExists (infoHash, cb) {
|
|
||||||
const torrentPath = path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
|
||||||
fs.exists(torrentPath, function (exists) {
|
|
||||||
cb(torrentPath, exists)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save a JPG that represents a torrent.
|
// Save a JPG that represents a torrent.
|
||||||
// Auto chooses either a frame from a video file, an image, etc
|
// Auto chooses either a frame from a video file, an image, etc
|
||||||
function generateTorrentPoster (torrentKey) {
|
function generateTorrentPoster (torrentKey) {
|
||||||
@@ -241,7 +235,7 @@ function generateTorrentPoster (torrentKey) {
|
|||||||
torrentPoster(torrent, function (err, buf, extension) {
|
torrentPoster(torrent, function (err, buf, extension) {
|
||||||
if (err) return console.log('error generating poster: %o', err)
|
if (err) return console.log('error generating poster: %o', err)
|
||||||
// save it for next time
|
// save it for next time
|
||||||
fs.mkdirp(config.POSTER_PATH, function (err) {
|
mkdirp(config.POSTER_PATH, function (err) {
|
||||||
if (err) return console.log('error creating poster dir: %o', err)
|
if (err) return console.log('error creating poster dir: %o', err)
|
||||||
const posterFileName = torrent.infoHash + extension
|
const posterFileName = torrent.infoHash + extension
|
||||||
const posterFilePath = path.join(config.POSTER_PATH, posterFileName)
|
const posterFilePath = path.join(config.POSTER_PATH, posterFileName)
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1023 KiB After Width: | Height: | Size: 1011 KiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 143 KiB |
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 302 KiB After Width: | Height: | Size: 302 KiB |
|
Before Width: | Height: | Size: 710 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 478 KiB After Width: | Height: | Size: 479 KiB |
|
Before Width: | Height: | Size: 480 KiB After Width: | Height: | Size: 480 KiB |
|
Before Width: | Height: | Size: 480 KiB After Width: | Height: | Size: 480 KiB |
|
Before Width: | Height: | Size: 480 KiB After Width: | Height: | Size: 480 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 481 KiB After Width: | Height: | Size: 481 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 701 KiB After Width: | Height: | Size: 627 KiB |
|
Before Width: | Height: | Size: 932 KiB After Width: | Height: | Size: 844 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1014 KiB |
|
Before Width: | Height: | Size: 617 KiB After Width: | Height: | Size: 549 KiB |
|
Before Width: | Height: | Size: 617 KiB |
|
Before Width: | Height: | Size: 777 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1024 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1014 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1016 KiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 367 KiB After Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 344 KiB |
|
Before Width: | Height: | Size: 354 KiB After Width: | Height: | Size: 326 KiB |
|
Before Width: | Height: | Size: 422 KiB After Width: | Height: | Size: 390 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 479 KiB After Width: | Height: | Size: 430 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 230 KiB After Width: | Height: | Size: 214 KiB |
|
Before Width: | Height: | Size: 292 KiB After Width: | Height: | Size: 270 KiB |
|
Before Width: | Height: | Size: 381 KiB After Width: | Height: | Size: 352 KiB |
|
Before Width: | Height: | Size: 385 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 381 KiB After Width: | Height: | Size: 352 KiB |