Merge pull request #121 from samuelthomas2774/fix-plugin-getsetting

Fix Plugin.getSetting
This commit is contained in:
Alexei Stukov 2018-02-12 21:20:02 +02:00 committed by GitHub
commit 9aeb5972cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -35,8 +35,14 @@ export default class {
get enabled() { return this.userConfig.enabled }
get pluginConfig() { return this.userConfig.config }
getSetting(settingId) {
return this.userConfig.config.find(setting => setting.id === settingId);
getSetting(setting_id, category_id) {
for (let category of this.pluginConfig) {
if (category_id && category.category !== category_id) return;
for (let setting of category.settings) {
if (setting.id !== setting_id) return;
return setting.value;
}
}
}
async saveSettings(newSettings) {

View File

@ -2,11 +2,12 @@ module.exports = (Plugin, Api, Vendor) => {
const { $, moment, _ } = Vendor;
const { Events, Logger } = Api;
return class extends Plugin {
return class extends Plugin {
onStart() {
Events.subscribe('TEST_EVENT', this.eventTest);
Logger.log('onStart');
Logger.log(`Setting "default-0" value: ${this.getSetting('default-0')}`);
return true;
}
@ -19,6 +20,16 @@ module.exports = (Plugin, Api, Vendor) => {
eventTest(e) {
Logger.log(e);
}
settingChanged(category, setting_id, value) {
if (!this.enabled) return;
Logger.log(`${category}/${setting_id} changed to ${value}`);
}
settingsChanged(settings) {
if (!this.enabled) return;
Logger.log([ 'Settings updated', settings ]);
}
}
}
}