Remove in-app Safari settings on macOS

Closes #469
This commit is contained in:
Shadowfacts 2024-04-15 09:34:44 -04:00
parent 66f0ba6891
commit 6784ed7fdf
5 changed files with 34 additions and 13 deletions

View File

@ -24,3 +24,17 @@ struct ConfirmReblogKey: PreferenceKey {
struct TimelineSyncModeKey: PreferenceKey {
static var defaultValue: TimelineSyncMode { .icloud }
}
struct InAppSafariKey: PreferenceKey {
static var defaultValue: Bool {
#if targetEnvironment(macCatalyst) || os(visionOS)
false
#else
if ProcessInfo.processInfo.isiOSAppOnMac {
false
} else {
true
}
#endif
}
}

View File

@ -10,7 +10,7 @@ import UIKit
extension PreferenceStore {
func migrate(from legacy: LegacyPreferences) {
let migrations: [any MigrationProtocol] = [
var migrations: [any MigrationProtocol] = [
Migration(from: \.theme.theme, to: \.$theme),
Migration(from: \.pureBlackDarkMode, to: \.$pureBlackDarkMode),
Migration(from: \.accentColor, to: \.$accentColor),
@ -41,8 +41,6 @@ extension PreferenceStore {
Migration(from: \.attachmentAltBadgeInverted, to: \.$attachmentAltBadgeInverted),
Migration(from: \.openLinksInApps, to: \.$openLinksInApps),
Migration(from: \.useInAppSafari, to: \.$useInAppSafari),
Migration(from: \.inAppSafariAutomaticReaderMode, to: \.$inAppSafariAutomaticReaderMode),
Migration(from: \.expandAllContentWarnings, to: \.$expandAllContentWarnings),
Migration(from: \.collapseLongPosts, to: \.$collapseLongPosts),
Migration(from: \.oppositeCollapseKeywords, to: \.$oppositeCollapseKeywords),
@ -65,6 +63,12 @@ extension PreferenceStore {
Migration(from: \.hasShownLocalTimelineDescription, to: \.$hasShownLocalTimelineDescription),
Migration(from: \.hasShownFederatedTimelineDescription, to: \.$hasShownFederatedTimelineDescription),
]
#if !targetEnvironment(macCatalyst) && !os(visionOS)
migrations.append(contentsOf: [
Migration(from: \.useInAppSafari, to: \.$useInAppSafari),
Migration(from: \.inAppSafariAutomaticReaderMode, to: \.$inAppSafariAutomaticReaderMode),
] as [any MigrationProtocol])
#endif
for migration in migrations {
migration.migrate(from: legacy, to: self)

View File

@ -44,7 +44,7 @@ public final class PreferenceStore: ObservableObject, Codable {
// MARK: Behavior
@Preference<TrueKey> public var openLinksInApps
@Preference<TrueKey> public var useInAppSafari
@Preference<InAppSafariKey> public var useInAppSafari
@Preference<FalseKey> public var inAppSafariAutomaticReaderMode
@Preference<FalseKey> public var expandAllContentWarnings
@Preference<TrueKey> public var collapseLongPosts

View File

@ -58,13 +58,15 @@ struct BehaviorPrefsView: View {
Toggle(isOn: $preferences.openLinksInApps) {
Text("Open Links in Apps")
}
#if !os(visionOS)
Toggle(isOn: $preferences.useInAppSafari) {
Text("Use In-App Safari")
#if !targetEnvironment(macCatalyst) && !os(visionOS)
if !ProcessInfo.processInfo.isiOSAppOnMac {
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)
}
Toggle(isOn: $preferences.inAppSafariAutomaticReaderMode) {
Text("Always Use Reader Mode in In-App Safari")
}.disabled(!preferences.useInAppSafari)
#endif
}
.appGroupedListRowBackground()

View File

@ -47,10 +47,11 @@ extension TuskerNavigationDelegate {
func selected(url: URL, allowResolveStatuses: Bool = true, allowUniversalLinks: Bool = true) {
func openSafari() {
#if os(visionOS)
#if targetEnvironment(macCatalyst) || os(visionOS)
UIApplication.shared.open(url)
#else
if Preferences.shared.useInAppSafari,
if !ProcessInfo.processInfo.isiOSAppOnMac,
Preferences.shared.useInAppSafari,
url.scheme == "https" || url.scheme == "http" {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode