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
This commit is contained in:
1 parent
51cfcd1c32
commit
b450accb56
2 files changed
+27
-6
No files matched your search
@@ -269,10 +269,25 @@ pub async fn library_check_folder_accessible(path: String) -> Result<bool, Strin
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// Try to read the directory
|
||||
match std::fs::read_dir(path_ref) {
|
||||
Ok(_) => 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user