From 6784ed7fdfcef988215c8dcac8d3baf2a1311285 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 15 Apr 2024 09:34:44 -0400 Subject: [PATCH] Remove in-app Safari settings on macOS Closes #469 --- .../TuskerPreferences/Keys/BehaviorKeys.swift | 14 ++++++++++++++ .../Legacy/PreferenceStore+Migrate.swift | 12 ++++++++---- .../TuskerPreferences/PreferenceStore.swift | 2 +- Tusker/Screens/Preferences/BehaviorPrefsView.swift | 14 ++++++++------ Tusker/TuskerNavigationDelegate.swift | 5 +++-- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/Packages/TuskerPreferences/Sources/TuskerPreferences/Keys/BehaviorKeys.swift b/Packages/TuskerPreferences/Sources/TuskerPreferences/Keys/BehaviorKeys.swift index 1e66c23eab..17ac09fa89 100644 --- a/Packages/TuskerPreferences/Sources/TuskerPreferences/Keys/BehaviorKeys.swift +++ b/Packages/TuskerPreferences/Sources/TuskerPreferences/Keys/BehaviorKeys.swift @@ -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 + } +} diff --git a/Packages/TuskerPreferences/Sources/TuskerPreferences/Legacy/PreferenceStore+Migrate.swift b/Packages/TuskerPreferences/Sources/TuskerPreferences/Legacy/PreferenceStore+Migrate.swift index 43d87a7146..a5ea15bd18 100644 --- a/Packages/TuskerPreferences/Sources/TuskerPreferences/Legacy/PreferenceStore+Migrate.swift +++ b/Packages/TuskerPreferences/Sources/TuskerPreferences/Legacy/PreferenceStore+Migrate.swift @@ -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,7 +63,13 @@ 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) } diff --git a/Packages/TuskerPreferences/Sources/TuskerPreferences/PreferenceStore.swift b/Packages/TuskerPreferences/Sources/TuskerPreferences/PreferenceStore.swift index 3b7a42b4cf..fd74cc3a47 100644 --- a/Packages/TuskerPreferences/Sources/TuskerPreferences/PreferenceStore.swift +++ b/Packages/TuskerPreferences/Sources/TuskerPreferences/PreferenceStore.swift @@ -44,7 +44,7 @@ public final class PreferenceStore: ObservableObject, Codable { // MARK: Behavior @Preference public var openLinksInApps - @Preference public var useInAppSafari + @Preference public var useInAppSafari @Preference public var inAppSafariAutomaticReaderMode @Preference public var expandAllContentWarnings @Preference public var collapseLongPosts diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 57b6c98f3d..0d29bbfa27 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -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() diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 8432cbe110..7837b1f7fd 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -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