[Themes] Implement chat background image (#64)
* [Themes] hardcode fuyu chat bg * [Themes > BG] listen to theme file * remove .apply() * some uhh misc changes * readd * how * [Global] Minor changes --------- Co-authored-by: Beef <beefers@riseup.net>
This commit is contained in:
parent
ef0b162d3a
commit
20310db733
5 changed files with 40 additions and 10 deletions
|
@ -68,7 +68,7 @@ export async function evalPlugin(plugin: Plugin) {
|
|||
|
||||
const raw = (0, eval)(pluginString)(vendettaForPlugins);
|
||||
const ret = typeof raw == "function" ? raw() : raw;
|
||||
return ret.default || ret;
|
||||
return ret?.default || ret;
|
||||
}
|
||||
|
||||
export async function startPlugin(id: string) {
|
||||
|
@ -83,12 +83,12 @@ export async function startPlugin(id: string) {
|
|||
pluginRet.onLoad?.();
|
||||
}
|
||||
plugin.enabled = true;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
logger.error(`Plugin ${plugin.id} errored whilst loading, and will be unloaded`, e);
|
||||
|
||||
try {
|
||||
loadedPlugins[plugin.id]?.onUnload?.();
|
||||
} catch(e2) {
|
||||
} catch (e2) {
|
||||
logger.error(`Plugin ${plugin.id} errored whilst unloading`, e2);
|
||||
}
|
||||
|
||||
|
@ -106,10 +106,10 @@ export function stopPlugin(id: string, disable = true) {
|
|||
if (!settings.safeMode?.enabled) {
|
||||
try {
|
||||
pluginRet?.onUnload?.();
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
logger.error(`Plugin ${plugin.id} errored whilst unloading`, e);
|
||||
}
|
||||
|
||||
|
||||
delete loadedPlugins[id];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Theme, ThemeData } from "@types";
|
||||
import { findByProps } from "@metro/filters";
|
||||
import { ReactNative, chroma } from "@metro/common";
|
||||
import { findByName, findByProps } from "@metro/filters";
|
||||
import { instead } from "@lib/patcher";
|
||||
import { createFileBackend, createMMKVBackend, createStorage, wrapSync, awaitSyncWrapper } from "@lib/storage";
|
||||
import { safeFetch } from "@utils";
|
||||
|
@ -19,6 +19,21 @@ async function writeTheme(theme: Theme | {}) {
|
|||
await createFileBackend("vendetta_theme.json").set(theme);
|
||||
}
|
||||
|
||||
export function patchChatBackground() {
|
||||
const currentTheme = getCurrentTheme()?.data?.background;
|
||||
if (!currentTheme) return;
|
||||
|
||||
const MessagesWrapperConnected = findByName("MessagesWrapperConnected", false);
|
||||
if (!MessagesWrapperConnected) return;
|
||||
|
||||
return instead("default", MessagesWrapperConnected, (args, orig) => React.createElement(ReactNative.ImageBackground, {
|
||||
style: { flex: 1, height: "100%" },
|
||||
source: { uri: currentTheme.url },
|
||||
blurRadius: currentTheme.blur,
|
||||
children: orig(...args),
|
||||
}));
|
||||
}
|
||||
|
||||
function normalizeToHex(colorString: string): string {
|
||||
if (chroma.valid(colorString)) return chroma(colorString).hex();
|
||||
|
||||
|
@ -39,7 +54,7 @@ function processData(data: ThemeData) {
|
|||
|
||||
for (const key in semanticColors) {
|
||||
for (const index in semanticColors[key]) {
|
||||
semanticColors[key][index] = normalizeToHex(semanticColors[key][index]);
|
||||
semanticColors[key][index] &&= normalizeToHex(semanticColors[key][index] as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +173,10 @@ export async function initThemes() {
|
|||
const themeIndex = theme === "amoled" ? 2 : theme === "light" ? 1 : 0;
|
||||
|
||||
const semanticColorVal = selectedTheme.data?.semanticColors?.[name]?.[themeIndex];
|
||||
if (name === "CHAT_BACKGROUND" && typeof selectedTheme.data?.background?.alpha === "number") {
|
||||
return chroma(semanticColorVal || "black").alpha(1 - selectedTheme.data.background.alpha).hex();
|
||||
}
|
||||
|
||||
if (semanticColorVal) return semanticColorVal;
|
||||
|
||||
const rawValue = selectedTheme.data?.rawColors?.[colorDef.raw];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue