19 lines
738 B
TypeScript
19 lines
738 B
TypeScript
export type DisplaySurface = "top" | "bottom";
|
|
|
|
const DISPLAY_SURFACE_EVENT = "healer-man:display-surface";
|
|
let currentSurface: DisplaySurface = "top";
|
|
|
|
export function requestDisplaySurface(surface: DisplaySurface): void {
|
|
currentSurface = surface;
|
|
window.dispatchEvent(new CustomEvent<DisplaySurface>(DISPLAY_SURFACE_EVENT, { detail: surface }));
|
|
}
|
|
|
|
export function subscribeDisplaySurface(listener: (surface: DisplaySurface) => void): () => void {
|
|
const onSurface = (event: Event) => {
|
|
currentSurface = (event as CustomEvent<DisplaySurface>).detail;
|
|
listener(currentSurface);
|
|
};
|
|
window.addEventListener(DISPLAY_SURFACE_EVENT, onSurface);
|
|
return () => window.removeEventListener(DISPLAY_SURFACE_EVENT, onSurface);
|
|
}
|