Add internal settings access to the plugin API

This commit is contained in:
Samuel Elliott 2018-02-13 22:37:24 +00:00
parent 210d085caf
commit 9b9162346b
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,7 @@
*/
import { ClientLogger as Logger } from 'common';
import Settings from './settings';
import PluginManager from './pluginmanager';
import ThemeManager from './thememanager';
import Events from './events';
@ -66,6 +67,15 @@ export default class PluginApi {
}
}
getSetting(set, category, setting) {
return Settings.get(set, category, setting);
}
get Settings() {
return {
get: this.getSetting.bind(this)
};
}
async getPlugin(plugin_id) {
// This should require extra permissions
return await PluginManager.waitForPlugin(plugin_id);

View File

@ -7,7 +7,12 @@ module.exports = (Plugin, Api, Vendor) => {
onStart() {
Events.subscribe('TEST_EVENT', this.eventTest);
Logger.log('onStart');
Logger.log(`Setting "default-0" value: ${this.getSetting('default-0')}`);
Logger.log(`Plugin setting "default-0" value: ${this.getSetting('default-0')}`);
Logger.log(`Internal setting "core/default/test-setting" value: ${Api.Settings.get('core', 'default', 'test-setting')}`);
Events.subscribe('setting-updated', setting => {
console.log('Received internal setting update:', setting);
});
const exampleModule = new (Api.import('Example Module'));
Logger.log(`2+4=${exampleModule.add(2, 4)}`);