From 1d2577edb2039f8598bef304aafcbefd8c8a441d Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Tue, 16 Apr 2024 01:15:03 +0800 Subject: [PATCH] [themes] hacks not a good fix but it leads to better experience ig --- src/index.ts | 10 +++++++--- src/lib/managers/themes.ts | 23 +++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 62ac615..61f646c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { initVendettaObject } from "@core/vendettaObject"; import { patchAssets } from "@lib/api/assets"; import { patchCommands } from "@lib/api/commands"; import { injectFluxInterceptor } from "@lib/api/flux"; -import { removeFile } from "@lib/api/native/fs"; +import { removeFile, writeFile } from "@lib/api/native/fs"; import { isPyonLoader, isThemeSupported } from "@lib/api/native/loader"; import { FileManager } from "@lib/api/native/modules"; import { patchLogHook } from "@lib/debug"; @@ -22,8 +22,12 @@ export default async () => { // Themes if (isThemeSupported()) { try { - if (isPyonLoader() && FileManager.removeFile != null) { - removeFile("vendetta_theme.json", ""); + if (isPyonLoader()) { + if (FileManager.removeFile != null) { + removeFile("vendetta_theme.json", ""); + } else { + writeFile("vendetta_theme.json", "null", ""); + } } initThemes(); } catch (e) { diff --git a/src/lib/managers/themes.ts b/src/lib/managers/themes.ts index e5098ef..174a901 100644 --- a/src/lib/managers/themes.ts +++ b/src/lib/managers/themes.ts @@ -141,6 +141,10 @@ function processData(data: ThemeData) { if (Platform.OS === "android") applyAndroidAlphaKeys(rawColors); } + // this field is required by the spec but vd seems to ignore this + // so are most vd themes + data.spec ??= 2; + return data; } @@ -191,17 +195,17 @@ export async function installTheme(id: string) { await fetchTheme(id); } -export function selectTheme(theme: Theme | null) { +export function selectTheme(theme: Theme | null, write = true) { if (theme) theme.selected = true; Object.keys(themes).forEach( k => themes[k].selected = themes[k].id === theme?.id ); - if (theme === null) { + if (theme == null && write) { return writeTheme({}); + } else if (theme) { + return writeTheme(theme); } - - return writeTheme(theme); } export async function removeTheme(id: string) { @@ -258,16 +262,6 @@ function patchColor() { before("isThemeLight", isThemeModule, callback); before("updateTheme", ThemeManager, callback); - ThemeStore.addChangeListener(() => { - if (ThemeStore.theme) { - enabled = ThemeStore.theme === vdKey; - if (!enabled) { - selectTheme(null); - vdThemeFallback = ThemeStore.theme; - } - } - }); - after("get", mmkvStorage, ([a], ret) => { if (a === "SelectivelySyncedUserSettingsStore") { storageResolved = true; @@ -362,6 +356,7 @@ export function applyTheme(appliedTheme: Theme | null, fallbackTheme?: string) { if (!fallbackTheme) fallbackTheme = getDefaultFallbackTheme(); currentTheme = appliedTheme; + enabled = !!currentTheme; vdThemeFallback = fallbackTheme!!; vdKey = `vd-theme-${inc++}-${fallbackTheme}`;