2018-02-14 09:05:34 +01:00
|
|
|
module.exports = (Plugin, Api, Vendor, Dependencies) => {
|
2018-01-16 02:45:23 +01:00
|
|
|
|
2018-02-11 23:07:23 +01:00
|
|
|
const { $, moment, _ } = Vendor;
|
2018-03-02 20:42:17 +01:00
|
|
|
const { Events, Logger, InternalSettings, CssUtils } = Api;
|
2018-01-16 02:45:23 +01:00
|
|
|
|
2018-02-12 16:20:27 +01:00
|
|
|
return class extends Plugin {
|
2018-03-02 20:42:17 +01:00
|
|
|
async onStart() {
|
|
|
|
await this.injectStyles();
|
|
|
|
|
2018-02-12 00:04:07 +01:00
|
|
|
Events.subscribe('TEST_EVENT', this.eventTest);
|
2018-02-11 23:07:23 +01:00
|
|
|
Logger.log('onStart');
|
2018-02-14 00:23:52 +01:00
|
|
|
|
2018-02-13 23:37:24 +01:00
|
|
|
Logger.log(`Plugin setting "default-0" value: ${this.getSetting('default-0')}`);
|
2018-02-14 00:23:52 +01:00
|
|
|
this.events.on('setting-updated', event => {
|
|
|
|
console.log('Received plugin setting update:', event);
|
|
|
|
});
|
|
|
|
this.events.on('settings-updated', event => {
|
|
|
|
console.log('Received plugin settings update:', event);
|
|
|
|
});
|
2018-02-13 23:37:24 +01:00
|
|
|
|
2018-03-02 20:42:17 +01:00
|
|
|
this.settings.on('setting-updated', event => {
|
|
|
|
Logger.log(`Setting ${event.category.id}/${event.setting.id} changed from ${event.old_value} to ${event.value}:`, event);
|
|
|
|
});
|
|
|
|
|
|
|
|
// this.settings.categories.find(c => c.id === 'default').settings.find(s => s.id === 'default-5')
|
|
|
|
this.settings.getSetting('default', 'default-0').on('setting-updated', async event => {
|
|
|
|
Logger.log(`Some feature ${event.value ? 'enabled' : 'disabled'}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.settings.on('settings-updated', async event => {
|
|
|
|
await this.injectStyles();
|
|
|
|
|
|
|
|
Logger.log('Settings updated:', event, 'Waiting before saving complete...');
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
|
|
Logger.log('Done');
|
|
|
|
});
|
|
|
|
|
|
|
|
Logger.log(`Internal setting "core/default/test-setting" value: ${InternalSettings.get('core', 'default', 'test-setting')}`);
|
2018-02-14 00:23:52 +01:00
|
|
|
Events.subscribe('setting-updated', event => {
|
|
|
|
console.log('Received internal setting update:', event);
|
2018-02-13 23:37:24 +01:00
|
|
|
});
|
2018-02-13 17:26:20 +01:00
|
|
|
|
2018-02-14 09:05:34 +01:00
|
|
|
const exampleModule = new Dependencies['Example Module'];
|
2018-02-13 17:26:20 +01:00
|
|
|
Logger.log(`2+4=${exampleModule.add(2, 4)}`);
|
2018-01-31 09:32:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:42:17 +01:00
|
|
|
async injectStyles() {
|
|
|
|
const scss = await CssUtils.getConfigAsSCSS() + `.layer-kosS71 .guilds-wrapper + * {
|
|
|
|
&::before {
|
|
|
|
content: 'Example plugin stuff (test radio setting #{$default-5} selected)';
|
|
|
|
display: block;
|
|
|
|
padding: 10px 40px;
|
|
|
|
color: #eee;
|
|
|
|
background-color: #202225;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
}`;
|
|
|
|
Logger.log('Plugin SCSS:', scss);
|
|
|
|
await CssUtils.injectSass(scss);
|
|
|
|
}
|
|
|
|
|
2018-01-31 09:32:20 +01:00
|
|
|
onStop() {
|
2018-03-02 20:42:17 +01:00
|
|
|
CssUtils.deleteAllStyles();
|
2018-02-12 00:04:07 +01:00
|
|
|
Events.unsubscribeAll();
|
2018-02-11 23:07:23 +01:00
|
|
|
Logger.log('onStop');
|
2018-02-13 18:07:51 +01:00
|
|
|
console.log(this.showSettingsModal());
|
2018-01-23 14:19:55 +01:00
|
|
|
return true;
|
2018-01-16 02:45:23 +01:00
|
|
|
}
|
2018-02-12 00:04:07 +01:00
|
|
|
|
2018-02-21 18:46:27 +01:00
|
|
|
onUnload(reload) {
|
|
|
|
Logger.log('Unloading plugin');
|
|
|
|
delete require.cache[require.resolve('./component')];
|
|
|
|
}
|
|
|
|
|
2018-02-12 00:04:07 +01:00
|
|
|
eventTest(e) {
|
|
|
|
Logger.log(e);
|
|
|
|
}
|
2018-02-12 16:20:27 +01:00
|
|
|
|
2018-02-13 17:43:44 +01:00
|
|
|
get bridge() {
|
2018-02-12 23:49:44 +01:00
|
|
|
return {
|
|
|
|
test1: this.test1.bind(this),
|
|
|
|
test2: this.test2.bind(this)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
test1() { return 'It works!'; }
|
|
|
|
test2() { return 'This works too!'; }
|
|
|
|
|
2018-02-12 16:20:27 +01:00
|
|
|
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 ]);
|
|
|
|
}
|
2018-02-21 16:58:45 +01:00
|
|
|
|
|
|
|
get settingscomponent() {
|
|
|
|
const plugin = this;
|
|
|
|
return this._settingscomponent ? this._settingscomponent : this._settingscomponent = {
|
|
|
|
template: "<div style=\"margin-bottom: 15px; background-color: rgba(0, 0, 0, 0.2); border: 1px dashed rgba(255, 255, 255, 0.2); padding: 10px; color: #f6f6f7; font-weight: 500; font-size: 15px;\">Test custom setting {{ setting.id }}. This is from Plugin.settingscomponent.<br />Plugin ID: {{ plugin.id }}</div>",
|
|
|
|
props: ['setting', 'change'],
|
|
|
|
data() { return { plugin }; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettingsComponent(setting, change) {
|
|
|
|
return this._settingscomponent2 ? this._settingscomponent2 : this.settingscomponent2 = {
|
|
|
|
template: "<div style=\"margin-bottom: 15px; background-color: rgba(0, 0, 0, 0.2); border: 1px dashed rgba(255, 255, 255, 0.2); padding: 10px; color: #f6f6f7; font-weight: 500; font-size: 15px;\">Test custom setting {{ setting.id }}. This is from Plugin.getSettingsComponent().</div>",
|
|
|
|
props: ['setting', 'change']
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettingsComponentHTMLElement(setting, change) {
|
|
|
|
const el = document.createElement('div');
|
|
|
|
el.setAttribute('style', 'margin-bottom: 15px; background-color: rgba(0, 0, 0, 0.2); border: 1px dashed rgba(255, 255, 255, 0.2); padding: 10px; color: #f6f6f7; font-weight: 500; font-size: 15px;');
|
|
|
|
el.textContent = `Test custom setting ${setting.id}. This is from Plugin.getSettingsComponentHTMLElement(). Current value: ${setting.value}.`;
|
|
|
|
|
|
|
|
const button1 = document.createElement('button');
|
|
|
|
button1.setAttribute('class', 'bd-button bd-button-primary');
|
|
|
|
button1.setAttribute('style', 'display: inline-block; margin-left: 10px;');
|
|
|
|
button1.addEventListener('click', () => change(1));
|
|
|
|
button1.textContent = 'Set value to 1';
|
|
|
|
el.appendChild(button1);
|
|
|
|
|
|
|
|
const button2 = document.createElement('button');
|
|
|
|
button2.setAttribute('class', 'bd-button bd-button-primary');
|
|
|
|
button2.setAttribute('style', 'display: inline-block; margin-left: 10px;');
|
|
|
|
button2.addEventListener('click', () => change(2));
|
|
|
|
button2.textContent = 'Set value to 2';
|
|
|
|
el.appendChild(button2);
|
|
|
|
|
|
|
|
return el;
|
|
|
|
}
|
2018-01-16 02:45:23 +01:00
|
|
|
}
|
|
|
|
|
2018-02-12 16:20:27 +01:00
|
|
|
}
|