From 8f3f010e6d23d5749ebf93322cd220924fc33679 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 24 Sep 2024 16:53:15 +0300 Subject: [PATCH] refactor(core): return state in `unmanage` (#11105) * refactor(core): return state in `unmanage` * Update crates/tauri/src/lib.rs [skip ci] Co-authored-by: Fabian-Lars --------- Co-authored-by: Lucas Fernandes Nogueira Co-authored-by: Fabian-Lars --- crates/tauri/src/lib.rs | 6 +++--- crates/tauri/src/state.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index e9d11696a..45e37133d 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -699,12 +699,12 @@ pub trait Manager: sealed::ManagerBase { self.manager().state().set(state) } - /// Removes the state managed by the application for T. Returns `true` if it was actually removed - fn unmanage(&self) -> bool + /// Removes the state managed by the application for T. Returns the state if it was actually removed. + fn unmanage(&self) -> Option where T: Send + Sync + 'static, { - self.manager().state().unmanage::() + self.manager().state().unmanage() } /// Retrieves the managed state for the type `T`. diff --git a/crates/tauri/src/state.rs b/crates/tauri/src/state.rs index 1e03663d3..7049b22c4 100644 --- a/crates/tauri/src/state.rs +++ b/crates/tauri/src/state.rs @@ -140,10 +140,12 @@ impl StateManager { }) } - pub(crate) fn unmanage(&self) -> bool { + pub(crate) fn unmanage(&self) -> Option { self.with_map_mut(|map| { let type_id = TypeId::of::(); - map.remove(&type_id).is_some() + map + .remove(&type_id) + .and_then(|ptr| ptr.downcast().ok().map(|b| *b)) }) }