removed unused packages; hashing installed plugins; saving plugins config; detecting newly installed plugins.
This commit is contained in:
@@ -18,14 +18,12 @@
|
|||||||
"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",
|
||||||
"color": "^1.0.3",
|
|
||||||
"cp-file": "^4.0.1",
|
"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-config": "^0.2.1",
|
|
||||||
"es6-error": "^4.0.0",
|
"es6-error": "^4.0.0",
|
||||||
"fn-getter": "^1.0.0",
|
"fn-getter": "^1.0.0",
|
||||||
"gaze": "^1.1.2",
|
"gaze": "^1.1.2",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const {app, dialog} = require('electron')
|
|||||||
const {sync: mkdirpSync} = require('mkdirp')
|
const {sync: mkdirpSync} = require('mkdirp')
|
||||||
const ms = require('ms')
|
const ms = require('ms')
|
||||||
const shellEnv = require('shell-env')
|
const shellEnv = require('shell-env')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
|
|
||||||
@@ -38,11 +39,8 @@ module.exports = class Plugins {
|
|||||||
console.log('-- initializing plugins')
|
console.log('-- initializing plugins')
|
||||||
this.state = state
|
this.state = state
|
||||||
|
|
||||||
// initialize unsaved state
|
// initialize state
|
||||||
this.state.unsaved = Object.assign(this.state.unsaved || {}, {
|
this.state.saved = Object.assign(this.state.saved || {})
|
||||||
installedPlugins: Object.assign({}, this.state.saved.installedPlugins),
|
|
||||||
installedPluginVersions: Object.assign({}, this.state.saved.installedPluginVersions)
|
|
||||||
})
|
|
||||||
|
|
||||||
// init plugin directories if not present
|
// init plugin directories if not present
|
||||||
mkdirpSync(this.path)
|
mkdirpSync(this.path)
|
||||||
@@ -56,12 +54,12 @@ 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(() => {
|
||||||
const plugins_ = config.getPlugins()
|
const plugins = config.getPlugins()
|
||||||
if (plugins !== plugins_) {
|
if (plugins !== this.plugins) {
|
||||||
const id_ = this.getId(plugins_)
|
const id = this.getId(plugins)
|
||||||
if (this.id !== id_) {
|
if (this.id !== id) {
|
||||||
this.id = id_
|
this.id = id
|
||||||
this.plugins = plugins_
|
this.plugins = plugins
|
||||||
this.updatePlugins()
|
this.updatePlugins()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,8 +86,11 @@ module.exports = class Plugins {
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
getId (plugins_) {
|
getId (plugins) {
|
||||||
return JSON.stringify(plugins_)
|
const hash = crypto.createHash('sha256');
|
||||||
|
hash.update(JSON.stringify(plugins));
|
||||||
|
return hash.digest('hex')
|
||||||
|
// return JSON.stringify(plugins)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlugins (forceUpdate = false) {
|
updatePlugins (forceUpdate = false) {
|
||||||
@@ -100,7 +101,6 @@ module.exports = class Plugins {
|
|||||||
// return notify('Plugin update in progress')
|
// return notify('Plugin update in progress')
|
||||||
}
|
}
|
||||||
this.updating = true
|
this.updating = true
|
||||||
this.id_ = this.id
|
|
||||||
const hasPackages = this.syncPackageJSON()
|
const hasPackages = this.syncPackageJSON()
|
||||||
|
|
||||||
// there are plugins loaded from repositories
|
// there are plugins loaded from repositories
|
||||||
@@ -148,8 +148,7 @@ module.exports = class Plugins {
|
|||||||
|
|
||||||
// OK, no errors
|
// OK, no errors
|
||||||
// flag successful plugin update
|
// flag successful plugin update
|
||||||
this.state.unsaved.installedPlugins = this.id_
|
this.state.saved.installedPlugins = this.id
|
||||||
console.log('-- id_: ', this.id_)
|
|
||||||
|
|
||||||
// check if package based plugins were updated
|
// check if package based plugins were updated
|
||||||
const loaded = this.modules.length
|
const loaded = this.modules.length
|
||||||
@@ -157,7 +156,7 @@ module.exports = class Plugins {
|
|||||||
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
const pluginVersions = JSON.stringify(this.getPluginVersions())
|
||||||
console.log('-- pluginVersions: ', pluginVersions)
|
console.log('-- pluginVersions: ', pluginVersions)
|
||||||
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
const changed = this.state.saved.installedPluginVersions !== pluginVersions && loaded === total
|
||||||
this.state.unsaved.installedPluginVersions = pluginVersions
|
this.state.saved.installedPluginVersions = pluginVersions
|
||||||
|
|
||||||
// notify watchers
|
// notify watchers
|
||||||
if (this.forceUpdate || changed) {
|
if (this.forceUpdate || changed) {
|
||||||
@@ -353,6 +352,11 @@ module.exports = class Plugins {
|
|||||||
return mod
|
return mod
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('- plugin not installed: ', path)
|
console.log('- plugin not installed: ', path)
|
||||||
|
// plugin not installed
|
||||||
|
// node_modules removed? did a manual plugin uninstall?
|
||||||
|
// try installing and then loading if successfull
|
||||||
|
this.installPackages((err) => this.loadPlugins(err))
|
||||||
|
|
||||||
// console.error(err)
|
// console.error(err)
|
||||||
// this.alert(`Plugin error: Plugin "${basename(path)}" failed to load (${err.message})`)
|
// this.alert(`Plugin error: Plugin "${basename(path)}" failed to load (${err.message})`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user