bos-settings/frontend/src/lib/theme/index.ts
Breadway dce2031743 Settings redesign: hub-based navigation, plus hardening and bug fixes
Rework the settings app around hub pages (home, network, displays, input,
apps, privacy, system) with a redesigned sidebar, shared nav state, and new
hub view components. Alongside the redesign: validate webview inputs into
root commands (users, firewall, snapshots, wifi), fix set_charge_threshold
writing the percentage via tee stdin, prevent streaming installs from
hanging on inherited stdin, add frontend type fixes, sync versions to
0.8.2, and clean up clippy/svelte-check warnings.
2026-08-31 16:04:02 +08:00

29 lines
950 B
TypeScript

// Bridges bread-theme's pywal-derived palette into the webview. Mirrors
// bread_theme::gtk::apply_shared()'s two-phase pattern: fetch once at
// startup, then keep it live via a backend-pushed event - see
// src-tauri/src/commands/theme.rs for the file-watch side of this.
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
const STYLE_ELEMENT_ID = "bread-theme";
function applyThemeCss(css: string) {
let style = document.getElementById(STYLE_ELEMENT_ID);
if (!style) {
style = document.createElement("style");
style.id = STYLE_ELEMENT_ID;
document.head.appendChild(style);
}
style.textContent = css;
}
/** Call once at startup (e.g. from a root `$effect`/`onMount`). */
export async function initTheme(): Promise<void> {
const css = await invoke<string>("get_theme_css");
applyThemeCss(css);
await listen<string>("theme-changed", (event) => {
applyThemeCss(event.payload);
});
}