Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webdriver support #281

Merged
merged 48 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8b7a9e4
Add `Application` back, require it for `WebviewBuilder`
chippers May 14, 2021
790061e
Create automated webviews from webdriver clients
chippers May 14, 2021
c6ae772
cargo +nightly fmt
chippers May 14, 2021
aae8a7a
update env var value for automation
chippers May 15, 2021
fba16ba
allow closing the window from the webdriver client
chippers May 18, 2021
1909ba0
add support for win32 windows
chippers May 19, 2021
6486d50
add wry::Application support to macOS
chippers May 20, 2021
2b6a8ef
change how ApplicationExt work to match std
chippers May 20, 2021
79a703f
update all examples to use wry::Application
chippers May 20, 2021
fbfce7b
Merge branch 'dev' into feat/webdriver
chippers May 20, 2021
f144537
remove now unneeded uuid dependency
chippers May 20, 2021
0ea87fe
add webdriver support to new example
chippers May 20, 2021
95fcd28
cargo +nightly fmt
chippers May 20, 2021
c7491cb
remove automation flag from mac/win ApplicationInner
chippers May 20, 2021
cc7281d
allow dead_code in Application inner field
chippers May 20, 2021
588e3ae
cargo +nightly fmt
chippers May 20, 2021
90187d2
update all WebviewBuilder::new calls
chippers May 20, 2021
2bf9aac
cargo +nightly fmt
chippers May 20, 2021
201e4dc
super builder
chippers Jun 2, 2021
9ac9f56
Merge branch 'dev' into feat/webdriver
chippers Jun 2, 2021
dc20ee4
update ecma example
chippers Jun 2, 2021
c033e76
enable automation if specific build env is set
chippers Jun 2, 2021
a50a5ce
change build env var to feature
chippers Jun 2, 2021
c55ad74
move the super builder to its own module
chippers Jun 4, 2021
3f89ac1
cargo +nightly fmt
chippers Jun 4, 2021
a497e86
update builder docs
chippers Jun 4, 2021
c6dc106
explicitly allow inlining on wry::Builder
chippers Jun 4, 2021
98b5db4
revert everything to dev
chippers Jun 4, 2021
d82d857
update webkit2gtk to v2_18 to allow for automation
chippers Jun 4, 2021
238b67d
set custom cfg on rustdocs to allow for nightly doc features
chippers Jun 4, 2021
48823c5
simplify application module
chippers Jun 4, 2021
edc6a38
enable nightly doc features when cfg is set
chippers Jun 4, 2021
4f99382
add WebContext as a required item to `WebViewBuilder`
chippers Jun 4, 2021
585ccfc
Merge branch 'dev' into feat/webdriver
chippers Jun 4, 2021
d77b698
add changes file
chippers Jun 4, 2021
93bb302
move web_context to build from new
chippers Jun 4, 2021
2a271b9
update WebContextData path for windows,macos
chippers Jun 4, 2021
247f69c
mark WebContextData as private
chippers Jun 4, 2021
440b9ae
update examples and doc tests
chippers Jun 4, 2021
d114e38
allow os impl WebContextImpl to be dead_code
chippers Jun 4, 2021
8c8cca4
fix windows webview builder initialization
chippers Jun 4, 2021
662037b
add winrt note to add window close event handler
chippers Jun 4, 2021
0d51d78
add smart link to WebContext docs
chippers Jun 8, 2021
0ca465d
update WebContext doc smartlink
chippers Jun 8, 2021
5618819
remove doc_cfg from empty non-linux WebContextImpls
chippers Jun 8, 2021
f384c20
fix clippy error in unrelated code
chippers Jun 8, 2021
08c646c
make clippy happy (new nightly lints)
chippers Jun 8, 2021
d11fab1
Merge branch 'dev' into feat/webdriver
Jun 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/web_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Add `wry::webview::WebContext`. It's now a required argument on `WebViewBuilder::build`.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = [ "gui" ]

[package.metadata.docs.rs]
features = [ "dox" ]
rustdoc-args = [ "--cfg", "doc_cfg" ]
default-target = "x86_64-unknown-linux-gnu"
targets = [
"x86_64-pc-windows-msvc",
Expand Down Expand Up @@ -50,7 +51,7 @@ chrono = "0.4.19"
tempfile = "3.2.0"

[target."cfg(target_os = \"linux\")".dependencies]
webkit2gtk = { version = "0.11", features = [ "v2_10" ] }
webkit2gtk = { version = "0.11", features = [ "v2_18" ] }
webkit2gtk-sys = "0.13.0"
gio = "0.9"
glib = "0.10"
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_data_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> wry::Result<()> {
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
},
webview::WebViewBuilder,
webview::{WebContext, WebViewBuilder},
};

// Use a sample directory at the root of the project
Expand All @@ -24,15 +24,15 @@ fn main() -> wry::Result<()> {
println!("Webview storage path: {:#?}", &test_path);

let event_loop = EventLoop::new();
let web_context = WebContext::new(Some(test_path));
let window = WindowBuilder::new()
.with_title("Hello World")
.build(&event_loop)
.unwrap();
let _webview = WebViewBuilder::new(window)
.unwrap()
.with_url("https://tauri.studio")?
.with_data_directory(test_path)
.build()?;
.build(&web_context)?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn main() -> wry::Result<()> {
})
// tell the webview to load the custom protocol
.with_url("wry.dev://")?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_titlebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn main() -> wry::Result<()> {
.with_url(url)?
.with_initialization_script(script)
.with_rpc_handler(handler)
.build()?;
.build(&Default::default())?;
webviews.insert(webview.window().id(), webview);

event_loop.run(move |event, _, control_flow| {
Expand Down
2 changes: 1 addition & 1 deletion examples/detect_js_ecma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn main() -> wry::Result<()> {
</html>
"#,
)?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/dragndrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> wry::Result<()> {
println!("Window 1: {:?}", data);
false // Returning true will block the OS default behaviour.
})
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> wry::Result<()> {
let webview = WebViewBuilder::new(window)
.unwrap()
.with_url("https://www.wirple.com/")?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> wry::Result<()> {
.build(&event_loop)?;
let _webview = WebViewBuilder::new(window)?
.with_url("https://tauri.studio")?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/html_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> wry::Result<()> {
.build(&event_loop)?;
let _webview = WebViewBuilder::new(window)?
.with_url("https://html5test.com")?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn main() -> wry::Result<()> {
// Build the webview
let webview = WebViewBuilder::new(window)?
.with_url("https://tauri.studio")?
.build()?;
.build(&Default::default())?;
// launch WRY process
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
9 changes: 5 additions & 4 deletions examples/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ fn main() -> wry::Result<()> {
event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder},
},
webview::{RpcRequest, WebViewBuilder},
webview::{RpcRequest, WebContext, WebViewBuilder},
};

let event_loop = EventLoop::new();
let web_context = WebContext::default();
let window1 = WindowBuilder::new().build(&event_loop).unwrap();

let (window_tx, window_rx) = std::sync::mpsc::channel::<String>();
Expand All @@ -50,7 +51,7 @@ fn main() -> wry::Result<()> {
}"#,
)
.with_rpc_handler(handler)
.build()?;
.build(&web_context)?;
let mut webviews = HashMap::new();
webviews.insert(id, webview1);

Expand All @@ -64,14 +65,14 @@ fn main() -> wry::Result<()> {
let window2 = WindowBuilder::new()
.with_title("RODA RORA DA")
.with_inner_size(PhysicalSize::new(426, 197))
.build(&event_loop)
.build(event_loop)
.unwrap();
let id = window2.id();
let webview2 = WebViewBuilder::new(window2)
.unwrap()
.with_url(&url)
.unwrap()
.build()
.build(&web_context)
.unwrap();
webviews.insert(id, webview2);
} else if trigger && instant.elapsed() >= eight_secs {
Expand Down
2 changes: 1 addition & 1 deletion examples/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function getAsyncRpcResult() {
.unwrap()
.with_url(url)?
.with_rpc_handler(handler)
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
4 changes: 2 additions & 2 deletions examples/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ fn main() -> wry::Result<()> {
origin: MenuType::SystemTray,
} => {
if menu_id == open_new_window_id {
let window = Window::new(&event_loop).unwrap();
let window = Window::new(event_loop).unwrap();
let id = window.id();
let webview = WebViewBuilder::new(window)
.unwrap()
.with_url("https://tauri.studio")
.unwrap()
.build()
.build(&Default::default())
.unwrap();
webviews.insert(id, webview);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() -> wry::Result<()> {
</script>
</html>"#,
)?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
2 changes: 1 addition & 1 deletion examples/validate_webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> wry::Result<()> {
.build(&event_loop)?;
let _webview = WebViewBuilder::new(window)?
.with_url("https://tauri.studio")?
.build()?;
.build(&Default::default())?;

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! .build(&event_loop)?;
//! let _webview = WebViewBuilder::new(window)?
//! .with_url("https://tauri.studio")?
//! .build()?;
//! .build(&Default::default())?;
//!
//! event_loop.run(move |event, _, control_flow| {
//! *control_flow = ControlFlow::Wait;
Expand Down Expand Up @@ -77,6 +77,7 @@
//! [`with_file_drop_handler`]: crate::webview::WebView::with_file_drop_handler
//! [`with_custom_protocol`]: crate::webview::WebView::with_custom_protocol

#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![allow(clippy::new_without_default)]
#![allow(clippy::wrong_self_convention)]
#![allow(clippy::type_complexity)]
Expand Down
18 changes: 7 additions & 11 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! [`WebView`] struct and associated types.

mod mimetype;
mod web_context;

pub use web_context::WebContext;

#[cfg(target_os = "linux")]
mod webkitgtk;
Expand Down Expand Up @@ -126,13 +129,6 @@ impl WebViewBuilder {
self
}

/// Whether the WebView window should have a custom user data path. This is useful in Windows
/// when a bundled application can't have the webview data inside `Program Files`.
pub fn with_data_directory(mut self, data_directory: PathBuf) -> Self {
self.webview.data_directory.replace(data_directory);
self
}

/// Register custom file loading protocol
#[cfg(feature = "protocol")]
pub fn with_custom_protocol<F>(mut self, name: String, handler: F) -> Self
Expand Down Expand Up @@ -195,7 +191,7 @@ impl WebViewBuilder {
/// called in the same thread with the [`EventLoop`] you create.
///
/// [`EventLoop`]: crate::application::event_loop::EventLoop
pub fn build(mut self) -> Result<WebView> {
pub fn build(mut self, web_context: &WebContext) -> Result<WebView> {
if self.webview.rpc_handler.is_some() {
let js = r#"
(function() {
Expand Down Expand Up @@ -250,7 +246,7 @@ impl WebViewBuilder {
self.webview.initialization_scripts.push(js.to_string());
}
let window = Rc::new(self.window);
let webview = InnerWebView::new(window.clone(), self.webview)?;
let webview = InnerWebView::new(window.clone(), self.webview, web_context)?;
Ok(WebView { window, webview })
}
}
Expand Down Expand Up @@ -295,8 +291,8 @@ impl WebView {
/// called in the same thread with the [`EventLoop`] you create.
///
/// [`EventLoop`]: crate::application::event_loop::EventLoop
pub fn new(window: Window) -> Result<Self> {
WebViewBuilder::new(window)?.build()
pub fn new(window: Window, web_context: &WebContext) -> Result<Self> {
WebViewBuilder::new(window)?.build(web_context)
}

/// Get the [`Window`] associate with the [`WebView`]. This can let you perform window related
Expand Down
Loading