Settings: remove obsolete patch; add redundancy & more useful dbg copy

main
Vendicated 6 months ago
parent 840d571ce2
commit 0e4724ec0d
No known key found for this signature in database
GPG Key ID: D66986BAF75ECF18

@ -30,6 +30,9 @@ import { i18n, React } from "@webpack/common";
import gitHash from "~git-hash"; import gitHash from "~git-hash";
type SectionType = "HEADER" | "DIVIDER" | "CUSTOM";
type SectionTypes = Record<SectionType, SectionType>;
export default definePlugin({ export default definePlugin({
name: "Settings", name: "Settings",
description: "Adds Settings UI and debug info", description: "Adds Settings UI and debug info",
@ -41,33 +44,17 @@ export default definePlugin({
find: ".versionHash", find: ".versionHash",
replacement: [ replacement: [
{ {
match: /\[\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/, match: /\[\(0,\i\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/,
replace: (m, component, props) => { replace: (m, component, props) => {
props = props.replace(/children:\[.+\]/, ""); props = props.replace(/children:\[.+\]/, "");
return `${m},$self.makeInfoElements(${component}, ${props})`; return `${m},$self.makeInfoElements(${component}, ${props})`;
} }
}
]
}, },
// Discord Stable
// FIXME: remove once change merged to stable
{ {
find: "Messages.ACTIVITY_SETTINGS", match: /copyValue:\i\.join\(" "\)/,
replacement: { replace: "$& + $self.getInfoString()"
get match() {
switch (Settings.plugins.Settings.settingsLocation) {
case "top": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.USER_SETTINGS/;
case "aboveNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.BILLING_SETTINGS/;
case "belowNitro": return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.APP_SETTINGS/;
case "belowActivity": return /(?<=\{section:(\i\.\i)\.DIVIDER},)\{section:"changelog"/;
case "bottom": return /\{section:(\i\.\i)\.CUSTOM,\s*element:.+?}/;
case "aboveActivity":
default:
return /\{section:(\i\.\i)\.HEADER,\s*label:(\i)\.\i\.Messages\.ACTIVITY_SETTINGS/;
}
},
replace: "...$self.makeSettingsCategories($1),$&"
} }
]
}, },
// Discord Canary // Discord Canary
{ {
@ -77,6 +64,13 @@ export default definePlugin({
replace: (_, sectionTypes, commaOrSemi, elements, element) => `${commaOrSemi} $self.addSettings(${elements}, ${element}, ${sectionTypes}) ${commaOrSemi}` replace: (_, sectionTypes, commaOrSemi, elements, element) => `${commaOrSemi} $self.addSettings(${elements}, ${element}, ${sectionTypes}) ${commaOrSemi}`
} }
}, },
{
find: "useDefaultUserSettingsSections:function",
replacement: {
match: /(?<=useDefaultUserSettingsSections:function\(\){return )(\i)\}/,
replace: "$self.wrapSettingsHook($1)}"
}
},
{ {
find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL", find: "Messages.USER_SETTINGS_ACTIONS_MENU_LABEL",
replacement: { replacement: {
@ -86,9 +80,9 @@ export default definePlugin({
} }
], ],
customSections: [] as ((SectionTypes: Record<string, unknown>) => any)[], customSections: [] as ((SectionTypes: SectionTypes) => any)[],
makeSettingsCategories(SectionTypes: Record<string, unknown>) { makeSettingsCategories(SectionTypes: SectionTypes) {
return [ return [
{ {
section: SectionTypes.HEADER, section: SectionTypes.HEADER,
@ -167,7 +161,7 @@ export default definePlugin({
patchedSettings: new WeakSet(), patchedSettings: new WeakSet(),
addSettings(elements: any[], element: { header?: string; settings: string[]; }, sectionTypes: Record<string, unknown>) { addSettings(elements: any[], element: { header?: string; settings: string[]; }, sectionTypes: SectionTypes) {
if (this.patchedSettings.has(elements) || !this.isRightSpot(element)) return; if (this.patchedSettings.has(elements) || !this.isRightSpot(element)) return;
this.patchedSettings.add(elements); this.patchedSettings.add(elements);
@ -175,6 +169,20 @@ export default definePlugin({
elements.push(...this.makeSettingsCategories(sectionTypes)); elements.push(...this.makeSettingsCategories(sectionTypes));
}, },
wrapSettingsHook(originalHook: (...args: any[]) => Record<string, unknown>[]) {
return (...args: any[]) => {
const elements = originalHook(...args);
if (!this.patchedSettings.has(elements))
elements.unshift(...this.makeSettingsCategories({
HEADER: "HEADER",
DIVIDER: "DIVIDER",
CUSTOM: "CUSTOM"
}));
return elements;
};
},
options: { options: {
settingsLocation: { settingsLocation: {
type: OptionType.SELECT, type: OptionType.SELECT,
@ -213,15 +221,24 @@ export default definePlugin({
return ""; return "";
}, },
makeInfoElements(Component: React.ComponentType<React.PropsWithChildren>, props: React.PropsWithChildren) { getInfoRows() {
const { electronVersion, chromiumVersion, additionalInfo } = this; const { electronVersion, chromiumVersion, additionalInfo } = this;
return ( const rows = [`Vencord ${gitHash}${additionalInfo}`];
<>
<Component {...props}>Vencord {gitHash}{additionalInfo}</Component> if (electronVersion) rows.push(`Electron ${electronVersion}`);
{electronVersion && <Component {...props}>Electron {electronVersion}</Component>} if (chromiumVersion) rows.push(`Chromium ${chromiumVersion}`);
{chromiumVersion && <Component {...props}>Chromium {chromiumVersion}</Component>}
</> return rows;
},
getInfoString() {
return "\n" + this.getInfoRows().join("\n");
},
makeInfoElements(Component: React.ComponentType<React.PropsWithChildren>, props: React.PropsWithChildren) {
return this.getInfoRows().map((text, i) =>
<Component key={i} {...props}>{text}</Component>
); );
} }
}); });

Loading…
Cancel
Save