Migrate all IPC call sites to typed tauri-specta commands.*
🏗️ Build and Test JellyTau / Run Tests (pull_request) Successful in 4m39s
Traceability Validation / Check Requirement Traces (pull_request) Failing after 36s
🏗️ Build and Test JellyTau / Build Android APK (pull_request) Failing after 1m57s

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:
2026-06-21 08:47:04 +02:00
parent 14e9d7e03a
commit d01c2aab9f
47 changed files with 456 additions and 2119 deletions
+7 -10
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { auth } from "$lib/stores/auth";
import { get } from "svelte/store";
@@ -47,15 +47,12 @@
const repositoryHandle = repository.getHandle();
// Call Rust to get image as base64 data URL
const dataUrl = await invoke<string>("image_get_url", {
repositoryHandle,
request: {
itemId,
imageType,
maxWidth,
maxHeight,
tag,
},
const dataUrl = await commands.imageGetUrl(repositoryHandle, {
itemId,
imageType,
maxWidth,
maxHeight,
tag,
});
// Use data URL directly
@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { auth } from "$lib/stores/auth";
import { downloads } from "$lib/stores/downloads";
import { goto } from "$app/navigation";
@@ -34,7 +34,7 @@
loading = true;
const userId = $auth.user?.id;
if (userId) {
stats = await invoke<StorageStats>("get_download_storage_stats", { userId });
stats = await commands.getDownloadStorageStats(userId);
}
} catch (error) {
console.error("Failed to load storage stats:", error);
@@ -56,7 +56,7 @@
deleting = true;
const userId = $auth.user?.id;
if (userId) {
await invoke("delete_all_downloads", { userId });
await commands.deleteAllDownloads(userId);
await downloads.refresh(userId);
await loadStats();
}
@@ -73,7 +73,7 @@
deletingAlbum = albumId;
const userId = $auth.user?.id;
if (userId) {
await invoke("delete_album_downloads", { albumId, userId });
await commands.deleteAlbumDownloads(albumId, userId);
await downloads.refresh(userId);
await loadStats();
}
@@ -1,7 +1,7 @@
<script lang="ts">
import { downloads } from "$lib/stores/downloads";
import { auth } from "$lib/stores/auth";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import type { MediaItem } from "$lib/api/types";
interface Props {
@@ -89,18 +89,14 @@
const downloadIds = await downloads.downloadAlbum(albumId, userId, basePath);
// Get target directory for downloads
const targetDir = await invoke<string>("storage_get_path");
const targetDir = await commands.storageGetPath();
// Start each queued track download
for (let i = 0; i < tracks.length && i < downloadIds.length; i++) {
try {
const streamUrl = await repo.getAudioStreamUrl(tracks[i].id);
if (streamUrl) {
await invoke("start_download", {
downloadId: downloadIds[i],
streamUrl,
targetDir,
});
await commands.startDownload(downloadIds[i], streamUrl, targetDir);
}
} catch (e) {
console.error(`Failed to start download for track ${tracks[i].id}:`, e);
@@ -1,7 +1,6 @@
<script lang="ts">
import { downloads } from "$lib/stores/downloads";
import { auth } from "$lib/stores/auth";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import DownloadButtonCore from "./DownloadButtonCore.svelte";
import type { DownloadState } from "./DownloadButtonCore.svelte";
@@ -81,7 +80,7 @@
}
// Get target directory
const targetDir = await invoke<string>("storage_get_path");
const targetDir = await commands.storageGetPath();
console.log(" Target directory:", targetDir);
// Queue and start download in single atomic operation
@@ -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 type { MediaItem, PlaylistEntry } from "$lib/api/types";
import { auth } from "$lib/stores/auth";
import { toast } from "$lib/stores/toast";
@@ -51,17 +51,14 @@
const repo = auth.getRepository();
const repositoryHandle = repo.getHandle();
const trackIds = entries.map(e => e.id);
await invoke("player_play_tracks", {
repositoryHandle,
request: {
trackIds,
startIndex: 0,
shuffle: false,
context: {
type: "playlist",
playlistId: playlist.id,
playlistName: playlist.name,
},
await commands.playerPlayTracks(repositoryHandle, {
trackIds,
startIndex: 0,
shuffle: false,
context: {
type: "playlist",
playlistId: playlist.id,
playlistName: playlist.name,
},
});
} catch (e) {
@@ -76,17 +73,14 @@
const repo = auth.getRepository();
const repositoryHandle = repo.getHandle();
const trackIds = entries.map(e => e.id);
await invoke("player_play_tracks", {
repositoryHandle,
request: {
trackIds,
startIndex: 0,
shuffle: true,
context: {
type: "playlist",
playlistId: playlist.id,
playlistName: playlist.name,
},
await commands.playerPlayTracks(repositoryHandle, {
trackIds,
startIndex: 0,
shuffle: true,
context: {
type: "playlist",
playlistId: playlist.id,
playlistName: playlist.name,
},
});
} catch (e) {
@@ -1,7 +1,7 @@
<script lang="ts">
import { downloads, videoDownloads } from "$lib/stores/downloads";
import { auth } from "$lib/stores/auth";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { QUALITY_PRESETS, type QualityPreset } from "$lib/api/quality-presets";
interface Props {
@@ -53,7 +53,7 @@
console.log("📺 Starting season download for:", seasonName, "quality:", quality);
// Get target directory
const targetDir = await invoke<string>("storage_get_path");
const targetDir = await commands.storageGetPath();
const basePath = `${targetDir}/videos`;
// Queue all episodes in this season
@@ -1,7 +1,7 @@
<script lang="ts">
import { downloads, videoDownloads } from "$lib/stores/downloads";
import { auth } from "$lib/stores/auth";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { QUALITY_PRESETS, type QualityPreset } from "$lib/api/quality-presets";
interface Props {
@@ -47,7 +47,7 @@
console.log("📺 Starting series download for:", seriesName, "quality:", quality);
// Get target directory
const targetDir = await invoke<string>("storage_get_path");
const targetDir = await commands.storageGetPath();
const basePath = `${targetDir}/videos`;
// Queue all episodes
+14 -19
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import type { PlayTracksContext } from "$lib/api/bindings";
import { goto } from "$app/navigation";
import { queue } from "$lib/stores/queue";
import { auth } from "$lib/stores/auth";
@@ -62,14 +63,11 @@
if (context && context.type === "album") {
const repositoryHandle = repo.getHandle();
console.log(`[TrackList] Playing track: "${track.name}" (ID: ${track.id}, index in list: ${index})`);
await invoke("player_play_album_track", {
repositoryHandle,
request: {
albumId: context.albumId,
albumName: context.albumName,
trackId: track.id,
shuffle: false,
},
await commands.playerPlayAlbumTrack(repositoryHandle, {
albumId: context.albumId,
albumName: context.albumName,
trackId: track.id,
shuffle: false,
});
return;
}
@@ -80,7 +78,7 @@
const trackIds = tracks.map((t) => t.id);
// Determine context for queue
let playContext;
let playContext: PlayTracksContext;
if (context?.type === "playlist") {
playContext = {
type: "playlist",
@@ -88,17 +86,14 @@
playlistName: context.playlistName,
};
} else {
playContext = { type: "custom" };
playContext = { type: "custom", label: null };
}
await invoke("player_play_tracks", {
repositoryHandle,
request: {
trackIds,
startIndex: index,
shuffle: false,
context: playContext,
},
await commands.playerPlayTracks(repositoryHandle, {
trackIds,
startIndex: index,
shuffle: false,
context: playContext,
});
// Queue will auto-update from Rust backend event
@@ -1,7 +1,7 @@
<script lang="ts">
import { downloads } from "$lib/stores/downloads";
import { auth } from "$lib/stores/auth";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { QUALITY_PRESETS, type QualityPreset } from "$lib/api/quality-presets";
interface Props {
@@ -66,11 +66,11 @@
console.log("🎬 Starting video download for item:", itemId, "quality:", quality);
// Get stream URL based on quality
const streamUrl = repo.getVideoDownloadUrl(itemId, quality);
const streamUrl = await repo.getVideoDownloadUrl(itemId, quality);
console.log(" Stream URL obtained");
// Get target directory
const targetDir = await invoke<string>("storage_get_path");
const targetDir = await commands.storageGetPath();
// Create file path
const safeName = (itemName || itemId).replace(/[/\\:*?"<>|]/g, "_");
@@ -107,11 +107,7 @@
await downloads.pinItem(itemId);
// Actually start the download
await invoke("start_download", {
downloadId,
streamUrl,
targetDir,
});
await commands.startDownload(downloadId, streamUrl, targetDir);
console.log(" Download started");
} catch (error) {
console.error("Failed to start video download:", error);
+8 -8
View File
@@ -1,6 +1,6 @@
<!-- TRACES: UR-004, UR-005, UR-028 | DR-009 -->
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { goto } from "$app/navigation";
import type { MediaItem } from "$lib/api/types";
import { auth } from "$lib/stores/auth";
@@ -74,28 +74,28 @@
async function handleSeekEnd() {
seeking = false;
seekPending = true; // Keep showing target position until backend catches up
await invoke("player_seek", { position: seekValue });
await commands.playerSeek(seekValue);
}
// Control handlers for Controls component
async function handlePlayPause() {
await invoke("player_toggle");
await commands.playerToggle();
}
async function handlePrevious() {
await invoke("player_previous");
await commands.playerPrevious();
}
async function handleNext() {
await invoke("player_next");
await commands.playerNext();
}
async function handleToggleShuffle() {
await invoke("player_toggle_shuffle");
await commands.playerToggleShuffle();
}
async function handleCycleRepeat() {
await invoke("player_cycle_repeat");
await commands.playerCycleRepeat();
}
// Prefer album ID for artwork (all tracks in an album share the same cover)
@@ -128,7 +128,7 @@
async function handleQueueItemClick(index: number) {
try {
queue.skipTo(index);
await invoke("player_skip_to", { index });
await commands.playerSkipTo(index);
} catch (e) {
console.error("Failed to skip to queue item:", e);
}
+7 -7
View File
@@ -14,7 +14,7 @@
* @req: UR-010 - Control playback of Jellyfin remote sessions
*/
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { goto } from "$app/navigation";
import type { MediaItem } from "$lib/api/types";
import { auth } from "$lib/stores/auth";
@@ -105,23 +105,23 @@
// Control handlers for Controls component
async function handlePlayPause() {
await invoke("player_toggle");
await commands.playerToggle();
}
async function handlePrevious() {
await invoke("player_previous");
await commands.playerPrevious();
}
async function handleNext() {
await invoke("player_next");
await commands.playerNext();
}
async function handleToggleShuffle() {
await invoke("player_toggle_shuffle");
await commands.playerToggleShuffle();
}
async function handleCycleRepeat() {
await invoke("player_cycle_repeat");
await commands.playerCycleRepeat();
}
// Scrubbing (seek) handler
@@ -133,7 +133,7 @@
const newPosition = percent * displayDuration;
try {
await invoke("player_seek", { position: newPosition });
await commands.playerSeek(newPosition);
haptics.tap();
} catch (err) {
console.error("Failed to seek:", err);
+3 -6
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { dndzone, SOURCES, TRIGGERS } from "svelte-dnd-action";
import type { MediaItem } from "$lib/api/types";
import { auth } from "$lib/stores/auth";
@@ -79,10 +79,7 @@
queue.moveInQueue(fromIndex, toIndex);
// Sync with backend
await invoke("player_move_in_queue", {
fromIndex,
toIndex,
});
await commands.playerMoveInQueue(fromIndex, toIndex);
} catch (e) {
console.error("Failed to move queue item:", e);
// The store already updated optimistically, refresh if needed
@@ -109,7 +106,7 @@
e.stopPropagation();
try {
queue.removeFromQueue(index);
await invoke("player_remove_from_queue", { index });
await commands.playerRemoveFromQueue(index);
} catch (err) {
console.error("Failed to remove from queue:", err);
}
+33 -41
View File
@@ -1,7 +1,7 @@
<!-- TRACES: UR-003, UR-005, UR-020, UR-021, UR-026 | DR-010, DR-023, DR-024 -->
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { listen } from "@tauri-apps/api/event";
import Hls from "hls.js";
import type { MediaItem } from "$lib/api/types";
@@ -140,13 +140,7 @@
const userId = auth.getUserId();
if (!userId) return;
const preference = await invoke<{ seriesId: string, audioTrackDisplayTitle?: string | null, audioTrackLanguage?: string | null, audioTrackIndex?: number | null } | null>(
"storage_get_series_audio_preference",
{
userId,
seriesId: media.seriesId
}
);
const preference = await commands.storageGetSeriesAudioPreference(userId, media.seriesId);
if (preference) {
console.log("[VideoPlayer] Loaded series audio preference:", preference);
@@ -403,14 +397,12 @@
// Call Rust backend to start playback
// Rust will choose ExoPlayer (Android), libmpv (Linux), or tell us to use HTML5
// Send minimal video data - no complex serialization to avoid Tauri Android issues
const response: any = await invoke("player_play_item", {
item: {
streamUrl: currentStreamUrl,
title: media.name,
id: media.id,
videoCodec: needsTranscoding ? "hevc" : "h264",
needsTranscoding: needsTranscoding,
},
const response: any = await commands.playerPlayItem({
streamUrl: currentStreamUrl,
title: media.name,
id: media.id,
videoCodec: needsTranscoding ? "hevc" : "h264",
needsTranscoding: needsTranscoding,
});
// Rust tells us which backend it's using
@@ -422,7 +414,7 @@
if (useHtml5Element && !needsTranscoding) {
try {
console.log("[VideoPlayer] Using HTML5 for direct stream - stopping backend player to prevent dual audio");
await invoke("player_stop");
await commands.playerStop();
didStopBackendEarly = true; // Track that we stopped the backend
} catch (err) {
console.warn("[VideoPlayer] Failed to stop backend player:", err);
@@ -460,7 +452,7 @@
// For non-transcoded content, try to stop any backend player that might have started
if (!needsTranscoding) {
try {
await invoke("player_stop");
await commands.playerStop();
didStopBackendEarly = true;
} catch (stopErr) {
// Ignore errors when stopping
@@ -536,7 +528,7 @@
if (didStartNativePlayback && !didStopBackendEarly) {
try {
console.log("[VideoPlayer] Stopping backend player on component unmount");
await invoke("player_stop");
await commands.playerStop();
} catch (err) {
console.error("[VideoPlayer] Failed to stop backend player:", err);
}
@@ -768,7 +760,7 @@
async function togglePlayPause() {
if (!useHtml5Element) {
try {
const response = await invoke<{ state: string }>("player_toggle");
const response = (await commands.playerToggle()) as any;
isPlaying = response.state === "playing";
} catch (err) {
console.error("[VideoPlayer] Failed to toggle native player:", err);
@@ -807,13 +799,13 @@
}
// Backend smart seeking handles both native and HTML5
const response = await invoke<{strategy: string, position?: number, newUrl?: string, seekOffset?: number}>("player_seek_video", {
repositoryHandle: repo.getHandle(),
position: targetTime,
mediaSourceId: mediaSourceId ?? null,
audioStreamIndex: selectedAudioTrackIndex ?? null,
useHtml5: useHtml5Element,
});
const response = (await commands.playerSeekVideo(
repo.getHandle(),
targetTime,
mediaSourceId ?? null,
selectedAudioTrackIndex ?? null,
useHtml5Element
)) as any;
console.log("[VideoPlayer] Backend seek response:", response);
@@ -1095,14 +1087,14 @@
if (!repo) throw new Error("Not authenticated");
// Call unified backend command
const response = await invoke<{strategy: string, success?: boolean, newUrl?: string, position?: number}>("player_switch_audio_track", {
repositoryHandle: repo.getHandle(),
const response = (await commands.playerSwitchAudioTrack(
repo.getHandle(),
streamIndex,
arrayIndex,
useHtml5: useHtml5Element,
currentPosition: useHtml5Element && videoElement ? videoElement.currentTime + seekOffset : null,
mediaSourceId: mediaSourceId ?? null,
});
useHtml5Element,
useHtml5Element && videoElement ? videoElement.currentTime + seekOffset : null,
mediaSourceId ?? null
)) as any;
// Handle response based on strategy
if (response.strategy === "reloadStream" && useHtml5Element && videoElement) {
@@ -1171,14 +1163,14 @@
// Find the selected track info
const selectedTrack = audioTracks().find(t => t.index === streamIndex);
if (selectedTrack) {
await invoke("storage_save_series_audio_preference", {
await commands.storageSaveSeriesAudioPreference(
userId,
seriesId: media.seriesId,
serverId: media.serverId,
audioTrackDisplayTitle: selectedTrack.displayTitle || null,
audioTrackLanguage: selectedTrack.language || null,
audioTrackIndex: streamIndex,
});
media.seriesId,
media.serverId ?? "",
selectedTrack.displayTitle || null,
selectedTrack.language || null,
streamIndex
);
console.log("[VideoPlayer] Saved series audio preference:", selectedTrack.displayTitle || selectedTrack.language);
}
} catch (err) {
@@ -1229,7 +1221,7 @@
// Use array index for ExoPlayer (0-based position in subtitle tracks array)
// If streamIndex is null (disable), pass null; otherwise use arrayIndex
const indexToUse = streamIndex === null ? null : (arrayIndex !== undefined ? arrayIndex : streamIndex);
await invoke("player_set_subtitle_track", { streamIndex: indexToUse });
await commands.playerSetSubtitleTrack(indexToUse);
console.log("[VideoPlayer] Native backend subtitle track changed - arrayIndex:", arrayIndex, "used:", indexToUse);
} catch (error) {
console.error("[VideoPlayer] Failed to set subtitle track:", error);
@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { volume, isMuted, mergedVolume } from "$lib/stores/player";
import { isRemoteMode } from "$lib/stores/playbackMode";
import { selectedSession, sessions } from "$lib/stores/sessions";
@@ -31,7 +31,7 @@
// Remote mode: send volume as 0-100 integer to remote session
await sessions.sendVolume($selectedSession.id, Math.round(newVolume * 100));
} else {
await invoke("player_set_volume", { volume: newVolume });
await commands.playerSetVolume(newVolume);
}
}
@@ -39,7 +39,7 @@
if ($isRemoteMode && $selectedSession) {
await sessions.sendToggleMute($selectedSession.id);
} else {
await invoke("player_toggle_mute");
await commands.playerToggleMute();
}
}
@@ -1,7 +1,7 @@
<!-- TRACES: UR-010 | DR-037 -->
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/api/bindings";
import { sessions, controllableSessions, selectedSession } from "$lib/stores";
import SessionPickerModal from "./SessionPickerModal.svelte";
@@ -42,18 +42,18 @@
// Set initial hint based on connection state
const hint = isConnected ? "cast_active" : "cast_discovery";
await invoke("sessions_set_polling_hint", { hint });
await commands.sessionsSetPollingHint(hint);
});
onDestroy(async () => {
// Reset to normal polling when component unmounts
await invoke("sessions_set_polling_hint", { hint: "normal" });
await commands.sessionsSetPollingHint("normal");
});
// Update polling hint when connection state changes
$effect(() => {
const hint = isConnected ? "cast_active" : "cast_discovery";
invoke("sessions_set_polling_hint", { hint });
commands.sessionsSetPollingHint(hint);
});
const isConnected = $derived($selectedSession !== null);