commit
a97682b2a4
|
@ -16,6 +16,7 @@ import { ClientLogger as Logger } from 'common';
|
|||
class BetterDiscord {
|
||||
|
||||
constructor() {
|
||||
window.pm = PluginManager;
|
||||
window.events = Events;
|
||||
window.wpm = WebpackModules;
|
||||
DOM.injectStyle(BdCss, 'bdmain');
|
||||
|
|
|
@ -98,11 +98,14 @@ export default class {
|
|||
|
||||
try {
|
||||
const readUserConfig = await this.readUserConfig(contentPath);
|
||||
userConfig.config = userConfig.defaultConfig.map(config => {
|
||||
userConfig.enabled = readUserConfig.enabled || false;
|
||||
userConfig.config = readConfig.defaultConfig.map(config => {
|
||||
const userSet = readUserConfig.config.find(c => c.id === config.id);
|
||||
return userSet || config;
|
||||
});
|
||||
} catch (err) {/*We don't care if this fails it either means that user config doesn't exist or there's something wrong with it so we revert to default config*/ }
|
||||
} catch (err) { /*We don't care if this fails it either means that user config doesn't exist or there's something wrong with it so we revert to default config*/
|
||||
|
||||
}
|
||||
|
||||
const configs = {
|
||||
defaultConfig: readConfig.defaultConfig,
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { FileUtils } from 'common';
|
||||
|
||||
export default class {
|
||||
|
||||
constructor(pluginInternals) {
|
||||
|
@ -37,6 +39,7 @@ export default class {
|
|||
}
|
||||
|
||||
saveSettings(newSettings) {
|
||||
console.log(this);
|
||||
let changed = false;
|
||||
for (let newSetting of newSettings) {
|
||||
const setting = this.pluginConfig.find(s => s.id === newSetting.id && s.value !== newSetting.value);
|
||||
|
@ -46,6 +49,7 @@ export default class {
|
|||
changed = true;
|
||||
}
|
||||
if (changed && this.settingsSaved) this.settingsSaved(this.pluginConfig);
|
||||
FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({enabled: this.enabled, config: this.pluginConfig}));
|
||||
}
|
||||
|
||||
start() {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
background: #000;
|
||||
opacity: .85;
|
||||
padding: 20px;
|
||||
z-index: 9000;
|
||||
}
|
||||
|
||||
.bd-modal {
|
||||
|
@ -29,6 +30,7 @@
|
|||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
pointer-events: none;
|
||||
z-index: 9001;
|
||||
}
|
||||
|
||||
.bd-modal .bd-modal-inner {
|
||||
|
|
|
@ -13,14 +13,20 @@
|
|||
<div class="bd-backdrop" @click="attemptToClose"></div>
|
||||
<Modal :headerText="plugin.name + ' Settings'" :close="attemptToClose">
|
||||
<div slot="body" class="bd-plugin-settings-body">
|
||||
|
||||
<template v-for="category in categories">
|
||||
<template v-if="category === 'default'">
|
||||
<PluginSetting v-for="setting in configCache" v-if="!setting.category || setting.category === 'default'" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</template>
|
||||
<div v-else class="bd-category-container">
|
||||
<span>{{category}}</span>
|
||||
<PluginSetting v-for="setting in configCache" v-if="setting.category === category" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
<template v-for="category in configCache">
|
||||
<div v-if="category.category === 'default' || !category.type">
|
||||
<PluginSetting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
<div v-else-if="category.type === 'static'">
|
||||
{{category.category}} static with header
|
||||
<PluginSetting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
<div v-else-if="category.type === 'drawer'">
|
||||
{{category.category}} drawer
|
||||
<PluginSetting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
<div v-else>
|
||||
<PluginSetting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -44,8 +50,7 @@
|
|||
return {
|
||||
changed: false,
|
||||
warnclose: false,
|
||||
configCache: [],
|
||||
categories: ['default']
|
||||
configCache: []
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
@ -54,29 +59,35 @@
|
|||
},
|
||||
methods: {
|
||||
checkForChanges() {
|
||||
for (let cachedSetting of this.configCache) {
|
||||
if (this.plugin.pluginConfig.find(s => s.id === cachedSetting.id && s.value !== cachedSetting.value)) {
|
||||
return true;
|
||||
for (let category of this.configCache) {
|
||||
const cat = this.plugin.pluginConfig.find(c => c.category === category.category);
|
||||
for (let setting of category.settings) {
|
||||
if (cat.settings.find(s => s.id === setting.id).value !== setting.value) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
textInputKd(settingId) {
|
||||
},
|
||||
settingChange(settingId, newValue) {
|
||||
this.configCache.find(s => s.id === settingId).value = newValue;
|
||||
for (let category of this.configCache) {
|
||||
const found = category.settings.find(s => s.id === settingId);
|
||||
if (found) {
|
||||
found.value = newValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.changed = this.checkForChanges();
|
||||
},
|
||||
saveSettings() {
|
||||
this.plugin.saveSettings(this.configCache);
|
||||
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||
//this.plugin.saveSettings(this.configCache);
|
||||
//this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||
// TODO later
|
||||
this.changed = false;
|
||||
},
|
||||
resetSettings() {
|
||||
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||
this.changed = false;
|
||||
},
|
||||
attemptToClose() {
|
||||
attemptToClose(e) {
|
||||
if (!this.changed) return this.close();
|
||||
this.warnclose = true;
|
||||
setTimeout(() => {
|
||||
|
@ -86,11 +97,7 @@
|
|||
},
|
||||
beforeMount() {
|
||||
this.configCache = JSON.parse(JSON.stringify(this.plugin.pluginConfig));
|
||||
this.configCache.forEach(s => {
|
||||
if (!s.category || s.category === 'default') return;
|
||||
if (this.categories.includes(s.category)) return;
|
||||
this.categories.push(s.category);
|
||||
});
|
||||
console.log(this.configCache);
|
||||
this.changed = this.checkForChanges();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,99 +8,110 @@
|
|||
"main": "index.js",
|
||||
"defaultConfig": [
|
||||
{
|
||||
"id": "test-setting-1",
|
||||
"category": "test category",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting",
|
||||
"hint": "Bool Test Setting Hint"
|
||||
"category_default_comment": "default category has no header and is always displayed first",
|
||||
"category": "default",
|
||||
"settings": [
|
||||
{
|
||||
"id": "default-0",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
},
|
||||
{
|
||||
"id": "default-1",
|
||||
"type": "text",
|
||||
"value": "defaultValue",
|
||||
"text": "Text Test Setting",
|
||||
"hint": "Text Test Setting Hint"
|
||||
},
|
||||
{
|
||||
"id": "default-2",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
},
|
||||
{
|
||||
"id": "default-3",
|
||||
"type": "file",
|
||||
"value": null,
|
||||
"text": "Test File Setting 1",
|
||||
"hint": "File selector with the default options."
|
||||
},
|
||||
{
|
||||
"id": "default-4",
|
||||
"type": "file",
|
||||
"value": null,
|
||||
"text": "Test File Setting 2",
|
||||
"hint": "File selector with custom button text and the ability to open directories and multiple items.",
|
||||
"dialogOptions": {
|
||||
"buttonLabel": "Select",
|
||||
"properties": [
|
||||
"openFile",
|
||||
"openDirectory",
|
||||
"multiSelections"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "test-setting-2",
|
||||
"category": "test category 2",
|
||||
"type": "text",
|
||||
"value": "defaultValue",
|
||||
"text": "Text Test Setting",
|
||||
"hint": "Text Test Setting Hint"
|
||||
"category_header_comment": "Setting a category other than default has a header with category name as the text",
|
||||
"category": "Test Category",
|
||||
"drawer_type_comment": "// Drawer type will create an expandable drawer for the settings",
|
||||
"type": "drawer",
|
||||
"settings": [
|
||||
{
|
||||
"id": "drawer-0",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
},
|
||||
{
|
||||
"id": "drawer-1",
|
||||
"type": "text",
|
||||
"value": "defaultValue",
|
||||
"text": "Text Test Setting",
|
||||
"hint": "Text Test Setting Hint"
|
||||
},
|
||||
{
|
||||
"id": "drawer-2",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "test-setting-3",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 2",
|
||||
"hint": "Bool Test Setting Hint 2"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-4",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-5",
|
||||
"category": "test category",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 4",
|
||||
"hint": "Bool Test Setting Hint 4"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-6",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 5",
|
||||
"hint": "Bool Test Setting Hint 5"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-7",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 6",
|
||||
"hint": "Bool Test Setting Hint 6"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-8",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 7",
|
||||
"hint": "Bool Test Setting Hint 7"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-9",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 8",
|
||||
"hint": "Bool Test Setting Hint 8"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-10",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 9",
|
||||
"hint": "Bool Test Setting Hint 9"
|
||||
},
|
||||
{
|
||||
"id": "test-setting-file-1",
|
||||
"type": "file",
|
||||
"value": null,
|
||||
"text": "Test File Setting 1",
|
||||
"hint": "File selector with the default options."
|
||||
},
|
||||
{
|
||||
"id": "test-setting-file-2",
|
||||
"type": "file",
|
||||
"value": null,
|
||||
"text": "Test File Setting 2",
|
||||
"hint": "File selector with custom button text and the ability to open directories and multiple items.",
|
||||
"dialogOptions": {
|
||||
"buttonLabel": "Select",
|
||||
"properties": [
|
||||
"openFile",
|
||||
"openDirectory",
|
||||
"multiSelections"
|
||||
]
|
||||
}
|
||||
"category": "Test Category 2",
|
||||
"static_type_comment": "Static type will behave like default but will have a header",
|
||||
"type": "static",
|
||||
"settings": [
|
||||
{
|
||||
"id": "static-0",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
},
|
||||
{
|
||||
"id": "static-1",
|
||||
"type": "text",
|
||||
"value": "defaultValue",
|
||||
"text": "Text Test Setting",
|
||||
"hint": "Text Test Setting Hint"
|
||||
},
|
||||
{
|
||||
"id": "static-2",
|
||||
"type": "bool",
|
||||
"value": false,
|
||||
"text": "Bool Test Setting 3",
|
||||
"hint": "Bool Test Setting Hint 3"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue