code style
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
console.time('init')
|
console.time('init')
|
||||||
|
|
||||||
var airplay = require('airplay-js')
|
var airplay = require('airplay-js')
|
||||||
var cfg = require('application-config')('WebTorrent')
|
var cfg = require('application-config')('WebTorrent')
|
||||||
var cfgDirectory = require('application-config-path')('WebTorrent')
|
var cfgDirectory = require('application-config-path')('WebTorrent')
|
||||||
@@ -9,6 +10,7 @@ var dragDrop = require('drag-drop')
|
|||||||
var electron = require('electron')
|
var electron = require('electron')
|
||||||
var EventEmitter = require('events')
|
var EventEmitter = require('events')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
var ipcRenderer = electron.ipcRenderer
|
||||||
var mainLoop = require('main-loop')
|
var mainLoop = require('main-loop')
|
||||||
var networkAddress = require('network-address')
|
var networkAddress = require('network-address')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
@@ -84,7 +86,7 @@ function init () {
|
|||||||
|
|
||||||
// ...same thing if you paste a torrent
|
// ...same thing if you paste a torrent
|
||||||
document.addEventListener('paste', function () {
|
document.addEventListener('paste', function () {
|
||||||
electron.ipcRenderer.send('addTorrentFromPaste')
|
ipcRenderer.send('addTorrentFromPaste')
|
||||||
})
|
})
|
||||||
|
|
||||||
// ...keyboard shortcuts
|
// ...keyboard shortcuts
|
||||||
@@ -103,7 +105,7 @@ function init () {
|
|||||||
// ...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', function () {
|
window.addEventListener('focus', function () {
|
||||||
state.isFocused = true
|
state.isFocused = true
|
||||||
if (state.dock.badge > 0) electron.ipcRenderer.send('setBadge', '')
|
if (state.dock.badge > 0) ipcRenderer.send('setBadge', '')
|
||||||
state.dock.badge = 0
|
state.dock.badge = 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ function dispatch (action, ...args) {
|
|||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
if (action === 'toggleFullScreen') {
|
if (action === 'toggleFullScreen') {
|
||||||
electron.ipcRenderer.send('toggleFullScreen')
|
ipcRenderer.send('toggleFullScreen')
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
if (action === 'videoMouseMoved') {
|
if (action === 'videoMouseMoved') {
|
||||||
@@ -185,20 +187,20 @@ function dispatch (action, ...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupIpc () {
|
function setupIpc () {
|
||||||
electron.ipcRenderer.on('addTorrent', function (e, torrentId) {
|
ipcRenderer.on('addTorrent', function (e, torrentId) {
|
||||||
dispatch('addTorrent', torrentId)
|
dispatch('addTorrent', torrentId)
|
||||||
})
|
})
|
||||||
|
|
||||||
electron.ipcRenderer.on('seed', function (e, files) {
|
ipcRenderer.on('seed', function (e, files) {
|
||||||
dispatch('seed', files)
|
dispatch('seed', files)
|
||||||
})
|
})
|
||||||
|
|
||||||
electron.ipcRenderer.on('fullscreenChanged', function (e, isFullScreen) {
|
ipcRenderer.on('fullscreenChanged', function (e, isFullScreen) {
|
||||||
state.isFullScreen = isFullScreen
|
state.isFullScreen = isFullScreen
|
||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
|
|
||||||
electron.ipcRenderer.on('addFakeDevice', function (e, device) {
|
ipcRenderer.on('addFakeDevice', function (e, device) {
|
||||||
var player = new EventEmitter()
|
var player = new EventEmitter()
|
||||||
player.play = (networkURL) => console.log(networkURL)
|
player.play = (networkURL) => console.log(networkURL)
|
||||||
state.devices[device] = player
|
state.devices[device] = player
|
||||||
@@ -220,7 +222,7 @@ function detectDevices () {
|
|||||||
function loadState (callback) {
|
function loadState (callback) {
|
||||||
cfg.read(function (err, data) {
|
cfg.read(function (err, data) {
|
||||||
if (err) console.error(err)
|
if (err) console.error(err)
|
||||||
electron.ipcRenderer.send('log', 'loaded state from ' + cfg.filePath)
|
ipcRenderer.send('log', 'loaded state from ' + cfg.filePath)
|
||||||
|
|
||||||
// populate defaults if they're not there
|
// populate defaults if they're not there
|
||||||
state.saved = Object.assign({}, state.defaultSavedState, data)
|
state.saved = Object.assign({}, state.defaultSavedState, data)
|
||||||
@@ -238,7 +240,7 @@ function resumeTorrents () {
|
|||||||
|
|
||||||
// Write state.saved to the JSON state file
|
// Write state.saved to the JSON state file
|
||||||
function saveState () {
|
function saveState () {
|
||||||
electron.ipcRenderer.send('log', 'saving state to ' + cfg.filePath)
|
ipcRenderer.send('log', 'saving state to ' + cfg.filePath)
|
||||||
cfg.write(state.saved, function (err) {
|
cfg.write(state.saved, function (err) {
|
||||||
if (err) console.error(err)
|
if (err) console.error(err)
|
||||||
update()
|
update()
|
||||||
@@ -256,7 +258,7 @@ function updateDockIcon () {
|
|||||||
}
|
}
|
||||||
if (progress !== state.dock.progress) {
|
if (progress !== state.dock.progress) {
|
||||||
state.dock.progress = progress
|
state.dock.progress = progress
|
||||||
electron.ipcRenderer.send('setProgress', progress)
|
ipcRenderer.send('setProgress', progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,7 +367,7 @@ function addTorrentEvents (torrent) {
|
|||||||
|
|
||||||
if (!state.isFocused) {
|
if (!state.isFocused) {
|
||||||
state.dock.badge += 1
|
state.dock.badge += 1
|
||||||
electron.ipcRenderer.send('setBadge', state.dock.badge)
|
ipcRenderer.send('setBadge', state.dock.badge)
|
||||||
}
|
}
|
||||||
|
|
||||||
update()
|
update()
|
||||||
@@ -432,7 +434,7 @@ function closePlayer () {
|
|||||||
state.url = '/'
|
state.url = '/'
|
||||||
state.title = config.APP_NAME
|
state.title = config.APP_NAME
|
||||||
if (state.isFullScreen) {
|
if (state.isFullScreen) {
|
||||||
electron.ipcRenderer.send('toggleFullScreen')
|
ipcRenderer.send('toggleFullScreen')
|
||||||
}
|
}
|
||||||
restoreBounds()
|
restoreBounds()
|
||||||
stopServer()
|
stopServer()
|
||||||
@@ -507,14 +509,14 @@ function setDimensions (dimensions) {
|
|||||||
var x = Math.floor((screenWidth - width) / 2)
|
var x = Math.floor((screenWidth - width) / 2)
|
||||||
var y = Math.floor((screenHeight - height) / 2)
|
var y = Math.floor((screenHeight - height) / 2)
|
||||||
|
|
||||||
electron.ipcRenderer.send('setAspectRatio', aspectRatio)
|
ipcRenderer.send('setAspectRatio', aspectRatio)
|
||||||
electron.ipcRenderer.send('setBounds', {x, y, width, height})
|
ipcRenderer.send('setBounds', {x, y, width, height})
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreBounds () {
|
function restoreBounds () {
|
||||||
electron.ipcRenderer.send('setAspectRatio', 0)
|
ipcRenderer.send('setAspectRatio', 0)
|
||||||
if (state.mainWindowBounds) {
|
if (state.mainWindowBounds) {
|
||||||
electron.ipcRenderer.send('setBounds', state.mainWindowBounds, true)
|
ipcRenderer.send('setBounds', state.mainWindowBounds, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user