Skip to content

Commit

Permalink
move set_allows_automation to WebContext method (#302)
Browse files Browse the repository at this point in the history
* move set_allows_automation to WebContext method

* cargo +nightly fmt
  • Loading branch information
chippers authored Jun 22, 2021
1 parent a01f163 commit 4ad0bf1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changes/web-context-set-allows-automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"wry": patch
---

`WebContext::set_allows_automation` is now available to specify if the context should allow automation (e.g. WebDriver).
It is only enforced on Linux, but may expand platforms in the future.
25 changes: 15 additions & 10 deletions src/webview/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ impl WebContext {
pub fn data_directory(&self) -> Option<&Path> {
self.data.data_directory()
}

/// Set if this context allows automation.
///
/// **Note:** This is currently only enforced on Linux, and has the stipulation that
/// only 1 context allows automation at a time.
pub fn set_allows_automation(&mut self, flag: bool) {
self.os.set_allows_automation(flag);
}
}

impl Default for WebContext {
Expand Down Expand Up @@ -59,6 +67,8 @@ impl WebContextImpl {
fn new(_data: &WebContextData) -> Self {
Self
}

fn set_allows_automation(&mut self, _flag: bool) {}
}

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -129,6 +139,11 @@ pub mod unix {
automation,
}
}

pub fn set_allows_automation(&mut self, flag: bool) {
self.automation = flag;
self.context.set_automation_allowed(flag);
}
}

/// [`WebContext`](super::WebContext) items that only matter on unix.
Expand All @@ -143,11 +158,6 @@ pub mod unix {
///
/// **Note:** `libwebkit2gtk` only allows 1 automation context at a time.
fn allows_automation(&self) -> bool;

/// Set if this context allows automation.
///
/// **Note:** `libwebkit2gtk` only allows 1 automation context at a time.
fn set_allows_automation(&mut self, flag: bool);
}

impl WebContextExt for super::WebContext {
Expand All @@ -162,10 +172,5 @@ pub mod unix {
fn allows_automation(&self) -> bool {
self.os.automation
}

fn set_allows_automation(&mut self, flag: bool) {
self.os.automation = flag;
self.os.context.set_automation_allowed(flag);
}
}
}

0 comments on commit 4ad0bf1

Please sign in to comment.