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.
This commit is contained in:
2026-10-30 20:56:15 -05:00
parent b61be5065b
commit 27bc5c9844
2 changed files with 19 additions and 8 deletions

View File

@@ -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<FirstSync>) -> Result<Option<Sy
Err(e) => 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)
}