finish moving to collections

This commit is contained in:
Zack Rauen 2019-06-06 15:57:25 -04:00
parent c14d21eab4
commit 632d37f93e
18 changed files with 969 additions and 851 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
import Builtin, {onSettingChange} from "../structs/builtin";
import {SettingsCookie} from "data";
import Builtin from "../structs/builtin";
import {DiscordModules} from "modules";
export default new class DeveloperMode extends Builtin {
@ -7,7 +6,7 @@ export default new class DeveloperMode extends Builtin {
get category() {return "developer";}
get id() {return "developerMode";}
get selectorModeID() {return "copySelector";}
get selectorMode() {return SettingsCookie[this.selectorModeID];}
get selectorMode() {return this.get(this.selectorModeID);}
constructor() {
super();
@ -23,7 +22,7 @@ export default new class DeveloperMode extends Builtin {
}
});
if (this.selectorMode) this.enableSelectors();
this.selectorCancel = onSettingChange(this.category, this.selectorModeID, this.enableSelectors, this.disableSelectors);
this.selectorCancel = this.registerSetting(this.selectorModeID, this.enableSelectors, this.disableSelectors);
}
disabled() {

View File

@ -1,5 +1,5 @@
import Builtin, {onSettingChange} from "../structs/builtin";
import {SettingsCookie, Emotes, State} from "data";
import Builtin from "../structs/builtin";
import {Emotes, State} from "data";
import {DataStore, Utilities, Events} from "modules";
const headerHTML = `<div id="bda-qem">
@ -44,7 +44,7 @@ export default new class EmoteMenu extends Builtin {
get category() {return "general";}
get id() {return "emoteMenu";}
get hideEmojisID() {return "hideEmojiMenu";}
get hideEmojis() {return SettingsCookie[this.hideEmojisID];}
get hideEmojis() {return this.get(this.hideEmojisID);}
constructor() {
super();
@ -79,7 +79,7 @@ export default new class EmoteMenu extends Builtin {
childList: true,
subtree: true
});
this.hideEmojiCancel = onSettingChange(this.category, this.hideEmojisID, this.enableHideEmojis, this.disableHideEmojis);
this.hideEmojiCancel = this.registerSetting(this.hideEmojisID, this.enableHideEmojis, this.disableHideEmojis);
if (this.hideEmojis) this.enableHideEmojis();
// await this.waitForEmotes();
// this.updateTwitchEmotes();

View File

@ -6,24 +6,31 @@ import BDEmote from "../ui/emote";
import {Toasts} from "ui";
const bdEmoteSettingIDs = {
TwitchGlobal: "bda-es-7",
TwitchSubscriber: "bda-es-7",
BTTV: "bda-es-2",
FrankerFaceZ: "bda-es-1",
BTTV2: "bda-es-2"
TwitchGlobal: "twitch",
TwitchSubscriber: "twitch",
BTTV: "bttv",
FrankerFaceZ: "ffz",
BTTV2: "bttv"
};
export default new class EmoteModule extends Builtin {
get name() {return "Emotes";}
get collection() {return "emotes";}
get collection() {return "settings";}
get category() {return "general";}
get id() {return "";}
get categories() { return Object.keys(bdEmoteSettingIDs).filter(k => SettingsCookie[bdEmoteSettingIDs[k]]); }
get id() {return "emotes";}
get categories() { return Object.keys(bdEmoteSettingIDs).filter(k => this.isCategoryEnabled(bdEmoteSettingIDs[k])); }
get MessageContentComponent() {return WebpackModules.getModule(m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));}
async initialize() {
super.initialize();
isCategoryEnabled(id) {
return super.get("emotes", "categories", id);
}
get(id) {
return super.get("emotes", "general", id);
}
async enabled() {
// Disable emote module for now because it's annoying and slow
// await this.getBlacklist();
// await this.loadEmoteData(EmoteInfo);
@ -33,11 +40,16 @@ export default new class EmoteModule extends Builtin {
}
disabled() {
this.emptyEmotes();
if (this.cancelEmoteRender) return;
this.cancelEmoteRender();
delete this.cancelEmoteRender;
}
emptyEmotes() {
for (const cat in Emotes) Object.assign(Emotes, {[cat]: {}});
}
patchMessageContent() {
if (this.cancelEmoteRender) return;
this.cancelEmoteRender = Utilities.monkeyPatch(this.MessageContentComponent.prototype, "render", {after: ({returnValue}) => {

View File

@ -1,12 +1,11 @@
import Builtin, {onSettingChange} from "../structs/builtin";
import {SettingsCookie} from "data";
import Builtin from "../structs/builtin";
export default new class MinimalMode extends Builtin {
get name() {return "MinimalMode";}
get category() {return "appearance";}
get id() {return "minimalMode";}
get hideChannelsID() {return "hideChannels";}
get hideChannels() {return SettingsCookie[this.hideChannelsID];}
get hideChannels() {return this.get(this.hideChannelsID);}
constructor() {
super();
@ -17,7 +16,7 @@ export default new class MinimalMode extends Builtin {
enabled() {
$("body").addClass("bd-minimal");
if (this.hideChannels) this.enableHideChannels();
this.hideChannelCancel = onSettingChange(this.category, this.hideChannelsID, this.enableHideChannels, this.disableHideChannels);
this.hideChannelCancel = this.registerSetting(this.hideChannelsID, this.enableHideChannels, this.disableHideChannels);
}
disabled() {

View File

@ -1,5 +1,4 @@
import Builtin from "../structs/builtin";
import {SettingsCookie} from "data";
import {BDV2, DiscordModules} from "modules";
import {PublicServers as PSComponents} from "ui";
@ -45,7 +44,7 @@ export default new class PublicServers extends Builtin {
render() {
const root = this.root;
if (!root) {
console.log("FAILED TO LOCATE ROOT: .layers");
this.error("FAILED TO LOCATE ROOT: .layers");
return;
}
DiscordModules.ReactDOM.render(this.component, root);

View File

@ -12,9 +12,7 @@ import EmoteInfo from "./emotes/info";
import EmoteModifiers from "./emotes/modifiers";
import EmoteOverrides from "./emotes/overrides";
import SettingsCollection from "./settings/config";
import EmoteCollection from "./emotes/config";
import SettingsConfig from "./settings/config";
import SettingsState from "./settings/state";
export const Collections = [SettingsCollection, EmoteCollection];
export {State, SettingsInfo, SettingsCookie, Config, PluginCookie, ThemeCookie, Themes, Plugins, Emotes, EmoteBlacklist, EmoteInfo, EmoteModifiers, EmoteOverrides};
export {State, SettingsInfo, SettingsCookie, Config, PluginCookie, ThemeCookie, Themes, Plugins, Emotes, EmoteBlacklist, EmoteInfo, EmoteModifiers, EmoteOverrides, SettingsConfig, SettingsState};

View File

@ -1,89 +0,0 @@
export default [
{
type: "category",
id: "general",
name: "General",
collapsible: true,
settings: [
{
type: "switch",
id: "download",
name: "Download Emotes",
note: "Download emotes once a week to stay up to date",
value: true
},
{
type: "switch",
id: "emoteMenu",
name: "Emote Menu",
note: "Show Twitch/Favourite emotes in emote menu",
value: true
},
{
type: "switch",
id: "hideEmojiMenu",
name: "Hide Emoji Menu",
note: "Hides Discord's emoji menu when using emote menu",
value: true,
enableWith: "emoteMenu"
},
{
type: "switch",
id: "autoCaps",
name: "Emote Autocapitalization",
note: "Autocapitalize emote commands",
value: false
},
{
type: "switch",
id: "showNames",
name: "Show Names",
note: "Show emote names on hover",
value: false
},
{
type: "switch",
id: "modifiers",
name: "Show Emote Modifiers",
note: "Enable emote mods (flip, spin, pulse, spin2, spin3, 1spin, 2spin, 3spin, tr, bl, br, shake, shake2, shake3, flap)",
value: false
},
{
type: "switch",
id: "animateOnHover",
name: "Animate On Hover",
note: "Only animate the emote modifiers on hover",
value: false
}
]
},
{
type: "category",
id: "categories",
name: "Categories",
collapsible: true,
settings: [
{
type: "switch",
id: "twitch",
name: "Twitch",
note: "Show Twitch global & subscriber emotes",
value: false
},
{
type: "switch",
id: "ffz",
name: "FrankerFaceZ",
note: "Show emotes from FFZ",
value: true
},
{
type: "switch",
id: "bttv",
name: "BetterTTV",
note: "Show emotes from BTTV",
value: true
}
]
}
];

View File

@ -1 +0,0 @@
export default {};

View File

@ -1,172 +1,274 @@
export default [
{
type: "category",
id: "general",
name: "General",
collapsible: true,
type: "collection",
id: "settings",
name: "Settings",
settings: [
{
type: "switch",
id: "emotes",
name: "Emote System",
note: "Enables BD's emote system",
value: true
type: "category",
id: "general",
name: "General",
collapsible: true,
settings: [
{
type: "switch",
id: "emotes",
name: "Emote System",
note: "Enables BD's emote system",
value: true
},
{
type: "switch",
id: "publicServers",
name: "Public Servers",
note: "Display public servers button",
value: true
},
{
type: "switch",
id: "voiceDisconnect",
name: "Voice Disconnect",
note: "Disconnect from voice server when closing Discord",
value: false
},
{
type: "switch",
id: "twentyFourHour",
name: "24 Hour Timestamps",
note: "Hides channels when in minimal mode",
value: false,
},
{
type: "switch",
id: "classNormalizer",
name: "Normalize Classes",
note: "Adds stable classes to elements to help themes. (e.g. adds .da-channels to .channels-Ie2l6A)",
value: true
},
{
type: "switch",
id: "showToasts",
name: "Show Toasts",
note: "Shows a small notification for important information",
value: true
}
]
},
{
type: "switch",
id: "publicServers",
name: "Public Servers",
note: "Display public servers button",
value: true
type: "category",
id: "appearance",
name: "Appearance",
collapsible: true,
settings: [
{
type: "switch",
id: "voiceMode",
name: "Voice Mode",
note: "Hides everything that isn't voice chat",
value: false
},
{
type: "switch",
id: "minimalMode",
name: "Minimal Mode",
note: "Hide elements and reduce the size of elements",
value: false
},
{
type: "switch",
id: "hideChannels",
name: "Hide Channels",
note: "Hides channels when in minimal mode",
value: false,
enableWith: "minimalMode"
},
{
type: "switch",
id: "darkMode",
name: "Dark Mode",
note: "Make certain elements dark by default",
value: true
},
{
type: "switch",
id: "coloredText",
name: "Colored Text",
note: "Make text colour the same as role color",
value: false
}
]
},
{
type: "switch",
id: "voiceDisconnect",
name: "Voice Disconnect",
note: "Disconnect from voice server when closing Discord",
value: false
type: "category",
id: "content",
name: "Content Manager",
collapsible: true,
settings: [
{
type: "switch",
id: "contentErrors",
name: "Show Content Errors",
note: "Shows a modal with plugin/theme errors",
value: true
},
{
type: "switch",
id: "autoScroll",
name: "Scroll To Settings",
note: "Auto-scrolls to a plugin's settings when the button is clicked (only if out of view)",
value: true
},
{
type: "switch",
id: "autoReload",
name: "Automatic Loading",
note: "Automatically loads, reloads, and unloads plugins and themes",
value: true
}
]
},
{
type: "switch",
id: "twentyFourHour",
name: "24 Hour Timestamps",
note: "Hides channels when in minimal mode",
value: false,
type: "category",
id: "developer",
name: "Developer Settings",
collapsible: true,
shown: false,
settings: [
{
type: "switch",
id: "developerMode",
name: "Developer Mode",
note: "Allows activating debugger when pressing F8",
value: false
},
{
type: "switch",
id: "copySelector",
name: "Copy Selector",
note: "Adds a \"Copy Selector\" option to context menus when developer mode is active",
value: false,
enableWith: "developerMode"
}
]
},
{
type: "switch",
id: "classNormalizer",
name: "Normalize Classes",
note: "Adds stable classes to elements to help themes. (e.g. adds .da-channels to .channels-Ie2l6A)",
value: true
},
{
type: "switch",
id: "showToasts",
name: "Show Toasts",
note: "Shows a small notification for important information",
value: true
type: "category",
id: "window",
name: "Window Preferences",
collapsible: true,
shown: false,
settings: [
{
type: "switch",
id: "transparency",
name: "Enable Transparency",
note: "Enables the main window to be see-through (requires restart)",
value: false
},
{
type: "switch",
id: "frame",
name: "Window Frame",
note: "Adds the native os window frame to the main window",
value: false,
hidden: true
}
]
}
]
},
{
type: "category",
id: "appearance",
name: "Appearance",
collapsible: true,
type: "collection",
id: "emotes",
name: "Emotes",
enableWith: "settings.general.emotes",
settings: [
{
type: "switch",
id: "voiceMode",
name: "Voice Mode",
note: "Hides everything that isn't voice chat",
value: false
type: "category",
id: "general",
name: "General",
collapsible: true,
settings: [
{
type: "switch",
id: "download",
name: "Download Emotes",
note: "Download emotes once a week to stay up to date",
value: true
},
{
type: "switch",
id: "emoteMenu",
name: "Emote Menu",
note: "Show Twitch/Favourite emotes in emote menu",
value: true
},
{
type: "switch",
id: "hideEmojiMenu",
name: "Hide Emoji Menu",
note: "Hides Discord's emoji menu when using emote menu",
value: false,
enableWith: "emoteMenu"
},
{
type: "switch",
id: "autoCaps",
name: "Emote Autocapitalization",
note: "Autocapitalize emote commands",
value: false
},
{
type: "switch",
id: "showNames",
name: "Show Names",
note: "Show emote names on hover",
value: true
},
{
type: "switch",
id: "modifiers",
name: "Show Emote Modifiers",
note: "Enable emote mods (flip, spin, pulse, spin2, spin3, 1spin, 2spin, 3spin, tr, bl, br, shake, shake2, shake3, flap)",
value: true
},
{
type: "switch",
id: "animateOnHover",
name: "Animate On Hover",
note: "Only animate the emote modifiers on hover",
value: false
}
]
},
{
type: "switch",
id: "minimalMode",
name: "Minimal Mode",
note: "Hide elements and reduce the size of elements",
value: false
},
{
type: "switch",
id: "hideChannels",
name: "Hide Channels",
note: "Hides channels when in minimal mode",
value: false,
enableWith: "minimalMode"
},
{
type: "switch",
id: "darkMode",
name: "Dark Mode",
note: "Make certain elements dark by default",
value: true
},
{
type: "switch",
id: "coloredText",
name: "Colored Text",
note: "Make text colour the same as role color",
value: false
}
]
},
{
type: "category",
id: "content",
name: "Content Manager",
collapsible: true,
settings: [
{
type: "switch",
id: "contentErrors",
name: "Show Content Errors",
note: "Shows a modal with plugin/theme errors",
value: true
},
{
type: "switch",
id: "autoScroll",
name: "Scroll To Settings",
note: "Auto-scrolls to a plugin's settings when the button is clicked (only if out of view)",
value: true
},
{
type: "switch",
id: "autoReload",
name: "Automatic Loading",
note: "Automatically loads, reloads, and unloads plugins and themes",
value: true
}
]
},
{
type: "category",
id: "developer",
name: "Developer Settings",
collapsible: true,
shown: false,
settings: [
{
type: "switch",
id: "developerMode",
name: "Developer Mode",
note: "Allows activating debugger when pressing F8",
value: false
},
{
type: "switch",
id: "copySelector",
name: "Copy Selector",
note: "Adds a \"Copy Selector\" option to context menus when developer mode is active",
value: false,
enableWith: "developerMode"
}
]
},
{
type: "category",
id: "window",
name: "Window Preferences",
collapsible: true,
shown: false,
settings: [
{
type: "switch",
id: "transparency",
name: "Enable Transparency",
note: "Enables the main window to be see-through (requires restart)",
value: false
},
{
type: "switch",
id: "frame",
name: "Window Frame",
note: "Adds the native os window frame to the main window",
value: false,
hidden: true
type: "category",
id: "categories",
name: "Categories",
collapsible: true,
settings: [
{
type: "switch",
id: "twitch",
name: "Twitch",
note: "Show Twitch global & subscriber emotes",
value: true
},
{
type: "switch",
id: "ffz",
name: "FrankerFaceZ",
note: "Show emotes from FFZ",
value: true
},
{
type: "switch",
id: "bttv",
name: "BetterTTV",
note: "Show emotes from BTTV",
value: true
}
]
}
]
}

View File

@ -5,7 +5,7 @@ import {Config} from "data";
// import QuickEmoteMenu from "../builtins/emotemenu";
import PluginManager from "./pluginmanager";
import ThemeManager from "./thememanager";
import SettingsPanel from "./settingsmanager";
import Settings from "./settingsmanager";
import * as Builtins from "builtins";
import {Modals} from "ui";
@ -31,7 +31,7 @@ Core.prototype.init = async function() {
}
Utilities.log("Startup", "Initializing Settings");
SettingsPanel.initialize();
Settings.initialize();
Utilities.log("Startup", "Initializing EmoteModule");
// window.emotePromise = EmoteModule.init().then(() => {
// EmoteModule.initialized = true;
@ -45,7 +45,6 @@ Core.prototype.init = async function() {
await this.checkForGuilds();
BDV2.initialize();
Utilities.log("Startup", "Updating Settings");
SettingsPanel.initializeSettings();
for (const module in Builtins) Builtins[module].initialize();
Utilities.log("Startup", "Loading Plugins");
@ -107,7 +106,7 @@ Core.prototype.initObserver = function () {
// if (node.getElementsByClassName("socialLinks-3jqNFy").length) {
// node.setAttribute("layer-id", "user-settings");
// node.setAttribute("id", "user-settings");
// if (!document.getElementById("bd-settings-sidebar")) SettingsPanel.renderSidebar();
// if (!document.getElementById("bd-settings-sidebar")) Settings.renderSidebar();
// }
}
}

View File

@ -1,39 +1,54 @@
import {Config} from "data";
const fs = require("fs");
const path = require("path");
const releaseChannel = DiscordNative.globals.releaseChannel;
// Schema 1
// =======================
// %appdata%\BetterDiscord
// -> data\
// -> [releaseChannel].json (stable/canary/ptb)
// Schema 2
// =======================
// %appdata%\BetterDiscord
// -> data
// -> [releaseChannel]\ (stable/canary/ptb)
// -> settings.json
// -> plugins.json
// -> themes.json
export default new class DataStore {
constructor() {
this.data = {settings: {stable: {}, canary: {}, ptb: {}}};
this.data = {};
this.pluginData = {};
}
initialize() {
if (!fs.existsSync(path.resolve(this.BDFile, ".."))) fs.mkdirSync(path.resolve(this.BDFile, ".."));
if (!fs.existsSync(this.BDFile)) fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
const data = __non_webpack_require__(this.BDFile);
if (data.hasOwnProperty("settings")) this.data = data;
if (!fs.existsSync(this.settingsFile)) return;
let settings = __non_webpack_require__(this.settingsFile);
fs.unlinkSync(this.settingsFile);
if (settings.hasOwnProperty("settings")) settings = Object.assign({stable: {}, canary: {}, ptb: {}}, {[releaseChannel]: settings});
else settings = Object.assign({stable: {}, canary: {}, ptb: {}}, settings);
this.setBDData("settings", settings);
this.data = __non_webpack_require__(this.BDFile);
// if (data.hasOwnProperty("settings")) this.data = data;
// if (!fs.existsSync(this.settingsFile)) return;
// let settings = __non_webpack_require__(this.settingsFile);
// fs.unlinkSync(this.settingsFile);
// if (settings.hasOwnProperty("settings")) settings = Object.assign({stable: {}, canary: {}, ptb: {}}, {[releaseChannel]: settings});
// else settings = Object.assign({stable: {}, canary: {}, ptb: {}}, settings);
// this.setBDData("settings", settings);
}
get BDFile() {return this._BDFile || (this._BDFile = path.resolve(Config.dataPath, "bdstorage.json"));}
get settingsFile() {return this._settingsFile || (this._settingsFile = path.resolve(Config.dataPath, "bdsettings.json"));}
get BDFile() {return this._BDFile || (this._BDFile = path.resolve(Config.dataPath, "data", `${releaseChannel}.json`));}
// get settingsFile() {return this._settingsFile || (this._settingsFile = path.resolve(Config.dataPath, "bdsettings.json"));}
getPluginFile(pluginName) {return path.resolve(Config.dataPath, "plugins", pluginName + ".config.json");}
getSettingGroup(key) {
return this.data.settings[releaseChannel][key] || null;
}
// getSettingGroup(key) {
// return this.data.settings[key] || null;
// }
setSettingGroup(key, data) {
this.data.settings[releaseChannel][key] = data;
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
}
// setSettingGroup(key, data) {
// this.data.settings[key] = data;
// fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
// }
getBDData(key) {
return this.data[key] || "";
@ -44,6 +59,15 @@ export default new class DataStore {
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
}
getData(key) {
return this.data[key] || "";
}
setData(key, value) {
this.data[key] = value;
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
}
getPluginData(pluginName, key) {
if (this.pluginData[pluginName] !== undefined) return this.pluginData[pluginName][key] || undefined;
if (!fs.existsSync(this.getPluginFile(pluginName))) return undefined;

View File

@ -150,13 +150,13 @@ PluginModule.prototype.updatePluginList = function() {
};
PluginModule.prototype.loadPluginData = function () {
const saved = DataStore.getSettingGroup("plugins");
const saved = DataStore.getData("plugins");
if (!saved) return;
Object.assign(PluginCookie, saved);
};
PluginModule.prototype.savePluginData = function () {
DataStore.setSettingGroup("plugins", PluginCookie);
DataStore.setData("plugins", PluginCookie);
};
PluginModule.prototype.newMessage = function () {

View File

@ -1,8 +1,7 @@
import {SettingsCookie, Collections} from "data";
import {SettingsConfig, SettingsState} from "data";
import DataStore from "./datastore";
import ContentManager from "./contentmanager";
import BdApi from "./pluginapi";
// import EmoteModule from "./emotes";
import Events from "./emitter";
import WebpackModules from "./webpackmodules";
@ -10,59 +9,75 @@ import {SettingsPanel as SettingsRenderer} from "ui";
import Utilities from "./utilities";
import {Toasts} from "ui";
import EmoteSettings from "../data/emotes/config";
import EmoteState from "../data/emotes/state";
import TheSettings from "../data/settings/config";
import SettingsState from "../data/settings/state";
//WebpackModules.getModule(m => m.getSection && m.getProps && !m.getGuildId && !m.getChannel)
//WebpackModules.getByProps("getGuildId", "getSection")
export default new class SettingsManager {
constructor() {
this.renderer = new SettingsRenderer({onChange: this.updateSettings.bind(this)});
this.updateSettings = this.updateSettings.bind(this);
console.log(Collections);
this.renderer = new SettingsRenderer();
this.config = SettingsConfig;
this.state = SettingsState;
this.setup(SettingsConfig, SettingsState);
}
initialize() {
DataStore.initialize();
if (!DataStore.getSettingGroup("settings")) return this.saveSettings();
const savedSettings = this.loadSettings();
$("<style id=\"customcss\">").text(atob(DataStore.getBDData("bdcustomcss"))).appendTo(document.head);
for (const setting in savedSettings) {
if (savedSettings[setting] !== undefined) SettingsCookie[setting] = savedSettings[setting];
}
this.saveSettings();
// if (!DataStore.getSettingGroup("settings")) return this.saveSettings();
// const savedSettings = this.loadSettings();
// $("<style id=\"customcss\">").text(atob(DataStore.getBDData("bdcustomcss"))).appendTo(document.head);
// for (const setting in savedSettings) {
// if (savedSettings[setting] !== undefined) SettingsCookie[setting] = savedSettings[setting];
// }
// this.saveSettings();
this.loadSettings();
this.patchSections();
this.initializeConfig(TheSettings, SettingsState);
this.initializeConfig(EmoteSettings, EmoteState);
// Object.assign(this.state, this.defaultState);
// this.initializeConfig(EmoteSettings, EmoteState);
}
initializeConfig(defaultConfig, state) {
getPath(path, collectionId = "", categoryId = "") {
const collection = path.length == 3 ? path[0] : collectionId;
const category = path.length == 3 ? path[1] : path.length == 2 ? path[0] : categoryId;
const setting = path[path.length - 1];
return {collection, category, setting};
}
setup(collections, state) {
const config = {};
for (let s = 0; s < defaultConfig.length; s++) {
const current = defaultConfig[s];
if (current.type != "category") {config[current.id] = current.value;}
else {
config[current.id] = {};
for (let s = 0; s < current.settings.length; s++) {
const subCurrent = current.settings[s];
config[current.id][subCurrent.id] = subCurrent.value;
if (subCurrent.enableWith) {
Object.defineProperty(subCurrent, "disabled", {
get: () => {
return !state[current.id][subCurrent.enableWith];
}
});
for (let c = 0; c < collections.length; c++) {
const collection = collections[c];
const categories = collections[c].settings;
config[collection.id] = {};
for (let s = 0; s < categories.length; s++) {
const category = categories[s];
if (category.type != "category") {config[collection.id][category.id] = category.value;}
else {
config[collection.id][category.id] = {};
for (let s = 0; s < category.settings.length; s++) {
const setting = category.settings[s];
config[collection.id][category.id][setting.id] = setting.value;
if (setting.enableWith) {
const path = this.getPath(setting.enableWith.split("."), collection.id, category.id);
Object.defineProperty(setting, "disabled", {
get: () => {
return !state[path.collection][path.category][path.setting];
}
});
}
}
}
}
if (collection.enableWith) {
const path = this.getPath(collection.enableWith.split("."));
Object.defineProperty(collection, "disabled", {
get: () => {
return !state[path.collection][path.category][path.setting];
}
});
}
}
console.log(defaultConfig);
console.log(config);
Object.assign(state, config);
this.defaultState = config;
Object.assign(this.state, this.defaultState);
}
buildSettingsPanel(title, config, state, onChange) {
@ -73,7 +88,7 @@ export default new class SettingsManager {
}
async patchSections() {
const UserSettings = await this.getUserSettings(); // data.returnValue.type;
const UserSettings = await this.getUserSettings();
Utilities.monkeyPatch(UserSettings.prototype, "generateSections", {after: (data) => {
let location = data.returnValue.findIndex(s => s.section.toLowerCase() == "linux") + 1;
const insert = (section) => {
@ -83,9 +98,14 @@ export default new class SettingsManager {
console.log(data); /* eslint-disable-line no-console */
insert({section: "DIVIDER"});
insert({section: "HEADER", label: "BandagedBD"});
// insert({section: "BBD Settings", label: "Settings", element: () => this.renderer.core2});
insert({section: "BBD Settings", label: "Settings", element: () => this.buildSettingsPanel("Settings", TheSettings, SettingsState, this.updateSettings.bind(this, SettingsState))});
if (SettingsState.general.emotes) insert({section: "BBD Emotes", label: "Emotes", element: () => this.buildSettingsPanel("Emote Settings", EmoteSettings, EmoteState, this.updateSettings.bind(this, EmoteState))});
for (const collection of this.config) {
if (collection.disabled) continue;
insert({
section: collection.name,
label: collection.name,
element: () => this.buildSettingsPanel(collection.name, collection.settings, SettingsState[collection.id], this.onSettingChange.bind(this, collection.id))
});
}
insert({section: "BBD Test", label: "Test Tab", onClick: function() {Toasts.success("This can just be a click listener!", {forceShow: true});}});
insert({section: "CUSTOM", element: () => this.renderer.attribution});
}});
@ -109,46 +129,55 @@ export default new class SettingsManager {
}
saveSettings() {
DataStore.setSettingGroup("settings", SettingsCookie);
DataStore.setData("settings", this.state);
}
loadSettings() {
return DataStore.getSettingGroup("settings");
const previousState = DataStore.getData("settings");
if (!previousState) return this.saveSettings();
for (const collection in this.defaultState) {
if (!previousState[collection]) Object.assign(previousState, {[collection]: this.defaultState[collection]});
for (const category in this.defaultState[collection]) {
if (!previousState[collection][category]) Object.assign(previousState[collection][category], {[category]: this.defaultState[collection][category]});
for (const setting in this.defaultState[collection][category]) {
if (previousState[collection][category][setting] == undefined) continue;
this.state[collection][category][setting] = previousState[collection][category][setting];
}
}
}
this.saveSettings(); // in case new things were added
}
onSettingChange(collection, category, id, enabled) {
collection[category][id] = enabled;
Events.dispatch("setting-updated", category, id, enabled);
// console.log(collection);
if (id == "emotes") this.forceUpdate();
onSettingChange(collection, category, id, value) {
const before = this.config.filter(c => c.disabled).length;
this.state[collection][category][id] = value;
Events.dispatch("setting-updated", collection, category, id, value);
const after = this.config.filter(c => c.disabled).length;
this.saveSettings();
if (before != after) this.forceUpdate();
}
getSetting(category, id) {
if (arguments.length == 2) return SettingsState[category][id];
const collection = arguments[0] == "emotes" ? EmoteState : SettingsState;
return collection && collection[arguments[1]][arguments[2]];
getSetting(collection, category, id) {
if (arguments.length == 2) return this.config[0].find(c => c.id == arguments[0]).settings.find(s => s.id == arguments[1]);
return this.config.find(c => c.id == collection).find(c => c.id == category).settings.find(s => s.id == id);
}
get(category, id) {
if (arguments.length == 2) return SettingsState[category][id];
const collection = arguments[0] == "emotes" ? EmoteState : SettingsState;
return collection && collection[arguments[1]][arguments[2]];
get(collection, category, id) {
if (arguments.length == 2) return this.state[this.config[0].id][arguments[0]][arguments[1]];
return this.state[collection][category][id];
}
on(collection, category, identifier, callback) {
const handler = (col, cat, id, value) => {
if (col !== collection || cat !== category || id !== identifier) return;
callback(value);
};
Events.on("setting-updated", handler);
return () => {Events.off("setting-updated", handler);};
}
updateSettings(collection, category, id, enabled) {
// console.log("Updating ", collection);
// console.log(category, id, enabled);
collection[category][id] = enabled;
Events.dispatch("setting-updated", category, id, enabled);
// console.log(collection);
if (id == "emotes") this.forceUpdate();
// SettingsCookie[id] = enabled;
// if (id == "bda-es-4") {
// if (enabled) EmoteModule.autoCapitalize();
// else EmoteModule.disableAutoCapitalize();
// }
if (id == "fork-ps-5") {
if (enabled) {
@ -173,10 +202,10 @@ export default new class SettingsManager {
initializeSettings() {
// if (SettingsCookie["bda-es-4"]) EmoteModule.autoCapitalize();
if (SettingsCookie["fork-ps-5"]) {
ContentManager.watchContent("plugin");
ContentManager.watchContent("theme");
}
// if (SettingsCookie["fork-ps-5"]) {
// ContentManager.watchContent("plugin");
// ContentManager.watchContent("theme");
// }
this.saveSettings();
}

View File

@ -99,13 +99,13 @@ ThemeModule.prototype.updateThemeList = function() {
};
ThemeModule.prototype.loadThemeData = function() {
const saved = DataStore.getSettingGroup("themes");
const saved = DataStore.getData("themes");
if (!saved) return;
Object.assign(ThemeCookie, saved);
};
ThemeModule.prototype.saveThemeData = function () {
DataStore.setSettingGroup("themes", ThemeCookie);
DataStore.setData("themes", ThemeCookie);
};
export default new ThemeModule();

View File

@ -1,18 +1,7 @@
import {SettingsCookie} from "data";
import SettingState from "../data/settings/state";
import EmoteState from "../data/emotes/state";
import {SettingsState} from "data";
import Utilities from "../modules/utilities";
import Events from "../modules/emitter";
export function onSettingChange(category, identifier, onEnable, onDisable) {
const handler = (cat, id, enabled) => {
if (category !== cat || id !== identifier) return;
if (enabled) onEnable();
else onDisable();
};
Events.on("setting-updated", handler);
return () => {Events.off("setting-updated", handler);};
}
import Settings from "../modules/settingsmanager";
export default class BuiltinModule {
@ -22,15 +11,49 @@ export default class BuiltinModule {
get id() {return "None";}
async initialize() {
const state = this.collection == "settings" ? SettingState : EmoteState;
if (state[this.category][this.id]) await this.enable();
Events.on("setting-updated", (category, id, enabled) => {
if (category !== this.category || id !== this.id) return;
if (SettingsState[this.collection][this.category][this.id]) await this.enable();
Events.on("setting-updated", (collection, category, id, enabled) => {
if (collection != this.collection || category !== this.category || id !== this.id) return;
if (enabled) this.enable();
else this.disable();
});
}
registerSetting(collection, category, id, onEnable, onDisable) {
if (arguments.length == 4) {
collection = this.collection;
category = arguments[0];
id = arguments[1];
onEnable = arguments[2];
onDisable = arguments[3];
}
else if (arguments.length == 3) {
collection = this.collection;
category = this.category;
id = arguments[0];
onEnable = arguments[1];
onDisable = arguments[2];
}
return Settings.on(collection, category, id, (value) => {
if (value) onEnable();
else onDisable();
});
}
get(collection, category, id) {
if (arguments.length == 2) {
collection = this.collection;
category = arguments[0];
id = arguments[1];
}
else if (arguments.length == 1) {
collection = this.collection;
category = this.category;
id = arguments[0];
}
return Settings.get(collection, category, id);
}
async enable() {
this.log("Enabled");
await this.enabled();

View File

@ -49,12 +49,9 @@ export default class Group extends React.Component {
return <div className={groupClass}>
<Title text={this.props.name} collapsible={this.props.collapsible} onClick={() => this.toggleCollapse()} button={this.props.button} isGroup={true} />
<div className="bd-settings-container" ref={this.container}>
{settings.filter(s => !s.hidden).map((setting) => {
// console.log(setting);
const item = <Switch disabled={setting.disabled} id={setting.id} key={setting.id} name={setting.name} note={setting.note} checked={setting.value} onChange={this.onChange} />;
const shouldHide = setting.shouldHide ? setting.shouldHide() : false;
if (!shouldHide) return item;
})}
{settings.filter(s => !s.hidden).map((setting) =>
<Switch disabled={setting.disabled} id={setting.id} key={setting.id} name={setting.name} note={setting.note} checked={setting.value} onChange={this.onChange} />
)}
</div>
{this.props.showDivider && <Divider />}
</div>;

View File

@ -21,10 +21,6 @@ import SettingsTitle from "./title";
export default class V2_SettingsPanel {
constructor({onChange}) {
this.onChange = onChange;
}
get coreSettings() {
const settings = this.getSettings("core");
const categories = [...new Set(settings.map(s => s.category))];
@ -47,7 +43,7 @@ export default class V2_SettingsPanel {
}, []);
}
getSettingsPanel(title, groups, onChange) {
return [React.createElement(SettingsTitle, {text: title}), groups.map(section => {