Migrate all IPC call sites to typed tauri-specta commands.*
Replace the remaining ~155 untyped invoke() calls across stores, services, components, and routes with the generated commands.* wrappers from $lib/api/bindings, so every IPC call is compile-time-checked against the command signatures. - Register repository_get_subtitle_url and repository_get_video_download_url in specta_builder() and the invoke_handler; regenerate bindings.ts. - Source duplicated wire types (AutoplaySettings, CacheConfig, Session, ConnectivityStatus, audio/video settings, etc.) from bindings. - Fix two bugs surfaced by the typed wrappers: - VideoDownloadButton passed an un-awaited Promise as the stream URL. - setAutoplaySettings omitted the required userId argument. - Update unit tests asserting the old invoke(name, args) shape. - Remove the five param-naming guard tests; the compiler and codegen now enforce what they checked. svelte-check: 0 errors. vitest: green. cargo test --lib: green.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import { page } from "$app/stores";
|
||||
import { goto } from "$app/navigation";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import "../app.css";
|
||||
import { auth, needsReauth, isAuthenticated } from "$lib/stores/auth";
|
||||
import { connectivity, isConnected } from "$lib/stores/connectivity";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { commands } from "$lib/api/bindings";
|
||||
import { downloads, activeDownloads, completedDownloads, pendingDownloads, failedDownloads } from "$lib/stores/downloads";
|
||||
import { auth } from "$lib/stores/auth";
|
||||
import DownloadItem from "$lib/components/downloads/DownloadItem.svelte";
|
||||
@@ -85,7 +85,7 @@
|
||||
try {
|
||||
const userId = $auth.user?.id;
|
||||
if (userId) {
|
||||
await invoke("clear_stale_downloads", { userId });
|
||||
await commands.clearStaleDownloads(userId);
|
||||
await downloads.refresh(userId);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -224,7 +224,7 @@
|
||||
const userId = $auth.user?.id;
|
||||
if (userId) {
|
||||
if (confirm('Delete ALL downloads (including completed)? This cannot be undone.')) {
|
||||
await invoke("delete_all_downloads", { userId });
|
||||
await commands.deleteAllDownloads(userId);
|
||||
await downloads.refresh(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { onMount, onDestroy, setContext } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/stores";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { commands } from "$lib/api/bindings";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { auth, isAuthenticated, isLoading as isAuthLoading, currentUser } from "$lib/stores/auth";
|
||||
import { library } from "$lib/stores/library";
|
||||
@@ -66,14 +66,7 @@
|
||||
|
||||
async function updateQueueStatus() {
|
||||
try {
|
||||
const queue = await invoke<{
|
||||
items: any[];
|
||||
currentIndex: number | null;
|
||||
hasNext: boolean;
|
||||
hasPrevious: boolean;
|
||||
shuffle: boolean;
|
||||
repeat: string;
|
||||
}>("player_get_queue");
|
||||
const queue = await commands.playerGetQueue();
|
||||
|
||||
// Reset failure counter on success
|
||||
failedAttempts = 0;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { onMount, untrack } from "svelte";
|
||||
import { page } from "$app/stores";
|
||||
import { goto } from "$app/navigation";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { commands } from "$lib/api/bindings";
|
||||
import type { MediaItem, Library } from "$lib/api/types";
|
||||
import { library, libraryItems, isLibraryLoading, currentLibrary, libraries } from "$lib/stores/library";
|
||||
import { auth } from "$lib/stores/auth";
|
||||
@@ -221,14 +221,11 @@
|
||||
const repo = auth.getRepository();
|
||||
const repositoryHandle = repo.getHandle();
|
||||
const firstTrack = $libraryItems[0];
|
||||
await invoke("player_play_album_track", {
|
||||
repositoryHandle,
|
||||
request: {
|
||||
albumId: item.id,
|
||||
albumName: item.name,
|
||||
trackId: firstTrack.id,
|
||||
shuffle: false,
|
||||
},
|
||||
await commands.playerPlayAlbumTrack(repositoryHandle, {
|
||||
albumId: item.id,
|
||||
albumName: item.name,
|
||||
trackId: firstTrack.id,
|
||||
shuffle: false,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to play album:", e);
|
||||
@@ -248,14 +245,11 @@
|
||||
const repositoryHandle = repo.getHandle();
|
||||
// Pick a random track to start with
|
||||
const randomTrack = $libraryItems[Math.floor(Math.random() * $libraryItems.length)];
|
||||
await invoke("player_play_album_track", {
|
||||
repositoryHandle,
|
||||
request: {
|
||||
albumId: item.id,
|
||||
albumName: item.name,
|
||||
trackId: randomTrack.id,
|
||||
shuffle: true,
|
||||
},
|
||||
await commands.playerPlayAlbumTrack(repositoryHandle, {
|
||||
albumId: item.id,
|
||||
albumName: item.name,
|
||||
trackId: randomTrack.id,
|
||||
shuffle: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to shuffle play album:", e);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { page } from "$app/stores";
|
||||
import { goto } from "$app/navigation";
|
||||
import { invoke, convertFileSrc } from "@tauri-apps/api/core";
|
||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
||||
import { commands } from "$lib/api/bindings";
|
||||
import type { PlayQueueRequest } from "$lib/api/bindings";
|
||||
import type { MediaItem } from "$lib/api/types";
|
||||
import { auth } from "$lib/stores/auth";
|
||||
import { library } from "$lib/stores/library";
|
||||
@@ -125,7 +127,7 @@
|
||||
loading = false;
|
||||
// Sync queue status
|
||||
try {
|
||||
const queueStatus = await invoke<{ hasNext: boolean; hasPrevious: boolean }>("player_get_queue");
|
||||
const queueStatus = await commands.playerGetQueue();
|
||||
hasNext = queueStatus.hasNext;
|
||||
hasPrevious = queueStatus.hasPrevious;
|
||||
} catch (e) {
|
||||
@@ -145,7 +147,7 @@
|
||||
// This prevents audio from continuing in the background and clears stale state
|
||||
if (isVideo) {
|
||||
try {
|
||||
await invoke("player_stop");
|
||||
await commands.playerStop();
|
||||
queue.clear();
|
||||
console.log("loadAndPlay: Stopped audio backend for video playback");
|
||||
} catch (e) {
|
||||
@@ -159,10 +161,7 @@
|
||||
|
||||
if (!startPosition && userId) {
|
||||
try {
|
||||
const progress = await invoke<{ positionTicks: number } | null>(
|
||||
"storage_get_playback_progress",
|
||||
{ userId, itemId: id }
|
||||
);
|
||||
const progress = await commands.storageGetPlaybackProgress(userId, id);
|
||||
console.log("Resume check - retrieved progress:", progress);
|
||||
|
||||
if (progress && progress.positionTicks > 0 && item.runTimeTicks) {
|
||||
@@ -208,7 +207,7 @@
|
||||
isOfflinePlayback = true;
|
||||
|
||||
// Get the storage path and construct full file path
|
||||
const storagePath = await invoke<string>("storage_get_path");
|
||||
const storagePath = await commands.storageGetPath();
|
||||
const fullPath = `${storagePath}/${localDownload.filePath}`;
|
||||
console.log("loadAndPlay: Full local path:", fullPath);
|
||||
|
||||
@@ -230,20 +229,17 @@
|
||||
const repo = auth.getRepository();
|
||||
const repositoryHandle = repo.getHandle();
|
||||
|
||||
await invoke("player_play_tracks", {
|
||||
repositoryHandle,
|
||||
request: {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
await commands.playerPlayTracks(repositoryHandle, {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
});
|
||||
if (startPosition) {
|
||||
await invoke("player_seek", { position: startPosition });
|
||||
await commands.playerSeek(startPosition);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -336,13 +332,11 @@
|
||||
}));
|
||||
|
||||
// Use player_play_queue to set up the backend queue
|
||||
await invoke("player_play_queue", {
|
||||
request: {
|
||||
items: queueItems,
|
||||
startIndex: actualStartIndex,
|
||||
shuffle: shuffleParam,
|
||||
},
|
||||
});
|
||||
await commands.playerPlayQueue({
|
||||
items: queueItems,
|
||||
startIndex: actualStartIndex,
|
||||
shuffle: shuffleParam,
|
||||
} as unknown as PlayQueueRequest);
|
||||
|
||||
// Queue will auto-update from Rust backend event
|
||||
console.log("loadAndPlay: Successfully set up queue with", audioTracks.length, "tracks");
|
||||
@@ -353,16 +347,13 @@
|
||||
const repo = auth.getRepository();
|
||||
const repositoryHandle = repo.getHandle();
|
||||
|
||||
await invoke("player_play_tracks", {
|
||||
repositoryHandle,
|
||||
request: {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
await commands.playerPlayTracks(repositoryHandle, {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -375,16 +366,13 @@
|
||||
const repo = auth.getRepository();
|
||||
const repositoryHandle = repo.getHandle();
|
||||
|
||||
await invoke("player_play_tracks", {
|
||||
repositoryHandle,
|
||||
request: {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
await commands.playerPlayTracks(repositoryHandle, {
|
||||
trackIds: [item.id],
|
||||
startIndex: 0,
|
||||
shuffle: false,
|
||||
context: {
|
||||
type: "search",
|
||||
searchQuery: "",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -394,7 +382,7 @@
|
||||
|
||||
// Seek to start position if provided
|
||||
if (startPosition) {
|
||||
await invoke("player_seek", { position: startPosition });
|
||||
await commands.playerSeek(startPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,24 +430,17 @@
|
||||
|
||||
async function updateStatus() {
|
||||
try {
|
||||
const status = await invoke<{
|
||||
state: { kind: string; position?: number; duration?: number };
|
||||
shuffle: boolean;
|
||||
repeat: string;
|
||||
}>("player_get_status");
|
||||
const status = await commands.playerGetStatus();
|
||||
|
||||
if (status.state.kind === "playing" || status.state.kind === "paused") {
|
||||
isPlaying = status.state.kind === "playing";
|
||||
// Note: position/duration are now derived from player store (updated by events)
|
||||
}
|
||||
shuffle = status.shuffle;
|
||||
repeat = status.repeat as "off" | "all" | "one";
|
||||
repeat = status.repeat;
|
||||
|
||||
// Update queue status
|
||||
const queue = await invoke<{
|
||||
hasNext: boolean;
|
||||
hasPrevious: boolean;
|
||||
}>("player_get_queue");
|
||||
const queue = await commands.playerGetQueue();
|
||||
hasNext = queue.hasNext;
|
||||
hasPrevious = queue.hasPrevious;
|
||||
} catch (e) {
|
||||
@@ -522,10 +503,7 @@
|
||||
try {
|
||||
const repo = auth.getRepository();
|
||||
const repoHandle = repo.getHandle();
|
||||
await invoke("player_on_playback_ended", {
|
||||
itemId: mediaId,
|
||||
repositoryHandle: repoHandle,
|
||||
});
|
||||
await commands.playerOnPlaybackEnded(mediaId, repoHandle);
|
||||
} catch (e) {
|
||||
console.error("[AutoPlay] Failed to handle playback ended:", e);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<!-- TRACES: UR-023 | DR-048 -->
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { commands } from "$lib/api/bindings";
|
||||
import type { AudioSettings, VideoSettings, VolumeLevel } from "$lib/api/bindings";
|
||||
import {
|
||||
getCacheStats,
|
||||
setCacheLimit,
|
||||
@@ -12,21 +13,6 @@
|
||||
type ImageCacheStats,
|
||||
} from "$lib/services/imageCache";
|
||||
|
||||
type VolumeLevel = "loud" | "normal" | "quiet";
|
||||
|
||||
interface AudioSettings {
|
||||
crossfadeDuration: number;
|
||||
gaplessPlayback: boolean;
|
||||
normalizeVolume: boolean;
|
||||
volumeLevel: VolumeLevel;
|
||||
}
|
||||
|
||||
interface VideoSettings {
|
||||
autoPlayNextEpisode: boolean;
|
||||
autoPlayCountdownSeconds: number;
|
||||
autoPlayMaxEpisodes: number;
|
||||
}
|
||||
|
||||
const episodeLimitOptions = [
|
||||
{ value: 0, label: "Unlimited" },
|
||||
{ value: 1, label: "1" },
|
||||
@@ -75,8 +61,8 @@
|
||||
try {
|
||||
loading = true;
|
||||
const [audioResult, videoResult] = await Promise.all([
|
||||
invoke<AudioSettings>("player_get_audio_settings"),
|
||||
invoke<VideoSettings>("player_get_video_settings"),
|
||||
commands.playerGetAudioSettings(),
|
||||
commands.playerGetVideoSettings(),
|
||||
]);
|
||||
settings = audioResult;
|
||||
videoSettings = videoResult;
|
||||
@@ -142,8 +128,8 @@
|
||||
saving = true;
|
||||
saveMessage = "";
|
||||
await Promise.all([
|
||||
invoke("player_set_audio_settings", { settings }),
|
||||
invoke("player_set_video_settings", { settings: videoSettings }),
|
||||
commands.playerSetAudioSettings(settings),
|
||||
commands.playerSetVideoSettings(videoSettings),
|
||||
]);
|
||||
saveMessage = "Settings saved successfully!";
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user