Add support for the Mac Catalyst build

The Mac Catalyst Version doesn't allow the import of the api, so
compiler flags now check if the import isn't allowed and then remove
all references to Apple Translate.
This commit is contained in:
Paul Schuetz 2024-05-09 23:13:41 +02:00
parent 7f3bfb6a7b
commit bb81bc43e4
No known key found for this signature in database
GPG key ID: 4FDE1FB89050039E
3 changed files with 43 additions and 16 deletions

View file

@ -53,12 +53,8 @@ struct TranslationSettingsView: View {
private var translationSelector: some View {
@Bindable var preferences = preferences
Picker("settings.translation.preferred-translation-type", selection: $preferences.preferredTranslationType) {
ForEach(TranslationType.allCases, id: \.self) { type in
if #available(iOS 17.4, *) {
Text(type.description).tag(type)
} else if type != .useApple {
Text(type.description).tag(type)
}
ForEach(allTTCases, id: \.self) { type in
Text(type.description).tag(type)
}
}
#if !os(visionOS)
@ -66,6 +62,23 @@ struct TranslationSettingsView: View {
#endif
}
var allTTCases: [TranslationType] {
TranslationType.allCases.filter { type in
if type != .useApple {
return true
}
#if canImport(_Translation_SwiftUI)
if #available(iOS 17.4, *) {
return true
} else {
return false
}
#else
return false
#endif
}
}
@ViewBuilder
private var deepLPicker: some View {
@Bindable var preferences = preferences

View file

@ -64,6 +64,10 @@ import SwiftUI
@AppStorage("sidebar_expanded") public var isSidebarExpanded: Bool = false
init() {
prepareTranslationType()
}
private func prepareTranslationType() {
let sharedDefault = UserDefaults.standard
if let alwaysUseDeepl = (sharedDefault.object(forKey: "always_use_deepl") as? Bool) {
if alwaysUseDeepl {
@ -71,10 +75,16 @@ import SwiftUI
}
sharedDefault.removeObject(forKey: "always_use_deepl")
}
#if canImport(_Translation_SwiftUI)
if #unavailable(iOS 17.4),
preferredTranslationType == .useApple {
preferredTranslationType = .useServerIfPossible
}
#else
if preferredTranslationType == .useApple {
preferredTranslationType = .useServerIfPossible
}
#endif
}
}

View file

@ -5,8 +5,20 @@ import Foundation
import Models
import Network
import SwiftUI
#if canImport(_Translation_SwiftUI)
import Translation
extension View {
func addTranslateView(isPresented: Binding<Bool>, text: String) -> some View {
if #available(iOS 17.4, *) {
return self.translationPresentation(isPresented: isPresented, text: text)
} else {
return self
}
}
}
#endif
@MainActor
public struct StatusRowView: View {
@Environment(\.openWindow) private var openWindow
@ -220,7 +232,9 @@ public struct StatusRowView: View {
StatusDataControllerProvider.shared.dataController(for: viewModel.finalStatus,
client: viewModel.client)
)
#if canImport(_Translation_SwiftUI)
.addTranslateView(isPresented: $viewModel.showAppleTranslation, text: viewModel.finalStatus.content.asRawText)
#endif
}
@ViewBuilder
@ -357,13 +371,3 @@ public struct StatusRowView: View {
.withPreviewsEnv()
.environment(Theme.shared)
}
extension View {
func addTranslateView(isPresented: Binding<Bool>, text: String) -> some View {
if #available(iOS 17.4, *) {
return self.translationPresentation(isPresented: isPresented, text: text)
} else {
return self
}
}
}