feat: multiwindow support

This commit is contained in:
Jonathan Kelley committed 2022-12-30 22:05:15 -05:00
1 parent 3cfaaea7ea
commit 880aa737a6
5 files changed
+182 -76

No files matched your search

+14 -6
View File
@@ -1,15 +1,18 @@
use crate::desktop_context::UserWindowEvent;
use crate::desktop_context::{EventData, UserWindowEvent};
use futures_util::task::ArcWake;
use std::sync::Arc;
use wry::application::event_loop::EventLoopProxy;
use wry::application::{event_loop::EventLoopProxy, window::WindowId};
/// Create a waker that will send a poll event to the event loop.
///
/// This lets the VirtualDom "come up for air" and process events while the main thread is blocked by the WebView.
///
/// All other IO lives in the Tokio runtime,
pub fn tao_waker(proxy: &EventLoopProxy<UserWindowEvent>) -> std::task::Waker {
struct DomHandle(EventLoopProxy<UserWindowEvent>);
pub fn tao_waker(proxy: &EventLoopProxy<UserWindowEvent>, id: WindowId) -> std::task::Waker {
struct DomHandle {
proxy: EventLoopProxy<UserWindowEvent>,
id: WindowId,
}
// this should be implemented by most platforms, but ios is missing this until
// https://github.com/tauri-apps/wry/issues/830 is resolved
@@ -18,9 +21,14 @@ pub fn tao_waker(proxy: &EventLoopProxy<UserWindowEvent>) -> std::task::Waker {
impl ArcWake for DomHandle {
fn wake_by_ref(arc_self: &Arc<Self>) {
_ = arc_self.0.send_event(UserWindowEvent::Poll);
_ = arc_self
.proxy
.send_event(UserWindowEvent(EventData::Poll, arc_self.id));
}
}
futures_util::task::waker(Arc::new(DomHandle(proxy.clone())))
futures_util::task::waker(Arc::new(DomHandle {
id,
proxy: proxy.clone(),
}))
}