From b450accb56fa91e7d19e286d3aca20ae67ffa98e Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 20 Jan 2026 00:27:28 -0600 Subject: [PATCH] Fix LocalLibrary infinite loading in offline mode Problem: When app is in offline mode, LocalLibrary gets stuck in infinite loading screen and becomes unusable. Root cause: loadFolders() was calling checkFolderAccessibility() for each network folder. The backend command library_check_folder_accessible uses blocking std::fs::read_dir which can hang for 20-30 seconds per unreachable network path. Solution: Frontend (LocalLibraryView.svelte): - Skip network folder accessibility checks when offline - Assume network folders are inaccessible in offline mode - Only check accessibility when online Backend (library/commands.rs): - Add 2-second timeout to library_check_folder_accessible - Use tokio::task::spawn_blocking to avoid blocking async runtime - Log timeout warnings for unreachable network paths This allows LocalLibrary to load instantly when offline, showing only local disk content as intended. Files changed: - src/lib/components/views/LocalLibraryView.svelte - src-tauri/src/library/commands.rs --- src-tauri/src/library/commands.rs | 23 +++++++++++++++---- .../components/views/LocalLibraryView.svelte | 10 ++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/library/commands.rs b/src-tauri/src/library/commands.rs index 0ff9f9198..882809fa2 100644 --- a/src-tauri/src/library/commands.rs +++ b/src-tauri/src/library/commands.rs @@ -269,10 +269,25 @@ pub async fn library_check_folder_accessible(path: String) -> Result Ok(true), - Err(_) => Ok(false), + // Try to read the directory with a timeout to avoid hanging on network paths + let path_clone = path.clone(); + let check_result = tokio::time::timeout( + std::time::Duration::from_secs(2), + tokio::task::spawn_blocking(move || { + std::fs::read_dir(Path::new(&path_clone)).is_ok() + }) + ).await; + + match check_result { + Ok(Ok(accessible)) => Ok(accessible), + Ok(Err(_)) => { + log::warn!("Failed to spawn blocking task for folder check: {}", path); + Ok(false) + }, + Err(_) => { + log::warn!("Timeout checking folder accessibility (likely unreachable network path): {}", path); + Ok(false) + } } } diff --git a/src/lib/components/views/LocalLibraryView.svelte b/src/lib/components/views/LocalLibraryView.svelte index 6a65f217b..370b51446 100644 --- a/src/lib/components/views/LocalLibraryView.svelte +++ b/src/lib/components/views/LocalLibraryView.svelte @@ -329,10 +329,16 @@ async function loadFolders() { try { folders = await invoke('library_get_folders_with_metadata'); - // Check accessibility for network folders + // Check accessibility for network folders (skip when offline to avoid hanging) for (const folder of folders) { if (folder.isNetwork) { - checkFolderAccessibility(folder); + if (isOffline) { + // When offline, assume network folders are inaccessible + folderAccessibility.set(folder.id, false); + } else { + // When online, check accessibility + checkFolderAccessibility(folder); + } } else { folderAccessibility.set(folder.id, true); }