From ba5a06c108e993ae5549fec39d39c691ae68efd3 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 6 Nov 2020 19:07:28 +0800 Subject: [PATCH 1/2] Account / Explainers Fixes #2553 Fixes #2554 Introduces Mail-inspired add account sheets --- .../Accounts/AccountsAddCloudKit.xib | 78 ++++----- Mac/Preferences/Accounts/AccountsAddLocal.xib | 122 ++++++------- .../AccountsAddLocalWindowController.swift | 2 +- .../Accounts/AccountsFeedWrangler.xib | 155 ++++++++++------ ...AccountsFeedWranglerWindowController.swift | 13 ++ Mac/Preferences/Accounts/AccountsFeedbin.xib | 160 +++++++++++------ .../AccountsFeedbinWindowController.swift | 14 +- Mac/Preferences/Accounts/AccountsNewsBlur.xib | 154 ++++++++++------ .../AccountsNewsBlurWindowController.swift | 13 ++ .../Accounts/AccountsReaderAPI.xib | 165 +++++++++++------- .../AccountsReaderAPIWindowController.swift | 29 ++- .../Accounts/AddAccountHelpView.swift | 16 +- .../Accounts/AddAccountsView.swift | 2 - .../EnableExtensionPointHelpView.swift | 27 ++- .../EnableExtensionPointView.swift | 23 ++- ...ensionPointPreferencesViewController.swift | 18 +- 16 files changed, 630 insertions(+), 361 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKit.xib b/Mac/Preferences/Accounts/AccountsAddCloudKit.xib index b6dc5afd1..2e660df44 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKit.xib +++ b/Mac/Preferences/Accounts/AccountsAddCloudKit.xib @@ -17,40 +17,14 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - + + - - + + + + + + + + + + + + + + + + + - + + + - - - + + + + + + + - + diff --git a/Mac/Preferences/Accounts/AccountsAddLocal.xib b/Mac/Preferences/Accounts/AccountsAddLocal.xib index 315c287f2..265de3209 100644 --- a/Mac/Preferences/Accounts/AccountsAddLocal.xib +++ b/Mac/Preferences/Accounts/AccountsAddLocal.xib @@ -20,70 +20,15 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + diff --git a/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift b/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift index 753fc4e75..8aedbccd7 100644 --- a/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift @@ -23,7 +23,7 @@ class AccountsAddLocalWindowController: NSWindowController { override func windowDidLoad() { super.windowDidLoad() - localAccountNameTextField.stringValue = Account.defaultLocalAccountName + localAccountNameTextField.stringValue = NSLocalizedString("Create a local account on your Mac.", comment: "Account Local") } // MARK: API diff --git a/Mac/Preferences/Accounts/AccountsFeedWrangler.xib b/Mac/Preferences/Accounts/AccountsFeedWrangler.xib index d28eadf16..4c7c0b4ff 100644 --- a/Mac/Preferences/Accounts/AccountsFeedWrangler.xib +++ b/Mac/Preferences/Accounts/AccountsFeedWrangler.xib @@ -3,15 +3,19 @@ + - + + + + @@ -28,40 +32,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - @@ -70,7 +47,7 @@ - + @@ -80,11 +57,11 @@ - + - + @@ -93,7 +70,7 @@ - + @@ -103,11 +80,11 @@ - + - + @@ -117,17 +94,6 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + - - + + + + @@ -182,5 +226,8 @@ Gw + + + diff --git a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift index 5b84ce7af..bab79f8de 100644 --- a/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedWranglerWindowController.swift @@ -12,6 +12,10 @@ import RSWeb import Secrets class AccountsFeedWranglerWindowController: NSWindowController { + + @IBOutlet weak var signInTextField: NSTextField! + @IBOutlet weak var noAccountTextField: NSTextField! + @IBOutlet weak var createNewAccountButton: NSButton! @IBOutlet weak var progressIndicator: NSProgressIndicator! @IBOutlet weak var usernameTextField: NSTextField! @IBOutlet weak var passwordTextField: NSSecureTextField! @@ -30,8 +34,12 @@ class AccountsFeedWranglerWindowController: NSWindowController { if let account = account, let credentials = try? account.retrieveCredentials(type: .basic) { usernameTextField.stringValue = credentials.username actionButton.title = NSLocalizedString("Update", comment: "Update") + signInTextField.stringValue = NSLocalizedString("Update your Feed Wrangler account credentials.", comment: "SignIn") + noAccountTextField.isHidden = true + createNewAccountButton.isHidden = true } else { actionButton.title = NSLocalizedString("Create", comment: "Create") + signInTextField.stringValue = NSLocalizedString("Sign in to your Feed Wrangler account.", comment: "SignIn") } } @@ -113,4 +121,9 @@ class AccountsFeedWranglerWindowController: NSWindowController { } } } + + @IBAction func createAccountWithProvider(_ sender: Any) { + NSWorkspace.shared.open(URL(string: "https://feedwrangler.net/users/new")!) + } + } diff --git a/Mac/Preferences/Accounts/AccountsFeedbin.xib b/Mac/Preferences/Accounts/AccountsFeedbin.xib index 8edd2ce12..f5f01ae92 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbin.xib +++ b/Mac/Preferences/Accounts/AccountsFeedbin.xib @@ -3,15 +3,19 @@ + - + + + + @@ -28,43 +32,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + - @@ -73,7 +47,7 @@ - + @@ -83,11 +57,11 @@ - + - + @@ -96,7 +70,7 @@ - + @@ -106,11 +80,11 @@ - + - + @@ -120,17 +94,6 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + @@ -185,5 +226,8 @@ Gw + + + diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index b022e75b5..56f0e8d42 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -13,6 +13,9 @@ import Secrets class AccountsFeedbinWindowController: NSWindowController { + @IBOutlet weak var signInTextField: NSTextField! + @IBOutlet weak var noAccountTextField: NSTextField! + @IBOutlet weak var createNewAccountButton: NSButton! @IBOutlet weak var progressIndicator: NSProgressIndicator! @IBOutlet weak var usernameTextField: NSTextField! @IBOutlet weak var passwordTextField: NSSecureTextField! @@ -31,8 +34,12 @@ class AccountsFeedbinWindowController: NSWindowController { if let account = account, let credentials = try? account.retrieveCredentials(type: .basic) { usernameTextField.stringValue = credentials.username actionButton.title = NSLocalizedString("Update", comment: "Update") + signInTextField.stringValue = NSLocalizedString("Update your Feedbin account credentials.", comment: "SignIn") + noAccountTextField.isHidden = true + createNewAccountButton.isHidden = true } else { - actionButton.title = NSLocalizedString("Add Account", comment: "Add Account") + actionButton.title = NSLocalizedString("Create", comment: "Add Account") + signInTextField.stringValue = NSLocalizedString("Sign in to your Feedbin account.", comment: "SignIn") } } @@ -117,5 +124,10 @@ class AccountsFeedbinWindowController: NSWindowController { } } + + @IBAction func createAccountWithProvider(_ sender: Any) { + NSWorkspace.shared.open(URL(string: "https://feedbin.com/signup")!) + } + } diff --git a/Mac/Preferences/Accounts/AccountsNewsBlur.xib b/Mac/Preferences/Accounts/AccountsNewsBlur.xib index 798f154a1..b6133daa2 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlur.xib +++ b/Mac/Preferences/Accounts/AccountsNewsBlur.xib @@ -3,15 +3,19 @@ + - + + + + @@ -28,40 +32,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - @@ -70,7 +47,7 @@ - + @@ -80,11 +57,11 @@ - + - + @@ -93,7 +70,7 @@ - + @@ -103,11 +80,11 @@ - + - + @@ -117,17 +94,6 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - + + + + + + @@ -182,5 +225,8 @@ Gw + + + diff --git a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift index e3fc527b2..4ae73333d 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift @@ -12,6 +12,10 @@ import RSWeb import Secrets class AccountsNewsBlurWindowController: NSWindowController { + + @IBOutlet weak var signInTextField: NSTextField! + @IBOutlet weak var noAccountTextField: NSTextField! + @IBOutlet weak var createNewAccountButton: NSButton! @IBOutlet weak var progressIndicator: NSProgressIndicator! @IBOutlet weak var usernameTextField: NSTextField! @IBOutlet weak var passwordTextField: NSSecureTextField! @@ -30,8 +34,12 @@ class AccountsNewsBlurWindowController: NSWindowController { if let account = account, let credentials = try? account.retrieveCredentials(type: .newsBlurBasic) { usernameTextField.stringValue = credentials.username actionButton.title = NSLocalizedString("Update", comment: "Update") + signInTextField.stringValue = NSLocalizedString("Update your NewsBlur account credentials.", comment: "SignIn") + noAccountTextField.isHidden = true + createNewAccountButton.isHidden = true } else { actionButton.title = NSLocalizedString("Create", comment: "Create") + signInTextField.stringValue = NSLocalizedString("Sign in to your NewsBlur account.", comment: "SignIn") } } @@ -113,4 +121,9 @@ class AccountsNewsBlurWindowController: NSWindowController { } } } + + @IBAction func createAccountWithProvider(_ sender: Any) { + NSWorkspace.shared.open(URL(string: "https://newsblur.com")!) + } + } diff --git a/Mac/Preferences/Accounts/AccountsReaderAPI.xib b/Mac/Preferences/Accounts/AccountsReaderAPI.xib index 749dbccdf..b96744cdc 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPI.xib +++ b/Mac/Preferences/Accounts/AccountsReaderAPI.xib @@ -3,6 +3,7 @@ + @@ -11,8 +12,9 @@ - + + @@ -28,49 +30,19 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + - @@ -79,7 +51,7 @@ - + @@ -89,11 +61,11 @@ - + - + @@ -102,7 +74,7 @@ - + @@ -112,11 +84,11 @@ - + - + @@ -128,7 +100,7 @@ - + @@ -138,7 +110,7 @@ - + @@ -149,17 +121,6 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - - + + + + @@ -212,4 +252,9 @@ Gw + + + + + diff --git a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift index ccec1dedd..15ab289fb 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift @@ -23,6 +23,7 @@ class AccountsReaderAPIWindowController: NSWindowController { @IBOutlet weak var passwordTextField: NSSecureTextField! @IBOutlet weak var errorMessageLabel: NSTextField! @IBOutlet weak var actionButton: NSButton! + @IBOutlet weak var noAccountTextField: NSTextField! var account: Account? var accountType: AccountType? @@ -38,19 +39,23 @@ class AccountsReaderAPIWindowController: NSWindowController { switch accountType { case .freshRSS: titleImageView.image = AppAssets.accountFreshRSS - titleLabel.stringValue = NSLocalizedString("FreshRSS", comment: "FreshRSS") + titleLabel.stringValue = NSLocalizedString("Sign in to your FreshRSS account.", comment: "FreshRSS") + noAccountTextField.stringValue = NSLocalizedString("Don't have a FreshRSS account?", comment: "No FreshRSS") case .inoreader: titleImageView.image = AppAssets.accountInoreader - titleLabel.stringValue = NSLocalizedString("InoReader", comment: "InoReader") + titleLabel.stringValue = NSLocalizedString("Sign in to your InoReader account.", comment: "InoReader") gridView.row(at: 2).isHidden = true + noAccountTextField.stringValue = NSLocalizedString("Don't have an InoReader account?", comment: "No InoReader") case .bazQux: titleImageView.image = AppAssets.accountBazQux - titleLabel.stringValue = NSLocalizedString("BazQux", comment: "BazQux") + titleLabel.stringValue = NSLocalizedString("Sign in to your BazQux account.", comment: "BazQux") gridView.row(at: 2).isHidden = true + noAccountTextField.stringValue = NSLocalizedString("Don't have a BazQux account?", comment: "No BazQux") case .theOldReader: titleImageView.image = AppAssets.accountTheOldReader - titleLabel.stringValue = NSLocalizedString("The Old Reader", comment: "The Old Reader") + titleLabel.stringValue = NSLocalizedString("Sign in to your The Old Reader account.", comment: "The Old Reader") gridView.row(at: 2).isHidden = true + noAccountTextField.stringValue = NSLocalizedString("Don't have a The Old Reader account?", comment: "No OldReader") default: break } @@ -172,5 +177,21 @@ class AccountsReaderAPIWindowController: NSWindowController { } } + + @IBAction func createAccountWithProvider(_ sender: Any) { + switch accountType { + case .freshRSS: + NSWorkspace.shared.open(URL(string: "https://freshrss.org")!) + case .inoreader: + NSWorkspace.shared.open(URL(string: "https://www.inoreader.com")!) + case .bazQux: + NSWorkspace.shared.open(URL(string: "https://bazqux.com")!) + case .theOldReader: + NSWorkspace.shared.open(URL(string: "https://theoldreader.com")!) + default: + return + } + } + } diff --git a/Mac/Preferences/Accounts/AddAccountHelpView.swift b/Mac/Preferences/Accounts/AddAccountHelpView.swift index fa7675f63..373fe6edb 100644 --- a/Mac/Preferences/Accounts/AddAccountHelpView.swift +++ b/Mac/Preferences/Accounts/AddAccountHelpView.swift @@ -15,6 +15,7 @@ struct AddAccountHelpView: View { var delegate: AccountsPreferencesAddAccountDelegate? var helpText: String @State private var hoveringId: String? = nil + @State private var iCloudUnavailableError: Bool = false var body: some View { VStack { @@ -24,7 +25,11 @@ struct AddAccountHelpView: View { .resizable() .frame(width: 20, height: 20, alignment: .center) .onTapGesture { - delegate?.presentSheetForAccount(account) + if account == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) { + iCloudUnavailableError = true + } else { + delegate?.presentSheetForAccount(account) + } hoveringId = nil } .onHover(perform: { hovering in @@ -42,7 +47,14 @@ struct AddAccountHelpView: View { Text(helpText) .multilineTextAlignment(.center) .padding(.top, 8) - + } + .alert(isPresented: $iCloudUnavailableError, content: { + Alert(title: Text(NSLocalizedString("Error", comment: "Error")), + message: Text(NSLocalizedString("You've already set up an iCloud account.", comment: "Error")), + dismissButton: Alert.Button.cancel({ + iCloudUnavailableError = false + })) + }) } } diff --git a/Mac/Preferences/Accounts/AddAccountsView.swift b/Mac/Preferences/Accounts/AddAccountsView.swift index e79828846..664f2c476 100644 --- a/Mac/Preferences/Accounts/AddAccountsView.swift +++ b/Mac/Preferences/Accounts/AddAccountsView.swift @@ -151,8 +151,6 @@ struct AddAccountsView: View { .aspectRatio(contentMode: .fit) .frame(width: 25, height: 25, alignment: .center) .padding(.leading, 4) - - Text(account.localizedAccountName()) } .tag(account) diff --git a/Mac/Preferences/ExtensionPoints/EnableExtensionPointHelpView.swift b/Mac/Preferences/ExtensionPoints/EnableExtensionPointHelpView.swift index dfebd08cb..a9f9f24de 100644 --- a/Mac/Preferences/ExtensionPoints/EnableExtensionPointHelpView.swift +++ b/Mac/Preferences/ExtensionPoints/EnableExtensionPointHelpView.swift @@ -11,7 +11,12 @@ import SwiftUI import RSCore struct EnableExtensionPointHelpView: View { - let imageLiterals = ["extensionPointMarsEdit", "extensionPointMicroblog", "extensionPointReddit", "extensionPointTwitter"] + + var extensionPoints: [ExtensionPoint.Type] { + let types = ExtensionPointManager.shared.availableExtensionPointTypes.filter({ $0 is SendToCommand.Type }) + + ExtensionPointManager.shared.availableExtensionPointTypes.filter({ !($0 is SendToCommand.Type) }) + return types + } var helpText: String weak var preferencesController: ExtensionPointPreferencesViewController? @@ -20,23 +25,31 @@ struct EnableExtensionPointHelpView: View { var body: some View { VStack { HStack { - ForEach(imageLiterals, id: \.self) { name in - Image(name) + ForEach(0..? // required because presentationMode.dismiss() doesn't work weak var enabler: ExtensionPointPreferencesEnabler? - @State private var extensionPointTypeName = String(describing: Self.feedProviderExtensionPointTypes.first) + @State private var extensionPointTypeName = String(describing: Self.sendToCommandExtensionPointTypes.first) + private var selectedType: ExtensionPoint.Type? - init(enabler: ExtensionPointPreferencesEnabler?) { + init(enabler: ExtensionPointPreferencesEnabler?, selectedType: ExtensionPoint.Type? ) { self.enabler = enabler + self.selectedType = selectedType } var body: some View { @@ -60,7 +63,7 @@ struct EnableExtensionPointView: View { }) .help("Add Extension") .keyboardShortcut(.defaultAction) - + .disabled(disableContinue()) } else { Button(action: { enabler?.enable(typeFromName(extensionPointTypeName)) @@ -69,6 +72,7 @@ struct EnableExtensionPointView: View { Text("Continue") .frame(width: 80) }) + .disabled(disableContinue()) } } .padding(.top, 12) @@ -78,6 +82,11 @@ struct EnableExtensionPointView: View { .fixedSize(horizontal: false, vertical: true) .frame(width: 420) .padding() + .onAppear { + if selectedType != nil { + extensionPointTypeName = String(describing: selectedType!) + } + } } var feedProviderExtensionPoints: some View { @@ -101,7 +110,7 @@ struct EnableExtensionPointView: View { Text(extensionPointType.title) } - .tag(extensionPointTypeNames) + .tag(extensionPointTypeName) }) }) .pickerStyle(RadioGroupPickerStyle()) @@ -138,7 +147,7 @@ struct EnableExtensionPointView: View { Text(extensionPointType.title) } - .tag(extensionPointTypeNames) + .tag(extensionPointTypeName) }) }) .pickerStyle(RadioGroupPickerStyle()) @@ -169,6 +178,10 @@ struct EnableExtensionPointView: View { } fatalError() } + + func disableContinue() -> Bool { + ExtensionPointManager.shared.availableExtensionPointTypes.count == 0 + } } diff --git a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift index 892a65a69..2a596f66b 100644 --- a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift +++ b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift @@ -45,7 +45,13 @@ final class ExtensionPointPreferencesViewController: NSViewController { } @IBAction func enableExtensionPoints(_ sender: Any) { - let controller = NSHostingController(rootView: EnableExtensionPointView(enabler: self)) + let controller = NSHostingController(rootView: EnableExtensionPointView(enabler: self, selectedType: nil)) + controller.rootView.parent = controller + presentAsSheet(controller) + } + + func enableExtensionPointFromSelection(_ selection: ExtensionPoint.Type) { + let controller = NSHostingController(rootView: EnableExtensionPointView(enabler: self, selectedType: selection)) controller.rootView.parent = controller presentAsSheet(controller) } @@ -179,7 +185,10 @@ private extension ExtensionPointPreferencesViewController { if tableView.selectedRow == -1 { var helpText = "" - if activeExtensionPoints.count == 0 { + if ExtensionPointManager.shared.availableExtensionPointTypes.count == 0 { + helpText = NSLocalizedString("You've added all available extension points.", comment: "Extension Explainer") + } + else if activeExtensionPoints.count == 0 { helpText = NSLocalizedString("Add an extension by clicking the + button.", comment: "Extension Explainer") } else { helpText = NSLocalizedString("Select an extension or add a new extension point by clicking the + button.", comment: "Extension Explainer") @@ -219,7 +228,10 @@ private extension ExtensionPointPreferencesViewController { if tableView.selectedRow == -1 { var helpText = "" - if activeExtensionPoints.count == 0 { + if ExtensionPointManager.shared.availableExtensionPointTypes.count == 0 { + helpText = NSLocalizedString("You've added all available extension points.", comment: "Extension Explainer") + } + else if activeExtensionPoints.count == 0 { helpText = NSLocalizedString("Add an extension by clicking the + button.", comment: "Extension Explainer") } else { helpText = NSLocalizedString("Select an extension or add a new extension point by clicking the + button.", comment: "Extension Explainer") From 29dfbbb28b974fbfb4c6505400c8674ea28b1ed3 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 6 Nov 2020 19:09:52 +0800 Subject: [PATCH 2/2] Fixes autolayout warning that had no impact --- Mac/Preferences/Accounts/AccountsAddLocal.xib | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsAddLocal.xib b/Mac/Preferences/Accounts/AccountsAddLocal.xib index 265de3209..36e5232cf 100644 --- a/Mac/Preferences/Accounts/AccountsAddLocal.xib +++ b/Mac/Preferences/Accounts/AccountsAddLocal.xib @@ -24,10 +24,10 @@ - + - +