First working POC

This commit is contained in:
2026-01-26 22:21:54 +01:00
commit cfddc1edea
255 changed files with 77606 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
/**
* Sleep Timer Store (Display Only - Backend-First Architecture)
*
* This store reflects sleep timer state from the backend.
* All logic is in the Rust backend (PlayerController).
*
* The backend emits SleepTimerChanged events to update this store.
*/
import { writable, derived } from "svelte/store";
export type SleepTimerMode =
| { kind: "off" }
| { kind: "time"; endTime: number }
| { kind: "endOfTrack" }
| { kind: "episodes"; remaining: number };
interface SleepTimerState {
mode: SleepTimerMode;
remainingSeconds: number;
}
function createSleepTimerStore() {
const initialState: SleepTimerState = {
mode: { kind: "off" },
remainingSeconds: 0,
};
const { subscribe, set } = writable<SleepTimerState>(initialState);
return {
subscribe,
set, // Updated by playerEvents.ts when backend emits SleepTimerChanged event
};
}
export const sleepTimer = createSleepTimerStore();
// Derived stores for convenient access
export const sleepTimerMode = derived(sleepTimer, ($s) => $s.mode);
export const sleepTimerActive = derived(
sleepTimer,
($s) => $s.mode.kind !== "off"
);
export const sleepTimerRemainingSeconds = derived(
sleepTimer,
($s) => $s.remainingSeconds
);
export const sleepTimerRemainingEpisodes = derived(sleepTimer, ($s) =>
$s.mode.kind === "episodes" ? $s.mode.remaining : 0
);