Skip to content

Commit

Permalink
[themes] hacks
Browse files Browse the repository at this point in the history
not a good fix but it leads to better experience ig
  • Loading branch information
pylixonly committed Apr 15, 2024
1 parent ccb2a37 commit 1d2577e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
23 changes: 9 additions & 14 deletions src/lib/managers/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`;

Expand Down

0 comments on commit 1d2577e

Please sign in to comment.