From 12091de1ae483dcc4138fc5f9c77ca99ae91c2f1 Mon Sep 17 00:00:00 2001
From: Graeme Arthur <2030310+graeme@users.noreply.github.com>
Date: Tue, 22 Oct 2024 12:15:31 +0200
Subject: [PATCH] Fix lock icon colour in dark mode
---
.../PasswordManagementItemListModel.swift | 4 +
.../PasswordManagementViewController.swift | 75 ++++++++-----------
.../View/PasswordManager.storyboard | 44 ++---------
3 files changed, 40 insertions(+), 83 deletions(-)
diff --git a/DuckDuckGo/SecureVault/Model/PasswordManagementItemListModel.swift b/DuckDuckGo/SecureVault/Model/PasswordManagementItemListModel.swift
index 21eef35196..e0c3ca3d70 100644
--- a/DuckDuckGo/SecureVault/Model/PasswordManagementItemListModel.swift
+++ b/DuckDuckGo/SecureVault/Model/PasswordManagementItemListModel.swift
@@ -303,6 +303,10 @@ final class PasswordManagementItemListModel: ObservableObject {
autofillPreferences.isAutoLockEnabled ? UserText.pmEmptyStateDefaultDescription : UserText.pmEmptyStateDefaultDescriptionAutolockOff
}
+ var emptyStateMessageViewHeight: CGFloat {
+ autofillPreferences.isAutoLockEnabled ? 32 : 16
+ }
+
var emptyStateMessageLinkText: String {
UserText.learnMore
}
diff --git a/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift b/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift
index 3d322ed17d..3bb5bc7f38 100644
--- a/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift
+++ b/DuckDuckGo/SecureVault/View/PasswordManagementViewController.swift
@@ -63,8 +63,8 @@ final class PasswordManagementViewController: NSViewController {
@IBOutlet var emptyState: NSView!
@IBOutlet var emptyStateImageView: NSImageView!
@IBOutlet var emptyStateTitle: NSTextField!
- @IBOutlet var emptyStateMessage: NSTextView!
@IBOutlet var emptyStateMessageHeight: NSLayoutConstraint!
+ @IBOutlet var emptyStateMessageContainer: NSView!
@IBOutlet var emptyStateButton: NSButton!
@IBOutlet weak var exportLoginItem: NSMenuItem!
@IBOutlet var lockScreen: NSView!
@@ -173,9 +173,7 @@ final class PasswordManagementViewController: NSViewController {
emptyStateTitle.attributedStringValue = NSAttributedString.make(emptyStateTitle.stringValue, lineHeight: 1.14, kern: -0.23)
- emptyStateMessage.isSelectable = true
- emptyStateMessage.delegate = self
- setUpEmptyStateMessageAttributedText()
+ setUpEmptyStateMessageView()
addVaultItemButton.toolTip = UserText.addItemTooltip
moreButton.toolTip = UserText.moreOptionsTooltip
@@ -201,47 +199,20 @@ final class PasswordManagementViewController: NSViewController {
.store(in: &cancellables)
}
- private func setUpEmptyStateMessageAttributedText() {
+ private func setUpEmptyStateMessageView() {
guard let listModel else { return }
- emptyStateMessage.delegate = self
- let linkAttributes: [NSAttributedString.Key: Any] = [
- .foregroundColor: NSColor.linkBlue,
- .cursor: NSCursor.pointingHand
- ]
+ let message = " \(listModel.emptyStateMessageDescription) [\(listModel.emptyStateMessageLinkText)](\(listModel.emptyStateMessageLinkURL))"
- emptyStateMessage.linkTextAttributes = linkAttributes
-
- let attachment = NSTextAttachment()
- attachment.image = NSImage(resource: .lockSolid16).tinted(with: NSColor.blackWhite80)
- attachment.bounds = CGRect(x: 0, y: -1, width: 12, height: 12)
- let attributedTextImage = NSMutableAttributedString(attachment: attachment)
-
- let string = NSMutableAttributedString(attributedString: attributedTextImage)
-
- let messageString = NSMutableAttributedString(string: " " + listModel.emptyStateMessageDescription + " ")
- string.append(messageString)
-
- let linkString = NSMutableAttributedString(string: listModel.emptyStateMessageLinkText, attributes: [
- .link: listModel.emptyStateMessageLinkURL
- ])
- string.append(linkString)
-
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.alignment = .center
- string.addAttributes([
- .cursor: NSCursor.arrow,
- .paragraphStyle: paragraphStyle,
- .font: NSFont.systemFont(ofSize: 13, weight: .regular),
- .foregroundColor: NSColor.blackWhite80
- ], range: NSRange(location: 0, length: string.length))
-
- let maxSize = NSSize(width: 280, height: 20000)
- let bounds = string.boundingRect(with: maxSize, options: .usesLineFragmentOrigin)
-
- emptyStateMessageHeight.constant = bounds.height
-
- emptyStateMessage.textStorage?.setAttributedString(string)
+ let hostingView = NSHostingView(rootView: PasswordManagementEmptyStateMessage(
+ message: message,
+ image: .lockSolid16
+ ))
+ hostingView.frame = emptyStateMessageContainer.bounds
+ hostingView.autoresizingMask = [.height, .width]
+ hostingView.translatesAutoresizingMaskIntoConstraints = true
+ emptyStateMessageContainer.addSubview(hostingView)
+ emptyStateMessageHeight.constant = listModel.emptyStateMessageViewHeight
}
private func setupStrings() {
@@ -252,7 +223,7 @@ final class PasswordManagementViewController: NSViewController {
unlockYourAutofillLabel.title = UserText.passwordManagerUnlockAutofill
autofillTitleLabel.stringValue = UserText.passwordManagementTitle
emptyStateTitle.stringValue = UserText.pmEmptyStateDefaultTitle
- setUpEmptyStateMessageAttributedText()
+ setUpEmptyStateMessageView()
emptyStateButton.title = UserText.pmEmptyStateDefaultButtonTitle
}
@@ -1079,10 +1050,10 @@ final class PasswordManagementViewController: NSViewController {
emptyStateImageView.image = image
emptyStateTitle.attributedStringValue = NSAttributedString.make(title, lineHeight: 1.14, kern: -0.23)
if !hideMessage {
- setUpEmptyStateMessageAttributedText()
+ setUpEmptyStateMessageView()
}
- emptyStateMessage.isHidden = hideMessage
emptyStateButton.isHidden = hideButton
+ emptyStateMessageContainer.isHidden = hideMessage
}
private func requestSync() {
@@ -1159,3 +1130,17 @@ extension PasswordManagementViewController: NSMenuItemValidation {
return !accounts.isEmpty
}
}
+
+struct PasswordManagementEmptyStateMessage: View {
+ let message: String
+ let image: ImageResource
+
+ var body: some View {
+ (
+ Text(Image(image)).baselineOffset(-1.0)
+ +
+ Text(.init(message))
+ )
+ .multilineTextAlignment(.center)
+ }
+}
diff --git a/DuckDuckGo/SecureVault/View/PasswordManager.storyboard b/DuckDuckGo/SecureVault/View/PasswordManager.storyboard
index f256d250f0..01287cf6f2 100644
--- a/DuckDuckGo/SecureVault/View/PasswordManager.storyboard
+++ b/DuckDuckGo/SecureVault/View/PasswordManager.storyboard
@@ -68,45 +68,13 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+