new window returns desktop context
This commit is contained in:
1 parent
61d100e1f8
commit
a5c46b0e5c
2 files changed
+21
-18
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::rc::Weak;
|
|
||||||
|
|
||||||
use crate::create_new_window;
|
use crate::create_new_window;
|
||||||
use crate::eval::EvalResult;
|
use crate::eval::EvalResult;
|
||||||
@@ -112,8 +111,8 @@ impl DesktopContext {
|
|||||||
/// You can use this to control other windows from the current window.
|
/// You can use this to control other windows from the current window.
|
||||||
///
|
///
|
||||||
/// Be careful to not create a cycle of windows, or you might leak memory.
|
/// Be careful to not create a cycle of windows, or you might leak memory.
|
||||||
pub fn new_window(&self, dom: VirtualDom, cfg: Config) -> Weak<WebView> {
|
pub fn new_window(&self, dom: VirtualDom, cfg: Config) -> DesktopContext {
|
||||||
let window = create_new_window(
|
let (window, desktop_context) = create_new_window(
|
||||||
cfg,
|
cfg,
|
||||||
&self.event_loop,
|
&self.event_loop,
|
||||||
&self.proxy,
|
&self.proxy,
|
||||||
@@ -133,11 +132,9 @@ impl DesktopContext {
|
|||||||
.send_event(UserWindowEvent(EventData::Poll, id))
|
.send_event(UserWindowEvent(EventData::Poll, id))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let webview = window.webview.clone();
|
|
||||||
|
|
||||||
self.pending_windows.borrow_mut().push(window);
|
self.pending_windows.borrow_mut().push(window);
|
||||||
|
|
||||||
Rc::downgrade(&webview)
|
desktop_context
|
||||||
}
|
}
|
||||||
|
|
||||||
/// trigger the drag-window event
|
/// trigger the drag-window event
|
||||||
|
|||||||
+18
-12
@@ -144,8 +144,7 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
|||||||
|
|
||||||
let shortcut_manager = ShortcutRegistry::new(&event_loop);
|
let shortcut_manager = ShortcutRegistry::new(&event_loop);
|
||||||
|
|
||||||
// By default, we'll create a new window when the app starts
|
let (web_view, _) = create_new_window(
|
||||||
queue.borrow_mut().push(create_new_window(
|
|
||||||
cfg,
|
cfg,
|
||||||
&event_loop,
|
&event_loop,
|
||||||
&proxy,
|
&proxy,
|
||||||
@@ -153,7 +152,10 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
|||||||
&queue,
|
&queue,
|
||||||
&event_handlers,
|
&event_handlers,
|
||||||
shortcut_manager.clone(),
|
shortcut_manager.clone(),
|
||||||
));
|
);
|
||||||
|
|
||||||
|
// By default, we'll create a new window when the app starts
|
||||||
|
queue.borrow_mut().push(web_view);
|
||||||
|
|
||||||
event_loop.run(move |window_event, event_loop, control_flow| {
|
event_loop.run(move |window_event, event_loop, control_flow| {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
@@ -280,26 +282,30 @@ fn create_new_window(
|
|||||||
queue: &WebviewQueue,
|
queue: &WebviewQueue,
|
||||||
event_handlers: &WindowEventHandlers,
|
event_handlers: &WindowEventHandlers,
|
||||||
shortcut_manager: ShortcutRegistry,
|
shortcut_manager: ShortcutRegistry,
|
||||||
) -> WebviewHandler {
|
) -> (WebviewHandler, DesktopContext) {
|
||||||
let webview = webview::build(&mut cfg, event_loop, proxy.clone());
|
let webview = webview::build(&mut cfg, event_loop, proxy.clone());
|
||||||
|
let desktop_context = DesktopContext::new(
|
||||||
dom.base_scope().provide_context(DesktopContext::new(
|
|
||||||
webview.clone(),
|
webview.clone(),
|
||||||
proxy.clone(),
|
proxy.clone(),
|
||||||
event_loop.clone(),
|
event_loop.clone(),
|
||||||
queue.clone(),
|
queue.clone(),
|
||||||
event_handlers.clone(),
|
event_handlers.clone(),
|
||||||
shortcut_manager,
|
shortcut_manager,
|
||||||
));
|
);
|
||||||
|
|
||||||
|
dom.base_scope().provide_context(desktop_context.clone());
|
||||||
|
|
||||||
let id = webview.window().id();
|
let id = webview.window().id();
|
||||||
|
|
||||||
// We want to poll the virtualdom and the event loop at the same time, so the waker will be connected to both
|
// We want to poll the virtualdom and the event loop at the same time, so the waker will be connected to both
|
||||||
WebviewHandler {
|
(
|
||||||
webview,
|
WebviewHandler {
|
||||||
dom,
|
webview,
|
||||||
waker: waker::tao_waker(proxy, id),
|
dom,
|
||||||
}
|
waker: waker::tao_waker(proxy, id),
|
||||||
|
},
|
||||||
|
desktop_context,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WebviewHandler {
|
struct WebviewHandler {
|
||||||
|
|||||||
Reference in new issue
Block a user