removed extra logging; cleanup
This commit is contained in:
@@ -120,7 +120,6 @@ function watch() {
|
|||||||
}
|
}
|
||||||
this.on('changed', () => {
|
this.on('changed', () => {
|
||||||
try {
|
try {
|
||||||
console.log('-- config updated: ', configFile)
|
|
||||||
updateConfig()
|
updateConfig()
|
||||||
console.log('WebTorrent configuration reloaded!')
|
console.log('WebTorrent configuration reloaded!')
|
||||||
watchers.forEach(fn => fn())
|
watchers.forEach(fn => fn())
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ function init () {
|
|||||||
|
|
||||||
// init new plugins then notify user
|
// init new plugins then notify user
|
||||||
plugins.subscribe(() => {
|
plugins.subscribe(() => {
|
||||||
console.log('-- new plugins finished installing')
|
|
||||||
|
|
||||||
// update menu and windows
|
// update menu and windows
|
||||||
// passing thru new plugin decorators
|
// passing thru new plugin decorators
|
||||||
initApp(state)
|
initApp(state)
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ const config = require('./config')
|
|||||||
module.exports = class Plugins {
|
module.exports = class Plugins {
|
||||||
constructor () {
|
constructor () {
|
||||||
// modules path
|
// modules path
|
||||||
this.path = resolve(config.getConfigPath(), 'webtorrent-plugins')
|
this.path = resolve(config.getConfigPath(), 'plugins')
|
||||||
console.log('- plugins path: ', this.path)
|
log('path: ', this.path)
|
||||||
this.availableExtensions = new Set([
|
this.availableExtensions = new Set([
|
||||||
'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware',
|
'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware',
|
||||||
'reduceUI', 'reduceSessions', 'reduceTermGroups',
|
'reduceUI', 'reduceSessions', 'reduceTermGroups',
|
||||||
@@ -34,7 +34,6 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init (state) {
|
init (state) {
|
||||||
console.log('-- initializing plugins')
|
|
||||||
this.state = state
|
this.state = state
|
||||||
|
|
||||||
// initialize state
|
// initialize state
|
||||||
@@ -52,12 +51,11 @@ module.exports = class Plugins {
|
|||||||
// we listen on configuration updates to trigger
|
// we listen on configuration updates to trigger
|
||||||
// plugin installation
|
// plugin installation
|
||||||
config.subscribe(() => {
|
config.subscribe(() => {
|
||||||
console.log('--> CONFIG UPDATED, check if plugins update is needed')
|
|
||||||
const plugins = config.getPlugins()
|
const plugins = config.getPlugins()
|
||||||
if (plugins !== this.plugins) {
|
if (plugins !== this.plugins) {
|
||||||
const id = this.getId(plugins)
|
const id = this.getId(plugins)
|
||||||
if (this.id !== id) {
|
if (this.id !== id) {
|
||||||
console.log('--> UPDATE PLUGINS')
|
log('UPDATING...')
|
||||||
this.id = id
|
this.id = id
|
||||||
this.plugins = plugins
|
this.plugins = plugins
|
||||||
this.paths = this.getPaths(this.plugins)
|
this.paths = this.getPaths(this.plugins)
|
||||||
@@ -66,19 +64,17 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// we schedule the initial plugins update
|
// schedule the initial plugins update
|
||||||
// a bit after the user launches the terminal
|
// a bit after the user launches the app
|
||||||
// to prevent slowness
|
// to prevent slowness
|
||||||
// TODO: handle force updates
|
|
||||||
if (this.needsUpdate()) {
|
if (this.needsUpdate()) {
|
||||||
// install immediately if the user changed plugins
|
|
||||||
console.log('plugins have changed / not init, scheduling plugins installation')
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updatePlugins()
|
this.updatePlugins()
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
log('installation scheduled')
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise update plugins every 5 hours
|
// update plugins every 5 hours
|
||||||
setInterval(this.updatePlugins, ms('5h'))
|
setInterval(this.updatePlugins, ms('5h'))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +101,6 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updatePlugins (forceUpdate = false) {
|
updatePlugins (forceUpdate = false) {
|
||||||
console.log('-- update plugins')
|
|
||||||
this.forceUpdate = forceUpdate
|
this.forceUpdate = forceUpdate
|
||||||
if (this.updating) {
|
if (this.updating) {
|
||||||
// TODO
|
// TODO
|
||||||
@@ -117,7 +112,6 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPlugins (err, localOnly = false) {
|
loadPlugins (err, localOnly = false) {
|
||||||
console.log('- loadPlugins')
|
|
||||||
this.updating = false
|
this.updating = false
|
||||||
|
|
||||||
// handle errors first
|
// handle errors first
|
||||||
@@ -125,13 +119,13 @@ module.exports = class Plugins {
|
|||||||
console.error(err.stack)
|
console.error(err.stack)
|
||||||
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
|
||||||
this.alert(
|
this.alert(
|
||||||
'Error updating plugins: We could not find the `npm` command. Make sure it\'s in $PATH'
|
'Error updating plugins: We could not find the "npm" command. Make sure it\'s in $PATH'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.alert(
|
this.alert(
|
||||||
'Error updating plugins: Check `~/.webtorrent_plugins/npm-debug.log` for more information.'
|
'Error updating plugins: Check `${this.path}/npm-debug.log` for more information.'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -156,23 +150,13 @@ module.exports = class Plugins {
|
|||||||
const loaded = this.modules.length
|
const loaded = this.modules.length
|
||||||
const total = this.paths.plugins.length
|
const total = this.paths.plugins.length
|
||||||
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
||||||
console.log('-- pluginVersions: ', pluginVersions)
|
|
||||||
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
||||||
this.state.saved.installedPluginVersions = pluginVersions
|
this.state.saved.installedPluginVersions = pluginVersions
|
||||||
|
|
||||||
// notify watchers
|
// notify watchers
|
||||||
if (this.forceUpdate || changed) {
|
if (this.forceUpdate || changed) {
|
||||||
console.log(`- notify watchers: this.forceUpdate: ${this.forceUpdate} / changed: ${changed}`)
|
|
||||||
if (changed) {
|
|
||||||
// this.alert(
|
|
||||||
// 'Plugins Updated: Restart the app or hot-reload with "View" > "Reload" to enjoy the updates!'
|
|
||||||
// )
|
|
||||||
} else {
|
|
||||||
this.alert(
|
|
||||||
'Plugins Updated: No changes!'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
this.watchers.forEach(fn => fn(err, {forceUpdate: this.forceUpdate}))
|
this.watchers.forEach(fn => fn(err, {forceUpdate: this.forceUpdate}))
|
||||||
|
log('instalation completed')
|
||||||
}
|
}
|
||||||
|
|
||||||
// save state
|
// save state
|
||||||
@@ -215,10 +199,7 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
syncPackageJSON () {
|
syncPackageJSON () {
|
||||||
console.log('- syncPackageJSON')
|
|
||||||
const dependencies = this.toDependencies(this.plugins)
|
const dependencies = this.toDependencies(this.plugins)
|
||||||
|
|
||||||
console.log('- set plugins package file')
|
|
||||||
const pkg = {
|
const pkg = {
|
||||||
name: 'webtorrent-plugins',
|
name: 'webtorrent-plugins',
|
||||||
description: 'Auto-generated from WebTorrent config.',
|
description: 'Auto-generated from WebTorrent config.',
|
||||||
@@ -240,7 +221,8 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
alert (message) {
|
alert (message) {
|
||||||
console.log(`[ PLUGINS MSG ]--> ${message}`)
|
log(message)
|
||||||
|
// TODO: display notifications
|
||||||
// dialog.showMessageBox({
|
// dialog.showMessageBox({
|
||||||
// message,
|
// message,
|
||||||
// buttons: ['Ok']
|
// buttons: ['Ok']
|
||||||
@@ -253,27 +235,21 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toDependencies (plugins) {
|
toDependencies (plugins) {
|
||||||
console.log('- toDependencies: plugins: ', plugins)
|
|
||||||
const obj = {}
|
const obj = {}
|
||||||
const pluginNames = Object.keys(plugins)
|
const pluginNames = Object.keys(plugins)
|
||||||
|
|
||||||
pluginNames.forEach(name => {
|
pluginNames.forEach(name => {
|
||||||
let url = plugins[name]
|
let url = plugins[name]
|
||||||
if (this.isLocalPath(url)) return
|
if (this.isLocalPath(url)) return
|
||||||
|
|
||||||
console.log('- set package as plugin dependency')
|
|
||||||
obj[name] = url
|
obj[name] = url
|
||||||
})
|
})
|
||||||
console.log('- dependencies: ', obj)
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
installPackages (fn) {
|
installPackages (fn) {
|
||||||
console.log('- installPackages')
|
|
||||||
const {shell = '', npmRegistry} = config
|
const {shell = '', npmRegistry} = config
|
||||||
|
|
||||||
shellEnv(shell).then(env => {
|
shellEnv(shell).then(env => {
|
||||||
console.log('- SHELL')
|
|
||||||
if (npmRegistry) {
|
if (npmRegistry) {
|
||||||
env.NPM_CONFIG_REGISTRY = npmRegistry
|
env.NPM_CONFIG_REGISTRY = npmRegistry
|
||||||
}
|
}
|
||||||
@@ -291,8 +267,6 @@ module.exports = class Plugins {
|
|||||||
const whichShell = shell.match(/fish/) ? 'fish' : 'posix'
|
const whichShell = shell.match(/fish/) ? 'fish' : 'posix'
|
||||||
|
|
||||||
// Use the install command that is appropriate for our shell
|
// Use the install command that is appropriate for our shell
|
||||||
console.log('- installPackages: exec: ', installCommands[whichShell])
|
|
||||||
console.log('- install path: ', this.path)
|
|
||||||
exec(installCommands[whichShell], {
|
exec(installCommands[whichShell], {
|
||||||
cwd: this.path//,
|
cwd: this.path//,
|
||||||
// env,
|
// env,
|
||||||
@@ -331,10 +305,8 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requirePlugins () {
|
requirePlugins () {
|
||||||
console.log('- requirePlugins')
|
|
||||||
const {plugins} = this.paths
|
const {plugins} = this.paths
|
||||||
let installNeeded = false
|
let installNeeded = false
|
||||||
console.log('- requirePlugins: paths: ', plugins)
|
|
||||||
|
|
||||||
const load = (path) => {
|
const load = (path) => {
|
||||||
let mod
|
let mod
|
||||||
@@ -353,14 +325,10 @@ module.exports = class Plugins {
|
|||||||
|
|
||||||
return mod
|
return mod
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('- plugin not installed: ', path)
|
|
||||||
// plugin not installed
|
// plugin not installed
|
||||||
// node_modules removed? did a manual plugin uninstall?
|
// node_modules removed? did a manual plugin uninstall?
|
||||||
// try installing and then loading if successfull
|
// try installing and then loading if successfull
|
||||||
installNeeded = true
|
installNeeded = true
|
||||||
|
|
||||||
// console.error(err)
|
|
||||||
// this.alert(`Plugin error: Plugin "${basename(path)}" failed to load (${err.message})`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +339,6 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onApp (app) {
|
onApp (app) {
|
||||||
console.log('-- plugins onApp')
|
|
||||||
this.modules.forEach(plugin => {
|
this.modules.forEach(plugin => {
|
||||||
if (plugin.onApp) {
|
if (plugin.onApp) {
|
||||||
plugin.onApp(app)
|
plugin.onApp(app)
|
||||||
@@ -406,12 +373,10 @@ module.exports = class Plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decorateMenu (tpl) {
|
decorateMenu (tpl) {
|
||||||
console.log('-- plugins: decorate menu')
|
|
||||||
return this.decorateObject(tpl, 'decorateMenu')
|
return this.decorateObject(tpl, 'decorateMenu')
|
||||||
}
|
}
|
||||||
|
|
||||||
decorateWindow (options) {
|
decorateWindow (options) {
|
||||||
console.log('-- plugins: decorate window')
|
|
||||||
return this.decorateObject(options, 'decorateWindow')
|
return this.decorateObject(options, 'decorateWindow')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,3 +393,18 @@ module.exports = class Plugins {
|
|||||||
return this.decorateObject(defaults, 'decorateBrowserOptions')
|
return this.decorateObject(defaults, 'decorateBrowserOptions')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs passed arguments to console using a prefix.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function log() {
|
||||||
|
const prefix = '[ PLUGINS ]-->'
|
||||||
|
const args = [prefix]
|
||||||
|
|
||||||
|
for (var i=0; i<arguments.length; ++i) {
|
||||||
|
args.push(arguments[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log.apply(console, args)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user