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