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)) }) }