diff --git a/client/src/structs/settings/settingscategory.js b/client/src/structs/settings/settingscategory.js index 88c96ff7..6497c11a 100644 --- a/client/src/structs/settings/settingscategory.js +++ b/client/src/structs/settings/settingscategory.js @@ -10,6 +10,7 @@ import Setting from './setting'; import EventEmitter from 'events'; +import { ClientLogger as Logger } from 'common'; import { SettingUpdatedEvent, SettingsUpdatedEvent } from 'structs'; export default class SettingsCategory { diff --git a/client/src/structs/settings/types/basesetting.js b/client/src/structs/settings/types/basesetting.js index f8cc90d2..e638400b 100644 --- a/client/src/structs/settings/types/basesetting.js +++ b/client/src/structs/settings/types/basesetting.js @@ -47,10 +47,6 @@ export default class Setting { return undefined; } - // get changed() { - // return this.args.changed; - // } - get text() { return this.args.text; } @@ -59,6 +55,10 @@ export default class Setting { return this.args.hint; } + get path() { + return this.args.path; + } + get disabled() { return this.args.disabled || false; } diff --git a/client/src/structs/settings/types/custom.js b/client/src/structs/settings/types/custom.js index b8cb5b79..eb95de93 100644 --- a/client/src/structs/settings/types/custom.js +++ b/client/src/structs/settings/types/custom.js @@ -11,19 +11,15 @@ import Setting from './basesetting'; import SettingsCategory from '../settingscategory'; import SettingsScheme from '../settingsscheme'; +import path from 'path'; export default class CustomSetting extends Setting { constructor(args) { super(args); - if (this.args.class_file) { - const component = window.require(path.join(this.path, this.args.class_file)); - const setting_class = this.args.class ? component[this.args.class](CustomSetting) : component.default ? component.default(CustomSetting) : component(CustomSetting); - - const setting = new setting_class(this.args); - if (setting instanceof CustomSetting) return setting; - } + if (this.args.class_file && this.path) + this.setClass(this.args.class_file, this.args.class); } get file() { @@ -38,12 +34,27 @@ export default class CustomSetting extends Setting { return this.args.component; } - get path() { - return this.args.path; - } - get debug() { return this.args.debug || false; } + setContentPath(_path) { + this.args.path = _path; + + if (this.args.class_file) + this.setClass(this.args.class_file, this.args.class); + + console.log(`Custom setting ${this.id}:`, this); + } + + setClass(class_file, class_export) { + const component = window.require(path.join(this.path, this.args.class_file)); + const setting_class = class_export ? component[class_export](CustomSetting) : component.default ? component.default(CustomSetting) : component(CustomSetting); + + if (!(setting_class.prototype instanceof CustomSetting)) + throw {message: 'Custom setting class function returned a class that doesn\'t extend from CustomSetting.'}; + + this.__proto__ = setting_class.prototype; + } + } diff --git a/tests/plugins/Example/component.js b/tests/plugins/Example/component.js index c82c1359..f7fd7fe3 100644 --- a/tests/plugins/Example/component.js +++ b/tests/plugins/Example/component.js @@ -2,3 +2,20 @@ module.exports.default = { template: "