mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Reduces Browsers to in-app and system default
This commit is contained in:
parent
7a726e6d8a
commit
3bc18e2891
@ -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 = "<group>"; };
|
||||
175EBD7326D2405A009B5B23 /* BrowserConfigurationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserConfigurationViewController.swift; sourceTree = "<group>"; };
|
||||
175EBD7526D240D8009B5B23 /* BrowserCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserCell.swift; sourceTree = "<group>"; };
|
||||
1760888026D1F04500E853E9 /* BrowserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserManager.swift; sourceTree = "<group>"; };
|
||||
176813B62564B9F800D98635 /* WidgetData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetData.swift; sourceTree = "<group>"; };
|
||||
176813BD2564BA2800D98635 /* WidgetDataEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDataEncoder.swift; sourceTree = "<group>"; };
|
||||
176813C92564BA5400D98635 /* WidgetDataDecoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetDataDecoder.swift; sourceTree = "<group>"; };
|
||||
@ -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 */,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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" {
|
||||
|
@ -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)
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icons8-brave-web-browser.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icons8-chrome.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icons8-microsoft-edge.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
Binary file not shown.
@ -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"
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.6 KiB |
@ -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
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "1password.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icons8-opera.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
%PDF-1.4
|
||||
%µí®û
|
||||
4 0 obj
|
||||
<< /Length 5 0 R
|
||||
/Filter /FlateDecode
|
||||
>>
|
||||
stream
|
||||
xœmTAŽ1»ûþ@]K–méû„"@·—=´ý?PRžLr($æŒ$S©Ÿo‚¯Ùëã«ü.=ýù¬ßôúù·¨µè<0B>¾ªH[<i•Þzà/·K}à8v›Œ¢¬v%²nÞ–J!0?¡ÁÓ<C381><C393>s´X“‘}Ìz§3ûד„‚’»
m‘†¯:+$ùØ} “q*<2A>*Ú,XFv^é,™mh[s<>ÏÍo4&(
|
||||
¨¨"V.¨Ò46ÀöYú,;ßàRo®^½éÞUн—lWÆNÕÜŒ‘«Éò*³>ùã;«é¾<C3A9>5‡Ç…KU”•ÉÌ®£Ž‘Ý£®LjÁÀÝ6ßx‹Pr™sVëmƒ®Ds„›2¼p<C2BC>Òú®6Ú”Åd–$Ÿ:ôHì¢}¨À²@kBѳ/âˆÄC‰t<E280B0>D´ÑÌ =^ÚM!°,ËþBÈȬCãYòu§±$É hWó–G
|
||||
Í©Ž3ÌÚp¶”hâ¹%EÊ7íFOu/,gLHÙ”\=
|
||||
+O”ÄÔfØa]1ÒMÿI:Ø‘<C398>Þ"9¬ƒtqÙÔ4 M»šOT»üóî7³í§ÙV1/‰àà<C3A0>VFMRöçT"%ŽÓUÊUè깉hjx[%í½ÓX6ÅÓÛºOtë‘8§! ÁŽSa_Y—ΫÙʺu½‚Ï’Í™ÐJH'ÎK´œa/Ô3É
A“Úa¼ï†Ó—áV{½u®q¢’ð8ù
|
||||
ÇcÀSédí#¯¡ã$vX0–„Ex3çò‘>ÿc"Çær„ØŸ¾R-WãnåRB•uƒ£YyÜ:—‚™”Ž{+Y—øtêÆ)Ø<>7zn)fI‡€/•õ+Íî(Þ¾x÷ÌLô³|”ò"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
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "safari.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true
|
||||
}
|
||||
}
|
Binary file not shown.
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func showBrowserForCurrentArticle() {
|
||||
|
@ -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? {
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -10,8 +10,6 @@ import UIKit
|
||||
|
||||
class BrowserConfigurationViewController: UITableViewController {
|
||||
|
||||
let browserManager = BrowserManager.shared
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
title = NSLocalizedString("Browser Selection", comment: "Browser")
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -418,7 +418,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="NetNewsWire Help" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="uGk-2d-oFc">
|
||||
<rect key="frame" x="20" y="0.0" width="334" height="44"/>
|
||||
<rect key="frame" x="15" y="0.0" width="351" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
@ -435,7 +435,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Website" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="6G3-yV-Eyh">
|
||||
<rect key="frame" x="20" y="0.0" width="334" height="44"/>
|
||||
<rect key="frame" x="15" y="0.0" width="351" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
@ -452,7 +452,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Release Notes" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="NeD-y8-KrM">
|
||||
<rect key="frame" x="20" y="0.0" width="334" height="44"/>
|
||||
<rect key="frame" x="15" y="0.0" width="351" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
@ -550,11 +550,11 @@
|
||||
<rect key="frame" x="20" y="1367.5" width="374" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="jK8-tv-hBD" id="I7Q-GQ-u8Y">
|
||||
<rect key="frame" x="0.0" y="0.0" width="356.5" height="44"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="355" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="About NetNewsWire" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="76A-Ng-kfs">
|
||||
<rect key="frame" x="15" y="0.0" width="333.5" height="44"/>
|
||||
<rect key="frame" x="15" y="0.0" width="332" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
@ -1012,7 +1012,7 @@
|
||||
<rect key="frame" x="20" y="49.5" width="374" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ec8-pH-8WV" id="WwZ-5H-APR">
|
||||
<rect key="frame" x="0.0" y="0.0" width="333.5" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="330" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="browser.name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6GG-kE-13U">
|
||||
|
@ -28,7 +28,7 @@ class SettingsViewController: UITableViewController {
|
||||
var scrollToArticlesSection = false
|
||||
weak var presentingParentController: UIViewController?
|
||||
|
||||
let browserManger = BrowserManager.shared
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
// This hack mostly works around a bug in static tables with dynamic type. See: https://spin.atomicobject.com/2018/10/15/dynamic-type-static-uitableview/
|
||||
@ -82,7 +82,12 @@ class SettingsViewController: UITableViewController {
|
||||
}
|
||||
|
||||
colorPaletteDetailLabel.text = String(describing: AppDefaults.userInterfaceColorPalette)
|
||||
currentBrowserLabel.text = browserManger.currentBrowser().displayName
|
||||
if AppDefaults.shared.browserPreference == Browser.inApp.browserID {
|
||||
currentBrowserLabel.text = Browser.inApp.displayName
|
||||
} else {
|
||||
currentBrowserLabel.text = Browser.defaultBrowser.displayName
|
||||
}
|
||||
|
||||
|
||||
let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0))
|
||||
buildLabel.font = UIFont.systemFont(ofSize: 11.0)
|
||||
|
Loading…
Reference in New Issue
Block a user