Merge pull request #1818 from surajrathod/master

This commit is contained in:
Feross Aboukhadijeh
2020-11-23 03:11:34 +01:00
committed by GitHub
30 changed files with 151 additions and 178 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@ node_modules/
build/ build/
dist/ dist/
npm-debug.log* npm-debug.log*
.vscode/
# JetBrains IntelliJ IDEA project files # JetBrains IntelliJ IDEA project files
.idea .idea

View File

@@ -1,6 +1,6 @@
const appConfig = require('application-config')('WebTorrent') const appConfig = require('application-config')('WebTorrent')
const path = require('path') const path = require('path')
const electron = require('electron') const { app, remote } = require('electron')
const arch = require('arch') const arch = require('arch')
const APP_NAME = 'WebTorrent' const APP_NAME = 'WebTorrent'
@@ -126,10 +126,10 @@ function getPath (key) {
return '' return ''
} else if (process.type === 'renderer') { } else if (process.type === 'renderer') {
// Electron renderer process // Electron renderer process
return electron.remote.app.getPath(key) return remote.app.getPath(key)
} else { } else {
// Electron main process // Electron main process
return electron.app.getPath(key) return app.getPath(key)
} }
} }

View File

@@ -4,9 +4,9 @@ module.exports = {
function init () { function init () {
const config = require('./config') const config = require('./config')
const electron = require('electron') const { crashReporter } = require('electron')
electron.crashReporter.start({ crashReporter.start({
productName: config.APP_NAME, productName: config.APP_NAME,
submitURL: config.CRASH_REPORT_URL, submitURL: config.CRASH_REPORT_URL,
globalExtra: { _companyName: config.APP_NAME }, globalExtra: { _companyName: config.APP_NAME },

View File

@@ -2,7 +2,7 @@ module.exports = {
init init
} }
const electron = require('electron') const { dialog } = require('electron')
const config = require('../config') const config = require('../config')
const log = require('./log') const log = require('./log')
@@ -44,7 +44,7 @@ function onResponse (err, res, data) {
} }
} }
electron.dialog.showMessageBox({ dialog.showMessageBox({
type: 'info', type: 'info',
buttons: ['OK'], buttons: ['OK'],
title: data.title, title: data.title,

View File

@@ -6,7 +6,7 @@ module.exports = {
openFiles openFiles
} }
const electron = require('electron') const { dialog } = require('electron')
const log = require('./log') const log = require('./log')
const windows = require('./windows') const windows = require('./windows')
@@ -61,7 +61,7 @@ function openFiles () {
properties: ['openFile'] properties: ['openFile']
} }
setTitle(opts.title) setTitle(opts.title)
const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('onOpen', selectedPaths) windows.main.dispatch('onOpen', selectedPaths)
@@ -79,7 +79,7 @@ function openTorrentFile () {
properties: ['openFile', 'multiSelections'] properties: ['openFile', 'multiSelections']
} }
setTitle(opts.title) setTitle(opts.title)
const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
selectedPaths.forEach(function (selectedPath) { selectedPaths.forEach(function (selectedPath) {
@@ -114,7 +114,7 @@ function resetTitle () {
*/ */
function showOpenSeed (opts) { function showOpenSeed (opts) {
setTitle(opts.title) setTitle(opts.title)
const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('showCreateTorrent', selectedPaths) windows.main.dispatch('showCreateTorrent', selectedPaths)

View File

@@ -25,8 +25,7 @@ function uninstall () {
} }
function installDarwin () { function installDarwin () {
const electron = require('electron') const { app } = require('electron')
const app = electron.app
// On Mac, only protocols that are listed in `Info.plist` can be set as the // On Mac, only protocols that are listed in `Info.plist` can be set as the
// default handler at runtime. // default handler at runtime.

View File

@@ -1,7 +1,6 @@
console.time('init') console.time('init')
const electron = require('electron') const { app, ipcMain } = require('electron')
const app = electron.app
// Start crash reporter early, so it takes effect for child processes // Start crash reporter early, so it takes effect for child processes
const crashReporter = require('../crash-reporter') const crashReporter = require('../crash-reporter')
@@ -67,8 +66,6 @@ function init () {
app.setPath('temp', path.join(config.CONFIG_PATH, 'Temp')) app.setPath('temp', path.join(config.CONFIG_PATH, 'Temp'))
} }
const ipcMain = electron.ipcMain
let isReady = false // app ready, windows can be created let isReady = false // app ready, windows can be created
app.ipcReady = false // main window has finished loading and IPC is ready app.ipcReady = false // main window has finished loading and IPC is ready
app.isQuitting = false app.isQuitting = false

View File

@@ -3,9 +3,7 @@ module.exports = {
setModule setModule
} }
const electron = require('electron') const { app, ipcMain } = require('electron')
const app = electron.app
const log = require('./log') const log = require('./log')
const menu = require('./menu') const menu = require('./menu')
@@ -23,14 +21,12 @@ function setModule (name, module) {
} }
function init () { function init () {
const ipc = electron.ipcMain ipcMain.once('ipcReady', function (e) {
ipc.once('ipcReady', function (e) {
app.ipcReady = true app.ipcReady = true
app.emit('ipcReady') app.emit('ipcReady')
}) })
ipc.once('ipcReadyWebTorrent', function (e) { ipcMain.once('ipcReadyWebTorrent', function (e) {
app.ipcReadyWebTorrent = true app.ipcReadyWebTorrent = true
log('sending %d queued messages from the main win to the webtorrent window', log('sending %d queued messages from the main win to the webtorrent window',
messageQueueMainToWebTorrent.length) messageQueueMainToWebTorrent.length)
@@ -44,11 +40,11 @@ function init () {
* Dialog * Dialog
*/ */
ipc.on('openTorrentFile', () => { ipcMain.on('openTorrentFile', () => {
const dialog = require('./dialog') const dialog = require('./dialog')
dialog.openTorrentFile() dialog.openTorrentFile()
}) })
ipc.on('openFiles', () => { ipcMain.on('openFiles', () => {
const dialog = require('./dialog') const dialog = require('./dialog')
dialog.openFiles() dialog.openFiles()
}) })
@@ -57,11 +53,11 @@ function init () {
* Dock * Dock
*/ */
ipc.on('setBadge', (e, ...args) => { ipcMain.on('setBadge', (e, ...args) => {
const dock = require('./dock') const dock = require('./dock')
dock.setBadge(...args) dock.setBadge(...args)
}) })
ipc.on('downloadFinished', (e, ...args) => { ipcMain.on('downloadFinished', (e, ...args) => {
const dock = require('./dock') const dock = require('./dock')
dock.downloadFinished(...args) dock.downloadFinished(...args)
}) })
@@ -70,7 +66,7 @@ function init () {
* Player Events * Player Events
*/ */
ipc.on('onPlayerOpen', function () { ipcMain.on('onPlayerOpen', function () {
const powerSaveBlocker = require('./power-save-blocker') const powerSaveBlocker = require('./power-save-blocker')
const shortcuts = require('./shortcuts') const shortcuts = require('./shortcuts')
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
@@ -81,14 +77,14 @@ function init () {
thumbar.enable() thumbar.enable()
}) })
ipc.on('onPlayerUpdate', function (e, ...args) { ipcMain.on('onPlayerUpdate', function (e, ...args) {
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
menu.onPlayerUpdate(...args) menu.onPlayerUpdate(...args)
thumbar.onPlayerUpdate(...args) thumbar.onPlayerUpdate(...args)
}) })
ipc.on('onPlayerClose', function () { ipcMain.on('onPlayerClose', function () {
const powerSaveBlocker = require('./power-save-blocker') const powerSaveBlocker = require('./power-save-blocker')
const shortcuts = require('./shortcuts') const shortcuts = require('./shortcuts')
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
@@ -99,7 +95,7 @@ function init () {
thumbar.disable() thumbar.disable()
}) })
ipc.on('onPlayerPlay', function () { ipcMain.on('onPlayerPlay', function () {
const powerSaveBlocker = require('./power-save-blocker') const powerSaveBlocker = require('./power-save-blocker')
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
@@ -107,7 +103,7 @@ function init () {
thumbar.onPlayerPlay() thumbar.onPlayerPlay()
}) })
ipc.on('onPlayerPause', function () { ipcMain.on('onPlayerPause', function () {
const powerSaveBlocker = require('./power-save-blocker') const powerSaveBlocker = require('./power-save-blocker')
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
@@ -119,7 +115,7 @@ function init () {
* Folder Watcher Events * Folder Watcher Events
*/ */
ipc.on('startFolderWatcher', function () { ipcMain.on('startFolderWatcher', function () {
if (!modules.folderWatcher) { if (!modules.folderWatcher) {
log('IPC ERR: folderWatcher module is not defined.') log('IPC ERR: folderWatcher module is not defined.')
return return
@@ -128,7 +124,7 @@ function init () {
modules.folderWatcher.start() modules.folderWatcher.start()
}) })
ipc.on('stopFolderWatcher', function () { ipcMain.on('stopFolderWatcher', function () {
if (!modules.folderWatcher) { if (!modules.folderWatcher) {
log('IPC ERR: folderWatcher module is not defined.') log('IPC ERR: folderWatcher module is not defined.')
return return
@@ -141,15 +137,16 @@ function init () {
* Shell * Shell
*/ */
ipc.on('openPath', (e, ...args) => {
ipcMain.on('openPath', (e, ...args) => {
const shell = require('./shell') const shell = require('./shell')
shell.openPath(...args) shell.openPath(...args)
}) })
ipc.on('showItemInFolder', (e, ...args) => { ipcMain.on('showItemInFolder', (e, ...args) => {
const shell = require('./shell') const shell = require('./shell')
shell.showItemInFolder(...args) shell.showItemInFolder(...args)
}) })
ipc.on('moveItemToTrash', (e, ...args) => { ipcMain.on('moveItemToTrash', (e, ...args) => {
const shell = require('./shell') const shell = require('./shell')
shell.moveItemToTrash(...args) shell.moveItemToTrash(...args)
}) })
@@ -158,7 +155,7 @@ function init () {
* File handlers * File handlers
*/ */
ipc.on('setDefaultFileHandler', (e, flag) => { ipcMain.on('setDefaultFileHandler', (e, flag) => {
const handlers = require('./handlers') const handlers = require('./handlers')
if (flag) handlers.install() if (flag) handlers.install()
@@ -169,7 +166,7 @@ function init () {
* Auto start on login * Auto start on login
*/ */
ipc.on('setStartup', (e, flag) => { ipcMain.on('setStartup', (e, flag) => {
const startup = require('./startup') const startup = require('./startup')
if (flag) startup.install() if (flag) startup.install()
@@ -182,19 +179,19 @@ function init () {
const main = windows.main const main = windows.main
ipc.on('setAspectRatio', (e, ...args) => main.setAspectRatio(...args)) ipcMain.on('setAspectRatio', (e, ...args) => main.setAspectRatio(...args))
ipc.on('setBounds', (e, ...args) => main.setBounds(...args)) ipcMain.on('setBounds', (e, ...args) => main.setBounds(...args))
ipc.on('setProgress', (e, ...args) => main.setProgress(...args)) ipcMain.on('setProgress', (e, ...args) => main.setProgress(...args))
ipc.on('setTitle', (e, ...args) => main.setTitle(...args)) ipcMain.on('setTitle', (e, ...args) => main.setTitle(...args))
ipc.on('show', () => main.show()) ipcMain.on('show', () => main.show())
ipc.on('toggleFullScreen', (e, ...args) => main.toggleFullScreen(...args)) ipcMain.on('toggleFullScreen', (e, ...args) => main.toggleFullScreen(...args))
ipc.on('setAllowNav', (e, ...args) => menu.setAllowNav(...args)) ipcMain.on('setAllowNav', (e, ...args) => menu.setAllowNav(...args))
/** /**
* External Media Player * External Media Player
*/ */
ipc.on('checkForExternalPlayer', function (e, path) { ipcMain.on('checkForExternalPlayer', function (e, path) {
const externalPlayer = require('./external-player') const externalPlayer = require('./external-player')
externalPlayer.checkInstall(path, function (err) { externalPlayer.checkInstall(path, function (err) {
@@ -202,7 +199,7 @@ function init () {
}) })
}) })
ipc.on('openExternalPlayer', (e, ...args) => { ipcMain.on('openExternalPlayer', (e, ...args) => {
const externalPlayer = require('./external-player') const externalPlayer = require('./external-player')
const thumbar = require('./thumbar') const thumbar = require('./thumbar')
@@ -211,7 +208,7 @@ function init () {
externalPlayer.spawn(...args) externalPlayer.spawn(...args)
}) })
ipc.on('quitExternalPlayer', () => { ipcMain.on('quitExternalPlayer', () => {
const externalPlayer = require('./external-player') const externalPlayer = require('./external-player')
externalPlayer.kill() externalPlayer.kill()
}) })
@@ -220,8 +217,8 @@ function init () {
* Message passing * Message passing
*/ */
const oldEmit = ipc.emit const oldEmit = ipcMain.emit
ipc.emit = function (name, e, ...args) { ipcMain.emit = function (name, e, ...args) {
// Relay messages between the main window and the WebTorrent hidden window // Relay messages between the main window and the WebTorrent hidden window
if (name.startsWith('wt-') && !app.isQuitting) { if (name.startsWith('wt-') && !app.isQuitting) {
if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') { if (e.sender.browserWindowOptions.title === 'webtorrent-hidden-window') {
@@ -244,6 +241,6 @@ function init () {
} }
// Emit all other events normally // Emit all other events normally
oldEmit.call(ipc, name, e, ...args) oldEmit.call(ipcMain, name, e, ...args)
} }
} }

View File

@@ -8,11 +8,9 @@ module.exports.error = error
* where they can be viewed in Developer Tools. * where they can be viewed in Developer Tools.
*/ */
const electron = require('electron') const { app } = require('electron')
const windows = require('./windows') const windows = require('./windows')
const app = electron.app
function log (...args) { function log (...args) {
if (app.ipcReady) { if (app.ipcReady) {
windows.main.send('log', ...args) windows.main.send('log', ...args)

View File

@@ -8,9 +8,7 @@ module.exports = {
onToggleFullScreen onToggleFullScreen
} }
const electron = require('electron') const { app, Menu } = require('electron')
const app = electron.app
const config = require('../config') const config = require('../config')
const windows = require('./windows') const windows = require('./windows')
@@ -18,8 +16,8 @@ const windows = require('./windows')
let menu = null let menu = null
function init () { function init () {
menu = electron.Menu.buildFromTemplate(getMenuTemplate()) menu = Menu.buildFromTemplate(getMenuTemplate())
electron.Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu)
} }
function togglePlaybackControls (flag) { function togglePlaybackControls (flag) {

View File

@@ -3,7 +3,7 @@ module.exports = {
disable disable
} }
const electron = require('electron') const { powerSaveBlocker } = require('electron')
const log = require('./log') const log = require('./log')
let blockId = 0 let blockId = 0
@@ -13,11 +13,11 @@ let blockId = 0
* display. * display.
*/ */
function enable () { function enable () {
if (electron.powerSaveBlocker.isStarted(blockId)) { if (powerSaveBlocker.isStarted(blockId)) {
// If a power saver block already exists, do nothing. // If a power saver block already exists, do nothing.
return return
} }
blockId = electron.powerSaveBlocker.start('prevent-display-sleep') blockId = powerSaveBlocker.start('prevent-display-sleep')
log(`powerSaveBlocker.enable: ${blockId}`) log(`powerSaveBlocker.enable: ${blockId}`)
} }
@@ -25,10 +25,10 @@ function enable () {
* Stop blocking the system from entering low-power mode. * Stop blocking the system from entering low-power mode.
*/ */
function disable () { function disable () {
if (!electron.powerSaveBlocker.isStarted(blockId)) { if (!powerSaveBlocker.isStarted(blockId)) {
// If a power saver block does not exist, do nothing. // If a power saver block does not exist, do nothing.
return return
} }
electron.powerSaveBlocker.stop(blockId) powerSaveBlocker.stop(blockId)
log(`powerSaveBlocker.disable: ${blockId}`) log(`powerSaveBlocker.disable: ${blockId}`)
} }

View File

@@ -5,7 +5,7 @@ module.exports = {
moveItemToTrash moveItemToTrash
} }
const electron = require('electron') const { shell } = require('electron')
const log = require('./log') const log = require('./log')
/** /**
@@ -13,15 +13,16 @@ const log = require('./log')
*/ */
function openExternal (url) { function openExternal (url) {
log(`openExternal: ${url}`) log(`openExternal: ${url}`)
electron.shell.openExternal(url) shell.openExternal(url)
} }
/** /**
* Open the given file in the desktops default manner. * Open the given file in the desktops default manner.
*/ */
function openPath (path) { function openPath (path) {
log(`openPath: ${path}`) log(`openPath: ${path}`)
electron.shell.openPath(path) shell.openPath(path)
} }
/** /**
@@ -29,7 +30,7 @@ function openPath (path) {
*/ */
function showItemInFolder (path) { function showItemInFolder (path) {
log(`showItemInFolder: ${path}`) log(`showItemInFolder: ${path}`)
electron.shell.showItemInFolder(path) shell.showItemInFolder(path)
} }
/** /**
@@ -37,5 +38,5 @@ function showItemInFolder (path) {
*/ */
function moveItemToTrash (path) { function moveItemToTrash (path) {
log(`moveItemToTrash: ${path}`) log(`moveItemToTrash: ${path}`)
electron.shell.moveItemToTrash(path) shell.moveItemToTrash(path)
} }

View File

@@ -3,20 +3,20 @@ module.exports = {
enable enable
} }
const electron = require('electron') const { globalShortcut } = require('electron')
const windows = require('./windows') const windows = require('./windows')
function enable () { function enable () {
// Register play/pause media key, available on some keyboards. // Register play/pause media key, available on some keyboards.
electron.globalShortcut.register( globalShortcut.register(
'MediaPlayPause', 'MediaPlayPause',
() => windows.main.dispatch('playPause') () => windows.main.dispatch('playPause')
) )
electron.globalShortcut.register( globalShortcut.register(
'MediaNextTrack', 'MediaNextTrack',
() => windows.main.dispatch('nextTrack') () => windows.main.dispatch('nextTrack')
) )
electron.globalShortcut.register( globalShortcut.register(
'MediaPreviousTrack', 'MediaPreviousTrack',
() => windows.main.dispatch('previousTrack') () => windows.main.dispatch('previousTrack')
) )
@@ -24,7 +24,7 @@ function enable () {
function disable () { function disable () {
// Return the media key to the OS, so other apps can use it. // Return the media key to the OS, so other apps can use it.
electron.globalShortcut.unregister('MediaPlayPause') globalShortcut.unregister('MediaPlayPause')
electron.globalShortcut.unregister('MediaNextTrack') globalShortcut.unregister('MediaNextTrack')
electron.globalShortcut.unregister('MediaPreviousTrack') globalShortcut.unregister('MediaPreviousTrack')
} }

View File

@@ -2,11 +2,10 @@ module.exports = {
handleEvent handleEvent
} }
const { app } = require('electron')
const path = require('path') const path = require('path')
const spawn = require('child_process').spawn const spawn = require('child_process').spawn
const electron = require('electron')
const app = electron.app
const handlers = require('./handlers') const handlers = require('./handlers')

View File

@@ -4,9 +4,7 @@ module.exports = {
setWindowFocus setWindowFocus
} }
const electron = require('electron') const { app, Tray, Menu } = require('electron')
const app = electron.app
const config = require('../config') const config = require('../config')
const windows = require('./windows') const windows = require('./windows')
@@ -67,7 +65,7 @@ function checkLinuxTraySupport (cb) {
} }
function createTray () { function createTray () {
tray = new electron.Tray(getIconPath()) tray = new Tray(getIconPath())
// On Windows, left click opens the app, right click opens the context menu. // On Windows, left click opens the app, right click opens the context menu.
// On Linux, any click (left or right) opens the context menu. // On Linux, any click (left or right) opens the context menu.
@@ -78,7 +76,7 @@ function createTray () {
} }
function updateTrayMenu () { function updateTrayMenu () {
const contextMenu = electron.Menu.buildFromTemplate(getMenuTemplate()) const contextMenu = Menu.buildFromTemplate(getMenuTemplate())
tray.setContextMenu(contextMenu) tray.setContextMenu(contextMenu)
} }

View File

@@ -2,7 +2,7 @@ module.exports = {
init init
} }
const electron = require('electron') const { autoUpdater } = require('electron')
const get = require('simple-get') const get = require('simple-get')
const config = require('../config') const config = require('../config')
@@ -47,31 +47,31 @@ function onResponse (err, res, data) {
} }
function initDarwinWin32 () { function initDarwinWin32 () {
electron.autoUpdater.on( autoUpdater.on(
'error', 'error',
(err) => log.error(`Update error: ${err.message}`) (err) => log.error(`Update error: ${err.message}`)
) )
electron.autoUpdater.on( autoUpdater.on(
'checking-for-update', 'checking-for-update',
() => log('Checking for update') () => log('Checking for update')
) )
electron.autoUpdater.on( autoUpdater.on(
'update-available', 'update-available',
() => log('Update available') () => log('Update available')
) )
electron.autoUpdater.on( autoUpdater.on(
'update-not-available', 'update-not-available',
() => log('No update available') () => log('No update available')
) )
electron.autoUpdater.on( autoUpdater.on(
'update-downloaded', 'update-downloaded',
(e, notes, name, date, url) => log(`Update downloaded: ${name}: ${url}`) (e, notes, name, date, url) => log(`Update downloaded: ${name}: ${url}`)
) )
electron.autoUpdater.setFeedURL({ url: AUTO_UPDATE_URL }) autoUpdater.setFeedURL({ url: AUTO_UPDATE_URL })
electron.autoUpdater.checkForUpdates() autoUpdater.checkForUpdates()
} }

View File

@@ -2,9 +2,7 @@ module.exports = {
init init
} }
const electron = require('electron') const { app } = require('electron')
const app = electron.app
/** /**
* Add a user task menu to the app icon on right-click. (Windows) * Add a user task menu to the app icon on right-click. (Windows)

View File

@@ -4,14 +4,14 @@ const about = module.exports = {
} }
const config = require('../../config') const config = require('../../config')
const electron = require('electron') const { BrowserWindow } = require('electron')
function init () { function init () {
if (about.win) { if (about.win) {
return about.win.show() return about.win.show()
} }
const win = about.win = new electron.BrowserWindow({ const win = about.win = new BrowserWindow({
backgroundColor: '#ECECEC', backgroundColor: '#ECECEC',
center: true, center: true,
fullscreen: false, fullscreen: false,

View File

@@ -14,11 +14,9 @@ const main = module.exports = {
win: null win: null
} }
const electron = require('electron') const { app, BrowserWindow, screen } = require('electron')
const debounce = require('debounce') const debounce = require('debounce')
const app = electron.app
const config = require('../../config') const config = require('../../config')
const log = require('../log') const log = require('../log')
const menu = require('../menu') const menu = require('../menu')
@@ -30,7 +28,7 @@ function init (state, options) {
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({ const win = main.win = new BrowserWindow({
backgroundColor: '#282828', backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3) darkTheme: true, // Forces dark theme (GTK+3)
height: initialBounds.height, height: initialBounds.height,
@@ -162,7 +160,7 @@ function setBounds (bounds, maximize) {
log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`) log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`)
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 = 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)}`)

View File

@@ -6,12 +6,12 @@ const webtorrent = module.exports = {
win: null win: null
} }
const electron = require('electron') const { app, BrowserWindow } = require('electron')
const config = require('../../config') const config = require('../../config')
function init () { function init () {
const win = webtorrent.win = new electron.BrowserWindow({ const win = webtorrent.win = new BrowserWindow({
backgroundColor: '#1E1E1E', backgroundColor: '#1E1E1E',
center: true, center: true,
fullscreen: false, fullscreen: false,
@@ -37,7 +37,7 @@ function init () {
// Prevent killing the WebTorrent process // Prevent killing the WebTorrent process
win.on('close', function (e) { win.on('close', function (e) {
if (electron.app.isQuitting) { if (app.isQuitting) {
return return
} }
e.preventDefault() e.preventDefault()

View File

@@ -1,12 +1,10 @@
const path = require('path') const path = require('path')
const colors = require('material-ui/styles/colors') const colors = require('material-ui/styles/colors')
const electron = require('electron') const { remote } = require('electron')
const React = require('react') const React = require('react')
const PropTypes = require('prop-types') const PropTypes = require('prop-types')
const remote = electron.remote
const RaisedButton = require('material-ui/RaisedButton').default const RaisedButton = require('material-ui/RaisedButton').default
const TextField = require('material-ui/TextField').default const TextField = require('material-ui/TextField').default

View File

@@ -1,5 +1,5 @@
const React = require('react') const React = require('react')
const electron = require('electron') const { shell } = require('electron')
const ModalOKCancel = require('./modal-ok-cancel') const ModalOKCancel = require('./modal-ok-cancel')
const { dispatcher } = require('../lib/dispatcher') const { dispatcher } = require('../lib/dispatcher')
@@ -36,7 +36,7 @@ module.exports = class UnsupportedMediaModal extends React.Component {
} }
onInstall () { onInstall () {
electron.shell.openExternal('http://www.videolan.org/vlc/') shell.openExternal('http://www.videolan.org/vlc/')
// TODO: dcposch send a dispatch rather than modifying state directly // TODO: dcposch send a dispatch rather than modifying state directly
const state = this.props.state const state = this.props.state

View File

@@ -1,5 +1,5 @@
const React = require('react') const React = require('react')
const electron = require('electron') const { shell } = require('electron')
const ModalOKCancel = require('./modal-ok-cancel') const ModalOKCancel = require('./modal-ok-cancel')
const { dispatch } = require('../lib/dispatcher') const { dispatch } = require('../lib/dispatcher')
@@ -25,7 +25,7 @@ module.exports = class UpdateAvailableModal extends React.Component {
function handleShow () { function handleShow () {
// TODO: use the GitHub urls from config.js // TODO: use the GitHub urls from config.js
electron.shell.openExternal('https://github.com/webtorrent/webtorrent-desktop/releases') shell.openExternal('https://github.com/webtorrent/webtorrent-desktop/releases')
dispatch('exitModal') dispatch('exitModal')
} }

View File

@@ -1,4 +1,4 @@
const electron = require('electron') const { ipcRenderer } = require('electron')
const path = require('path') const path = require('path')
const Cast = require('../lib/cast') const Cast = require('../lib/cast')
@@ -11,8 +11,6 @@ const TorrentSummary = require('../lib/torrent-summary')
const Playlist = require('../lib/playlist') const Playlist = require('../lib/playlist')
const State = require('../lib/state') const State = require('../lib/state')
const ipcRenderer = electron.ipcRenderer
// Controls playback of torrents and files within torrents // Controls playback of torrents and files within torrents
// both local (<video>,<audio>,external player) and remote (cast) // both local (<video>,<audio>,external player) and remote (cast)
module.exports = class PlaybackController { module.exports = class PlaybackController {

View File

@@ -1,5 +1,5 @@
const { dispatch } = require('../lib/dispatcher') const { dispatch } = require('../lib/dispatcher')
const ipcRenderer = require('electron').ipcRenderer const { ipcRenderer } = require('electron')
// Controls the Preferences screen // Controls the Preferences screen
module.exports = class PrefsController { module.exports = class PrefsController {

View File

@@ -1,10 +1,8 @@
const electron = require('electron') const { remote } = require('electron')
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const parallel = require('run-parallel') const parallel = require('run-parallel')
const remote = electron.remote
const { dispatch } = require('../lib/dispatcher') const { dispatch } = require('../lib/dispatcher')
module.exports = class SubtitlesController { module.exports = class SubtitlesController {

View File

@@ -1,5 +1,5 @@
const path = require('path') const path = require('path')
const ipcRenderer = require('electron').ipcRenderer const { ipcRenderer } = require('electron')
const TorrentSummary = require('../lib/torrent-summary') const TorrentSummary = require('../lib/torrent-summary')
const sound = require('../lib/sound') const sound = require('../lib/sound')

View File

@@ -1,14 +1,12 @@
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const electron = require('electron') const { ipcRenderer, remote, clipboard } = require('electron')
const { dispatch } = require('../lib/dispatcher') const { dispatch } = require('../lib/dispatcher')
const { TorrentKeyNotFoundError } = require('../lib/errors') const { TorrentKeyNotFoundError } = require('../lib/errors')
const sound = require('../lib/sound') const sound = require('../lib/sound')
const TorrentSummary = require('../lib/torrent-summary') const TorrentSummary = require('../lib/torrent-summary')
const ipcRenderer = electron.ipcRenderer
const instantIoRegex = /^(https:\/\/)?instant\.io\/#/ const instantIoRegex = /^(https:\/\/)?instant\.io\/#/
// Controls the torrent list: creating, adding, deleting, & manipulating torrents // Controls the torrent list: creating, adding, deleting, & manipulating torrents
@@ -249,59 +247,59 @@ module.exports = class TorrentListController {
openTorrentContextMenu (infoHash) { openTorrentContextMenu (infoHash) {
const torrentSummary = TorrentSummary.getByKey(this.state, infoHash) const torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
const menu = new electron.remote.Menu() const menu = new remote.Menu()
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: 'Remove From List', label: 'Remove From List',
click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, false) click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, false)
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: 'Remove Data File', label: 'Remove Data File',
click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, true) click: () => dispatch('confirmDeleteTorrent', torrentSummary.infoHash, true)
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
type: 'separator' type: 'separator'
})) }))
if (torrentSummary.files) { if (torrentSummary.files) {
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: process.platform === 'darwin' ? 'Show in Finder' : 'Show in Folder', label: process.platform === 'darwin' ? 'Show in Finder' : 'Show in Folder',
click: () => showItemInFolder(torrentSummary) click: () => showItemInFolder(torrentSummary)
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
type: 'separator' type: 'separator'
})) }))
} }
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: 'Copy Magnet Link to Clipboard', label: 'Copy Magnet Link to Clipboard',
click: () => electron.clipboard.writeText(torrentSummary.magnetURI) click: () => clipboard.writeText(torrentSummary.magnetURI)
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: 'Copy Instant.io Link to Clipboard', label: 'Copy Instant.io Link to Clipboard',
click: () => electron.clipboard.writeText(`https://instant.io/#${torrentSummary.infoHash}`) click: () => clipboard.writeText(`https://instant.io/#${torrentSummary.infoHash}`)
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new 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 enabled: torrentSummary.torrentFileName != null
})) }))
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
type: 'separator' type: 'separator'
})) }))
const sortedByName = this.state.saved.prefs.sortByName const sortedByName = this.state.saved.prefs.sortByName
menu.append(new electron.remote.MenuItem({ menu.append(new remote.MenuItem({
label: `${sortedByName ? '✓ ' : ''}Sort by Name`, label: `${sortedByName ? '✓ ' : ''}Sort by Name`,
click: () => dispatch('updatePreferences', 'sortByName', !sortedByName) click: () => dispatch('updatePreferences', 'sortByName', !sortedByName)
})) }))
menu.popup({ window: electron.remote.getCurrentWindow() }) menu.popup({ window: remote.getCurrentWindow() })
} }
// Takes a torrentSummary or torrentKey // Takes a torrentSummary or torrentKey
@@ -311,7 +309,7 @@ module.exports = class TorrentListController {
if (!torrentSummary) throw new TorrentKeyNotFoundError(torrentKey) if (!torrentSummary) throw new TorrentKeyNotFoundError(torrentKey)
const downloadPath = this.state.saved.prefs.downloadPath const downloadPath = this.state.saved.prefs.downloadPath
const newFileName = path.parse(torrentSummary.name).name + '.torrent' const newFileName = path.parse(torrentSummary.name).name + '.torrent'
const win = electron.remote.getCurrentWindow() const win = remote.getCurrentWindow()
const opts = { const opts = {
title: 'Save Torrent File', title: 'Save Torrent File',
defaultPath: path.join(downloadPath, newFileName), defaultPath: path.join(downloadPath, newFileName),
@@ -322,7 +320,7 @@ module.exports = class TorrentListController {
buttonLabel: 'Save' buttonLabel: 'Save'
} }
const savePath = electron.remote.dialog.showSaveDialogSync(win, opts) const savePath = remote.dialog.showSaveDialogSync(win, opts)
if (!savePath) return // They clicked Cancel if (!savePath) return // They clicked Cancel
console.log('Saving torrent ' + torrentKey + ' to ' + savePath) console.log('Saving torrent ' + torrentKey + ' to ' + savePath)

View File

@@ -7,7 +7,7 @@ module.exports = {
logPlayAttempt logPlayAttempt
} }
const electron = require('electron') const { remote } = require('electron')
const config = require('../../config') const config = require('../../config')
@@ -74,7 +74,7 @@ function reset () {
// Track screen resolution // Track screen resolution
function getScreenInfo () { function getScreenInfo () {
return electron.remote.screen.getAllDisplays().map((screen) => ({ return remote.screen.getAllDisplays().map((screen) => ({
width: screen.size.width, width: screen.size.width,
height: screen.size.height, height: screen.size.height,
scaleFactor: screen.scaleFactor scaleFactor: screen.scaleFactor

View File

@@ -5,7 +5,7 @@ console.time('init')
const crypto = require('crypto') const crypto = require('crypto')
const util = require('util') const util = require('util')
const defaultAnnounceList = require('create-torrent').announceList const defaultAnnounceList = require('create-torrent').announceList
const electron = require('electron') const { ipcRenderer } = require('electron')
const fs = require('fs') const fs = require('fs')
const mm = require('music-metadata') const mm = require('music-metadata')
const networkAddress = require('network-address') const networkAddress = require('network-address')
@@ -16,9 +16,6 @@ const config = require('../config')
const { TorrentKeyNotFoundError } = require('./lib/errors') const { TorrentKeyNotFoundError } = require('./lib/errors')
const torrentPoster = require('./lib/torrent-poster') const torrentPoster = require('./lib/torrent-poster')
// Send & receive messages from the main window
const ipc = electron.ipcRenderer
// Force use of webtorrent trackers on all torrents // Force use of webtorrent trackers on all torrents
global.WEBTORRENT_ANNOUNCE = defaultAnnounceList global.WEBTORRENT_ANNOUNCE = defaultAnnounceList
.map((arr) => arr[0]) .map((arr) => arr[0])
@@ -68,29 +65,29 @@ init()
function init () { function init () {
listenToClientEvents() listenToClientEvents()
ipc.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) => ipcRenderer.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections)) startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
ipc.on('wt-stop-torrenting', (e, infoHash) => ipcRenderer.on('wt-stop-torrenting', (e, infoHash) =>
stopTorrenting(infoHash)) stopTorrenting(infoHash))
ipc.on('wt-create-torrent', (e, torrentKey, options) => ipcRenderer.on('wt-create-torrent', (e, torrentKey, options) =>
createTorrent(torrentKey, options)) createTorrent(torrentKey, options))
ipc.on('wt-save-torrent-file', (e, torrentKey) => ipcRenderer.on('wt-save-torrent-file', (e, torrentKey) =>
saveTorrentFile(torrentKey)) saveTorrentFile(torrentKey))
ipc.on('wt-generate-torrent-poster', (e, torrentKey) => ipcRenderer.on('wt-generate-torrent-poster', (e, torrentKey) =>
generateTorrentPoster(torrentKey)) generateTorrentPoster(torrentKey))
ipc.on('wt-get-audio-metadata', (e, infoHash, index) => ipcRenderer.on('wt-get-audio-metadata', (e, infoHash, index) =>
getAudioMetadata(infoHash, index)) getAudioMetadata(infoHash, index))
ipc.on('wt-start-server', (e, infoHash) => ipcRenderer.on('wt-start-server', (e, infoHash) =>
startServer(infoHash)) startServer(infoHash))
ipc.on('wt-stop-server', (e) => ipcRenderer.on('wt-stop-server', (e) =>
stopServer()) stopServer())
ipc.on('wt-select-files', (e, infoHash, selections) => ipcRenderer.on('wt-select-files', (e, infoHash, selections) =>
selectFiles(infoHash, selections)) selectFiles(infoHash, selections))
ipc.send('ipcReadyWebTorrent') ipcRenderer.send('ipcReadyWebTorrent')
window.addEventListener('error', (e) => window.addEventListener('error', (e) =>
ipc.send('wt-uncaught-error', { message: e.error.message, stack: e.error.stack }), ipcRenderer.send('wt-uncaught-error', { message: e.error.message, stack: e.error.stack }),
true) true)
setInterval(updateTorrentProgress, 1000) setInterval(updateTorrentProgress, 1000)
@@ -98,8 +95,8 @@ function init () {
} }
function listenToClientEvents () { function listenToClientEvents () {
client.on('warning', (err) => ipc.send('wt-warning', null, err.message)) client.on('warning', (err) => ipcRenderer.send('wt-warning', null, err.message))
client.on('error', (err) => ipc.send('wt-error', null, err.message)) client.on('error', (err) => ipcRenderer.send('wt-error', null, err.message))
} }
// Starts a given TorrentID, which can be an infohash, magnet URI, etc. // Starts a given TorrentID, which can be an infohash, magnet URI, etc.
@@ -133,44 +130,44 @@ function createTorrent (torrentKey, options) {
const torrent = client.seed(paths, options) const torrent = client.seed(paths, options)
torrent.key = torrentKey torrent.key = torrentKey
addTorrentEvents(torrent) addTorrentEvents(torrent)
ipc.send('wt-new-torrent') ipcRenderer.send('wt-new-torrent')
} }
function addTorrentEvents (torrent) { function addTorrentEvents (torrent) {
torrent.on('warning', (err) => torrent.on('warning', (err) =>
ipc.send('wt-warning', torrent.key, err.message)) ipcRenderer.send('wt-warning', torrent.key, err.message))
torrent.on('error', (err) => torrent.on('error', (err) =>
ipc.send('wt-error', torrent.key, err.message)) ipcRenderer.send('wt-error', torrent.key, err.message))
torrent.on('infoHash', () => torrent.on('infoHash', () =>
ipc.send('wt-parsed', torrent.key, torrent.infoHash, torrent.magnetURI)) ipcRenderer.send('wt-parsed', torrent.key, torrent.infoHash, torrent.magnetURI))
torrent.on('metadata', torrentMetadata) torrent.on('metadata', torrentMetadata)
torrent.on('ready', torrentReady) torrent.on('ready', torrentReady)
torrent.on('done', torrentDone) torrent.on('done', torrentDone)
function torrentMetadata () { function torrentMetadata () {
const info = getTorrentInfo(torrent) const info = getTorrentInfo(torrent)
ipc.send('wt-metadata', torrent.key, info) ipcRenderer.send('wt-metadata', torrent.key, info)
updateTorrentProgress() updateTorrentProgress()
} }
function torrentReady () { function torrentReady () {
const info = getTorrentInfo(torrent) const info = getTorrentInfo(torrent)
ipc.send('wt-ready', torrent.key, info) ipcRenderer.send('wt-ready', torrent.key, info)
ipc.send('wt-ready-' + torrent.infoHash, torrent.key, info) ipcRenderer.send('wt-ready-' + torrent.infoHash, torrent.key, info)
updateTorrentProgress() updateTorrentProgress()
} }
function torrentDone () { function torrentDone () {
const info = getTorrentInfo(torrent) const info = getTorrentInfo(torrent)
ipc.send('wt-done', torrent.key, info) ipcRenderer.send('wt-done', torrent.key, info)
updateTorrentProgress() updateTorrentProgress()
torrent.getFileModtimes(function (err, fileModtimes) { torrent.getFileModtimes(function (err, fileModtimes) {
if (err) return onError(err) if (err) return onError(err)
ipc.send('wt-file-modtimes', torrent.key, fileModtimes) ipcRenderer.send('wt-file-modtimes', torrent.key, fileModtimes)
}) })
} }
} }
@@ -207,7 +204,7 @@ function saveTorrentFile (torrentKey) {
const fileName = torrent.infoHash + '.torrent' const fileName = torrent.infoHash + '.torrent'
if (!err) { if (!err) {
// We've already saved the file // We've already saved the file
return ipc.send('wt-file-saved', torrentKey, fileName) return ipcRenderer.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
@@ -215,7 +212,7 @@ function saveTorrentFile (torrentKey) {
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)
return ipc.send('wt-file-saved', torrentKey, fileName) return ipcRenderer.send('wt-file-saved', torrentKey, fileName)
}) })
}) })
}) })
@@ -235,7 +232,7 @@ function generateTorrentPoster (torrentKey) {
fs.writeFile(posterFilePath, buf, function (err) { fs.writeFile(posterFilePath, buf, function (err) {
if (err) return console.log('error saving poster: %o', err) if (err) return console.log('error saving poster: %o', err)
// show the poster // show the poster
ipc.send('wt-poster', torrentKey, posterFileName) ipcRenderer.send('wt-poster', torrentKey, posterFileName)
}) })
}) })
}) })
@@ -247,7 +244,7 @@ function updateTorrentProgress () {
if (prevProgress && util.isDeepStrictEqual(progress, prevProgress)) { if (prevProgress && util.isDeepStrictEqual(progress, prevProgress)) {
return /* don't send heavy object if it hasn't changed */ return /* don't send heavy object if it hasn't changed */
} }
ipc.send('wt-progress', progress) ipcRenderer.send('wt-progress', progress)
prevProgress = progress prevProgress = progress
} }
@@ -317,8 +314,8 @@ function startServerFromReadyTorrent (torrent, cb) {
networkAddress: networkAddress() networkAddress: networkAddress()
} }
ipc.send('wt-server-running', info) ipcRenderer.send('wt-server-running', info)
ipc.send('wt-server-' + torrent.infoHash, info) ipcRenderer.send('wt-server-' + torrent.infoHash, info)
}) })
} }
@@ -336,14 +333,14 @@ function getAudioMetadata (infoHash, index) {
// Set initial matadata to display the filename first. // Set initial matadata to display the filename first.
const metadata = { title: file.name } const metadata = { title: file.name }
ipc.send('wt-audio-metadata', infoHash, index, metadata) ipcRenderer.send('wt-audio-metadata', infoHash, index, metadata)
const options = { const options = {
native: false, native: false,
skipCovers: true, skipCovers: true,
fileSize: file.length, fileSize: file.length,
observer: event => { observer: event => {
ipc.send('wt-audio-metadata', infoHash, index, { ipcRenderer.send('wt-audio-metadata', infoHash, index, {
common: metadata.common, common: metadata.common,
format: metadata.format format: metadata.format
}) })
@@ -358,7 +355,7 @@ function getAudioMetadata (infoHash, index) {
onMetadata onMetadata
.then( .then(
metadata => { metadata => {
ipc.send('wt-audio-metadata', infoHash, index, metadata) ipcRenderer.send('wt-audio-metadata', infoHash, index, metadata)
console.log(`metadata for file='${file.name}' completed.`) console.log(`metadata for file='${file.name}' completed.`)
}, },
err => { err => {