-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add handler + setter to webviewattr * Basic impl for windows * Add new window request event example * Implement new window request event for linux * Attempt WKWebview implementation * Fix WKWebview implementation Also fixes incorrect drop impl * Improve formatting * Update examples/new_window_req_event.rs Remove set automation Co-authored-by: Amr Bashir <[email protected]> * Improve docs * Adjust to match changes in dev * fmt * changefil * fix windows Co-authored-by: Iain Laird <[email protected]> Co-authored-by: Amr Bashir <[email protected]>
- Loading branch information
1 parent
0cb6961
commit fa5456c
Showing
6 changed files
with
165 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"wry": minor | ||
--- | ||
|
||
Implement new window requested handler | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
fn main() -> wry::Result<()> { | ||
use wry::{ | ||
application::{ | ||
event::{Event, StartCause, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
window::WindowBuilder, | ||
}, | ||
webview::WebViewBuilder, | ||
}; | ||
|
||
enum UserEvent { | ||
NewWindow(String), | ||
} | ||
|
||
let html = r#" | ||
<body> | ||
<div> | ||
<p> WRYYYYYYYYYYYYYYYYYYYYYY! </p> | ||
<a href="https://www.wikipedia.org" target="_blank">Visit Wikipedia</a> | ||
<a href="https://www.github.com" target="_blank">(Try to) visit GitHub</a> | ||
</div> | ||
</body> | ||
"#; | ||
|
||
let event_loop: EventLoop<UserEvent> = EventLoop::with_user_event(); | ||
let proxy = event_loop.create_proxy(); | ||
let window = WindowBuilder::new() | ||
.with_title("Hello World") | ||
.build(&event_loop)?; | ||
let webview = WebViewBuilder::new(window)? | ||
.with_html(html)? | ||
.with_new_window_req_handler(move |uri: String| { | ||
let submitted = proxy.send_event(UserEvent::NewWindow(uri.clone())).is_ok(); | ||
|
||
submitted && uri.contains("wikipedia") | ||
}) | ||
.build()?; | ||
|
||
#[cfg(debug_assertions)] | ||
webview.open_devtools(); | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
|
||
match event { | ||
Event::NewEvents(StartCause::Init) => println!("Wry has started!"), | ||
Event::WindowEvent { | ||
event: WindowEvent::CloseRequested, | ||
.. | ||
} => *control_flow = ControlFlow::Exit, | ||
Event::UserEvent(UserEvent::NewWindow(uri)) => { | ||
println!("New Window: {}", uri); | ||
} | ||
_ => (), | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters