feat: add use_desktop_context hook

This commit is contained in:
mrxiaozhuox committed 2022-01-31 19:39:44 +08:00
1 parent e4eb982a36
commit 366cf75887
2 files changed
+13 -7

No files matched your search

+10
View File
@@ -1,3 +1,6 @@
use std::rc::Rc;
use dioxus_core::ScopeState;
use wry::application::event_loop::EventLoopProxy;
use crate::UserWindowEvent;
@@ -50,3 +53,10 @@ impl DesktopContext {
let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
}
}
/// use this function can get the `DesktopContext` context.
pub fn use_desktop_context(cx: &ScopeState) -> &Rc<DesktopContext> {
cx.use_hook(|_| cx.consume_context::<DesktopContext>())
.as_ref()
.unwrap()
}