From 50badaef2bd1ad08cbb12975280ad0a63768ab2b Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 9 Aug 2018 17:20:06 +0300 Subject: [PATCH 01/17] add collection and make kvp functional --- client/src/data/user.settings.default.json | 17 ++++++++--- client/src/structs/settings/setting.js | 3 +- .../src/structs/settings/types/collection.js | 29 +++++++++++++++++++ client/src/structs/settings/types/index.js | 1 + client/src/structs/settings/types/kvp.js | 2 +- .../ui/components/bd/setting/Collection.vue | 28 ++++++++++++++++++ .../ui/components/bd/setting/KeyValuePair.vue | 15 ++++++---- .../src/ui/components/bd/setting/Setting.vue | 5 +++- 8 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 client/src/structs/settings/types/collection.js create mode 100644 client/src/ui/components/bd/setting/Collection.vue diff --git a/client/src/data/user.settings.default.json b/client/src/data/user.settings.default.json index 3a57d7c8..0698f71f 100644 --- a/client/src/data/user.settings.default.json +++ b/client/src/data/user.settings.default.json @@ -171,10 +171,19 @@ "type": "drawer", "settings": [ { - "id": "kvp0", - "type": "kvp", - "text": "", - "value": { "key": "kvpKey", "value": "kvpValue" } + "id": "e2ekvps", + "type": ["kvp"], + "value": [ + { + "id": "kvp0", + "type": "kvp", + "text": "", + "value": { + "key": "kvpKey", + "value": "kvpValue" + } + } + ] } ] } diff --git a/client/src/structs/settings/setting.js b/client/src/structs/settings/setting.js index 82ba7ba1..3eec79b9 100644 --- a/client/src/structs/settings/setting.js +++ b/client/src/structs/settings/setting.js @@ -19,6 +19,7 @@ import KeybindSetting from './types/keybind'; import FileSetting from './types/file'; import GuildSetting from './types/guild'; import ArraySetting from './types/array'; +import CollectionSetting from './types/collection'; import KvpSetting from './types/kvp'; import CustomSetting from './types/custom'; @@ -26,7 +27,7 @@ export default class Setting { constructor(args, ...merge) { args = args.args || args; - + if (args.type instanceof Array) return new CollectionSetting(args, ...merge); if (args.type === 'color') args.type = 'colour'; if (args.type === 'bool') return new BoolSetting(args, ...merge); diff --git a/client/src/structs/settings/types/collection.js b/client/src/structs/settings/types/collection.js new file mode 100644 index 00000000..011a1eb1 --- /dev/null +++ b/client/src/structs/settings/types/collection.js @@ -0,0 +1,29 @@ +/** + * BetterDiscord Collection Setting Struct + * 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. + */ + +import BaseSetting from './basesetting'; +import Setting from '../setting'; + +export default class CollectionSetting extends BaseSetting { + + constructor(args) { + super(args); + this.subtype = args.type[0]; + args.type = 'collection'; + this.sub = new Setting({ type: this.subtype }); + } + + /** + * The value to use when the setting doesn't have a value. + */ + get defaultValue() { + return []; + } +} diff --git a/client/src/structs/settings/types/index.js b/client/src/structs/settings/types/index.js index 16f60e1e..3ad64c51 100644 --- a/client/src/structs/settings/types/index.js +++ b/client/src/structs/settings/types/index.js @@ -10,4 +10,5 @@ export { default as FileSetting } from './file'; export { default as GuildSetting } from './guild'; export { default as ArraySetting } from './array'; export { default as KvpSetting } from './kvp'; +export { default as CollectionSetting } from './kvp'; export { default as CustomSetting } from './custom'; diff --git a/client/src/structs/settings/types/kvp.js b/client/src/structs/settings/types/kvp.js index 52c4a04a..466b0094 100644 --- a/client/src/structs/settings/types/kvp.js +++ b/client/src/structs/settings/types/kvp.js @@ -16,6 +16,6 @@ export default class KvpSetting extends Setting { * The value to use when the setting doesn't have a value. */ get defaultValue() { - return { key: 'Channel ID', value: 'Encryption Key' }; + return { key: 'Key', value: 'Value' }; } } diff --git a/client/src/ui/components/bd/setting/Collection.vue b/client/src/ui/components/bd/setting/Collection.vue new file mode 100644 index 00000000..0a61edf2 --- /dev/null +++ b/client/src/ui/components/bd/setting/Collection.vue @@ -0,0 +1,28 @@ +/** + * BetterDiscord Setting Bool 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. +*/ + + + + diff --git a/client/src/ui/components/bd/setting/KeyValuePair.vue b/client/src/ui/components/bd/setting/KeyValuePair.vue index e946c72a..b0e2cade 100644 --- a/client/src/ui/components/bd/setting/KeyValuePair.vue +++ b/client/src/ui/components/bd/setting/KeyValuePair.vue @@ -12,12 +12,11 @@
- +
- +
-
@@ -25,7 +24,13 @@ diff --git a/client/src/ui/components/bd/setting/Setting.vue b/client/src/ui/components/bd/setting/Setting.vue index 481e4ea0..3fb42e2f 100644 --- a/client/src/ui/components/bd/setting/Setting.vue +++ b/client/src/ui/components/bd/setting/Setting.vue @@ -22,7 +22,8 @@ - + +
@@ -42,6 +43,7 @@ import FileSetting from './File.vue'; import GuildSetting from './Guild.vue'; import ArraySetting from './Array.vue'; + import Collection from './Collection.vue'; import KeyValuePair from './KeyValuePair.vue'; import CustomSetting from './Custom.vue'; @@ -62,6 +64,7 @@ FileSetting, GuildSetting, ArraySetting, + Collection, KeyValuePair, CustomSetting }, From 5af8a2168d5cbe43461affac1427041ed268811c Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Thu, 9 Aug 2018 11:31:11 -0400 Subject: [PATCH 02/17] fix class search --- client/src/ui/classnormaliser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/ui/classnormaliser.js b/client/src/ui/classnormaliser.js index f8509bf4..52cf0bf7 100644 --- a/client/src/ui/classnormaliser.js +++ b/client/src/ui/classnormaliser.js @@ -29,8 +29,8 @@ export default class ClassNormaliser extends Module { shouldIgnore(value) { if (!isNaN(value)) return true; if (value.endsWith('px') || value.endsWith('ch') || value.endsWith('em') || value.endsWith('ms')) return true; - if (value.startsWith('rgba')) return true; - if (value.includes('calc(')) return true; + if (value.startsWith('#') && (value.length == 7 || value.length == 4)) return true; + if (value.includes('calc(') || value.includes('rgba')) return true; return false; } From 883f7602928003d1eafa927a27bad1bd575e9e27 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Thu, 9 Aug 2018 18:22:15 +0100 Subject: [PATCH 03/17] Extend ArraySetting for collections --- client/src/structs/settings/setting.js | 6 ++- .../src/structs/settings/types/collection.js | 40 ++++++++++++++----- .../ui/components/bd/setting/Collection.vue | 21 ++++++---- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/client/src/structs/settings/setting.js b/client/src/structs/settings/setting.js index 3eec79b9..618596ce 100644 --- a/client/src/structs/settings/setting.js +++ b/client/src/structs/settings/setting.js @@ -27,7 +27,8 @@ export default class Setting { constructor(args, ...merge) { args = args.args || args; - if (args.type instanceof Array) return new CollectionSetting(args, ...merge); + + if (args.type instanceof Array) args.subtype = args.type[0], args.type = 'collection'; if (args.type === 'color') args.type = 'colour'; if (args.type === 'bool') return new BoolSetting(args, ...merge); @@ -41,8 +42,9 @@ export default class Setting { else if (args.type === 'file') return new FileSetting(args, ...merge); else if (args.type === 'guild') return new GuildSetting(args, ...merge); else if (args.type === 'array') return new ArraySetting(args, ...merge); - else if (args.type === 'custom') return new CustomSetting(args, ...merge); + else if (args.type === 'collection') return new CollectionSetting(args, ...merge); else if (args.type === 'kvp') return new KvpSetting(args, ...merge); + else if (args.type === 'custom') return new CustomSetting(args, ...merge); else throw {message: `Setting type ${args.type} unknown`}; } diff --git a/client/src/structs/settings/types/collection.js b/client/src/structs/settings/types/collection.js index 011a1eb1..2390f489 100644 --- a/client/src/structs/settings/types/collection.js +++ b/client/src/structs/settings/types/collection.js @@ -8,22 +8,42 @@ * LICENSE file in the root directory of this source tree. */ -import BaseSetting from './basesetting'; +import { Utils } from 'common'; +import ArraySetting from './array'; import Setting from '../setting'; -export default class CollectionSetting extends BaseSetting { +export default class CollectionSetting extends ArraySetting { - constructor(args) { - super(args); - this.subtype = args.type[0]; - args.type = 'collection'; - this.sub = new Setting({ type: this.subtype }); + constructor(args, ...merge) { + // The ArraySetting constructor will call createItem which requires this to be set + if (!(args.setting instanceof Setting)) args.setting = new Setting(args.setting || {type: args.subtype}); + + super(args, ...merge); + } + + get setting() { + return this.args.setting; } /** - * The value to use when the setting doesn't have a value. + * Creates a new setting for this collection setting. + * @param {Setting} item Values to merge into the new setting (optional) + * @return {Setting} The new set */ - get defaultValue() { - return []; + createItem(item) { + if (item instanceof Setting) + return item; + + const merge = [...arguments].filter(a => a); + const setting = this.setting.clone(...merge); + setting.args.id = item ? item.args ? item.args.id : item.id : Math.random(); + + setting.setSaved(); + setting.on('settings-updated', async event => { + await this.emit('item-updated', { item: setting, event, updatedSettings: event.updatedSettings }); + if (event.args.updating_array !== this) await this.updateValue(); + }); + return setting; } + } diff --git a/client/src/ui/components/bd/setting/Collection.vue b/client/src/ui/components/bd/setting/Collection.vue index 0a61edf2..87c582bd 100644 --- a/client/src/ui/components/bd/setting/Collection.vue +++ b/client/src/ui/components/bd/setting/Collection.vue @@ -1,5 +1,5 @@ /** - * BetterDiscord Setting Bool Component + * BetterDiscord Collection Setting Component * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks * All rights reserved. * https://betterdiscord.net @@ -10,19 +10,24 @@ diff --git a/client/src/ui/components/sidebar/Item.vue b/client/src/ui/components/sidebar/Item.vue index 64d3a170..df2d94d0 100644 --- a/client/src/ui/components/sidebar/Item.vue +++ b/client/src/ui/components/sidebar/Item.vue @@ -9,7 +9,7 @@ */ @@ -18,7 +18,7 @@ import { SidebarHeader, SidebarButton } from './'; export default { - props: ['item'], + props: ['item', 'active'], components: { SidebarHeader, SidebarButton diff --git a/client/src/ui/components/sidebar/index.js b/client/src/ui/components/sidebar/index.js index cedb40f2..4a9b1685 100644 --- a/client/src/ui/components/sidebar/index.js +++ b/client/src/ui/components/sidebar/index.js @@ -3,4 +3,4 @@ export { default as Sidebar } from './Sidebar.vue'; export { default as SidebarHeader } from './Header.vue'; export { default as SidebarButton } from './Button.vue'; export { default as SidebarItem } from './Item.vue'; -export { default as ContentColumn } from './ContentColumn.vue'; \ No newline at end of file +export { default as ContentColumn } from './ContentColumn.vue'; From 89a5bfba20625e69313abf14e6ed4f95e0a674bd Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Thu, 9 Aug 2018 23:49:10 +0100 Subject: [PATCH 11/17] Make the hide button setting functional --- .../styles/partials/bdsettings/button.scss | 15 ++++++++++- .../src/styles/partials/discordoverrides.scss | 26 ++++++++++--------- client/src/ui/bdui.js | 9 ++++++- .../src/ui/components/BdSettingsWrapper.vue | 19 +++++++++++--- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/client/src/styles/partials/bdsettings/button.scss b/client/src/styles/partials/bdsettings/button.scss index 9ab8ae99..e2fc7fb3 100644 --- a/client/src/styles/partials/bdsettings/button.scss +++ b/client/src/styles/partials/bdsettings/button.scss @@ -43,9 +43,22 @@ } } + &.bd-hide-button { + transition: opacity 0.4s ease-out; + opacity: 0; + + &.bd-active { + transition-timing-function: ease-in; + } + } + &.bd-active { - background: transparent; opacity: 1; + } + + &.bd-active, + &.bd-hide-button { + background: transparent; box-shadow: none; .bd-settings-button-btn { diff --git a/client/src/styles/partials/discordoverrides.scss b/client/src/styles/partials/discordoverrides.scss index 6d051e20..42d668a9 100644 --- a/client/src/styles/partials/discordoverrides.scss +++ b/client/src/styles/partials/discordoverrides.scss @@ -1,20 +1,22 @@ -[class*="guildsWrapper-"] { - padding-top: 49px !important; +body:not(.bd-hide-button) { + [class*="guildsWrapper-"] { + padding-top: 49px !important; - .platform-osx & { - margin-top: 26px; + .platform-osx & { + margin-top: 26px; + } } -} -[class*="guildsWrapper-"] + [class*="flex"] { - border-radius: 0 0 0 5px; -} + [class*="guildsWrapper-"] + [class*="flex"] { + border-radius: 0 0 0 5px; + } -[class*="unreadMentionsIndicatorTop-"] { - top: 49px; + [class*="unreadMentionsIndicatorTop-"] { + top: 49px; - .platform-osx & { - top: 50px; + .platform-osx & { + top: 50px; + } } } diff --git a/client/src/ui/bdui.js b/client/src/ui/bdui.js index 4cf25833..4d4e5261 100644 --- a/client/src/ui/bdui.js +++ b/client/src/ui/bdui.js @@ -8,7 +8,7 @@ * LICENSE file in the root directory of this source tree. */ -import { Events, DiscordApi } from 'modules'; +import { Events, DiscordApi, Settings } from 'modules'; import { remote } from 'electron'; import DOM from './dom'; import Vue from './vue'; @@ -17,6 +17,13 @@ import { BdSettingsWrapper, BdModals, BdToasts } from './components'; export default class { static initUiEvents() { + const hideButtonSetting = Settings.getSetting('ui', 'default', 'hide-button'); + hideButtonSetting.on('setting-updated', event => { + if (event.value) document.body.classList.add('bd-hide-button'); + else document.body.classList.remove('bd-hide-button'); + }); + if (hideButtonSetting.value) document.body.classList.add('bd-hide-button'); + this.pathCache = { isDm: null, server: DiscordApi.currentGuild, diff --git a/client/src/ui/components/BdSettingsWrapper.vue b/client/src/ui/components/BdSettingsWrapper.vue index 196639a4..96c34a7b 100644 --- a/client/src/ui/components/BdSettingsWrapper.vue +++ b/client/src/ui/components/BdSettingsWrapper.vue @@ -9,8 +9,8 @@ */