Update internal settings format and use a generic settings panel
This commit is contained in:
parent
52f8c1cf31
commit
09cff282cb
|
@ -2,54 +2,85 @@
|
|||
{
|
||||
"id": "core",
|
||||
"text": "Core",
|
||||
"headertext": "Core Settings",
|
||||
"settings": [
|
||||
{
|
||||
"id": "test-setting",
|
||||
"text": "Test Setting",
|
||||
"hint": "Test Setting",
|
||||
"enabled": false,
|
||||
"disabled": false
|
||||
"category": "default",
|
||||
"settings": [
|
||||
{
|
||||
"id": "test-setting",
|
||||
"type": "bool",
|
||||
"text": "Test Setting",
|
||||
"hint": "Test Setting",
|
||||
"value": false,
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"id": "test-setting2",
|
||||
"type": "bool",
|
||||
"text": "Test Setting 2",
|
||||
"hint": "Test Setting 2",
|
||||
"value": true,
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"id": "voice-disconnect",
|
||||
"type": "bool",
|
||||
"text": "Voice Disconnect",
|
||||
"hint": "Disconnect from voice server when Discord closes",
|
||||
"value": false,
|
||||
"disabled": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "test-setting2",
|
||||
"text": "Test Setting 2",
|
||||
"hint": "Test Setting 2",
|
||||
"enabled": true,
|
||||
"disabled": false
|
||||
},
|
||||
{
|
||||
"id": "voice-disconnect",
|
||||
"text": "Voice Disconnect",
|
||||
"hint": "Disconnect from voice server when Discord closes",
|
||||
"enabled": false,
|
||||
"disabled": true
|
||||
},
|
||||
{
|
||||
"id": "developer-mode",
|
||||
"text": "Developer Mode",
|
||||
"hint": "BetterDiscord developer mode",
|
||||
"enabled": false,
|
||||
"disabled": true
|
||||
"category": "Advanced",
|
||||
"type": "drawer",
|
||||
"settings": [
|
||||
{
|
||||
"id": "developer-mode",
|
||||
"type": "bool",
|
||||
"text": "Developer Mode",
|
||||
"hint": "BetterDiscord developer mode",
|
||||
"value": false,
|
||||
"disabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "ui",
|
||||
"text": "UI",
|
||||
"headertext": "UI Settings",
|
||||
"settings": [
|
||||
|
||||
{
|
||||
"category": "default",
|
||||
"settings": [
|
||||
{
|
||||
"id": "hide-button",
|
||||
"type": "bool",
|
||||
"text": "Hide the BetterDiscord menu button",
|
||||
"hint": "When this is enabled you can use Control/Command + B to open the BetterDiscord menu",
|
||||
"value": false,
|
||||
"disabled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "emotes",
|
||||
"text": "Emotes",
|
||||
"headertext": "Emote Settings",
|
||||
"settings": []
|
||||
},
|
||||
{
|
||||
"id": "security",
|
||||
"text": "Security",
|
||||
"headertext": "Security Settings",
|
||||
"settings": [
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
|
@ -24,15 +24,20 @@ export default class {
|
|||
|
||||
this.settings = defaultSettings;
|
||||
|
||||
for (let newCategory of settings) {
|
||||
let category = this.settings.find(c => c.id === newCategory.id);
|
||||
if (!category) continue;
|
||||
for (let newSet of settings) {
|
||||
let set = this.settings.find(s => s.id === newSet.id);
|
||||
if (!set) continue;
|
||||
|
||||
for (let newSetting of newCategory.settings) {
|
||||
let setting = category.settings.find(s => s.id === newSetting.id);
|
||||
if (!setting) continue;
|
||||
for (let newCategory of newSet.settings) {
|
||||
let category = this.settings.find(c => c.category === newCategory.category);
|
||||
if (!category) continue;
|
||||
|
||||
setting.enabled = newSetting.enabled;
|
||||
for (let newSetting of newCategory.settings) {
|
||||
let setting = category.settings.find(s => s.id === newSetting.id);
|
||||
if (!setting) continue;
|
||||
|
||||
setting.value = newSetting.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -48,13 +53,18 @@ export default class {
|
|||
|
||||
const settingsPath = path.resolve(this.dataPath, 'user.settings.json');
|
||||
await FileUtils.writeJsonToFile(settingsPath, {
|
||||
settings: this.getSettings.map(category => {
|
||||
settings: this.getSettings.map(set => {
|
||||
return {
|
||||
id: category.id,
|
||||
settings: category.settings.map(setting => {
|
||||
id: set.id,
|
||||
settings: set.settings.map(category => {
|
||||
return {
|
||||
id: setting.id,
|
||||
enabled: setting.enabled
|
||||
category: category.category,
|
||||
settings: category.settings.map(setting => {
|
||||
return {
|
||||
id: setting.id,
|
||||
value: setting.value
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
};
|
||||
|
@ -67,6 +77,25 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
static setSetting(set_id, category_id, setting_id, value) {
|
||||
for (let set of this.getSettings) {
|
||||
if (set.id !== set_id) continue;
|
||||
|
||||
for (let category of set.settings) {
|
||||
if (category.category !== category_id) continue;
|
||||
|
||||
for (let setting of category.settings) {
|
||||
if (setting.id !== setting_id) continue;
|
||||
|
||||
setting.value = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static get getSettings() {
|
||||
return this.settings ? this.settings : defaultSettings;
|
||||
}
|
||||
|
|
|
@ -34,18 +34,14 @@
|
|||
</div>
|
||||
</div>
|
||||
<ContentColumn slot="content">
|
||||
<div v-if="activeContent('core') || animatingContent('core')" :class="{active: activeContent('core'), animating: animatingContent('core')}">
|
||||
<CoreSettings :settings="coreSettings" :enableSetting="enableSetting" :disableSetting="disableSetting" />
|
||||
</div>
|
||||
<div v-if="activeContent('ui') || animatingContent('ui')" :class="{active: activeContent('ui'), animating: animatingContent('ui')}">
|
||||
<UISettings />
|
||||
<div v-for="set in settings" v-if="activeContent(set.id) || animatingContent(set.id)" :class="{active: activeContent(set.id), animating: animatingContent(set.id)}">
|
||||
<SettingsWrapper :headertext="set.headertext">
|
||||
<SettingsPanel :settings="set.settings" :change="(c, s, v) => changeSetting(set.id, c, s, v)" />
|
||||
</SettingsWrapper>
|
||||
</div>
|
||||
<div v-if="activeContent('css') || animatingContent('css')" :class="{active: activeContent('css'), animating: animatingContent('css')}">
|
||||
<CssEditorView />
|
||||
</div>
|
||||
<div v-if="activeContent('emotes') || animatingContent('emotes')" :class="{active: activeContent('emotes'), animating: animatingContent('emotes')}">
|
||||
<EmoteSettings />
|
||||
</div>
|
||||
<div v-if="activeContent('plugins') || animatingContent('plugins')" :class="{active: activeContent('plugins'), animating: animatingContent('plugins')}">
|
||||
<PluginsView />
|
||||
</div>
|
||||
|
@ -61,7 +57,7 @@
|
|||
import { shell } from 'electron';
|
||||
import { Settings } from 'modules';
|
||||
import { SidebarView, Sidebar, SidebarItem, ContentColumn } from './sidebar';
|
||||
import { CoreSettings, UISettings, EmoteSettings, CssEditorView, PluginsView, ThemesView } from './bd';
|
||||
import { SettingsWrapper, SettingsPanel, CssEditorView, PluginsView, ThemesView } from './bd';
|
||||
import { SvgX, MiGithubCircle, MiWeb, MiClose, MiTwitterCircle } from './common';
|
||||
|
||||
// Constants
|
||||
|
@ -88,14 +84,9 @@
|
|||
}
|
||||
},
|
||||
props: ['active', 'close'],
|
||||
computed: {
|
||||
coreSettings() {
|
||||
return this.settings.find(settingset => settingset.id === 'core').settings;
|
||||
}
|
||||
},
|
||||
components: {
|
||||
SidebarView, Sidebar, SidebarItem, ContentColumn,
|
||||
CoreSettings, UISettings, EmoteSettings, CssEditorView, PluginsView, ThemesView,
|
||||
SettingsWrapper, SettingsPanel, PluginsView, ThemesView,
|
||||
MiGithubCircle, MiWeb, MiClose, MiTwitterCircle
|
||||
},
|
||||
methods: {
|
||||
|
@ -123,24 +114,11 @@
|
|||
if (!item) return false;
|
||||
return item.id === this.lastActiveIndex;
|
||||
},
|
||||
enableSetting(cat, id) {
|
||||
switch (cat) {
|
||||
case 'core':
|
||||
this.coreSettings.find(setting => setting.id === id).enabled = true; break;
|
||||
}
|
||||
|
||||
Settings.saveSettings();
|
||||
},
|
||||
disableSetting(cat, id) {
|
||||
switch (cat) {
|
||||
case 'core':
|
||||
this.coreSettings.find(setting => setting.id === id).enabled = false; break;
|
||||
}
|
||||
|
||||
changeSetting(set_id, category_id, setting_id, value) {
|
||||
Settings.setSetting(set_id, category_id, setting_id, value);
|
||||
Settings.saveSettings();
|
||||
},
|
||||
openGithub() {
|
||||
console.log('open github?');
|
||||
shell.openExternal('https://github.com/JsSucks/BetterDiscordApp');
|
||||
},
|
||||
openWebsite() {
|
||||
|
|
|
@ -9,37 +9,16 @@
|
|||
*/
|
||||
|
||||
<template>
|
||||
<div class="bd-plugin-settings-modal">
|
||||
<div class="bd-plugin-settings-modal" :class="{'bd-edited': changed}">
|
||||
<div class="bd-backdrop" @click="attemptToClose" :class="{'bd-backdrop-out': closing}"></div>
|
||||
<Modal :headerText="plugin.name + ' Settings'" :close="attemptToClose" :class="{'bd-modal-out': closing}">
|
||||
<div slot="body" class="bd-plugin-settings-body">
|
||||
<template v-for="category in configCache">
|
||||
<div v-if="category.category === 'default' || !category.type">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
<div v-else-if="category.type === 'static'">
|
||||
<div class="bd-form-header">
|
||||
<span class="bd-form-header-text">{{category.category}} static with header</span>
|
||||
</div>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
<Drawer v-else-if="category.type === 'drawer'" :label="category.category + ' drawer'">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</Drawer>
|
||||
<div v-else>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
<SettingsPanel :settings="configCache" :change="settingChange" slot="body" class="bd-plugin-settings-body" />
|
||||
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
|
||||
<div class="bd-footer-alert-text">Unsaved changes</div>
|
||||
<div class="bd-button bd-reset-button bd-tp" :class="{'bd-disabled': saving}" @click="resetSettings">Reset</div>
|
||||
<div class="bd-button bd-ok" :class="{'bd-disabled': saving}" @click="saveSettings">
|
||||
<div v-if="saving" class="bd-spinner-7"></div>
|
||||
<template v-else>
|
||||
Save Changes
|
||||
</template>
|
||||
<template v-else>Save Changes</template>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
@ -47,9 +26,9 @@
|
|||
</template>
|
||||
<script>
|
||||
// Imports
|
||||
import Vue from 'vue';
|
||||
import { Modal } from '../common';
|
||||
import Setting from './setting/Setting.vue';
|
||||
import Drawer from '../common/Drawer.vue';
|
||||
import SettingsPanel from './SettingsPanel.vue';
|
||||
|
||||
export default {
|
||||
props: ['plugin','close'],
|
||||
|
@ -64,8 +43,7 @@
|
|||
},
|
||||
components: {
|
||||
Modal,
|
||||
Setting,
|
||||
Drawer
|
||||
SettingsPanel,
|
||||
},
|
||||
methods: {
|
||||
checkForChanges() {
|
||||
|
@ -75,22 +53,23 @@
|
|||
for (let setting of category.settings) {
|
||||
if (cat.settings.find(s => s.id === setting.id).value !== setting.value) {
|
||||
changed = true;
|
||||
setting.changed = true;
|
||||
Vue.set(setting, 'changed', true);
|
||||
} else {
|
||||
setting.changed = false;
|
||||
Vue.set(setting, 'changed', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
},
|
||||
settingChange(settingId, newValue) {
|
||||
for (let category of this.configCache) {
|
||||
const found = category.settings.find(s => s.id === settingId);
|
||||
if (found) {
|
||||
found.value = newValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
settingChange(category_id, setting_id, value) {
|
||||
const category = this.configCache.find(c => c.category === category_id);
|
||||
if (!category) return;
|
||||
|
||||
const setting = category.settings.find(s => s.id === setting_id);
|
||||
if (!setting) return;
|
||||
|
||||
setting.value = value;
|
||||
|
||||
this.changed = this.checkForChanges();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* BetterDiscord Settings Panel Component
|
||||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||
* All rights reserved.
|
||||
* https://betterdiscord.net
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<template v-for="category in settings">
|
||||
<div v-if="category.category === 'default' || !category.type">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
<div v-else-if="category.type === 'static'">
|
||||
<div class="bd-form-header">
|
||||
<span class="bd-form-header-text">{{category.category}} static with header</span>
|
||||
</div>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
<Drawer v-else-if="category.type === 'drawer'" :label="category.category">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</Drawer>
|
||||
<div v-else>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// Imports
|
||||
import Setting from './setting/Setting.vue';
|
||||
import Drawer from '../common/Drawer.vue';
|
||||
|
||||
export default {
|
||||
props: ['settings', 'change'],
|
||||
components: {
|
||||
Setting,
|
||||
Drawer
|
||||
},
|
||||
methods: {
|
||||
settingChange(setting_id, value) {
|
||||
for (let category of this.settings) {
|
||||
let setting = category.settings.find(s => s.id === setting_id);
|
||||
if (!setting) continue;
|
||||
|
||||
this.change(category.category, setting_id, value);
|
||||
}
|
||||
|
||||
this.$forceUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -12,26 +12,7 @@
|
|||
<div class="bd-plugin-settings-modal" :class="{'bd-edited': changed}">
|
||||
<div class="bd-backdrop" @click="attemptToClose" :class="{'bd-backdrop-out': closing}"></div>
|
||||
<Modal :headerText="theme.name + ' Settings'" :close="attemptToClose" :class="{'bd-modal-out': closing}">
|
||||
<div slot="body" class="bd-plugin-settings-body">
|
||||
<template v-for="category in configCache">
|
||||
<div v-if="category.category === 'default' || !category.type">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
<div v-else-if="category.type === 'static'">
|
||||
<div class="bd-form-header">
|
||||
<span class="bd-form-header-text">{{category.category}} static with header</span>
|
||||
</div>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
<Drawer v-else-if="category.type === 'drawer'" :label="category.category + ' drawer'">
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</Drawer>
|
||||
<div v-else>
|
||||
<Setting v-for="setting in category.settings" :key="setting.id" :setting="setting" :change="settingChange" :changed="setting.changed"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</div>
|
||||
<SettingsPanel :settings="configCache" :change="settingChange" slot="body" class="bd-plugin-settings-body" />
|
||||
<div slot="footer" class="bd-footer-alert" :class ="{'bd-active': changed, 'bd-warn': warnclose}">
|
||||
<div class="bd-footer-alert-text">Unsaved changes</div>
|
||||
<div class="bd-button bd-reset-button bd-tp" :class="{'bd-disabled': saving}" @click="resetSettings">Reset</div>
|
||||
|
@ -45,9 +26,9 @@
|
|||
</template>
|
||||
<script>
|
||||
// Imports
|
||||
import Vue from 'vue';
|
||||
import { Modal } from '../common';
|
||||
import Setting from './setting/Setting.vue';
|
||||
import Drawer from '../common/Drawer.vue';
|
||||
import SettingsPanel from './SettingsPanel.vue';
|
||||
|
||||
export default {
|
||||
props: ['theme', 'close'],
|
||||
|
@ -62,8 +43,7 @@
|
|||
},
|
||||
components: {
|
||||
Modal,
|
||||
Setting,
|
||||
Drawer
|
||||
SettingsPanel
|
||||
},
|
||||
methods: {
|
||||
checkForChanges() {
|
||||
|
@ -73,22 +53,23 @@
|
|||
for (let setting of category.settings) {
|
||||
if (cat.settings.find(s => s.id === setting.id).value !== setting.value) {
|
||||
changed = true;
|
||||
setting.changed = true;
|
||||
Vue.set(setting, 'changed', true);
|
||||
} else {
|
||||
setting.changed = false;
|
||||
Vue.set(setting, 'changed', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
},
|
||||
settingChange(settingId, newValue) {
|
||||
for (let category of this.configCache) {
|
||||
const found = category.settings.find(s => s.id === settingId);
|
||||
if (found) {
|
||||
found.value = newValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
settingChange(category_id, setting_id, value) {
|
||||
const category = this.configCache.find(c => c.category === category_id);
|
||||
if (!category) return;
|
||||
|
||||
const setting = category.settings.find(s => s.id === setting_id);
|
||||
if (!setting) return;
|
||||
|
||||
setting.value = value;
|
||||
|
||||
this.changed = this.checkForChanges();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export { default as SettingsWrapper } from './SettingsWrapper.vue';
|
||||
export { default as SettingsPanel } from './SettingsPanel.vue';
|
||||
export { default as CoreSettings } from './CoreSettings.vue';
|
||||
export { default as UISettings } from './UISettings.vue';
|
||||
export { default as EmoteSettings } from './EmoteSettings.vue';
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
export default {
|
||||
props: [
|
||||
'setting',
|
||||
'change',
|
||||
'changed'
|
||||
'change'
|
||||
],
|
||||
components: {
|
||||
BoolSetting,
|
||||
|
@ -47,6 +46,11 @@
|
|||
MultilineTextSetting,
|
||||
SliderSetting,
|
||||
FileSetting
|
||||
},
|
||||
computed: {
|
||||
changed() {
|
||||
return this.setting.changed || false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue