fix(tauri): make game-directory changes observable
Game-directory selection could reach update_game_directory and then fail before peer startup, while the frontend only logged the rejected invoke. Preserve the last accepted root until peer acknowledgement, surface backend rejection in the settings and main-window UI, and avoid holding the published control lock across runtime replies. Startup preflight remains fail-closed; synchronous setup stays lexically owned through scoped_blocking so cancellation cannot strand a partially published runtime. Add peer-cli scenario S50 to verify invalid changes preserve the existing library and valid changes acknowledge and refresh the library in both directions. Modernize the fixed-size hex decoders to satisfy the current workspace Clippy lint without changing their behavior. Test Plan: - `just fmt` -- passed - `just clippy` -- passed - `just test` -- passed - `just frontend-test` -- passed - `deno task build` -- passed - `just peer-cli-tests S50` -- passed - `just build` -- passed - `git diff --cached --check` -- passed
This commit is contained in:
1 parent
3bbfe919d2
commit
a49b51d3d8
9 files changed
+118
-8
No files matched your search
@@ -2980,7 +2980,14 @@ async fn update_game_directory(
|
||||
&app_invoke,
|
||||
initial_local_network_sharing,
|
||||
)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(|error| {
|
||||
log::error!(
|
||||
"Failed to accept game directory {}: {error}",
|
||||
games_folder.display()
|
||||
);
|
||||
error
|
||||
})?;
|
||||
let accepted_path = accepted_games_folder.to_string_lossy().into_owned();
|
||||
let accepted_path_changed = current_path != accepted_path;
|
||||
|
||||
@@ -3936,7 +3943,12 @@ where
|
||||
return Err("peer runtime ownership slot is already occupied".to_string());
|
||||
}
|
||||
|
||||
*slot = Some(start()?);
|
||||
// Peer startup performs finite filesystem and identity I/O before it
|
||||
// returns. Keep that work lexically owned by this invoke while handing
|
||||
// other Tokio workers off to the executor instead of blocking one of
|
||||
// them. `scoped_blocking` has no cancellation point, so a cancelled
|
||||
// invoke cannot abandon a half-created runtime in the ownership slot.
|
||||
*slot = Some(scoped_blocking(start)?);
|
||||
Ok(slot)
|
||||
}
|
||||
|
||||
@@ -3949,9 +3961,14 @@ async fn ensure_peer_started(
|
||||
let state = app_handle.state::<LanSpreadState>();
|
||||
let mut peer_ctrl = state.peer_ctrl.write().await;
|
||||
|
||||
if let Some(peer_ctrl) = peer_ctrl.as_ref() {
|
||||
if let Some(peer_sender) = peer_ctrl.as_ref().cloned() {
|
||||
// Do not hold the publication lock while waiting for the peer's
|
||||
// acknowledgement. Startup keeps the lock until publication below so
|
||||
// cancellation cannot strand a runtime without its control channel;
|
||||
// an already-published runtime needs only its cloned sender.
|
||||
drop(peer_ctrl);
|
||||
let (reply, result) = oneshot::channel();
|
||||
peer_ctrl
|
||||
peer_sender
|
||||
.send(PeerCommand::SetGameDir {
|
||||
path: games_folder.to_path_buf(),
|
||||
reply,
|
||||
@@ -4013,9 +4030,11 @@ async fn ensure_peer_started(
|
||||
);
|
||||
let sender = handle.sender();
|
||||
*peer_ctrl = Some(sender);
|
||||
drop(peer_ctrl);
|
||||
*local_peer_id_slot = Some(local_peer_id);
|
||||
drop(installation_identity_slot);
|
||||
drop(local_peer_id_slot);
|
||||
drop(peer_runtime);
|
||||
if let Err(error) = publish_identity_diagnostic(app_handle, identity_durability).await {
|
||||
log::error!("Failed to publish identity persistence diagnostic: {error}");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user