-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
* Modify webcontext to take EventLoopProxy Adjust relevant structs/functions to take generic arguments due to new constraint. * Attempt to make other platforms accept generic webcontext * Modify with_event_loop proxy to allow different event_loop types * Fix WebViewBuilder to be able to switch types * Add event loop proxy getter * Add getter and setter for naviagtion event constructor callback * Complete initial implementation of nav events, cancellation * Move majority implementation into WebView/WebViewData No longer make WebContext generic over user event type. Only take single closure, which defines behaviour to execute when navigation occurs, and also whether to cancel navigation. If user wishes to submit an event, they should simply move an event proxy into the event closure and submit an event through it - see updated example. WebViewBuilder will now raise return an error if there is no WebContext to attach callback to. * Revert changes to Gtk WebContext * Revert changes to wkwebview * Extend event to cover new window/popup events * Move navigation callback into WebViewAttributes * Remove unnecessary brackets in WebView Co-authored-by: Amr Bashir <[email protected]> * Remove new window handler Implement in a different PR * Remove references to new window values * Implement navigation event callback handler on gtk * Add navigation handler on macOS The function is still not called yet. But this is a prove it can work. * Call the navigation handler on macOS * Update navifation logic and type signature * Fix errors on windows Co-authored-by: Amr Bashir <[email protected]> Co-authored-by: Yu-Wei Wu <[email protected]>
- Loading branch information
1 parent
6fb9b82
commit aa8af02
Showing
8 changed files
with
178 additions
and
4 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,5 @@ | ||
--- | ||
"wry": patch | ||
--- | ||
|
||
Add navigation handler to decide if a url is allowed to navigate. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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 { | ||
Navigation(String), | ||
} | ||
|
||
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_url("http://neverssl.com")? | ||
.with_navigation_handler(move |uri: String| { | ||
let submitted = proxy.send_event(UserEvent::Navigation(uri.clone())).is_ok(); | ||
|
||
submitted && uri.contains("neverssl") | ||
}) | ||
.build()?; | ||
|
||
#[cfg(debug_assertions)] | ||
webview.devtool(); | ||
|
||
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::Navigation(uri)) => { | ||
println!("{}", 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
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