Refactor settings

This commit is contained in:
James Babcock committed 2026-06-01 15:35:35 -07:00
1 parent d67afcbfdb
commit 5da3b48c7d
13 files changed
+538 -721

No files matched your search

+23 -57
View File
@@ -1,72 +1,38 @@
import { GrayImage } from "../graphics/image";
import { type MediaControllerState } from "../native/media-controller";
import { type DashboardPluginId } from "./dashboard-settings";
import { Layer } from "./layers";
import { DashboardPlugin } from "./dashboard-plugin";
import { NightscoutDashboardPlugin } from "./apps/nightscout";
import { NightscoutState } from "~/native/nightscout-bridge";
import { MusicControllerDashboardPlugin } from "./apps/music-controller";
import { DebugLogDashboardPlugin } from "./apps/debug-log";
export type DashboardPluginState = {
logLines: string[];
media: MediaControllerState;
nightscout: NightscoutState;
nightscoutConfigured: boolean;
};
export { DashboardPlugin } from "./dashboard-plugin";
export type { DashboardPluginCardBounds, DashboardPluginCardRenderArgs, DashboardPluginState } from "./dashboard-plugin";
export type DashboardPluginCardBounds = {
x: number;
y: number;
width: number;
height: number;
};
export type DashboardPluginCardRenderArgs = {
image: GrayImage;
bounds: DashboardPluginCardBounds;
selected: boolean;
state: DashboardPluginState;
};
export abstract class DashboardPlugin {
readonly id: DashboardPluginId;
readonly label: string;
constructor(config: {
id: DashboardPluginId;
label: string;
}) {
this.id = config.id;
this.label = config.label;
let dashboardPlugins: DashboardPlugin[] | null = null;
function getDashboardPlugins(): DashboardPlugin[] {
if (!dashboardPlugins) {
dashboardPlugins = [
{
id: "blank",
label: "Blank",
renderCard: () => {},
createFullscreenLayer: () => null,
},
new DebugLogDashboardPlugin(),
new MusicControllerDashboardPlugin(),
new NightscoutDashboardPlugin(),
];
}
return dashboardPlugins;
};
abstract renderCard(args: DashboardPluginCardRenderArgs): void;
createFullscreenLayer(getState: () => DashboardPluginState): Layer | null {
return null;
}
}
const DASHBOARD_PLUGINS: DashboardPlugin[] = [
{
id: "blank",
label: "Blank",
renderCard: () => {},
createFullscreenLayer: () => null,
},
new DebugLogDashboardPlugin(),
new MusicControllerDashboardPlugin(),
new NightscoutDashboardPlugin(),
];
const PLUGIN_MAP = new Map<DashboardPluginId, DashboardPlugin>(
DASHBOARD_PLUGINS.map((plugin) => [plugin.id, plugin]),
);
export function listDashboardPlugins(): DashboardPlugin[] {
return [...DASHBOARD_PLUGINS];
return [...getDashboardPlugins()];
}
export function getDashboardPlugin(pluginId: DashboardPluginId): DashboardPlugin {
const PLUGIN_MAP = new Map<DashboardPluginId, DashboardPlugin>(
getDashboardPlugins().map((plugin) => [plugin.id, plugin]),
);
return PLUGIN_MAP.get(pluginId) ?? PLUGIN_MAP.get("blank")!;
}