From a462b8e81ea56658d4953d9c42884c8c611614f7 Mon Sep 17 00:00:00 2001 From: Beef Date: Sun, 8 Jan 2023 22:33:41 +0000 Subject: [PATCH] [UI > Settings] Fix removing billing settings and potential memory leak --- src/lib/debug.ts | 4 +--- src/ui/settings/index.tsx | 16 +++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/debug.ts b/src/lib/debug.ts index a8cfa72..e513599 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -4,8 +4,6 @@ import { showToast } from "@ui/toasts"; import logger from "@lib/logger"; export let socket: WebSocket; -let iLoveBundlers = eval; - export function connectToDebugger(url: string) { if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) { socket.close(); @@ -22,7 +20,7 @@ export function connectToDebugger(url: string) { socket.addEventListener("message", (message: any) => { try { - iLoveBundlers(message.data); + (0, eval)(message.data); } catch (e) { console.error(e); } diff --git a/src/ui/settings/index.tsx b/src/ui/settings/index.tsx index 17974d0..640afdd 100644 --- a/src/ui/settings/index.tsx +++ b/src/ui/settings/index.tsx @@ -9,7 +9,7 @@ import AssetBrowser from "@ui/settings/pages/AssetBrowser"; const screensModule = findByDisplayName("getScreens", false); const settingsModule = findByDisplayName("UserSettingsOverviewWrapper", false); -let settingsInjected = false; +let prevPatches: Function[] = []; export default function initSettings() { after("default", screensModule, (args, existingScreens) => { @@ -31,19 +31,21 @@ export default function initSettings() { }); after("default", settingsModule, (args, ret) => { + for (let p of prevPatches) p(); + prevPatches = []; + const Overview = findInReactTree(ret.props.children, i => i.type && i.type.name === "UserSettingsOverview"); // Upload logs button gone - after("renderSupportAndAcknowledgements", Overview.type.prototype, (args, { props: { children } }) => { + prevPatches.push(after("renderSupportAndAcknowledgements", Overview.type.prototype, (args, { props: { children } }) => { const index = children.findIndex((c: any) => c?.type?.name === "UploadLogsButton"); if (index !== -1) children.splice(index, 1); - }); + })); - after("render", Overview.type.prototype, (args, { props: { children } }) => { + prevPatches.push(after("render", Overview.type.prototype, (args, { props: { children } }) => { const titles = [i18n.Messages["BILLING_SETTINGS"], i18n.Messages["PREMIUM_SETTINGS"]]; const index = children.findIndex((c: any) => titles.includes(c.props.title)); - children.splice(index === -1 ? 4 : index, settingsInjected ? 1 : 0, ); - if (!settingsInjected) settingsInjected = true; - }); + children.splice(index === -1 ? 4 : index, 0, ); + })); }); } \ No newline at end of file