refactor(frontend): migrate Library and Offline commands to V2
Update frontend to use v2_library_* and v2_get_pending_playlists. Progress: 138 legacy commands remaining.
This commit is contained in:
1 parent
8d3627b743
commit
65632f08d5
10 files changed
+34
-34
No files matched your search
@@ -94,7 +94,7 @@
|
||||
|
||||
checkingAccessibility = true;
|
||||
try {
|
||||
accessible = await invoke<boolean>('library_check_folder_accessible', { path: folder.path });
|
||||
accessible = await invoke<boolean>('v2_library_check_folder_accessible', { path: folder.path });
|
||||
} catch (err) {
|
||||
console.error('Failed to check folder accessibility:', err);
|
||||
accessible = false;
|
||||
@@ -151,7 +151,7 @@
|
||||
// Re-check accessibility for the new path
|
||||
checkingAccessibility = true;
|
||||
try {
|
||||
accessible = await invoke<boolean>('library_check_folder_accessible', { path: currentPath });
|
||||
accessible = await invoke<boolean>('v2_library_check_folder_accessible', { path: currentPath });
|
||||
} catch (err) {
|
||||
accessible = false;
|
||||
} finally {
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
// Load local track counts
|
||||
async function loadLocalTrackCounts() {
|
||||
try {
|
||||
const counts = await invoke<Record<string, number>>('playlist_get_all_local_track_counts');
|
||||
const counts = await invoke<Record<string, number>>('v2_playlist_get_all_local_track_counts');
|
||||
const map = new Map<number, number>();
|
||||
for (const [id, count] of Object.entries(counts)) {
|
||||
map.set(Number(id), count);
|
||||
@@ -401,7 +401,7 @@
|
||||
let localTrackPaths: string[] = [];
|
||||
if (isLocalTracks && trackIds.length > 0) {
|
||||
// Fetch tracks to get their file paths
|
||||
const tracks = await invoke<Array<{ id: number; file_path: string }>>('library_get_tracks_by_ids', {
|
||||
const tracks = await invoke<Array<{ id: number; file_path: string }>>('v2_library_get_tracks_by_ids', {
|
||||
trackIds
|
||||
});
|
||||
localTrackPaths = tracks.map(track => track.file_path);
|
||||
@@ -502,7 +502,7 @@
|
||||
let localTrackPaths: string[] = [];
|
||||
if (isLocalTracks && trackIds.length > 0) {
|
||||
// Fetch tracks to get their file paths
|
||||
const tracks = await invoke<Array<{ id: number; file_path: string }>>('library_get_tracks_by_ids', {
|
||||
const tracks = await invoke<Array<{ id: number; file_path: string }>>('v2_library_get_tracks_by_ids', {
|
||||
trackIds
|
||||
});
|
||||
localTrackPaths = tracks.map(track => track.file_path);
|
||||
|
||||
@@ -1099,7 +1099,7 @@
|
||||
if (isOffline) {
|
||||
// In offline mode, show only pending playlists (created offline)
|
||||
console.log('[Sidebar] Loading pending playlists in offline mode');
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('get_pending_playlists');
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('v2_get_pending_playlists');
|
||||
|
||||
// Store pending playlists metadata and populate localTrackCounts
|
||||
const newPendingMap = new Map<number, import('$lib/stores/offlineStore').PendingPlaylist>();
|
||||
@@ -1161,7 +1161,7 @@
|
||||
|
||||
async function loadLocalTrackCounts() {
|
||||
try {
|
||||
const counts = await invoke<Record<string, number>>('playlist_get_all_local_track_counts');
|
||||
const counts = await invoke<Record<string, number>>('v2_playlist_get_all_local_track_counts');
|
||||
const map = new Map<number, number>();
|
||||
for (const [id, count] of Object.entries(counts)) {
|
||||
map.set(Number(id), count);
|
||||
|
||||
@@ -1046,7 +1046,7 @@
|
||||
if (!album) {
|
||||
const includePlex = isPlexLibraryEnabled();
|
||||
const [localAlbums, plexAlbumsRaw] = await Promise.all([
|
||||
invoke<LocalAlbum[]>('library_get_albums', {
|
||||
invoke<LocalAlbum[]>('v2_library_get_albums', {
|
||||
includeHidden: false,
|
||||
excludeNetworkFolders: shouldExcludeNetworkFolders()
|
||||
}),
|
||||
@@ -1285,7 +1285,7 @@
|
||||
const fetchStart = performance.now();
|
||||
const includePlex = isPlexLibraryEnabled();
|
||||
const [albumsResult, statsResult, plexAlbumsRaw] = await Promise.all([
|
||||
invoke<LocalAlbum[]>('library_get_albums', {
|
||||
invoke<LocalAlbum[]>('v2_library_get_albums', {
|
||||
includeHidden: false,
|
||||
excludeNetworkFolders: excludeNetwork
|
||||
}),
|
||||
@@ -1390,7 +1390,7 @@
|
||||
|
||||
async function checkFolderAccessibility(folder: LibraryFolder) {
|
||||
try {
|
||||
const accessible = await invoke<boolean>('library_check_folder_accessible', { path: folder.path });
|
||||
const accessible = await invoke<boolean>('v2_library_check_folder_accessible', { path: folder.path });
|
||||
folderAccessibility.set(folder.id, accessible);
|
||||
folderAccessibility = new Map(folderAccessibility);
|
||||
} catch (err) {
|
||||
@@ -1553,7 +1553,7 @@
|
||||
}
|
||||
|
||||
try {
|
||||
await invoke('library_remove_folder', { path: folder.path });
|
||||
await invoke('v2_library_remove_folder', { path: folder.path });
|
||||
selectedFolders.delete(folder.id);
|
||||
selectedFolders = new Set(selectedFolders);
|
||||
await loadFolders();
|
||||
@@ -1598,7 +1598,7 @@
|
||||
await invoke('library_scan_folder', { folderId });
|
||||
// Start polling for progress
|
||||
const progressInterval = setInterval(async () => {
|
||||
scanProgress = await invoke<ScanProgress>('library_get_scan_progress');
|
||||
scanProgress = await invoke<ScanProgress>('v2_library_get_scan_progress');
|
||||
if (scanProgress.status === 'Complete' || scanProgress.status === 'Cancelled' || scanProgress.status === 'Error') {
|
||||
clearInterval(progressInterval);
|
||||
scanning = false;
|
||||
@@ -1623,7 +1623,7 @@
|
||||
for (const folderId of selectedFolders) {
|
||||
const folder = folders.find(f => f.id === folderId);
|
||||
if (folder) {
|
||||
await invoke('library_remove_folder', { path: folder.path });
|
||||
await invoke('v2_library_remove_folder', { path: folder.path });
|
||||
}
|
||||
}
|
||||
selectedFolders.clear();
|
||||
@@ -1654,7 +1654,7 @@
|
||||
// Start polling for progress
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
scanProgress = await invoke<ScanProgress>('library_get_scan_progress');
|
||||
scanProgress = await invoke<ScanProgress>('v2_library_get_scan_progress');
|
||||
if (scanProgress.status === 'Complete' || scanProgress.status === 'Cancelled' || scanProgress.status === 'Error') {
|
||||
clearInterval(pollInterval);
|
||||
scanning = false;
|
||||
@@ -1826,7 +1826,7 @@
|
||||
|
||||
if (!selected || typeof selected !== 'string') return;
|
||||
|
||||
const cachedPath = await invoke<string>('library_set_album_artwork', {
|
||||
const cachedPath = await invoke<string>('v2_library_set_album_artwork', {
|
||||
albumGroupKey: selectedAlbum.id,
|
||||
artworkPath: selected
|
||||
});
|
||||
@@ -1917,7 +1917,7 @@
|
||||
if (onTrackPlay) {
|
||||
await Promise.resolve(onTrackPlay(track));
|
||||
} else if (trackSource === 'local') {
|
||||
await invoke('library_play_track', { trackId: track.id });
|
||||
await invoke('v2_library_play_track', { trackId: track.id });
|
||||
} else {
|
||||
throw new Error('Plex playback handler not available');
|
||||
}
|
||||
@@ -2161,7 +2161,7 @@
|
||||
|
||||
async function handleHideAlbum(album: LocalAlbum) {
|
||||
try {
|
||||
await invoke('library_set_album_hidden', { albumGroupKey: album.id, hidden: true });
|
||||
await invoke('v2_library_set_album_hidden', { albumGroupKey: album.id, hidden: true });
|
||||
await loadLibraryData();
|
||||
} catch (err) {
|
||||
console.error('Failed to hide album:', err);
|
||||
@@ -2171,7 +2171,7 @@
|
||||
|
||||
async function handleShowAlbum(album: LocalAlbum) {
|
||||
try {
|
||||
await invoke('library_set_album_hidden', { albumGroupKey: album.id, hidden: false });
|
||||
await invoke('v2_library_set_album_hidden', { albumGroupKey: album.id, hidden: false });
|
||||
await loadHiddenAlbums();
|
||||
await loadLibraryData();
|
||||
} catch (err) {
|
||||
@@ -2182,7 +2182,7 @@
|
||||
|
||||
async function loadHiddenAlbums() {
|
||||
try {
|
||||
hiddenAlbums = await invoke<LocalAlbum[]>('library_get_albums', {
|
||||
hiddenAlbums = await invoke<LocalAlbum[]>('v2_library_get_albums', {
|
||||
includeHidden: true,
|
||||
excludeNetworkFolders: shouldExcludeNetworkFolders()
|
||||
});
|
||||
@@ -2327,7 +2327,7 @@
|
||||
|
||||
console.log('Downloaded to:', localPath);
|
||||
|
||||
await invoke('library_set_album_artwork', {
|
||||
await invoke('v2_library_set_album_artwork', {
|
||||
albumGroupKey: selectedAlbum.id,
|
||||
artworkPath: localPath
|
||||
});
|
||||
@@ -2336,7 +2336,7 @@
|
||||
applyAlbumArtworkUpdate(selectedAlbum.id, localPath);
|
||||
}
|
||||
|
||||
await invoke('library_set_album_hidden', {
|
||||
await invoke('v2_library_set_album_hidden', {
|
||||
albumGroupKey: selectedAlbum.id,
|
||||
hidden: editingAlbumHidden
|
||||
});
|
||||
|
||||
@@ -505,12 +505,12 @@
|
||||
if (playlistId < 0) {
|
||||
// For pending playlists, load local tracks from the pending playlist data
|
||||
const pendingId = -playlistId;
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('get_pending_playlists');
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('v2_get_pending_playlists');
|
||||
const pending = pendingPlaylists.find(p => p.id === pendingId);
|
||||
|
||||
if (pending && pending.localTrackIds.length > 0) {
|
||||
// Load the actual local track data
|
||||
const localTrackData = await invoke<LocalLibraryTrack[]>('library_get_tracks_by_ids', {
|
||||
const localTrackData = await invoke<LocalLibraryTrack[]>('v2_library_get_tracks_by_ids', {
|
||||
trackIds: pending.localTrackIds
|
||||
});
|
||||
|
||||
@@ -581,7 +581,7 @@
|
||||
if (playlistId < 0) {
|
||||
// === Pending (offline) playlist ===
|
||||
const pendingId = -playlistId;
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('get_pending_playlists');
|
||||
const pendingPlaylists = await invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('v2_get_pending_playlists');
|
||||
const pending = pendingPlaylists.find(p => p.id === pendingId);
|
||||
|
||||
if (!pending) {
|
||||
|
||||
@@ -364,10 +364,10 @@
|
||||
// Offline mode: Load both regular playlists AND pending playlists
|
||||
const [playlistsResult, pendingPlaylistsResult, settingsResult, statsResult, localCountsResult] = await Promise.all([
|
||||
invoke<Playlist[]>('v2_get_user_playlists'),
|
||||
invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('get_pending_playlists'),
|
||||
invoke<import('$lib/stores/offlineStore').PendingPlaylist[]>('v2_get_pending_playlists'),
|
||||
invoke<PlaylistSettings[]>('v2_playlist_get_all_settings'),
|
||||
invoke<PlaylistStats[]>('v2_playlist_get_all_stats'),
|
||||
invoke<Record<string, number>>('playlist_get_all_local_track_counts')
|
||||
invoke<Record<string, number>>('v2_playlist_get_all_local_track_counts')
|
||||
]);
|
||||
|
||||
// Process regular playlists
|
||||
@@ -425,7 +425,7 @@
|
||||
invoke<Playlist[]>('v2_get_user_playlists'),
|
||||
invoke<PlaylistSettings[]>('v2_playlist_get_all_settings'),
|
||||
invoke<PlaylistStats[]>('v2_playlist_get_all_stats'),
|
||||
invoke<Record<string, number>>('playlist_get_all_local_track_counts')
|
||||
invoke<Record<string, number>>('v2_playlist_get_all_local_track_counts')
|
||||
]);
|
||||
|
||||
playlists = playlistsResult;
|
||||
|
||||
@@ -2717,8 +2717,8 @@
|
||||
isClearingArtwork = true;
|
||||
try {
|
||||
// Clear both legacy artwork cache and new thumbnails cache
|
||||
await invoke('library_clear_artwork_cache');
|
||||
await invoke('library_clear_thumbnails_cache');
|
||||
await invoke('v2_library_clear_artwork_cache');
|
||||
await invoke('v2_library_clear_thumbnails_cache');
|
||||
console.log('Artwork caches cleared');
|
||||
await loadArtworkCacheStats();
|
||||
} catch (err) {
|
||||
@@ -2738,8 +2738,8 @@
|
||||
clearLyricsCache(),
|
||||
invoke('musicbrainz_clear_cache'),
|
||||
invoke('v2_clear_vector_store'),
|
||||
invoke('library_clear_artwork_cache'),
|
||||
invoke('library_clear_thumbnails_cache')
|
||||
invoke('v2_library_clear_artwork_cache'),
|
||||
invoke('v2_library_clear_thumbnails_cache')
|
||||
]);
|
||||
console.log('All caches cleared');
|
||||
// Reload all stats
|
||||
|
||||
@@ -183,7 +183,7 @@ export async function playTrack(
|
||||
}
|
||||
setCurrentTrack(track);
|
||||
} else if (isLocal) {
|
||||
await invoke('library_play_track', { trackId: track.id });
|
||||
await invoke('v2_library_play_track', { trackId: track.id });
|
||||
} else {
|
||||
const result = await invoke<PlayTrackResult>('v2_play_track', {
|
||||
trackId: track.id,
|
||||
|
||||
@@ -364,7 +364,7 @@ export async function createPendingPlaylist(
|
||||
* Get all playlists pending sync
|
||||
*/
|
||||
export async function getPendingPlaylists(): Promise<PendingPlaylist[]> {
|
||||
return invoke<PendingPlaylist[]>('get_pending_playlists');
|
||||
return invoke<PendingPlaylist[]>('v2_get_pending_playlists');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -362,7 +362,7 @@ export async function togglePlay(): Promise<void> {
|
||||
} else if (currentTrack.isLocal || currentTrack.id < 0) {
|
||||
// Local filesystem track
|
||||
const localTrackId = Math.abs(currentTrack.id);
|
||||
await invoke('library_play_track', { trackId: localTrackId });
|
||||
await invoke('v2_library_play_track', { trackId: localTrackId });
|
||||
} else {
|
||||
// Qobuz track - use v2_play_track
|
||||
await invoke('v2_play_track', {
|
||||
|
||||
Reference in new issue
Block a user