1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-17 15:45:43 +01:00
Files
frontend/src/data/ws-themes.ts
Wendelin 830d8d2410 Add type import check to eslint (#22488)
* Add type import check to eslint

* Add type imports with eslint --fix
2024-10-30 11:12:30 +00:00

53 lines
1.3 KiB
TypeScript

import type { Connection } from "home-assistant-js-websocket";
import { createCollection } from "home-assistant-js-websocket";
export interface ThemeVars {
// Incomplete
"primary-color": string;
"text-primary-color": string;
"accent-color": string;
[key: string]: string;
}
export type Theme = ThemeVars & {
modes?: {
light?: ThemeVars;
dark?: ThemeVars;
};
};
export interface Themes {
default_theme: string;
default_dark_theme: string | null;
themes: Record<string, Theme>;
// Currently effective dark mode. Will never be undefined. If user selected "auto"
// in theme picker, this property will still contain either true or false based on
// what has been determined via system preferences and support from the selected theme.
darkMode: boolean;
// Currently globally active theme name
theme: string;
}
const fetchThemes = (conn) =>
conn.sendMessagePromise({
type: "frontend/get_themes",
});
const subscribeUpdates = (conn, store) =>
conn.subscribeEvents(
() => fetchThemes(conn).then((data) => store.setState(data, true)),
"themes_updated"
);
export const subscribeThemes = (
conn: Connection,
onChange: (themes: Themes) => void
) =>
createCollection<Themes>(
"_thm",
fetchThemes,
subscribeUpdates,
conn,
onChange
);