bugfixes for last night

This commit is contained in:
Zack Rauen 2019-06-26 14:34:01 -04:00
parent 1f028f22c7
commit eb4358e626
7 changed files with 26 additions and 22 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ import {Settings, DataStore, React, WebpackModules, Events, DOMManager, Strings}
import CSSEditor from "../ui/customcss/csseditor";
import FloatingWindowContainer from "../ui/floating/container";
import SettingsTitle from "../ui/settings/title";
import Utilities from "../modules/utilities";
const fs = require("fs");
const electron = require("electron");
@ -42,10 +43,10 @@ export default new class CustomCSS extends Builtin {
})],
onClick: (thisObject) => {
if (this.isDetached) return;
if (this.nativeOpen) this.openNative();
else if (this.startDetached) this.openDetached();
else thisObject._reactInternalFiber.child.memoizedProps.children.props.onSetSection(Strings.Panels.customcss);
this.setSection = thisObject._reactInternalFiber.child.memoizedProps.children.props.onSetSection;
if (this.nativeOpen) return this.openNative();
else if (this.startDetached) return this.openDetached();
const settingsView = Utilities.findInRenderTree(thisObject._reactInternalFiber, m => m && m.onSetSection, {walkable: ["child", "memoizedProps", "props", "children"]});
if (settingsView && settingsView.onSetSection) settingsView.onSetSection(this.id);
}
});
this.loadCSS();

View File

@ -13,7 +13,6 @@ export default new class ReactComponents {
get listeners() {return listeners;}
constructor() {
this.walkReactTree(document.querySelector("#app-mount")._reactRootContainer._internalRoot.current);
Patcher.after("ReactComponents", React, "createElement", (_, __, returnValue) => {
this.walkRenderTree(returnValue);
});
@ -32,7 +31,9 @@ export default new class ReactComponents {
});
}
initialize() {}
initialize() {
this.walkReactTree(document.querySelector("#app-mount")._reactRootContainer._internalRoot.current);
}
get(name, filter) {
return new Promise(resolve => {

View File

@ -45,7 +45,7 @@ export default new class SettingsManager {
registerPanel(id, name, options) {
if (this.panels.find(p => p.id == id)) return Logger.error("Settings", "Already have a panel with id " + id);
const {element, onClick, order = 1} = options;
const section = {id, order, label: name, section: name};
const section = {id, order, label: name, section: id};
if (onClick) section.clickListener = onClick;
if (element) section.element = element instanceof DiscordModules.React.Component ? () => DiscordModules.React.createElement(element, {}) : typeof(element) == "function" ? element : () => element;
this.panels.push(section);
@ -124,12 +124,9 @@ export default new class SettingsManager {
}
onSettingChange(collection, category, id, value) {
// const before = this.collections.length + this.panels.length;
this.state[collection][category][id] = value;
Events.dispatch("setting-updated", collection, category, id, value);
// const after = this.collections.length + this.panels.length;
this.saveSettings();
// if (before != after) setTimeout(this.forceUpdate.bind(this), 50);
}
getSetting(collection, category, id) {
@ -171,7 +168,6 @@ export default new class SettingsManager {
for (let c = 0; c < this.collections.length; c++) {
const collection = this.collections[c];
const CS = Strings.Collections[collection.id];
console.log(CS);
if (!CS) continue;
collection.name = CS.name || collection.name;
const categories = this.collections[c].settings;
@ -194,7 +190,7 @@ export default new class SettingsManager {
for (let p = 0; p < this.panels.length; p++) {
const panel = this.panels[p];
const Str = Strings.Panels[panel.id];
panel.name = Str || panel.name;
panel.label = Str || panel.label;
}
}
};

View File

@ -14,7 +14,6 @@ export function setLocale(newLocale) {
currentLocale = newLocale;
Utilities.extend(Messages, RawStrings[currentLocale]);
Events.emit("strings-updated");
console.log("Changed to " + newLocale);
}
Utilities.extend(Messages, RawStrings[currentLocale]);

View File

@ -28,7 +28,7 @@ export default class CssEditor extends React.Component {
{label: React.createElement(Save, {size: "18px"}), tooltip: Strings.CustomCSS.save, onClick: this.saveCss},
{label: React.createElement(Edit, {size: "18px"}), tooltip: Strings.CustomCSS.openNative, onClick: this.openNative},
{label: React.createElement(Cog, {size: "18px"}), tooltip: Strings.CustomCSS.settings, onClick: "showSettings"},
{label: Strings.Collections.settings.developer.liveUpdate.name, type:"checkbox", onChange: this.toggleLiveUpdate, checked: Settings.get("settings", "customcss", "liveUpdate"), side: "right"}
{label: Strings.Collections.settings.customcss.liveUpdate.name, type:"checkbox", onChange: this.toggleLiveUpdate, checked: Settings.get("settings", "customcss", "liveUpdate"), side: "right"}
];
if (this.openDetached) this.controls.push({label: React.createElement(Detach, {size: "18px"}), tooltip: Strings.CustomCSS.openDetached, onClick: this.openDetached, side: "right"});
}

View File

@ -11,11 +11,20 @@ export default new class SettingsRenderer {
this.patchSections();
}
onChange(onChange) {
return (collection, category, id) => {
const before = Settings.collections.length + Settings.panels.length;
onChange(collection, category, id);
const after = Settings.collections.length + Settings.panels.length;
if (before != after) setTimeout(this.forceUpdate.bind(this), 50);
};
}
buildSettingsPanel(title, config, state, onChange, button = null) {
config.forEach(section => {
section.settings.forEach(item => item.value = state[section.id][item.id]);
});
return this.getSettingsPanel(title, config, onChange, button);
return this.getSettingsPanel(title, config, this.onChange(onChange), button);
}
getSettingsPanel(title, groups, onChange, button = null) {
@ -43,9 +52,7 @@ export default new class SettingsRenderer {
Patcher.after("SettingsManager", WebpackModules.getByDisplayName("FluxContainer(GuildSettings)").prototype, "render", (thisObject) => {
thisObject._reactInternalFiber.return.return.return.return.return.return.memoizedProps.id = "guild-settings";
});
console.log("getting user settings")
const UserSettings = await ReactComponents.get("UserSettings", m => m.prototype && m.prototype.generateSections);
console.log("got 'em")
Patcher.after("SettingsManager", UserSettings.prototype, "render", (thisObject) => {
thisObject._reactInternalFiber.return.return.return.return.return.return.return.memoizedProps.id = "user-settings";
});