Skip to content

Commit

Permalink
fix: crash after opening settings and late ignition
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeIlLeone committed Feb 8, 2024
1 parent fb2f049 commit 6f41403
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
40 changes: 7 additions & 33 deletions src/renderer/coremods/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
import { Messages } from "@common/i18n";
import { Text } from "@components";
import { Injector } from "@replugged";
import { filters, waitForModule } from "src/renderer/modules/webpack";
import type { Section as SectionType } from "src/types/coremods/settings";
import { Divider, Header, Section, insertSections, settingsTools } from "./lib";
import { General, Plugins, QuickCSS, Themes, Updater } from "./pages";

const injector = new Injector();

export { insertSections };

interface VersionMod {
default: () => React.ReactElement;
export function VersionInfo(): React.ReactElement {
return (
<Text variant="text-xs/normal" color="text-muted" tag="span" style={{ textTransform: "none" }}>
{Messages.REPLUGGED_VERSION.format({ version: window.RepluggedNative.getVersion() })}
</Text>
);
}
async function injectVersionInfo(): Promise<void> {
const mod = await waitForModule<VersionMod>(filters.bySource(".versionHash"), { raw: true });

injector.after(mod.exports, "default", (_, res) => {
res.props.children.push(
<Text
variant="text-xs/normal"
color="text-muted"
tag="span"
style={{ textTransform: "none" }}>
{Messages.REPLUGGED_VERSION.format({ version: window.RepluggedNative.getVersion() })}
</Text>,
);
});
}

export async function start(): Promise<void> {
void injectVersionInfo();

export function start(): void {
settingsTools.addAfter("Billing", [
Divider(),
Header("Replugged"),
Expand Down Expand Up @@ -61,17 +46,6 @@ export async function start(): Promise<void> {
elem: Updater,
}),
]);

const mod = await waitForModule<{
default: {
prototype: {
getPredicateSections: (_: unknown) => SectionType[];
};
};
}>(filters.bySource("getPredicateSections"));
injector.after(mod.default.prototype, "getPredicateSections", (_, res) => {
return insertSections(res);
});
}

export function stop(): void {
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/coremods/settings/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { PlaintextPatch } from "src/types";

const coremodStr = "replugged.coremods.coremods.settings";

export default [
{
find: "getPredicateSections",
replacements: [
{
match: /this\.props\.sections\.filter\((.+?)\)}/,
replace: (_, sections) =>
`${coremodStr}.insertSections(this.props.sections.filter(${sections}))};`,
},
],
},
{
find: ".versionHash",
replacements: [
{
match: /appArch,children:.{0,200}?className:\w+\.line,.{0,100}children:\w+}\):null/,
replace: `$&,${coremodStr}.VersionInfo()`,
},
],
},
] as PlaintextPatch[];
2 changes: 2 additions & 0 deletions src/renderer/managers/coremods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { default as notices } from "../coremods/notices/plaintextPatches";
import { default as contextMenu } from "../coremods/contextMenu/plaintextPatches";
import { default as languagePlaintext } from "../coremods/language/plaintextPatches";
import { default as commandsPlaintext } from "../coremods/commands/plaintextPatches";
import { default as settingsPlaintext } from "../coremods/settings/plaintextPatches";
import { Logger } from "../modules/logger";

const logger = Logger.api("Coremods");
Expand Down Expand Up @@ -85,6 +86,7 @@ export function runPlaintextPatches(): Promise<void> {
contextMenu,
languagePlaintext,
commandsPlaintext,
settingsPlaintext,
].forEach(patchPlaintext);
res();
});
Expand Down

0 comments on commit 6f41403

Please sign in to comment.