Skip to content

Commit

Permalink
Merge remote-tracking branch 'lucasfernog/feat/close-devtools' into f…
Browse files Browse the repository at this point in the history
…eat/close-devtools
  • Loading branch information
lucasfernog committed Mar 28, 2022
2 parents 3fe8053 + f7d45c1 commit 6bec4c0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .changes/is-devtool-visible.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"wry": minor
---

Added `is_devtools_visible` function to `Webview`.
Added `is_devtools_open` function to `Webview`.
2 changes: 1 addition & 1 deletion src/webview/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl InnerWebView {
pub fn close_devtools(&self) {}

#[cfg(any(debug_assertions, feature = "devtools"))]
pub fn is_devtools_visible(&self) -> bool {
pub fn is_devtools_open(&self) -> bool {
false
}

Expand Down
6 changes: 3 additions & 3 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a> WebViewBuilder<'a> {
///
/// # Warning
/// This will call private functions on **macOS**. It's still enabled if set in **debug** build on mac,
/// but requires `devtool` feature flag to actually enable it in **release** build.
/// but requires `devtools` feature flag to actually enable it in **release** build.
pub fn with_devtools(mut self, devtools: bool) -> Self {
self.webview.devtools = devtools;
self
Expand Down Expand Up @@ -455,8 +455,8 @@ impl WebView {
///
/// - **Windows / Android / iOS:** Not supported.
#[cfg(any(debug_assertions, feature = "devtools"))]
pub fn is_devtoolss_open(&self) -> bool {
self.webview.is_devtools_visible()
pub fn is_devtools_open(&self) -> bool {
self.webview.is_devtools_open()
}

pub fn inner_size(&self) -> PhysicalSize<u32> {
Expand Down
24 changes: 12 additions & 12 deletions src/webview/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod web_context;
pub struct InnerWebView {
pub(crate) webview: Rc<WebView>,
#[cfg(any(debug_assertions, feature = "devtools"))]
is_inspector_visible: Arc<AtomicBool>,
is_inspector_open: Arc<AtomicBool>,
}

impl InnerWebView {
Expand Down Expand Up @@ -278,26 +278,26 @@ impl InnerWebView {
}

#[cfg(any(debug_assertions, feature = "devtools"))]
let is_inspector_visible = {
let is_inspector_visible = Arc::new(AtomicBool::default());
let is_inspector_open = {
let is_inspector_open = Arc::new(AtomicBool::default());
if let Some(inspector) = WebViewExt::inspector(&*webview) {
let is_inspector_visible_ = is_inspector_visible.clone();
let is_inspector_open_ = is_inspector_open.clone();
inspector.connect_bring_to_front(move |_| {
is_inspector_visible_.store(true, Ordering::Relaxed);
is_inspector_open_.store(true, Ordering::Relaxed);
false
});
let is_inspector_visible_ = is_inspector_visible.clone();
let is_inspector_open_ = is_inspector_open.clone();
inspector.connect_closed(move |_| {
is_inspector_visible_.store(false, Ordering::Relaxed);
is_inspector_open_.store(false, Ordering::Relaxed);
});
}
is_inspector_visible
is_inspector_open
};

let w = Self {
webview,
#[cfg(any(debug_assertions, feature = "devtools"))]
is_inspector_visible,
is_inspector_open,
};

// Initialize message handler
Expand Down Expand Up @@ -372,7 +372,7 @@ impl InnerWebView {
if let Some(inspector) = WebViewExt::inspector(&*self.webview) {
inspector.show();
// `bring-to-front` is not received in this case
self.is_inspector_visible.store(true, Ordering::Relaxed);
self.is_inspector_open.store(true, Ordering::Relaxed);
}
}

Expand All @@ -386,8 +386,8 @@ impl InnerWebView {

/// Gets the devtool window's current vibility state.
#[cfg(any(debug_assertions, feature = "devtools"))]
pub fn is_devtools_visible(&self) -> bool {
self.is_inspector_visible.load(Ordering::Relaxed)
pub fn is_devtools_open(&self) -> bool {
self.is_inspector_open.load(Ordering::Relaxed)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ window.addEventListener('mousemove', (e) => window.chrome.webview.postMessage('_

/// Gets the devtool window's current vibility state.
#[cfg(any(debug_assertions, feature = "devtools"))]
pub fn is_devtools_visible(&self) -> bool {
pub fn is_devtools_open(&self) -> bool {
false
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ r#"Object.defineProperty(window, 'ipc', {
///
/// - **iOS:** Not supported.
#[cfg(any(debug_assertions, feature = "devtools"))]
pub fn is_devtools_visible(&self) -> bool {
pub fn is_devtools_open(&self) -> bool {
#[cfg(target_os = "macos")]
unsafe {
// taken from <https://github.com/WebKit/WebKit/blob/784f93cb80a386c29186c510bba910b67ce3adc1/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm#L1939>
Expand Down

0 comments on commit 6bec4c0

Please sign in to comment.