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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user