diff --git a/src/lib/api/autoplay.ts b/src/lib/api/autoplay.ts index fe8d6f5..eb8e3f1 100644 --- a/src/lib/api/autoplay.ts +++ b/src/lib/api/autoplay.ts @@ -1,24 +1,11 @@ /** * Autoplay API * - * Functions to control autoplay settings in the backend. + * Functions to control autoplay in the backend. */ import { invoke } from "@tauri-apps/api/core"; -export interface AutoplaySettings { - enabled: boolean; - countdownSeconds: number; -} - -export async function getAutoplaySettings(): Promise { - return invoke("player_get_autoplay_settings"); -} - -export async function setAutoplaySettings(settings: AutoplaySettings): Promise { - return invoke("player_set_autoplay_settings", { settings }); -} - export async function cancelAutoplayCountdown(): Promise { return invoke("player_cancel_autoplay_countdown"); } diff --git a/src/lib/api/conversions.ts b/src/lib/api/conversions.ts deleted file mode 100644 index 16a6d88..0000000 --- a/src/lib/api/conversions.ts +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Rust-based conversion utilities via Tauri commands - * - * These functions provide centralized conversion logic in Rust. - * All conversions are handled by the Rust backend for consistency. - */ - -import { invoke } from '@tauri-apps/api/core'; - -/** - * Format time in seconds to MM:SS display string - * @param seconds - Time in seconds - * @returns Formatted string like "3:45" or "12:09" - */ -export async function formatTime(seconds: number): Promise { - return invoke('format_time_seconds', { seconds }); -} - -/** - * Format time in seconds to HH:MM:SS or MM:SS display string - * Automatically chooses format based on duration - * @param seconds - Time in seconds - * @returns Formatted string like "1:23:45" or "3:45" - */ -export async function formatTimeLong(seconds: number): Promise { - return invoke('format_time_seconds_long', { seconds }); -} - -/** - * Convert Jellyfin ticks to seconds - * @param ticks - Time in Jellyfin ticks (10,000,000 ticks = 1 second) - * @returns Time in seconds - */ -export async function ticksToSeconds(ticks: number): Promise { - return invoke('convert_ticks_to_seconds', { ticks }); -} - -/** - * Calculate progress percentage from position and duration - * @param position - Current position in seconds - * @param duration - Total duration in seconds - * @returns Progress as percentage (0.0 to 100.0) - */ -export async function calculateProgress(position: number, duration: number): Promise { - return invoke('calc_progress', { position, duration }); -} - -/** - * Convert percentage volume (0-100) to normalized (0.0-1.0) - * @param percent - Volume as percentage (0 to 100) - * @returns Normalized volume (0.0 to 1.0) - */ -export async function percentToVolume(percent: number): Promise { - return invoke('convert_percent_to_volume', { percent }); -} - -/** - * Synchronous time formatting utilities for high-frequency UI updates - * - * These are kept in TypeScript for performance reasons when formatting - * needs to happen frequently (e.g., position updates every 100ms). - * - * For less frequent conversions, prefer the async Rust-based functions above. - */ - -/** - * Format time in seconds to MM:SS display string (synchronous) - * @param seconds - Time in seconds - * @returns Formatted string like "3:45" or "12:09" - */ -export function formatTimeSync(seconds: number): string { - const mins = Math.floor(seconds / 60); - const secs = Math.floor(seconds % 60); - return `${mins}:${secs.toString().padStart(2, '0')}`; -} - -/** - * Format time in seconds to HH:MM:SS or MM:SS display string (synchronous) - * @param seconds - Time in seconds - * @returns Formatted string like "1:23:45" or "3:45" - */ -export function formatTimeLongSync(seconds: number): string { - const hours = Math.floor(seconds / 3600); - const mins = Math.floor((seconds % 3600) / 60); - const secs = Math.floor(seconds % 60); - - if (hours > 0) { - return `${hours}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; - } - return `${mins}:${secs.toString().padStart(2, '0')}`; -} - -/** - * Calculate progress percentage (synchronous) - * @param position - Current position in seconds - * @param duration - Total duration in seconds - * @returns Progress as percentage (0 to 100) - */ -export function calculateProgressSync(position: number, duration: number): number { - if (duration <= 0) return 0; - return Math.min(100, Math.max(0, (position / duration) * 100)); -} diff --git a/src/lib/api/sleep-timer.ts b/src/lib/api/sleep-timer.ts deleted file mode 100644 index 1bb9e13..0000000 --- a/src/lib/api/sleep-timer.ts +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Sleep Timer API - * - * Functions to control the sleep timer in the backend. - */ - -import { invoke } from "@tauri-apps/api/core"; -import type { SleepTimerMode } from "$lib/services/playerEvents"; - -export interface SleepTimerState { - mode: SleepTimerMode; - remainingSeconds: number; -} - -export async function setSleepTimer(mode: SleepTimerMode): Promise { - return invoke("player_set_sleep_timer", { mode }); -} - -export async function cancelSleepTimer(): Promise { - return invoke("player_cancel_sleep_timer"); -} - -export async function getSleepTimer(): Promise { - return invoke("player_get_sleep_timer"); -} - -// Helper functions for common timer modes - -export async function setTimeBasedTimer(minutes: number): Promise { - const endTime = Date.now() + minutes * 60 * 1000; - return setSleepTimer({ kind: "time", endTime }); -} - -export async function setEndOfTrackTimer(): Promise { - return setSleepTimer({ kind: "endOfTrack" }); -} - -export async function setEpisodesTimer(count: number): Promise { - return setSleepTimer({ kind: "episodes", remaining: count }); -} diff --git a/src/lib/stores/sleepTimer.ts b/src/lib/stores/sleepTimer.ts index 4f00e86..d60b0b0 100644 --- a/src/lib/stores/sleepTimer.ts +++ b/src/lib/stores/sleepTimer.ts @@ -1,15 +1,17 @@ /** - * Sleep Timer Store (Display Only - Backend-First Architecture) + * Sleep Timer Store (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. + * Components call store methods which invoke the backend API. * * TRACES: UR-026 | DR-029 */ import { writable, derived } from "svelte/store"; +import { invoke } from "@tauri-apps/api/core"; export type SleepTimerMode = | { kind: "off" } @@ -33,6 +35,30 @@ function createSleepTimerStore() { return { subscribe, set, // Updated by playerEvents.ts when backend emits SleepTimerChanged event + + // Methods that invoke the backend API + async setTimeTimer(minutes: number): Promise { + const endTime = Date.now() + minutes * 60 * 1000; + await invoke("player_set_sleep_timer", { + mode: { kind: "time", endTime }, + }); + }, + + async setEndOfTrackTimer(): Promise { + await invoke("player_set_sleep_timer", { + mode: { kind: "endOfTrack" }, + }); + }, + + async setEpisodesTimer(count: number): Promise { + await invoke("player_set_sleep_timer", { + mode: { kind: "episodes", remaining: count }, + }); + }, + + async cancel(): Promise { + await invoke("player_cancel_sleep_timer"); + }, }; }