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 <fabianlars@fabianlars.de>

---------

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
This commit is contained in:
Amr Bashir 2024-09-24 16:53:15 +03:00 committed by GitHub
parent 4078923f6b
commit 8f3f010e6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -699,12 +699,12 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
self.manager().state().set(state)
}
/// Removes the state managed by the application for T. Returns `true` if it was actually removed
fn unmanage<T>(&self) -> bool
/// Removes the state managed by the application for T. Returns the state if it was actually removed.
fn unmanage<T>(&self) -> Option<T>
where
T: Send + Sync + 'static,
{
self.manager().state().unmanage::<T>()
self.manager().state().unmanage()
}
/// Retrieves the managed state for the type `T`.

View File

@ -140,10 +140,12 @@ impl StateManager {
})
}
pub(crate) fn unmanage<T: Send + Sync + 'static>(&self) -> bool {
pub(crate) fn unmanage<T: Send + Sync + 'static>(&self) -> Option<T> {
self.with_map_mut(|map| {
let type_id = TypeId::of::<T>();
map.remove(&type_id).is_some()
map
.remove(&type_id)
.and_then(|ptr| ptr.downcast().ok().map(|b| *b))
})
}