From 9d06aab19ac802531906a35bc3126eb259e5d33c Mon Sep 17 00:00:00 2001 From: Beef Date: Sun, 8 Jan 2023 23:24:24 +0000 Subject: [PATCH] [Bugfix] Fix breaking light and AMOLED theme --- src/index.ts | 2 ++ src/ui/fixTheme.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/ui/fixTheme.ts diff --git a/src/index.ts b/src/index.ts index 521415d..eae7b63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ import * as components from "@ui/components"; import * as toasts from "@ui/toasts"; import { patchAssets, all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets"; import initSettings from "@ui/settings"; +import { fixTheme } from "@ui/fixTheme"; import { connectToDebugger, patchLogHook } from "@lib/debug"; import { initPlugins, plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings } from "@lib/plugins"; @@ -56,6 +57,7 @@ async function init() { initSettings(); patchAssets(); patchLogHook(); + fixTheme(); initPlugins(); } catch (e: Error | any) { erroredOnLoad = true; diff --git a/src/ui/fixTheme.ts b/src/ui/fixTheme.ts new file mode 100644 index 0000000..cde4a7d --- /dev/null +++ b/src/ui/fixTheme.ts @@ -0,0 +1,31 @@ +// Loosely based on https://github.com/Aliucord/AliucordRN/blob/main/src/ui/patchTheme.ts +// Literally could not figure this out, many thanks + +import { findByProps, findByStoreName } from "@metro/filters"; +import { FluxDispatcher } from "@metro/common"; +import logger from "@/lib/logger"; + +const ThemeManager = findByProps("updateTheme", "overrideTheme"); +const AMOLEDThemeManager = findByProps("setAMOLEDThemeEnabled"); +const ThemeStore = findByStoreName("ThemeStore"); +const UnsyncedUserSettingsStore = findByStoreName("UnsyncedUserSettingsStore"); + +export function fixTheme() { + try { + if (ThemeStore) { + function override() { + const theme = ThemeStore.theme || "dark"; + ThemeManager.overrideTheme(theme); + + if (AMOLEDThemeManager && UnsyncedUserSettingsStore.useAMOLEDTheme === 2) { + AMOLEDThemeManager.setAMOLEDThemeEnabled(true); + } + FluxDispatcher.unsubscribe("I18N_LOAD_START", override); + } + + FluxDispatcher.subscribe("I18N_LOAD_START", override); + } + } catch(e) { + logger.error("Failed to fix theme...", e) + } +} \ No newline at end of file