Add a typed platform package to decouple the frontend from Tauri (#539)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-08-14 12:44:01 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent 0068be9ffc
commit 2383f06e71
107 changed files with 954 additions and 505 deletions
+4 -27
View File
@@ -1,5 +1,4 @@
import { listen } from "@tauri-apps/api/event";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { platform } from "@yaakapp-internal/platform";
export type Appearance = "light" | "dark";
@@ -10,7 +9,7 @@ export function getCSSAppearance(): Appearance {
}
export async function getWindowAppearance(): Promise<Appearance> {
const appearance = await getCurrentWebviewWindow().theme();
const appearance = await platform.window.theme();
return appearance ?? getCSSAppearance();
}
@@ -24,35 +23,13 @@ export function subscribeToCSSAppearanceChange(cb: (appearance: Appearance) => v
export function subscribeToWindowAppearanceChange(
cb: (appearance: Appearance) => void,
): () => void {
const container = {
unsubscribe: () => {},
};
void getCurrentWebviewWindow()
.onThemeChanged((theme) => {
cb(theme.payload);
})
.then((listener) => {
container.unsubscribe = listener;
});
return () => container.unsubscribe();
return platform.window.onThemeChanged(cb);
}
export function subscribeToSystemAppearanceChange(
cb: (appearance: Appearance) => void,
): () => void {
const container = {
unsubscribe: () => {},
};
void listen<Appearance>(SYSTEM_APPEARANCE_CHANGE_EVENT, (event) => {
cb(event.payload);
}).then((listener) => {
container.unsubscribe = listener;
});
return () => container.unsubscribe();
return platform.listen<Appearance>(SYSTEM_APPEARANCE_CHANGE_EVENT, cb);
}
export function resolveAppearance(