支持window.open

This commit is contained in:
Tw93
2023-01-08 18:13:22 +08:00
parent e6fc124554
commit 13442f1801
2 changed files with 25 additions and 2 deletions

View File

@@ -12,6 +12,10 @@ use wry::{
webview::WebViewBuilder,
};
enum UserEvent {
NewWindow(String),
}
#[cfg(target_os = "macos")]
use wry::application::{
accelerator::{Accelerator, SysMods},
@@ -82,7 +86,9 @@ fn main() -> wry::Result<()> {
fullscreen,
..
} = get_windows_config().1.unwrap_or_default();
let event_loop = EventLoop::new();
let event_loop: EventLoop<UserEvent> = EventLoop::with_user_event();
let proxy = event_loop.create_proxy();
let common_window = WindowBuilder::new()
.with_title("")
@@ -145,6 +151,10 @@ fn main() -> wry::Result<()> {
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.with_new_window_req_handler(move |uri: String| {
let submitted = proxy.send_event(UserEvent::NewWindow(uri.clone())).is_ok();
submitted
})
.with_back_forward_navigation_gestures(true)
.build()?
};
@@ -175,6 +185,10 @@ fn main() -> wry::Result<()> {
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.with_web_context(&mut web_content)
.with_new_window_req_handler(move |uri: String| {
let submitted = proxy.send_event(UserEvent::NewWindow(uri.clone())).is_ok();
submitted
})
.build()?
};
#[cfg(feature = "devtools")]
@@ -203,6 +217,11 @@ fn main() -> wry::Result<()> {
println!("Clicked on {:?}", menu_id);
println!("Clicked on {:?}", webview.window().is_visible());
}
Event::UserEvent(UserEvent::NewWindow(uri)) => {
if &uri.to_string() != "about:blank" {
webview.load_url(&uri);
}
}
_ => (),
}
});

View File

@@ -55,7 +55,11 @@ window.addEventListener("DOMContentLoaded", (_event) => {
padding-top: 20px;
}
.chakra-ui-light #app .chakra-heading, .chakra-ui-dark #app .chakra-heading, .chakra-ui-light #app .chakra-stack, .chakra-ui-dark #app .chakra-stack {
.chakra-ui-light #app .chakra-heading,
.chakra-ui-dark #app .chakra-heading,
.chakra-ui-light #app .chakra-stack,
.chakra-ui-dark #app .chakra-stack,
.app-main .sidebar-mouse-in-out {
padding-top: 10px;
}