Add preferences for using in-app vs out of app Safari and using Reader Mode for in-app

This commit is contained in:
Shadowfacts 2019-11-14 19:53:27 -05:00
parent 5076aec54e
commit c85836eda6
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 26 additions and 2 deletions

View File

@ -46,6 +46,8 @@ class Preferences: Codable, ObservableObject {
self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts)
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
self.inAppSafariAutomaticReaderMode = try container.decode(Bool.self, forKey: .inAppSafariAutomaticReaderMode)
self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts)
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
@ -65,6 +67,8 @@ class Preferences: Codable, ObservableObject {
try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts)
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
try container.encode(openLinksInApps, forKey: .openLinksInApps)
try container.encode(useInAppSafari, forKey: .useInAppSafari)
try container.encode(inAppSafariAutomaticReaderMode, forKey: .inAppSafariAutomaticReaderMode)
try container.encode(showFavoriteAndReblogCounts, forKey: .showFavoriteAndReblogCounts)
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
@ -83,6 +87,8 @@ class Preferences: Codable, ObservableObject {
@Published var automaticallySaveDrafts = true
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
@Published var openLinksInApps = true
@Published var useInAppSafari = true
@Published var inAppSafariAutomaticReaderMode = false
// MARK: - Digital Wellness
@Published var showFavoriteAndReblogCounts = true
@ -101,6 +107,8 @@ class Preferences: Codable, ObservableObject {
case automaticallySaveDrafts
case contentWarningCopyMode
case openLinksInApps
case useInAppSafari
case inAppSafariAutomaticReaderMode
case showFavoriteAndReblogCounts
case defaultNotificationsType

View File

@ -47,6 +47,12 @@ struct BehaviorPrefsView: View {
Toggle(isOn: $preferences.openLinksInApps) {
Text("Open Links in Apps")
}
Toggle(isOn: $preferences.useInAppSafari) {
Text("Use In-App Safari")
}
Toggle(isOn: $preferences.inAppSafariAutomaticReaderMode) {
Text("Always Use Reader Mode in In-App Safari")
}.disabled(!preferences.useInAppSafari)
}
}
}

View File

@ -74,14 +74,24 @@ extension TuskerNavigationDelegate where Self: UIViewController {
}
func selected(url: URL) {
func openSafari() {
if Preferences.shared.useInAppSafari {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode
present(SFSafariViewController(url: url, configuration: config), animated: true)
} else {
UIApplication.shared.open(url, options: [:])
}
}
if (Preferences.shared.openLinksInApps) {
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in
if (!success) {
self.present(SFSafariViewController(url: url), animated: true)
openSafari()
}
}
} else {
present(SFSafariViewController(url: url), animated: true)
openSafari()
}
}