mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:21 +01:00
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
import { fireAndForget } from "../fireAndForget";
|
|
|
|
export type Appearance = "light" | "dark";
|
|
|
|
export function getCSSAppearance(): Appearance {
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
}
|
|
|
|
export async function getWindowAppearance(): Promise<Appearance> {
|
|
const a = await getCurrentWebviewWindow().theme();
|
|
return a ?? getCSSAppearance();
|
|
}
|
|
|
|
/**
|
|
* Subscribe to appearance (dark/light) changes. Note, we use Tauri Window appearance instead of
|
|
* CSS appearance because CSS won't fire the way we handle window theme management.
|
|
*/
|
|
export function subscribeToWindowAppearanceChange(
|
|
cb: (appearance: Appearance) => void,
|
|
): () => void {
|
|
const container = {
|
|
unsubscribe: () => {},
|
|
};
|
|
|
|
fireAndForget(
|
|
getCurrentWebviewWindow()
|
|
.onThemeChanged((t) => {
|
|
cb(t.payload);
|
|
})
|
|
.then((l) => {
|
|
container.unsubscribe = l;
|
|
}),
|
|
);
|
|
|
|
return () => container.unsubscribe();
|
|
}
|
|
|
|
export function resolveAppearance(
|
|
preferredAppearance: Appearance,
|
|
appearanceSetting: string,
|
|
): Appearance {
|
|
const appearance = appearanceSetting === "system" ? preferredAppearance : appearanceSetting;
|
|
return appearance === "dark" ? "dark" : "light";
|
|
}
|
|
|
|
export function subscribeToPreferredAppearance(cb: (a: Appearance) => void) {
|
|
cb(getCSSAppearance());
|
|
fireAndForget(getWindowAppearance().then(cb));
|
|
subscribeToWindowAppearanceChange(cb);
|
|
}
|