From eb170ad26b542f82e76b2c817c46dfe6326d0942 Mon Sep 17 00:00:00 2001 From: Tomas Strba <57389842+tomasstrba@users.noreply.github.com> Date: Fri, 11 Mar 2022 15:43:18 +0100 Subject: [PATCH] Dev tools visibility fix (#457) Task/Issue URL: https://app.asana.com/0/1199178362774117/1201903875992992/f Fix of dev tools visibility after switching between tabs --- DuckDuckGo/BrowserTab/Model/Tab.swift | 2 +- .../View/BrowserTabViewController.swift | 4 ++-- DuckDuckGo/BrowserTab/View/WebView.swift | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo/BrowserTab/Model/Tab.swift b/DuckDuckGo/BrowserTab/Model/Tab.swift index 20cd92cb62..80563314d9 100644 --- a/DuckDuckGo/BrowserTab/Model/Tab.swift +++ b/DuckDuckGo/BrowserTab/Model/Tab.swift @@ -592,7 +592,7 @@ extension Tab: UserContentControllerDelegate { } -extension Tab: ChildAutofillUserScriptDelegate { +extension Tab: BrowserTabViewControllerClickDelegate { func browserTabViewController(_ browserTabViewController: BrowserTabViewController, didClickAtPoint: NSPoint) { guard let autofillScript = autofillScript else { return } autofillScript.clickPoint = didClickAtPoint diff --git a/DuckDuckGo/BrowserTab/View/BrowserTabViewController.swift b/DuckDuckGo/BrowserTab/View/BrowserTabViewController.swift index 01170b732c..383ca14f4d 100644 --- a/DuckDuckGo/BrowserTab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/BrowserTab/View/BrowserTabViewController.swift @@ -23,12 +23,12 @@ import Combine import SwiftUI import BrowserServicesKit -protocol ChildAutofillUserScriptDelegate: AnyObject { +protocol BrowserTabViewControllerClickDelegate: AnyObject { func browserTabViewController(_ browserTabViewController: BrowserTabViewController, didClickAtPoint: CGPoint) } -// swiftlint:disable type_body_length // swiftlint:disable file_length +// swiftlint:disable type_body_length final class BrowserTabViewController: NSViewController { diff --git a/DuckDuckGo/BrowserTab/View/WebView.swift b/DuckDuckGo/BrowserTab/View/WebView.swift index 93540b4edd..108d6a530d 100644 --- a/DuckDuckGo/BrowserTab/View/WebView.swift +++ b/DuckDuckGo/BrowserTab/View/WebView.swift @@ -42,6 +42,12 @@ final class WebView: WKWebView { "WKMenuItemIdentifierDownloadLinkedFile": UserText.downloadLinkedFileAs, "WKMenuItemIdentifierSearchWeb": UserText.searchWithDuckDuckGo ] + + deinit { + self.configuration.userContentController.removeAllUserScripts() + } + + // MARK: - Zoom static private let maxZoomLevel: CGFloat = 3.0 static private let minZoomLevel: CGFloat = 0.5 @@ -85,10 +91,6 @@ final class WebView: WKWebView { self.zoomLevel = max(self.zoomLevel - Self.zoomLevelStep, Self.minZoomLevel) } - deinit { - self.configuration.userContentController.removeAllUserScripts() - } - // MARK: - Back/Forward Navigation var frozenCanGoBack: Bool? @@ -142,6 +144,13 @@ final class WebView: WKWebView { // MARK: - Developer Tools + override func viewDidMoveToWindow() { + super.viewDidMoveToWindow() + if self.isInspectorShown { + self.openDeveloperTools() + } + } + @nonobjc var mainFrame: AnyObject? { guard self.responds(to: NSSelectorFromString("_mainFrame")) else { assertionFailure("WKWebView does not respond to _mainFrame") @@ -186,6 +195,8 @@ final class WebView: WKWebView { inspectorPerform("showResources") } + // MARK: - Fullscreen + var fullscreenWindowController: NSWindowController? { guard let fullscreenWindowController = self.window?.windowController, fullscreenWindowController.className.contains("FullScreen")