mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-02 21:39:36 +00:00
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:
parent
7f3bfb6a7b
commit
bb81bc43e4
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue