From 178e7370408131c378070688efc48a7beec2b263 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Thu, 26 Aug 2021 10:27:23 +0800 Subject: [PATCH] Converts to a browser preference to a `Bool`. --- NetNewsWire.xcodeproj/project.pbxproj | 14 --- iOS/AppDefaults.swift | 12 +-- iOS/Article/WebViewController.swift | 12 +-- .../MasterTimelineViewController.swift | 5 +- iOS/Settings/Browser.swift | 41 --------- iOS/Settings/BrowserCell.swift | 47 ---------- .../BrowserConfigurationViewController.swift | 78 ---------------- iOS/Settings/Settings.storyboard | 91 +++++-------------- iOS/Settings/SettingsViewController.swift | 26 +++--- 9 files changed, 50 insertions(+), 276 deletions(-) delete mode 100644 iOS/Settings/Browser.swift delete mode 100644 iOS/Settings/BrowserCell.swift delete mode 100644 iOS/Settings/BrowserConfigurationViewController.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 5da94ccf4..d225fb800 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -21,7 +21,6 @@ 17192AE62567B3FE00AAEACA /* org.sparkle-project.InstallerConnection.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 17192AE22567B3FE00AAEACA /* org.sparkle-project.InstallerConnection.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 17192AE72567B3FE00AAEACA /* org.sparkle-project.InstallerLauncher.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 17192AE32567B3FE00AAEACA /* org.sparkle-project.InstallerLauncher.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 17192AE82567B3FE00AAEACA /* org.sparkle-project.InstallerStatus.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 17192AE42567B3FE00AAEACA /* org.sparkle-project.InstallerStatus.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - 171BC38126D61F3F0032425C /* Browser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC05D2126D3E0770047E788 /* Browser.swift */; }; 171BCB8C24CB08A3006E22D9 /* FixAccountCredentialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BCB8B24CB08A3006E22D9 /* FixAccountCredentialView.swift */; }; 171BCB8D24CB08A3006E22D9 /* FixAccountCredentialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171BCB8B24CB08A3006E22D9 /* FixAccountCredentialView.swift */; }; 171BCBAF24CBBFD8006E22D9 /* EditAccountCredentialsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1769E33524BD9621000E1E8E /* EditAccountCredentialsModel.swift */; }; @@ -73,8 +72,6 @@ 173A642C2547BE9600267F6E /* AccountType+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173A64162547BE0900267F6E /* AccountType+Helpers.swift */; }; 175942AA24AD533200585066 /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; 175942AB24AD533200585066 /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; - 175EBD7426D2405A009B5B23 /* BrowserConfigurationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 175EBD7326D2405A009B5B23 /* BrowserConfigurationViewController.swift */; }; - 175EBD7626D240D8009B5B23 /* BrowserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 175EBD7526D240D8009B5B23 /* BrowserCell.swift */; }; 176813D02564BA5900D98635 /* WidgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176813B62564B9F800D98635 /* WidgetData.swift */; }; 176813D12564BA5900D98635 /* WidgetDataDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176813C92564BA5400D98635 /* WidgetDataDecoder.swift */; }; 176813D22564BA5900D98635 /* WidgetDataEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176813BD2564BA2800D98635 /* WidgetDataEncoder.swift */; }; @@ -1213,7 +1210,6 @@ DF98E2B02578AA5C00F18944 /* AddFeedWranglerAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF98E2AF2578AA5C00F18944 /* AddFeedWranglerAccountView.swift */; }; DF98E2BE2578AC0000F18944 /* AddNewsBlurAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF98E2BD2578AC0000F18944 /* AddNewsBlurAccountView.swift */; }; DF98E2C62578AD1B00F18944 /* AddReaderAPIAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF98E2C52578AD1B00F18944 /* AddReaderAPIAccountView.swift */; }; - DFC05D2226D3E0770047E788 /* Browser.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC05D2126D3E0770047E788 /* Browser.swift */; }; FA80C11724B0728000974098 /* AddFolderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA80C11624B0728000974098 /* AddFolderView.swift */; }; FA80C11824B0728000974098 /* AddFolderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA80C11624B0728000974098 /* AddFolderView.swift */; }; FA80C13E24B072AA00974098 /* AddFolderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA80C13D24B072AA00974098 /* AddFolderModel.swift */; }; @@ -1556,8 +1552,6 @@ 17386B792577C4BF0014C8B2 /* AddLocalAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddLocalAccountView.swift; sourceTree = ""; }; 17386BC32577CC600014C8B2 /* AddFeedbinAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeedbinAccountView.swift; sourceTree = ""; }; 173A64162547BE0900267F6E /* AccountType+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountType+Helpers.swift"; sourceTree = ""; }; - 175EBD7326D2405A009B5B23 /* BrowserConfigurationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserConfigurationViewController.swift; sourceTree = ""; }; - 175EBD7526D240D8009B5B23 /* BrowserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserCell.swift; sourceTree = ""; }; 176813B62564B9F800D98635 /* WidgetData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetData.swift; sourceTree = ""; }; 176813BD2564BA2800D98635 /* WidgetDataEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDataEncoder.swift; sourceTree = ""; }; 176813C92564BA5400D98635 /* WidgetDataDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDataDecoder.swift; sourceTree = ""; }; @@ -2143,7 +2137,6 @@ DF98E2AF2578AA5C00F18944 /* AddFeedWranglerAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeedWranglerAccountView.swift; sourceTree = ""; }; DF98E2BD2578AC0000F18944 /* AddNewsBlurAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddNewsBlurAccountView.swift; sourceTree = ""; }; DF98E2C52578AD1B00F18944 /* AddReaderAPIAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddReaderAPIAccountView.swift; sourceTree = ""; }; - DFC05D2126D3E0770047E788 /* Browser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Browser.swift; sourceTree = ""; }; FA80C11624B0728000974098 /* AddFolderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFolderView.swift; sourceTree = ""; }; FA80C13D24B072AA00974098 /* AddFolderModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFolderModel.swift; sourceTree = ""; }; FF3ABF09232599450074C542 /* ArticleSorterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleSorterTests.swift; sourceTree = ""; }; @@ -2800,9 +2793,6 @@ 51A16992235E10D600EB091F /* AddAccountViewController.swift */, 519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */, 519ED455244828C3007F8E94 /* AddExtensionPointViewController.swift */, - DFC05D2126D3E0770047E788 /* Browser.swift */, - 175EBD7326D2405A009B5B23 /* BrowserConfigurationViewController.swift */, - 175EBD7526D240D8009B5B23 /* BrowserCell.swift */, 516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */, 516A09382360A2AE00EAE89B /* SettingsComboTableViewCell.swift */, 516A091D23609A3600EAE89B /* SettingsComboTableViewCell.xib */, @@ -4892,7 +4882,6 @@ 51B5C8BE23F37B2400032075 /* ShareDefaultContainer.swift in Sources */, 51B5C8BA23F368D000032075 /* ExtensionContainersFile.swift in Sources */, 51B5C8BB23F368D000032075 /* ExtensionFeedAddRequest.swift in Sources */, - 171BC38126D61F3F0032425C /* Browser.swift in Sources */, 51A9A5E82380CA130033AADF /* ShareFolderPickerCell.swift in Sources */, 51A9A5EF2380D63B0033AADF /* IconImage.swift in Sources */, 51A9A5ED2380D6000033AADF /* AppAssets.swift in Sources */, @@ -5501,7 +5490,6 @@ 510289CD24519A1D00426DDF /* SelectComboTableViewCell.swift in Sources */, 514B7C8323205EFB00BAC947 /* RootSplitViewController.swift in Sources */, 51FA73A52332BE110090D516 /* ArticleExtractor.swift in Sources */, - DFC05D2226D3E0770047E788 /* Browser.swift in Sources */, 51314704235C41FC00387FDC /* Intents.intentdefinition in Sources */, FF3ABF162325AF5D0074C542 /* ArticleSorter.swift in Sources */, 51C4525C226508DF00C03939 /* String-Extensions.swift in Sources */, @@ -5558,7 +5546,6 @@ 51C4528E2265099C00C03939 /* SmartFeedsController.swift in Sources */, 51C9DE5823EA2EF4003D5A6D /* WrapperScriptMessageHandler.swift in Sources */, 51627A6B238629D8007B3B4B /* MasterFeedDataSource.swift in Sources */, - 175EBD7626D240D8009B5B23 /* BrowserCell.swift in Sources */, 51B5C87D23F2346200032075 /* ExtensionContainersFile.swift in Sources */, 51102165233A7D6C0007A5F7 /* ArticleExtractorButton.swift in Sources */, 5141E7392373C18B0013FF27 /* WebFeedInspectorViewController.swift in Sources */, @@ -5620,7 +5607,6 @@ 51C4529F22650A1900C03939 /* AuthorAvatarDownloader.swift in Sources */, 5108F6D22375EED2001ABC45 /* TimelineCustomizerViewController.swift in Sources */, 519E743D22C663F900A78E47 /* SceneDelegate.swift in Sources */, - 175EBD7426D2405A009B5B23 /* BrowserConfigurationViewController.swift in Sources */, FFD43E412340F488009E5CA3 /* MarkAsReadAlertController.swift in Sources */, 51C452A322650A1E00C03939 /* HTMLMetadataDownloader.swift in Sources */, 51C4528D2265095F00C03939 /* AddFolderViewController.swift in Sources */, diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index eff58dcd2..c3935b68b 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -54,7 +54,7 @@ final class AppDefaults { static let addWebFeedAccountID = "addWebFeedAccountID" static let addWebFeedFolderName = "addWebFeedFolderName" static let addFolderAccountID = "addFolderAccountID" - static let browserPreference = "browserPreference" + static let useSystemBrowser = "useSystemBrowser" } let isDeveloperBuild: Bool = { @@ -120,16 +120,12 @@ final class AppDefaults { } } - var browserPreference: String { + var useSystemBrowser: Bool { get { - guard let preference = UserDefaults.standard.string(forKey: Key.browserPreference) else { - return Browser.inApp.browserID - } - return preference + return UserDefaults.standard.bool(forKey: Key.useSystemBrowser) } set { - UserDefaults.standard.setValue(newValue, forKey: Key.browserPreference) - NotificationCenter.default.post(name: .browserPreferenceDidChange, object: nil) + UserDefaults.standard.setValue(newValue, forKey: Key.useSystemBrowser) } } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 47131eefb..cba86084f 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -250,11 +250,11 @@ class WebViewController: UIViewController { func openInAppBrowser() { guard let url = article?.preferredURL else { return } - if AppDefaults.shared.browserPreference == Browser.inApp.browserID { + if AppDefaults.shared.useSystemBrowser { + UIApplication.shared.open(url, options: [:]) + } else { let vc = SFSafariViewController(url: url) present(vc, animated: true) - } else { - UIApplication.shared.open(url, options: [:]) } } } @@ -348,11 +348,11 @@ extension WebViewController: WKNavigationDelegate { let components = URLComponents(url: url, resolvingAgainstBaseURL: false) if components?.scheme == "http" || components?.scheme == "https" { decisionHandler(.cancel) - if AppDefaults.shared.browserPreference == Browser.inApp.browserID { + if AppDefaults.shared.useSystemBrowser { + UIApplication.shared.open(url, options: [:]) + } else { let vc = SFSafariViewController(url: url) self.present(vc, animated: true, completion: nil) - } else { - UIApplication.shared.open(url, options: [:]) } } else if components?.scheme == "mailto" { diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index a69d23fe6..770bc84bd 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -899,9 +899,8 @@ private extension MasterTimelineViewController { func openInBrowserAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? { guard let _ = article.preferredURL else { return nil } - var displayName: String - AppDefaults.shared.browserPreference == Browser.inApp.displayName ? (displayName = Browser.inApp.displayName) : (displayName = Browser.defaultBrowser.displayName) - let title = NSLocalizedString("Open in \(displayName)", comment: "Open in Browser") + + let title = NSLocalizedString("Open in Browser", comment: "Open in Browser") let action = UIAlertAction(title: title, style: .default) { [weak self] action in self?.coordinator.showBrowserForArticle(article) completion(true) diff --git a/iOS/Settings/Browser.swift b/iOS/Settings/Browser.swift deleted file mode 100644 index 20bd99c72..000000000 --- a/iOS/Settings/Browser.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// Browser.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 23/08/2021. -// Copyright © 2021 Ranchero Software. All rights reserved. -// - -import Foundation - - - -/// The `Browser` enum contains browsers supported by NetNewsWire. -public enum Browser: CaseIterable { - - case inApp - case defaultBrowser - - var browserID: String { - switch self { - case .inApp: - return "browser.inapp" - case .defaultBrowser: - return "browser.safari" - } - } - - var displayName: String { - switch self { - case .inApp: - return NSLocalizedString("NetNewsWire", comment: "In-app") - case .defaultBrowser: - return NSLocalizedString("Default Browser", comment: "Default") - } - } -} - -// MARK: - Browser Notifications -public extension Notification.Name { - static let browserPreferenceDidChange = Notification.Name("browserPreferenceDidChange") -} diff --git a/iOS/Settings/BrowserCell.swift b/iOS/Settings/BrowserCell.swift deleted file mode 100644 index 3ad57a9f6..000000000 --- a/iOS/Settings/BrowserCell.swift +++ /dev/null @@ -1,47 +0,0 @@ -// -// BrowserCell.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 22/8/21. -// Copyright © 2021 Ranchero Software. All rights reserved. -// - -import UIKit - -class BrowserCell: VibrantTableViewCell { - - @IBOutlet weak var browserName: UILabel! - private var browser: Browser! - - override func updateVibrancy(animated: Bool) { - super.updateVibrancy(animated: animated) - updateLabelVibrancy(browserName, color: labelColor, animated: animated) - } - - override func awakeFromNib() { - super.awakeFromNib() - // Initialization code - } - - func configure(with browser: Browser) { - browserName.text = browser.displayName - self.browser = browser - - if AppDefaults.shared.browserPreference == browser.browserID { - accessoryType = .checkmark - } else { - accessoryType = .none - } - } - - func updateBrowserSelection() { - AppDefaults.shared.browserPreference = self.browser.browserID - } - - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - - // Configure the view for the selected state - } - -} diff --git a/iOS/Settings/BrowserConfigurationViewController.swift b/iOS/Settings/BrowserConfigurationViewController.swift deleted file mode 100644 index 21fce3901..000000000 --- a/iOS/Settings/BrowserConfigurationViewController.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// BrowserConfigurationViewController.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 22/8/21. -// Copyright © 2021 Ranchero Software. All rights reserved. -// - -import UIKit - -class BrowserConfigurationViewController: UITableViewController { - - override func viewDidLoad() { - super.viewDidLoad() - title = NSLocalizedString("Browser Selection", comment: "Browser") - NotificationCenter.default.addObserver(self, selector: #selector(browserPreferenceDidChange), name: .browserPreferenceDidChange, object: nil) - } - - // MARK: - Table view data source - - override func numberOfSections(in tableView: UITableView) -> Int { - return 2 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if indexPath.section == 0 { - let cell = tableView.dequeueReusableCell(withIdentifier: "BrowserCell", for: indexPath) as! BrowserCell - cell.configure(with: Browser.allCases[0]) - return cell - } - - if indexPath.section == 1 { - let cell = tableView.dequeueReusableCell(withIdentifier: "BrowserCell", for: indexPath) as! BrowserCell - cell.configure(with: Browser.allCases[1]) - return cell - } - - return tableView.dequeueReusableCell(withIdentifier: "BrowserCell") ?? UITableViewCell() - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - guard let cell = tableView.cellForRow(at: indexPath) as? BrowserCell else { - return - } - cell.updateBrowserSelection() - navigationController?.popViewController(animated: true) - } - - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - if section == 0 { - return NSLocalizedString("Open Links In", comment: "Open Links") - } - return nil - } - - override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { - if section == 0 { - return NSLocalizedString("Links will open in NetNewsWire.", comment: "NNW browser footer.") - } - - if section == 1 { - return NSLocalizedString("Links will open in the default system browser configured in Settings.", comment: "Default browser footer.") - } - - return nil - } - - // MARK: - Notifications - @objc func browserPreferenceDidChange() { - tableView.reloadData() - } - -} diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 9d7372ede..33501761a 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -297,35 +297,38 @@ - + - + - - - - - - + + + + + + + - @@ -343,7 +346,7 @@ - + @@ -361,7 +364,7 @@ - + @@ -550,11 +553,11 @@ - +