[Bugfix] Fix breaking light and AMOLED theme

This commit is contained in:
Beef 2023-01-08 23:24:24 +00:00
parent ad2c3573ed
commit 9d06aab19a
2 changed files with 33 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import * as components from "@ui/components";
import * as toasts from "@ui/toasts"; import * as toasts from "@ui/toasts";
import { patchAssets, all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets"; import { patchAssets, all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets";
import initSettings from "@ui/settings"; import initSettings from "@ui/settings";
import { fixTheme } from "@ui/fixTheme";
import { connectToDebugger, patchLogHook } from "@lib/debug"; import { connectToDebugger, patchLogHook } from "@lib/debug";
import { initPlugins, plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings } from "@lib/plugins"; import { initPlugins, plugins, fetchPlugin, evalPlugin, stopPlugin, removePlugin, getSettings } from "@lib/plugins";
@ -56,6 +57,7 @@ async function init() {
initSettings(); initSettings();
patchAssets(); patchAssets();
patchLogHook(); patchLogHook();
fixTheme();
initPlugins(); initPlugins();
} catch (e: Error | any) { } catch (e: Error | any) {
erroredOnLoad = true; erroredOnLoad = true;

31
src/ui/fixTheme.ts Normal file
View file

@ -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)
}
}