From 27bc5c9844498e7284225b634939fac1fc74f143 Mon Sep 17 00:00:00 2001 From: Garrett Mills Date: Fri, 30 Oct 2026 20:56:15 -0500 Subject: [PATCH] Libraries: refresh the list after any sync that changes it Only syncs started from the UI updated the list. One started in the backend, such as the sync after creating a library, left it stale: the new library kept saying it wasn't on the server yet, and Main stayed undeletable until the app reloaded. A sync that changes the libraries now emits an event the app refreshes on. --- src-tauri/src/sync.rs | 7 ++++++- src/App.tsx | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/sync.rs b/src-tauri/src/sync.rs index a3db0be..c8f60f5 100644 --- a/src-tauri/src/sync.rs +++ b/src-tauri/src/sync.rs @@ -47,7 +47,7 @@ use mtgc_core::sync::remote::{ }; use mtgc_core::sync::{self as core_sync, LibraryDoc, MergeReport}; use serde::Serialize; -use tauri::{AppHandle, Manager}; +use tauri::{AppHandle, Emitter, Manager}; use crate::state::{AppState, LocalLibrary, SyncAccount}; @@ -585,6 +585,11 @@ async fn run_sync(app: AppHandle, choice: Option) -> Result s.sync_error = Some(e.clone()), } drop(s); + // An event rather than the report alone: many syncs start here in the + // backend, with nothing in the UI waiting on their result. + if result.as_ref().is_ok_and(|r| r.libraries_changed) { + let _ = app.emit("libraries-changed", ()); + } crate::logged("sync_now", result).map(Some) } diff --git a/src/App.tsx b/src/App.tsx index 7dcf92e..f030b05 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -515,6 +515,18 @@ export default function App() { if (statusLoaded) refreshLibraries(); }, [statusLoaded, refreshLibraries]); + // A sync linked, downloaded, renamed or flagged a library — the open one's + // name in the top bar included. + useEffect(() => { + const un = listen("libraries-changed", () => { + refreshLibraries(); + api.getStatus().then(setStatus).catch(() => {}); + }); + return () => { + un.then((f) => f()); + }; + }, [refreshLibraries]); + /** Another library was opened, or the list changed: the open library may * be a different one now, so everything refetches. */ const librariesChanged = useCallback( @@ -544,18 +556,12 @@ export default function App() { } setDeckRefreshSignal((v) => v + 1); } - if (report?.libraries_changed) { - // Downloaded, renamed or deleted elsewhere — the open one's name in - // the top bar included. - refreshLibraries(); - api.getStatus().then(setStatus).catch(() => {}); - } return report; } finally { setSyncing(false); api.syncStatus().then(setSync).catch(() => {}); } - }, [refreshLibraries]); + }, []); // Automatic sync, whenever signed in (and not waiting on the first-sync // choice): once now, on every trip to or from the background — leaving