From 54c70907eee02951428dd63f80fab204603660f7 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Wed, 23 Aug 2023 16:26:49 +0600 Subject: [PATCH 1/2] fix saved popup frame applied to new window --- DuckDuckGo/Main/View/MainWindow.swift | 9 +++++++++ DuckDuckGo/Main/View/MainWindowController.swift | 2 -- .../NavigationBar/View/AddressBarViewController.swift | 7 +++++-- DuckDuckGo/Tab/ViewModel/TabViewModel.swift | 1 - 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DuckDuckGo/Main/View/MainWindow.swift b/DuckDuckGo/Main/View/MainWindow.swift index f694557a13..d9695f7604 100644 --- a/DuckDuckGo/Main/View/MainWindow.swift +++ b/DuckDuckGo/Main/View/MainWindow.swift @@ -28,6 +28,14 @@ final class MainWindow: NSWindow { return true } + override var frameAutosaveName: NSWindow.FrameAutosaveName { + return "MainWindow" + } + + override func setFrameAutosaveName(_ name: NSWindow.FrameAutosaveName) -> Bool { + return super.setFrameAutosaveName(self.frameAutosaveName) + } + init(frame: NSRect) { super.init(contentRect: frame, styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], @@ -53,6 +61,7 @@ final class MainWindow: NSWindow { titlebarAppearsTransparent = true // the window will be draggable using custom drag areas defined by WindowDraggingView isMovable = false +// setFrameAutosaveName("MainWindow") } // MARK: - First Responder Notification diff --git a/DuckDuckGo/Main/View/MainWindowController.swift b/DuckDuckGo/Main/View/MainWindowController.swift index 575e3f61bc..df1d6284fc 100644 --- a/DuckDuckGo/Main/View/MainWindowController.swift +++ b/DuckDuckGo/Main/View/MainWindowController.swift @@ -23,7 +23,6 @@ import Common @MainActor final class MainWindowController: NSWindowController { - private static let windowFrameSaveName = "MainWindow" private var fireViewModel: FireViewModel private static var knownFullScreenMouseDetectionWindows = Set() @@ -76,7 +75,6 @@ final class MainWindowController: NSWindowController { private func setupWindow() { window?.delegate = self - window?.setFrameAutosaveName(Self.windowFrameSaveName) if shouldShowOnboarding { mainViewController.tabCollectionViewModel.selectedTabViewModel?.tab.startOnboarding() diff --git a/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift b/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift index f5c54772e5..46443cd02b 100644 --- a/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift +++ b/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift @@ -22,8 +22,8 @@ import Lottie final class AddressBarViewController: NSViewController { - @IBOutlet weak var addressBarTextField: AddressBarTextField! - @IBOutlet weak var passiveTextField: NSTextField! + @IBOutlet var addressBarTextField: AddressBarTextField! + @IBOutlet var passiveTextField: NSTextField! @IBOutlet var inactiveBackgroundView: NSView! @IBOutlet var activeBackgroundView: NSView! @IBOutlet var activeOuterBorderView: NSView! @@ -100,6 +100,8 @@ final class AddressBarViewController: NSViewController { view.layer?.masksToBounds = false updateView() + // only activate active text field leading constraint on its appearance to avoid constraint conflicts + activeTextFieldMinXConstraint.isActive = false addressBarTextField.addressBarTextFieldDelegate = self addressBarTextField.tabCollectionViewModel = tabCollectionViewModel subscribeToSelectedTabViewModel() @@ -379,6 +381,7 @@ extension AddressBarViewController { @objc func textFieldFirstReponderNotification(_ notification: Notification) { if view.window?.firstResponder == addressBarTextField.currentEditor() { isFirstResponder = true + activeTextFieldMinXConstraint.isActive = true } else { isFirstResponder = false } diff --git a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift index bc325df672..65b13fc485 100644 --- a/DuckDuckGo/Tab/ViewModel/TabViewModel.swift +++ b/DuckDuckGo/Tab/ViewModel/TabViewModel.swift @@ -197,7 +197,6 @@ final class TabViewModel { func updateAddressBarStrings() { guard !errorViewState.isVisible else { let failingUrl = tab.error?.failingUrl - let failingUrlString = failingUrl?.absoluteString ?? "" let failingUrlHost = failingUrl?.host?.droppingWwwPrefix() ?? "" passiveAddressBarString = appearancePreferences.showFullURL ? addressBarString : failingUrlHost return From 522cefb4f15d4c976cf1a35bc01ac769199858b4 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Wed, 23 Aug 2023 16:51:08 +0600 Subject: [PATCH 2/2] cleanup --- DuckDuckGo/Main/View/MainWindow.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/DuckDuckGo/Main/View/MainWindow.swift b/DuckDuckGo/Main/View/MainWindow.swift index d9695f7604..9020157ab5 100644 --- a/DuckDuckGo/Main/View/MainWindow.swift +++ b/DuckDuckGo/Main/View/MainWindow.swift @@ -61,7 +61,6 @@ final class MainWindow: NSWindow { titlebarAppearsTransparent = true // the window will be draggable using custom drag areas defined by WindowDraggingView isMovable = false -// setFrameAutosaveName("MainWindow") } // MARK: - First Responder Notification