Make new_window asynchronous (#4297)
* Make new_window asynchronous * fix clippy
This commit is contained in:
1 parent
99a6b23df8
commit
e6ca0baa46
4 files changed
+118
-24
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use crate::element::DesktopElement;
|
||||
use crate::file_upload::DesktopFileDragEvent;
|
||||
use crate::menubar::DioxusMenu;
|
||||
use crate::PendingDesktopContext;
|
||||
use crate::{
|
||||
app::SharedContext,
|
||||
assets::AssetHandlerRegistry,
|
||||
@@ -207,6 +208,7 @@ impl WebviewInstance {
|
||||
|
||||
// https://developer.apple.com/documentation/appkit/nswindowcollectionbehavior/nswindowcollectionbehaviormanaged
|
||||
#[cfg(target_os = "macos")]
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
use cocoa::appkit::NSWindowCollectionBehavior;
|
||||
use cocoa::base::id;
|
||||
@@ -524,3 +526,33 @@ impl SynchronousEventResponse {
|
||||
Self { prevent_default }
|
||||
}
|
||||
}
|
||||
|
||||
/// A webview that is queued to be created. We can't spawn webviews outside of the main event loop because it may
|
||||
/// block on windows so we queue them into the shared context and then create them when the main event loop is ready.
|
||||
pub(crate) struct PendingWebview {
|
||||
dom: VirtualDom,
|
||||
cfg: Config,
|
||||
sender: tokio::sync::oneshot::Sender<DesktopContext>,
|
||||
}
|
||||
|
||||
impl PendingWebview {
|
||||
pub(crate) fn new(dom: VirtualDom, cfg: Config) -> (Self, PendingDesktopContext) {
|
||||
let (sender, receiver) = tokio::sync::oneshot::channel();
|
||||
let webview = Self { dom, cfg, sender };
|
||||
let pending = PendingDesktopContext { receiver };
|
||||
(webview, pending)
|
||||
}
|
||||
|
||||
pub(crate) fn create_window(self, shared: &Rc<SharedContext>) -> WebviewInstance {
|
||||
let window = WebviewInstance::new(self.cfg, self.dom, shared.clone());
|
||||
|
||||
let cx = window.dom.in_runtime(|| {
|
||||
ScopeId::ROOT
|
||||
.consume_context::<Rc<DesktopService>>()
|
||||
.unwrap()
|
||||
});
|
||||
_ = self.sender.send(cx);
|
||||
|
||||
window
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user