Merge pull request #3733 from omnivore-app/feat/ios-open-in-browser

Add open in system browser iOS setting
This commit is contained in:
Jackson Harper 2024-03-27 11:14:45 +08:00 committed by GitHub
commit f0699765a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 77 additions and 19 deletions

File diff suppressed because one or more lines are too long

View file

@ -23,6 +23,8 @@ struct LibraryTabView: View {
@State var isEditMode: EditMode = .inactive
@State var showExpandedAudioPlayer = false
@State var presentPushContainer = true
@State var pushLinkRequest: String?
private let syncManager = LibrarySyncManager()
@ -77,13 +79,34 @@ struct LibraryTabView: View {
var body: some View {
VStack(spacing: 0) {
WindowLink(level: .alert, transition: .move(edge: .bottom), isPresented: $showOperationToast) {
OperationToast(operationMessage: $operationMessage,
OperationToast(operationMessage: $operationMessage,
showOperationToast: $showOperationToast,
operationStatus: $operationStatus)
} label: {
EmptyView()
}.buttonStyle(.plain)
if let pushLinkRequest = pushLinkRequest {
PresentationLink(
transition: PresentationLinkTransition.slide(
options: PresentationLinkTransition.SlideTransitionOptions(
edge: .trailing,
options: PresentationLinkTransition.Options(
modalPresentationCapturesStatusBarAppearance: true,
preferredPresentationBackgroundColor: ThemeManager.currentBgColor
))),
isPresented: $presentPushContainer,
destination: {
WebReaderLoadingContainer(requestID: pushLinkRequest)
.background(ThemeManager.currentBgColor)
.environmentObject(dataService)
.environmentObject(audioController)
}, label: {
EmptyView()
}
)
}
TabView(selection: $selectedTab) {
if !hideFollowingTab {
NavigationView {
@ -145,15 +168,9 @@ struct LibraryTabView: View {
}
}
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushLibraryItem"))) { notification in
guard let folder = notification.userInfo?["libraryItemId"] as? String else { return }
guard let libraryItemId = notification.userInfo?["libraryItemId"] as? String else { return }
if folder == "following" {
selectedTab = "following"
followingViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
} else {
selectedTab = "inbox"
inboxViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
}
pushLinkRequest = libraryItemId
presentPushContainer = true
}
.onOpenURL { url in
inboxViewModel.linkRequest = nil

View file

@ -136,6 +136,9 @@ struct ProfileView: View {
#if os(iOS)
Section {
NavigationLink(destination: ReaderSettingsView()) {
Text(LocalText.readerSettingsGeneric)
}
NavigationLink(destination: PushNotificationSettingsView()) {
Text(LocalText.pushNotificationsGeneric)
}

View file

@ -0,0 +1,27 @@
import Services
import SwiftUI
import Views
import Utils
enum OpenLinkIn: String {
case insideApp
case systemBrowser
}
struct ReaderSettingsView: View {
@Environment(\.dismiss) private var dismiss
@AppStorage(UserDefaultKey.openExternalLinksIn.rawValue) var openExternalLinksIn = OpenLinkIn.insideApp.rawValue
var body: some View {
List {
Picker(selection: $openExternalLinksIn, content: {
Text("Inside app").tag(OpenLinkIn.insideApp.rawValue)
Text("Use system browser").tag(OpenLinkIn.systemBrowser.rawValue)
}, label: { Text("Open links:") })
.pickerStyle(MenuPickerStyle())
}.navigationTitle(LocalText.readerSettingsGeneric)
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("ScrollToTop"))) { _ in
dismiss()
}
}
}

View file

@ -414,16 +414,24 @@ struct WebReaderContainerView: View {
titleVisibility: .visible) {
Button(action: {
if let linkToOpen = linkToOpen {
safariWebLink = SafariWebLink(id: UUID(), url: linkToOpen)
if UserDefaults.standard.string(forKey: UserDefaultKey.openExternalLinksIn.rawValue) == OpenLinkIn.systemBrowser.rawValue, UIApplication.shared.canOpenURL(linkToOpen) {
UIApplication.shared.open(linkToOpen)
} else {
safariWebLink = SafariWebLink(id: UUID(), url: linkToOpen)
}
}
}, label: { Text(LocalText.genericOpen) })
Button(action: {
#if os(iOS)
UIPasteboard.general.string = item.unwrappedPageURLString
#else
// Pasteboard.general.string = item.unwrappedPageURLString TODO: fix for mac
#endif
Snackbar.show(message: "Link copied", dismissAfter: 2000)
if let linkToOpen = linkToOpen?.absoluteString {
#if os(iOS)
UIPasteboard.general.string = linkToOpen
#else
// Pasteboard.general.string = item.unwrappedPageURLString TODO: fix for mac
#endif
Snackbar.show(message: "Link copied", dismissAfter: 2000)
} else {
Snackbar.show(message: "Error copying link", dismissAfter: 2000)
}
}, label: { Text(LocalText.readerCopyLink) })
Button(action: {
if let linkToOpen = linkToOpen {

View file

@ -35,6 +35,7 @@ public enum UserDefaultKey: String {
case hideFeatureSection
case hideSystemLabels
case justifyText
case openExternalLinksIn
case prefersHideStatusBarInReader
case visibleShareExtensionTab
}

View file

@ -201,4 +201,5 @@ public enum LocalText {
public static let dismissButton = localText(key: "dismissButton")
public static let errorNetwork = localText(key: "errorNetwork")
public static let documentationGeneric = localText(key: "documentationGeneric")
public static let readerSettingsGeneric = localText(key: "readerSettingsGeneric")
}

View file

@ -171,7 +171,7 @@
"labelsGeneric" = "Labels";
"emailsGeneric" = "Emails";
"subscriptionsGeneric" = "Subscriptions";
"textToSpeechGeneric" = "Text to Speech";
"textToSpeechGeneric" = "Text to speech";
"privacyPolicyGeneric" = "Privacy Policy";
"termsAndConditionsGeneric" = "Terms and Conditions";
"feedbackGeneric" = "Feedback";
@ -196,7 +196,8 @@
"clubsGeneric" = "Clubs";
"filterGeneric" = "Filters";
"errorGeneric" = "Something went wrong, please try again.";
"pushNotificationsGeneric" = "Push Notifications";
"readerSettingsGeneric" = "Reader settings";
"pushNotificationsGeneric" = "Push notifications";
"dismissButton" = "Dismiss";
"errorNetwork" = "We are having trouble connecting to the internet.";
"documentationGeneric" = "Documentation";