Plugin reloading
This commit is contained in:
parent
1896a0d558
commit
e0df52b6ab
|
@ -116,14 +116,15 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main);
|
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main);
|
||||||
this.localContent.push(content);
|
if (reload) this.localContent[index] = content;
|
||||||
|
else this.localContent.push(content);
|
||||||
return content;
|
return content;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async readConfig(configPath) {
|
static async readConfig(configPath) {
|
||||||
configPath = path.resolve(configPath, 'config.json');
|
configPath = path.resolve(configPath, 'config.json');
|
||||||
return FileUtils.readJsonFromFile(configPath);
|
return FileUtils.readJsonFromFile(configPath);
|
||||||
|
|
|
@ -52,6 +52,18 @@ export default class extends ContentManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async reloadPlugin(plugin) {
|
||||||
|
const _plugin = plugin instanceof Plugin ? plugin : this.findPlugin(plugin);
|
||||||
|
if (!_plugin) throw { 'message': 'Attempted to reload a plugin that is not loaded?' };
|
||||||
|
if (!_plugin.stop()) throw { 'message': 'Plugin failed to stop!' };
|
||||||
|
const index = this.getPluginIndex(_plugin);
|
||||||
|
const { pluginPath, dirName } = _plugin;
|
||||||
|
|
||||||
|
delete window.require.cache[window.require.resolve(pluginPath)];
|
||||||
|
|
||||||
|
return this.preloadContent(dirName, true, index);
|
||||||
|
}
|
||||||
|
|
||||||
static get findPlugin() { return this.findContent }
|
static get findPlugin() { return this.findContent }
|
||||||
static get getPluginIndex() { return this.getContentIndex }
|
static get getPluginIndex() { return this.getContentIndex }
|
||||||
static get getPluginByName() { return this.getContentByName }
|
static get getPluginByName() { return this.getContentByName }
|
||||||
|
|
|
@ -71,7 +71,16 @@
|
||||||
},
|
},
|
||||||
refreshLocal() { },
|
refreshLocal() { },
|
||||||
togglePlugin() { },
|
togglePlugin() { },
|
||||||
reloadPlugin() { },
|
reloadPlugin(plugin) {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await this.pluginManager.reloadPlugin(plugin);
|
||||||
|
this.$forceUpdate();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
},
|
||||||
showSettings() { }
|
showSettings() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue