diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index c736e1da9..5da94ccf4 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 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 */; }; @@ -74,7 +75,6 @@ 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 */; }; - 1760888126D1F04500E853E9 /* BrowserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1760888026D1F04500E853E9 /* BrowserManager.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 */; }; @@ -1558,7 +1558,6 @@ 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 = ""; }; - 1760888026D1F04500E853E9 /* BrowserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserManager.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 = ""; }; @@ -2802,7 +2801,6 @@ 519ED47924482AEB007F8E94 /* EnableExtensionPointViewController.swift */, 519ED455244828C3007F8E94 /* AddExtensionPointViewController.swift */, DFC05D2126D3E0770047E788 /* Browser.swift */, - 1760888026D1F04500E853E9 /* BrowserManager.swift */, 175EBD7326D2405A009B5B23 /* BrowserConfigurationViewController.swift */, 175EBD7526D240D8009B5B23 /* BrowserCell.swift */, 516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */, @@ -4894,6 +4892,7 @@ 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 */, @@ -5616,7 +5615,6 @@ 516AE9E02372269A007DEEAA /* IconImage.swift in Sources */, 519ED456244828C3007F8E94 /* AddExtensionPointViewController.swift in Sources */, 51C45268226508F600C03939 /* MasterFeedUnreadCountView.swift in Sources */, - 1760888126D1F04500E853E9 /* BrowserManager.swift in Sources */, D3A39865246505DF00F9A366 /* FindInArticleActivity.swift in Sources */, 5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */, 51C4529F22650A1900C03939 /* AuthorAvatarDownloader.swift in Sources */, diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index c70c478d5..eff58dcd2 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -123,12 +123,13 @@ final class AppDefaults { var browserPreference: String { get { guard let preference = UserDefaults.standard.string(forKey: Key.browserPreference) else { - return "browser.inapp" + return Browser.inApp.browserID } return preference } set { UserDefaults.standard.setValue(newValue, forKey: Key.browserPreference) + NotificationCenter.default.post(name: .browserPreferenceDidChange, object: nil) } } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 922a095b1..47131eefb 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 BrowserManager.shared.currentBrowser() == .inApp { + if AppDefaults.shared.browserPreference == Browser.inApp.browserID { let vc = SFSafariViewController(url: url) present(vc, animated: true) } else { - BrowserManager.shared.openURL(urlString: url.absoluteString) + UIApplication.shared.open(url, options: [:]) } } } @@ -348,10 +348,11 @@ extension WebViewController: WKNavigationDelegate { let components = URLComponents(url: url, resolvingAgainstBaseURL: false) if components?.scheme == "http" || components?.scheme == "https" { decisionHandler(.cancel) - if BrowserManager.shared.currentBrowser() == .inApp { - openURL(url) + if AppDefaults.shared.browserPreference == Browser.inApp.browserID { + let vc = SFSafariViewController(url: url) + self.present(vc, animated: true, completion: nil) } else { - BrowserManager.shared.openURL(urlString: url.absoluteString) + UIApplication.shared.open(url, options: [:]) } } else if components?.scheme == "mailto" { diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index b2e5f8413..a69d23fe6 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -900,7 +900,7 @@ private extension MasterTimelineViewController { func openInBrowserAlertAction(_ article: Article, completion: @escaping (Bool) -> Void) -> UIAlertAction? { guard let _ = article.preferredURL else { return nil } var displayName: String - BrowserManager.shared.currentBrowser() == .inApp ? (displayName = Browser.safari.displayName) : (displayName = BrowserManager.shared.currentBrowser().displayName) + 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 action = UIAlertAction(title: title, style: .default) { [weak self] action in self?.coordinator.showBrowserForArticle(article) diff --git a/iOS/Resources/Assets.xcassets/browsers/Contents.json b/iOS/Resources/Assets.xcassets/browsers/Contents.json deleted file mode 100644 index 73c00596a..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/Contents.json deleted file mode 100644 index 6ff7b5b01..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "icons8-brave-web-browser.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/icons8-brave-web-browser.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/icons8-brave-web-browser.pdf deleted file mode 100644 index d20ed9cb4..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.brave.imageset/icons8-brave-web-browser.pdf and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/Contents.json deleted file mode 100644 index 1d65e4191..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "icons8-chrome.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/icons8-chrome.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/icons8-chrome.pdf deleted file mode 100644 index 7babc85aa..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.chrome.imageset/icons8-chrome.pdf and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/Contents.json deleted file mode 100644 index 648ebe289..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "icons8-microsoft-edge.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/icons8-microsoft-edge.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/icons8-microsoft-edge.pdf deleted file mode 100644 index 1682aa600..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.edge.imageset/icons8-microsoft-edge.pdf and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/Contents.json deleted file mode 100644 index a0c2f2974..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/Contents.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "images" : [ - { - "filename" : "firefox-logo-glyph.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true, - "template-rendering-intent" : "template" - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/firefox-logo-glyph.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/firefox-logo-glyph.pdf deleted file mode 100644 index e680ac94a..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.firefox.imageset/firefox-logo-glyph.pdf and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-120px-40pt@3x.png b/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-120px-40pt@3x.png deleted file mode 100644 index 724a12a23..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-120px-40pt@3x.png and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-40px-40pt@1x.png b/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-40px-40pt@1x.png deleted file mode 100644 index b5b617036..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-40px-40pt@1x.png and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-80px-40pt@2x.png b/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-80px-40pt@2x.png deleted file mode 100644 index 47a4b083a..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/AppIcon-80px-40pt@2x.png and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/Contents.json deleted file mode 100644 index 4b418c667..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.inapp.imageset/Contents.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "images" : [ - { - "filename" : "AppIcon-40px-40pt@1x.png", - "idiom" : "universal", - "scale" : "1x" - }, - { - "filename" : "AppIcon-80px-40pt@2x.png", - "idiom" : "universal", - "scale" : "2x" - }, - { - "filename" : "AppIcon-120px-40pt@3x.png", - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/1password.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/1password.pdf deleted file mode 100644 index 418cb7453..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/1password.pdf and /dev/null differ diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/Contents.json deleted file mode 100644 index cea03a9f2..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.onepassword.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "1password.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/Contents.json deleted file mode 100644 index 020c9a183..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "icons8-opera.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/icons8-opera.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/icons8-opera.pdf deleted file mode 100644 index b7fe0d20e..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.opera.imageset/icons8-opera.pdf +++ /dev/null @@ -1,72 +0,0 @@ -%PDF-1.4 -% -4 0 obj -<< /Length 5 0 R - /Filter /FlateDecode ->> -stream -xmTA1 @]Km"@=?PRLr($$So.= H[;龁5DžKU̮ݣLj6xPrsVmDs2p6ڔd$:H}@kB/CtD =^M!,BCYu$ɠhWG -ͩ3ph%E7FOu/,gLH\= -+Ofa]1MI:ؑ"9tq4 MOT7V1/VFMRT"%UU깉hjx[%X6ۺOt8!Sa_Yʺuϒ͙JH'Ka/3 AaӗV{uq8 -cSd#$vX0Ex3>c"r؟R-WnRBuYy:{+Yt)؏7zn)fI/+ (ÞxL|"D -endstream -endobj -5 0 obj - 656 -endobj -3 0 obj -<< - /ExtGState << - /a0 << /CA 1 /ca 1 >> - >> ->> -endobj -2 0 obj -<< /Type /Page % 1 - /Parent 1 0 R - /MediaBox [ 0 0 50 50 ] - /Contents 4 0 R - /Group << - /Type /Group - /S /Transparency - /I true - /CS /DeviceRGB - >> - /Resources 3 0 R ->> -endobj -1 0 obj -<< /Type /Pages - /Kids [ 2 0 R ] - /Count 1 ->> -endobj -6 0 obj -<< /Producer (cairo 1.16.0 (https://cairographics.org)) - /CreationDate (D:20210822124817Z) ->> -endobj -7 0 obj -<< /Type /Catalog - /Pages 1 0 R ->> -endobj -xref -0 8 -0000000000 65535 f -0000001058 00000 n -0000000842 00000 n -0000000770 00000 n -0000000015 00000 n -0000000748 00000 n -0000001123 00000 n -0000001234 00000 n -trailer -<< /Size 8 - /Root 7 0 R - /Info 6 0 R ->> -startxref -1286 -%%EOF diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/Contents.json b/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/Contents.json deleted file mode 100644 index 422493fef..000000000 --- a/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/Contents.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "images" : [ - { - "filename" : "safari.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true - } -} diff --git a/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/safari.pdf b/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/safari.pdf deleted file mode 100644 index a0f7f8e03..000000000 Binary files a/iOS/Resources/Assets.xcassets/browsers/browser.safari.imageset/safari.pdf and /dev/null differ diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 607d382e2..7bc4b4037 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -1229,12 +1229,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { func showBrowserForArticle(_ article: Article) { guard let url = article.preferredURL else { return } - if BrowserManager.shared.currentBrowser() == .inApp { - UIApplication.shared.open(url, options: [:]) - } else { - BrowserManager.shared.openURL(urlString: url.absoluteString) - } - + UIApplication.shared.open(url, options: [:]) } func showBrowserForCurrentArticle() { diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 902faaddb..39a26aa2d 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -77,7 +77,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { appDelegate.prepareAccountsForForeground() coordinator.configurePanelMode(for: window!.frame.size) coordinator.resetFocus() - BrowserManager.shared.configureAvailableBrowsers() } func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? { diff --git a/iOS/Settings/Browser.swift b/iOS/Settings/Browser.swift index 98d333c50..20bd99c72 100644 --- a/iOS/Settings/Browser.swift +++ b/iOS/Settings/Browser.swift @@ -11,82 +11,17 @@ import Foundation /// The `Browser` enum contains browsers supported by NetNewsWire. -/// -/// To support a new browser, create a case, configure it, add its URL scheme -/// to `LSApplicationQueriesSchemes` in `Info.plist`, and add an -/// appropriate image to the Asset catalog. The browserID should be used as the -/// image filename. public enum Browser: CaseIterable { case inApp - case safari - case brave - case chrome - case edge - case firefox - case opera - case onePassword - - var urlScheme: String { - switch self { - case .inApp: - return "" // not required, will open in SFSafariViewController - case .safari: - return "" // not required, will use openURL - case .brave: - return "brave://open-url?url=" - case .chrome: - return "googlechrome://" - case .edge: - return "microsoft-edge-https://" - case .firefox: - return "firefox://open-url?url=" - case .opera: - return "touch-http://" - case .onePassword: - return "ophttps://" - } - } - - var canOpenURL: Bool { - switch self { - case .inApp: - return true - case .safari: - return UIApplication.shared.canOpenURL(URL(string: "https://apple.com")!) - case .brave: - return UIApplication.shared.canOpenURL(URL(string: Browser.brave.urlScheme)!) - case .chrome: - return UIApplication.shared.canOpenURL(URL(string: Browser.chrome.urlScheme)!) - case .edge: - return UIApplication.shared.canOpenURL(URL(string: Browser.edge.urlScheme)!) - case .firefox: - return UIApplication.shared.canOpenURL(URL(string: Browser.firefox.urlScheme)!) - case .opera: - return UIApplication.shared.canOpenURL(URL(string: Browser.opera.urlScheme)!) - case .onePassword: - return UIApplication.shared.canOpenURL(URL(string: Browser.onePassword.urlScheme)!) - } - } + case defaultBrowser var browserID: String { switch self { case .inApp: return "browser.inapp" - case .safari: + case .defaultBrowser: return "browser.safari" - case .brave: - return "browser.brave" - case .chrome: - return "browser.chrome" - case .edge: - return "browser.edge" - case .firefox: - return "browser.firefox" - case .opera: - return "browser.opera" - case .onePassword: - return "browser.onepassword" } } @@ -94,20 +29,13 @@ public enum Browser: CaseIterable { switch self { case .inApp: return NSLocalizedString("NetNewsWire", comment: "In-app") - case .safari: + case .defaultBrowser: return NSLocalizedString("Default Browser", comment: "Default") - case .brave: - return NSLocalizedString("Brave", comment: "Brave") - case .chrome: - return NSLocalizedString("Chrome", comment: "Chrome") - case .edge: - return NSLocalizedString("Edge", comment: "Edge") - case .firefox: - return NSLocalizedString("Firefox", comment: "Firefox") - case .opera: - return NSLocalizedString("Opera", comment: "Opera") - case .onePassword: - return NSLocalizedString("1Password", comment: "1Password") } } } + +// 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 index 4f8459c5a..3ad57a9f6 100644 --- a/iOS/Settings/BrowserCell.swift +++ b/iOS/Settings/BrowserCell.swift @@ -27,7 +27,7 @@ class BrowserCell: VibrantTableViewCell { browserName.text = browser.displayName self.browser = browser - if BrowserManager.shared.currentBrowser().browserID == browser.browserID { + if AppDefaults.shared.browserPreference == browser.browserID { accessoryType = .checkmark } else { accessoryType = .none @@ -35,7 +35,7 @@ class BrowserCell: VibrantTableViewCell { } func updateBrowserSelection() { - BrowserManager.shared.currentBrowserPreference = self.browser.browserID + AppDefaults.shared.browserPreference = self.browser.browserID } override func setSelected(_ selected: Bool, animated: Bool) { diff --git a/iOS/Settings/BrowserConfigurationViewController.swift b/iOS/Settings/BrowserConfigurationViewController.swift index fb8cabd4c..21fce3901 100644 --- a/iOS/Settings/BrowserConfigurationViewController.swift +++ b/iOS/Settings/BrowserConfigurationViewController.swift @@ -9,8 +9,6 @@ import UIKit class BrowserConfigurationViewController: UITableViewController { - - let browserManager = BrowserManager.shared override func viewDidLoad() { super.viewDidLoad() @@ -21,31 +19,23 @@ class BrowserConfigurationViewController: UITableViewController { // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { - return 3 + return 2 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if section == 0 { return 1 } - if section == 1 { return 1 } - return browserManager.availableBrowsers.count - 2 + 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: browserManager.availableBrowsers[indexPath.row]) + 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: browserManager.availableBrowsers[indexPath.row + 1]) - return cell - } - - if indexPath.section == 2 { - let cell = tableView.dequeueReusableCell(withIdentifier: "BrowserCell", for: indexPath) as! BrowserCell - cell.configure(with: browserManager.availableBrowsers[indexPath.row + 2]) + cell.configure(with: Browser.allCases[1]) return cell } @@ -77,7 +67,6 @@ class BrowserConfigurationViewController: UITableViewController { return NSLocalizedString("Links will open in the default system browser configured in Settings.", comment: "Default browser footer.") } - return nil } diff --git a/iOS/Settings/BrowserManager.swift b/iOS/Settings/BrowserManager.swift deleted file mode 100644 index f13946c8a..000000000 --- a/iOS/Settings/BrowserManager.swift +++ /dev/null @@ -1,97 +0,0 @@ -// -// BrowserManager.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 22/8/21. -// Copyright © 2021 Ranchero Software. All rights reserved. -// - -import Foundation -import UIKit - -extension Notification.Name { - static let browserPreferenceDidChange = Notification.Name("browserPreferenceDidChange") -} - -public final class BrowserManager { - - /// The available browsers supported by the application. If `enableExtendedBrowserPreferences` - /// is `false`, this will only contain in-app and system browser options. - public private(set) var availableBrowsers = [Browser]() - - /// The currently selected `BrowserID`. The default is `Browser.inApp`. - public var currentBrowserPreference: String { - get { - return AppDefaults.shared.browserPreference - } - set { - AppDefaults.shared.browserPreference = newValue - NotificationCenter.default.post(name: .browserPreferenceDidChange, object: nil) - } - } - - /// When `true`, the user can select a specific browser instead of the system default browser. - private var enableExtendedBrowserPreferences = false - - public static let shared = BrowserManager() - - private init() { - configureAvailableBrowsers() - } - - /// Refreshes the available browsers. This is called when BrowserManager is inited, - /// and when the application returns to the foreground. - func configureAvailableBrowsers() { - if !enableExtendedBrowserPreferences { - availableBrowsers = [.inApp, .safari] - } else { - availableBrowsers = Browser.allCases.filter({ $0.canOpenURL == true }) - } - resetBrowserPreferenceIfRequired() - } - - /// Opens the URL in the specified browser. - /// - Parameter urlString: the url to open. - func openURL(urlString: String) { - guard let url = URL(string: urlString) else { - return - } - if currentBrowser() == .safari { - UIApplication.shared.open(url, options: [:], completionHandler: nil) - return - } - - switch currentBrowser() { - case .edge, .chrome, .opera, .onePassword: - var string = urlString - string = string.replacingOccurrences(of: "https://", with: "") - string = string.replacingOccurrences(of: "http://", with: "") - guard let browserURL = URL(string: currentBrowser().urlScheme + string) else { - return - } - UIApplication.shared.open(browserURL, options: [:], completionHandler: nil) - default: - guard let browserURL = URL(string: currentBrowser().urlScheme + urlString) else { - return - } - UIApplication.shared.open(browserURL, options: [:], completionHandler: nil) - } - } - - /// If the user has uninstalled a browser this will reset the browser back to the in-app default. - private func resetBrowserPreferenceIfRequired() { - if availableBrowsers.filter({ $0.browserID == currentBrowserPreference }).count == 0 { - currentBrowserPreference = Browser.inApp.browserID - } - } - - /// The currently selected browser. - /// - Returns: `Browser` - func currentBrowser() -> Browser { - guard let browser = Browser.allCases.filter({ $0.browserID == currentBrowserPreference }).first else { - resetBrowserPreferenceIfRequired() - return currentBrowser() - } - return browser - } -} diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 06b125e1b..9d7372ede 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -418,7 +418,7 @@