Skip to content

Commit

Permalink
Dev tools visibility fix (#457)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199178362774117/1201903875992992/f

Fix of dev tools visibility after switching between tabs
  • Loading branch information
tomasstrba authored Mar 11, 2022
1 parent 78473e2 commit eb170ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/BrowserTab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/BrowserTab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
19 changes: 15 additions & 4 deletions DuckDuckGo/BrowserTab/View/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit eb170ad

Please sign in to comment.