Эх сурвалжийг харах

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>
Amr Bashir 10 сар өмнө
parent
commit
8f3f010e6d

+ 3 - 3
crates/tauri/src/lib.rs

@@ -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`.

+ 4 - 2
crates/tauri/src/state.rs

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