Allow forcefully unloading plugins without reloading Discord

This commit is contained in:
Samuel Elliott 2018-05-29 21:48:58 +01:00
parent 68d4617e46
commit 3e41a11197
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 17 additions and 10 deletions

View File

@ -256,16 +256,22 @@ export default class {
/**
* Unload content.
* @param {Content|String} content Content to unload
* @param {Boolean} force If true the content will be unloaded even if an exception is thrown when disabling/unloading
* @param {Boolean} reload Whether to reload the content after
* @return {Content}
*/
static async unloadContent(content, reload) {
static async unloadContent(content, force, reload) {
content = this.findContent(content);
if (!content) throw {message: `Could not find a ${this.contentType} from ${content}.`};
try {
await content.disable(false);
await content.emit('unload', reload);
const disablePromise = content.disable(false);
const unloadPromise = content.emit('unload', reload);
if (!force) {
await disablePromise;
await unloadPromise;
}
const index = this.getContentIndex(content);
@ -288,10 +294,11 @@ export default class {
/**
* Reload content.
* @param {Content|String} content Content to reload
* @param {Boolean} force If true the content will be unloaded even if an exception is thrown when disabling/unloading
* @return {Content}
*/
static reloadContent(content) {
return this.unloadContent(content, true);
static reloadContent(content, force) {
return this.unloadContent(content, force, true);
}
/**

View File

@ -18,12 +18,12 @@ export default class Plugin extends Content {
get start() { return this.enable }
get stop() { return this.disable }
reload() {
return PluginManager.reloadPlugin(this);
reload(force) {
return PluginManager.reloadPlugin(this, force);
}
unload() {
return PluginManager.unloadPlugin(this);
unload(force) {
return PluginManager.unloadPlugin(this, force);
}
}

View File

@ -94,7 +94,7 @@ export default new class Settings {
}
} catch (err) {
// There was an error saving settings
Logger.err('Settings', err);
Logger.err('Settings', ['Failed to save internal settings', err]);
throw err;
}
}