π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Strip dead platform conditionals from the iOS app
Manav Rathi71d65758bb96
diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swiftindex 0d293251c2..4a708c2c35 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatView.swift@@ -71,7 +71,6 @@ struct ChatView: View {} else {mainContent(showsMenuButton: true).overlay(alignment: .leading) {- #if os(iOS)Color.clear.frame(width: 24).contentShape(Rectangle())@@ -86,14 +85,12 @@ struct ChatView: View {viewState.isDrawerOpen = true})- #endif}if viewState.isDrawerOpen {Color.black.opacity(0.25).ignoresSafeArea().onTapGesture { viewState.isDrawerOpen = false }- #if os(iOS).gesture(DragGesture(minimumDistance: 20).onEnded { value in@@ -103,7 +100,6 @@ struct ChatView: View {viewState.isDrawerOpen = false})- #endif}drawerView(isPinned: false)@@ -232,9 +228,7 @@ struct ChatView: View {viewState.pendingWhatsNew = WhatsNewService.shared.pendingWhatsNew()}}- #if os(iOS).ignoresSafeArea(.keyboard)- #endif}@ViewBuilderdiff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swiftindex 783704f1e9..c20b2a3978 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/ChatViewModel.swift@@ -74,7 +74,7 @@ final class ChatViewModel: ObservableObject {@Published var attachmentDownloads: [AttachmentDownloadItem] = []@Published var currentSessionMissingAttachments: [AttachmentDownloadItem] = []@Published var generationErrorMessage: String?- @Published var voiceInputState: VoiceInputState = .initial+ @Published var voiceInputState: VoiceInputState = .idle@Published var draftCursorMoveToken = UUID()private let provider: InferenceRsProvider@@ -426,9 +426,7 @@ final class ChatViewModel: ObservableObject {voiceTransientErrorTask?.cancel()voiceTransientErrorTask = nilvoiceTranscriber.cancel()- if voiceInputState != .unsupported {- voiceInputState = .idle- }+ voiceInputState = .idle}private func setVoiceInputState(_ state: VoiceInputState) {diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/LaTeXView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/LaTeXView.swiftindex ae1302977e..e07593c1e5 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/LaTeXView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/LaTeXView.swift@@ -40,7 +40,6 @@ struct InlineLaTeXView: View {}}-#if os(iOS)private struct MathLabelView: UIViewRepresentable {let latex: Stringlet rawLatex: String@@ -127,98 +126,3 @@ private final class MathLabelContainerView: UIView {}}-#elseif os(macOS)-private struct MathLabelView: NSViewRepresentable {- let latex: String- let rawLatex: String- let textColor: PlatformColor- let fontSize: CGFloat- let isInline: Bool-- func makeNSView(context: Context) -> MathLabelContainerView {- MathLabelContainerView()- }-- func updateNSView(_ view: MathLabelContainerView, context: Context) {- view.update(latex: latex, rawLatex: rawLatex, textColor: textColor, fontSize: fontSize, isInline: isInline)- }-}--private final class MathLabelContainerView: NSView {- private let mathLabel = MTMathUILabel()- private let fallbackLabel = NSTextField(labelWithString: "")- private var currentInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)-- override init(frame frameRect: NSRect) {- super.init(frame: frameRect)- fallbackLabel.lineBreakMode = .byWordWrapping- fallbackLabel.maximumNumberOfLines = 0- addSubview(mathLabel)- addSubview(fallbackLabel)- }-- required init?(coder: NSCoder) {- fatalError("init(coder:) has not been implemented")- }-- override var intrinsicContentSize: NSSize {- if !mathLabel.isHidden {- let childSize = mathLabel.intrinsicContentSize- return NSSize(- width: childSize.width + currentInsets.left + currentInsets.right,- height: childSize.height + currentInsets.top + currentInsets.bottom- )- }- let maxWidth = fallbackLabel.preferredMaxLayoutWidth > 0- ? fallbackLabel.preferredMaxLayoutWidth- : CGFloat.greatestFiniteMagnitude- let labelSize = fallbackLabel.sizeThatFits(NSSize(width: maxWidth, height: .greatestFiniteMagnitude))- return NSSize(- width: labelSize.width + currentInsets.left + currentInsets.right,- height: labelSize.height + currentInsets.top + currentInsets.bottom- )- }-- override func layout() {- super.layout()- let insetRect = NSRect(- x: currentInsets.left,- y: currentInsets.bottom,- width: max(0, bounds.width - currentInsets.left - currentInsets.right),- height: max(0, bounds.height - currentInsets.top - currentInsets.bottom)- )- mathLabel.frame = insetRect- fallbackLabel.frame = insetRect- let maxWidth = max(0, insetRect.width)- if fallbackLabel.preferredMaxLayoutWidth != maxWidth {- fallbackLabel.preferredMaxLayoutWidth = maxWidth- invalidateIntrinsicContentSize()- }- }-- func update(latex: String, rawLatex: String, textColor: PlatformColor, fontSize: CGFloat, isInline: Bool) {- currentInsets = isInline- ? NSEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)- : NSEdgeInsets(top: 4, left: 6, bottom: 4, right: 6)-- let nsInsets = isInline ? NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) : currentInsets-- mathLabel.fontSize = fontSize- mathLabel.textColor = textColor- mathLabel.contentInsets = nsInsets- mathLabel.displayErrorInline = false- mathLabel.latex = latex-- fallbackLabel.font = NSFont.systemFont(ofSize: fontSize)- fallbackLabel.textColor = textColor- fallbackLabel.stringValue = rawLatex-- let trimmedLatex = latex.trimmingCharacters(in: .whitespacesAndNewlines)- let shouldFallback = trimmedLatex.isEmpty || mathLabel.error != nil- mathLabel.isHidden = shouldFallback- fallbackLabel.isHidden = !shouldFallback-- invalidateIntrinsicContentSize()- }-}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swiftindex edd4307966..06aa7327be 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageInputView.swift@@ -1,9 +1,7 @@import SwiftUIimport PhotosUIimport UniformTypeIdentifiers-#if os(iOS)import UIKit-#endifstruct MessageInputView: View {@Binding var text: String@@ -115,7 +113,7 @@ struct MessageInputView: View {Image(systemName: "exclamationmark.circle").font(.system(size: 12, weight: .semibold)).foregroundStyle(EnsuColor.stopButton)- case .idle, .unsupported:+ case .idle:EmptyView()}Text(voiceStatus)@@ -138,8 +136,7 @@ struct MessageInputView: View {.lineLimit(1...5).font(EnsuTypography.message).foregroundStyle(EnsuColor.textPrimary)- .platformTextFieldStyle()- .platformTextInputAutocapitalization(.sentences)+ .textInputAutocapitalization(.sentences).padding(.vertical, textFieldPadding).onSubmit {if canSend {@@ -154,7 +151,6 @@ struct MessageInputView: View {inputResetToken = UUID()}}- #if os(iOS).background(CursorEndSynchronizer(token: moveCursorToEndToken,@@ -162,7 +158,6 @@ struct MessageInputView: View {).frame(width: 0, height: 0))- #endifif editingMessage == nil {let canUseAttachment = !isGenerating &&@@ -183,10 +178,6 @@ struct MessageInputView: View {hapticTap()}})- #if os(macOS)- .buttonStyle(.plain)- .frame(width: 32, height: 32, alignment: .center)- #endif.onChange(of: selectedPhotoItem) { newItem inguard let newItem else { return }guard !isImageAttachmentLimitReached else {@@ -205,7 +196,7 @@ struct MessageInputView: View {}}- if voiceInputState != .unsupported && editingMessage == nil {+ if editingMessage == nil {let isVoiceBusy = voiceInputState.isTranscriptionBusylet canUseVoice = voiceInputState.isRecording ||(!isGenerating && !isDownloading && !isAttachmentDownloadBlocked && !isVoiceBusy)@@ -242,9 +233,6 @@ struct MessageInputView: View {}}.disabled(!canUseVoice)- #if os(macOS)- .buttonStyle(.plain)- #endif}Button {@@ -290,7 +278,6 @@ struct MessageInputView: View {.clipShape(RoundedRectangle(cornerRadius: EnsuCornerRadius.input + 4, style: .continuous)).shadow(color: Color.black.opacity(0.12), radius: 10, x: 0, y: 6).overlay(alignment: .topTrailing) {- #if os(iOS)if isFocused {Button {hapticTap()@@ -308,7 +295,6 @@ struct MessageInputView: View {}.offset(y: -(32 + EnsuSpacing.sm))}- #endif}.padding(.horizontal, EnsuSpacing.pageHorizontal).padding(.bottom, bottomPadding)@@ -326,20 +312,14 @@ struct MessageInputView: View {}private var attachmentIconSize: CGFloat {- #if os(macOS)- return 18- #elsereturn 16- #endif}- #if os(iOS)private var keyboardDismissIconName: String {UIImage(systemName: "keyboard.chevron.compact.down") != nil? "keyboard.chevron.compact.down": "chevron.down"}- #endifprivate var attachmentFlowLayout: some View {FlowLayout(spacing: EnsuSpacing.sm) {@@ -438,7 +418,6 @@ struct InputBarHeightKey: PreferenceKey {}}-#if os(iOS)private struct CursorEndSynchronizer: UIViewRepresentable {let token: UUIDlet text: String@@ -523,4 +502,3 @@ private extension UIView {return inputs}}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swiftindex 0e77cc08ff..70eba5e7ba 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageList/MessageListComponents.swift@@ -1,13 +1,7 @@import SwiftUIimport Markdown-#if os(macOS)-import QuickLookUI-#elseimport QuickLook-#endif-#if os(iOS)import UIKit-#endifstruct BottomOffsetKey: PreferenceKey {static var defaultValue: CGFloat = 0@@ -31,7 +25,6 @@ struct AttachmentPreviewItem: Identifiable {var id: String { url.path }}-#if os(iOS)struct ImageAttachmentPreview: View {let url: URLlet accessibilityLabel: String@@ -149,22 +142,6 @@ struct QuickLookPreview: UIViewControllerRepresentable {}}}-#elseif os(macOS)-struct QuickLookPreview: NSViewRepresentable {- let url: URL-- func makeNSView(context: Context) -> QLPreviewView {- let view = QLPreviewView(frame: .zero, style: .normal)!- view.autostarts = true- view.previewItem = url as NSURL- return view- }-- func updateNSView(_ nsView: QLPreviewView, context: Context) {- nsView.previewItem = url as NSURL- }-}-#endifstruct UserMessageBubbleView: View {let message: RenderedChatMessage@@ -229,7 +206,6 @@ struct UserMessageBubbleView: View {.padding(EnsuSpacing.md).background(bubbleFill).clipShape(bubbleShape)- #if os(iOS).contextMenu {Button("Edit") {hapticTap()@@ -240,7 +216,6 @@ struct UserMessageBubbleView: View {onCopy()}}- #endifHStack(spacing: EnsuSpacing.sm) {Spacer()@@ -283,7 +258,6 @@ struct AssistantMessageBubbleView: View {}.padding(.vertical, EnsuSpacing.md).padding(.horizontal, EnsuSpacing.sm)- #if os(iOS).contextMenu {if !message.isSynthetic {Button("Copy") {@@ -298,7 +272,6 @@ struct AssistantMessageBubbleView: View {}}}- #endifif showsMetadata && !message.isSynthetic {HStack(spacing: EnsuSpacing.sm) {diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageListView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageListView.swiftindex a3ca6476ef..6ca0769c0b 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/MessageListView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/MessageListView.swift@@ -84,7 +84,6 @@ struct MessageListView: View {QuickLookPreview(url: item.url)}- #if os(iOS)content.fullScreenCover(item: $imagePreviewItem) { item inImageAttachmentPreview(@@ -93,9 +92,6 @@ struct MessageListView: View {onDismiss: { imagePreviewItem = nil })}- #else- content- #endif}private var currentScrollChange: ScrollChange {@@ -320,7 +316,6 @@ struct MessageListView: View {}private func performStreamingStartHapticIfNeeded() {- #if os(iOS)guard isGenerating,!didPerformStreamingStartHaptic,hasVisibleStreamingContent(streamingResponse) else {@@ -328,19 +323,16 @@ struct MessageListView: View {}hapticTap()didPerformStreamingStartHaptic = true- #endif}private func openAttachment(_ attachment: ChatAttachment) {guard let url = attachment.url else { return }guard FileManager.default.fileExists(atPath: url.path) else { return }- #if os(iOS)if attachment.kind == .image {imagePreviewItem = AttachmentPreviewItem(url: url, name: attachment.name)return}- #endiflet tempDir = FileManager.default.temporaryDirectorylet fileName = sanitizedAttachmentName(attachment)diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/SessionDrawerView.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/SessionDrawerView.swiftindex 73f2cded48..0562911fcf 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/SessionDrawerView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/SessionDrawerView.swift@@ -70,9 +70,8 @@ struct SessionDrawerView: View {TextField("Search chats", text: $searchQuery).font(EnsuTypography.body)- .platformTextInputAutocapitalization(.never)+ .textInputAutocapitalization(.never).autocorrectionDisabled()- .platformTextFieldStyle().foregroundStyle(EnsuColor.textPrimary).frame(maxWidth: .infinity, alignment: .leading)}diff --git a/mobile/native/apple/apps/ensu/Ensu/Chat/VoiceTranscriptionService.swift b/mobile/native/apple/apps/ensu/Ensu/Chat/VoiceTranscriptionService.swiftindex b4ea443f4e..15735ed42b 100644--- a/mobile/native/apple/apps/ensu/Ensu/Chat/VoiceTranscriptionService.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Chat/VoiceTranscriptionService.swift@@ -1,24 +1,13 @@import Foundation-#if os(iOS)import AVFoundation-#endifenum VoiceInputState: Equatable {case idle- case unsupportedcase recordingcase downloading(percent: Int?)case transcribingcase error(String)- static var initial: VoiceInputState {- #if os(iOS)- return .idle- #else- return .unsupported- #endif- }-var isRecording: Bool {if case .recording = self {return true@@ -30,7 +19,7 @@ enum VoiceInputState: Equatable {switch self {case .recording, .downloading, .transcribing:return true- case .idle, .unsupported, .error:+ case .idle, .error:return false}}@@ -39,7 +28,7 @@ enum VoiceInputState: Equatable {switch self {case .downloading, .transcribing:return true- case .idle, .unsupported, .recording, .error:+ case .idle, .recording, .error:return false}}@@ -48,7 +37,7 @@ enum VoiceInputState: Equatable {switch self {case .recording, .transcribing:return true- case .idle, .unsupported, .downloading, .error:+ case .idle, .downloading, .error:return false}}@@ -64,14 +53,14 @@ enum VoiceInputState: Equatable {switch self {case let .error(message):return message == "No speech detected." || message == "No speech captured."- case .idle, .unsupported, .recording, .downloading, .transcribing:+ case .idle, .recording, .downloading, .transcribing:return false}}var statusText: String? {switch self {- case .idle, .unsupported:+ case .idle:return nilcase .recording:return "Listening..."@@ -99,9 +88,7 @@ final class VoiceTranscriptionService {private var activeVoiceTaskId = UUID()private var activeDownloadId: UUID?- #if os(iOS)private let recorder = PcmAudioRecorder()- #endifinit(transcriber: Transcriber) {self.transcriber = transcriber@@ -111,7 +98,6 @@ final class VoiceTranscriptionService {onState: @escaping StateHandler,shouldStartRecording: @escaping @MainActor @Sendable () -> Bool = { true }) {- #if os(iOS)guard !recorder.isRecording else { return }let session = AVAudioSession.sharedInstance()@@ -137,16 +123,12 @@ final class VoiceTranscriptionService {@unknown default:onState(.error("Microphone permission is required for voice input."))}- #else- onState(.unsupported)- #endif}func stopAndTranscribe(onState: @escaping StateHandler,onTranscript: @escaping TranscriptHandler) {- #if os(iOS)guard recorder.isRecording else { return }onState(.transcribing)let recording = recorder.stop()@@ -216,9 +198,6 @@ final class VoiceTranscriptionService {}}}- #else- onState(.unsupported)- #endif}func cancel() {@@ -228,14 +207,11 @@ final class VoiceTranscriptionService {preloadTask = nilactiveVoiceTaskId = UUID()activeDownloadId = nil- #if os(iOS)if recorder.isRecording {_ = recorder.stop()}- #endif}- #if os(iOS)private func prepareModelAndStartRecording(onState: @escaping StateHandler,shouldStartRecording: @escaping @MainActor @Sendable () -> Bool@@ -373,10 +349,8 @@ final class VoiceTranscriptionService {private func minimumRecordingBytes(sampleRate: UInt32) -> Int {Int(sampleRate) / 4 * 2}- #endif}-#if os(iOS)private struct VoiceRecording {let sampleRate: UInt32let pcm: Data@@ -463,4 +437,3 @@ private final class TranscriptionProgressCallback: TranscriptionModelEventCallbahandler(event)}}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/Components/EnsuComponents.swift b/mobile/native/apple/apps/ensu/Ensu/Components/EnsuComponents.swiftindex cf3446049e..6fc8892d6a 100644--- a/mobile/native/apple/apps/ensu/Ensu/Components/EnsuComponents.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Components/EnsuComponents.swift@@ -1,9 +1,5 @@import SwiftUI-#if os(iOS)import UIKit-#elseif os(macOS)-import AppKit-#endifstruct PrimaryButton: View {let text: String@@ -47,16 +43,15 @@ private struct PrimaryButtonStyle: ButtonStyle {struct StyledTextField: View {let hint: String@Binding var text: String- var keyboardType: PlatformKeyboardType = .default+ var keyboardType: UIKeyboardType = .defaultvar body: some View {TextField(hint, text: $text).font(EnsuTypography.body).foregroundStyle(EnsuColor.textPrimary)- .platformTextFieldStyle()- .platformTextInputAutocapitalization(.never)+ .textInputAutocapitalization(.never).autocorrectionDisabled()- .platformKeyboardType(keyboardType)+ .keyboardType(keyboardType).padding(.horizontal, EnsuSpacing.inputHorizontal).padding(.vertical, EnsuSpacing.inputVertical).background(EnsuColor.fillFaint)@@ -272,7 +267,6 @@ struct ImageAttachmentThumbnail: View {return nil}- #if os(iOS)guard let image = UIImage(contentsOfFile: url.path) else {return nil}@@ -281,18 +275,6 @@ struct ImageAttachmentThumbnail: View {pixelWidth: image.size.width,pixelHeight: image.size.height)- #elseif os(macOS)- guard let image = NSImage(contentsOf: url) else {- return nil- }- return PlatformImageContent(- image: Image(nsImage: image),- pixelWidth: image.size.width,- pixelHeight: image.size.height- )- #else- return nil- #endif}}diff --git a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/EnsuTheme.swift b/mobile/native/apple/apps/ensu/Ensu/DesignSystem/EnsuTheme.swiftindex 81ab92defa..c4f647a432 100644--- a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/EnsuTheme.swift+++ b/mobile/native/apple/apps/ensu/Ensu/DesignSystem/EnsuTheme.swift@@ -1,11 +1,6 @@import SwiftUI-#if canImport(UIKit)import UIKittypealias PlatformColor = UIColor-#elseif canImport(AppKit)-import AppKit-typealias PlatformColor = NSColor-#endifenum EnsuColor {static let backgroundBase = Color(PlatformColor.dynamic(light: "#F8F5F0", dark: "#141414"))@@ -129,15 +124,8 @@ extension PlatformColor {}static func dynamic(light: String, dark: String) -> PlatformColor {- #if canImport(UIKit)return PlatformColor { trait intrait.userInterfaceStyle == .dark ? PlatformColor(hex: dark) : PlatformColor(hex: light)}- #else- return PlatformColor(name: nil) { appearance in- let isDark = appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua- return PlatformColor(hex: isDark ? dark : light)- }- #endif}}diff --git a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/KeyboardObserver.swift b/mobile/native/apple/apps/ensu/Ensu/DesignSystem/KeyboardObserver.swiftindex b4ce0f3319..79e14636e0 100644--- a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/KeyboardObserver.swift+++ b/mobile/native/apple/apps/ensu/Ensu/DesignSystem/KeyboardObserver.swift@@ -1,13 +1,10 @@import SwiftUI-#if canImport(UIKit)import UIKit-#endiffinal class KeyboardObserver: ObservableObject {@Published var height: CGFloat = 0@Published var isVisible: Bool = false- #if canImport(UIKit)private var showObserver: NSObjectProtocol?private var hideObserver: NSObjectProtocol?@@ -38,15 +35,10 @@ final class KeyboardObserver: ObservableObject {if let showObserver { NotificationCenter.default.removeObserver(showObserver) }if let hideObserver { NotificationCenter.default.removeObserver(hideObserver) }}- #else- init() {}- #endif}extension View {func hideKeyboard() {- #if canImport(UIKit)UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)- #endif}}diff --git a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/Platform.swift b/mobile/native/apple/apps/ensu/Ensu/DesignSystem/Platform.swiftdeleted file mode 100644index 21e5d0ab86..0000000000--- a/mobile/native/apple/apps/ensu/Ensu/DesignSystem/Platform.swift+++ /dev/null@@ -1,101 +0,0 @@-import SwiftUI--#if canImport(UIKit)-import UIKit--typealias PlatformKeyboardType = UIKeyboardType-typealias PlatformTextContentType = UITextContentType-typealias PlatformTextInputAutocapitalization = TextInputAutocapitalization-#else--enum PlatformKeyboardType {- case `default`- case emailAddress- case numberPad- case decimalPad- case URL-}--enum PlatformTextContentType {- case emailAddress- case password-}--enum PlatformTextInputAutocapitalization {- case never- case words- case sentences- case characters-}-#endif--extension View {- @ViewBuilder- func platformKeyboardType(_ type: PlatformKeyboardType) -> some View {- #if canImport(UIKit)- self.keyboardType(type)- #else- self- #endif- }-- @ViewBuilder- func platformTextContentType(_ type: PlatformTextContentType?) -> some View {- #if canImport(UIKit)- if let type {- self.textContentType(type)- } else {- self- }- #else- self- #endif- }-- @ViewBuilder- func platformTextInputAutocapitalization(_ style: PlatformTextInputAutocapitalization) -> some View {- #if canImport(UIKit)- self.textInputAutocapitalization(style)- #else- self- #endif- }-- @ViewBuilder- func platformTextFieldStyle() -> some View {- #if os(macOS)- self.textFieldStyle(.plain)- #else- self- #endif- }-- @ViewBuilder- func platformNavigationBarStyle() -> some View {- #if os(iOS)- self.navigationBarTitleDisplayMode(.inline)- .toolbarBackground(EnsuColor.backgroundBase, for: .navigationBar)- .toolbarBackground(.visible, for: .navigationBar)- #else- self- #endif- }-- @ViewBuilder- func platformBackButtonHidden(_ hidden: Bool) -> some View {- #if os(iOS)- self.navigationBarBackButtonHidden(hidden)- #else- self- #endif- }-- @ViewBuilder- func platformFullScreenCover<Content: View>(isPresented: Binding<Bool>, onDismiss: (() -> Void)? = nil, @ViewBuilder content: @escaping () -> Content) -> some View {- #if os(iOS)- self.fullScreenCover(isPresented: isPresented, onDismiss: onDismiss, content: content)- #else- self.sheet(isPresented: isPresented, onDismiss: onDismiss, content: content)- #endif- }-}diff --git a/mobile/native/apple/apps/ensu/Ensu/EnsuApp.swift b/mobile/native/apple/apps/ensu/Ensu/EnsuApp.swiftindex 0fd27caeb0..690a6f4505 100644--- a/mobile/native/apple/apps/ensu/Ensu/EnsuApp.swift+++ b/mobile/native/apple/apps/ensu/Ensu/EnsuApp.swift@@ -2,9 +2,7 @@ import SwiftUI@mainstruct EnsuApp: App {- #if os(iOS)@UIApplicationDelegateAdaptor(EnsuAppDelegate.self) private var appDelegate- #endifinit() {EnsuLogging.shared.start()diff --git a/mobile/native/apple/apps/ensu/Ensu/EnsuAppDelegate.swift b/mobile/native/apple/apps/ensu/Ensu/EnsuAppDelegate.swiftindex 80dd3941dc..10d3e6a0e5 100644--- a/mobile/native/apple/apps/ensu/Ensu/EnsuAppDelegate.swift+++ b/mobile/native/apple/apps/ensu/Ensu/EnsuAppDelegate.swift@@ -1,4 +1,3 @@-#if os(iOS)import UIKitfinal class EnsuAppDelegate: NSObject, UIApplicationDelegate {@@ -10,4 +9,3 @@ final class EnsuAppDelegate: NSObject, UIApplicationDelegate {ModelDownloadManager.shared.setBackgroundCompletionHandler(completionHandler)}}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/ModelSettings/ModelSettingsView.swift b/mobile/native/apple/apps/ensu/Ensu/ModelSettings/ModelSettingsView.swiftindex c6a29bd50e..5b2eeb62bb 100644--- a/mobile/native/apple/apps/ensu/Ensu/ModelSettings/ModelSettingsView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/ModelSettings/ModelSettingsView.swift@@ -1,4 +1,5 @@import SwiftUI+import UIKitstruct ModelSettingsView: View {@Environment(\.dismiss) private var dismiss@@ -24,14 +25,8 @@ struct ModelSettingsView: View {private let modelChoices: [ModelChoice] = {let defaults = EnsuRustDefaults.shared- #if os(iOS)let defaultModel = defaults.mobileDefaultModellet presets = defaults.mobileModelPresets- #else- let isHighRAM = ProcessInfo.processInfo.physicalMemory >= ModelSettingsStore.highRAMThresholdBytes- let defaultModel = isHighRAM ? defaults.desktopDefaultModel : defaults.mobileDefaultModel- let presets = isHighRAM ? defaults.desktopModelPresets : defaults.mobileModelPresets- #endifreturn [ModelChoice(id: Self.defaultOptionId,@@ -64,9 +59,7 @@ struct ModelSettingsView: View {Group {if embeddedInNavigation {content- #if os(iOS).navigationBarTitleDisplayMode(.inline)- #endif.toolbar {ToolbarItem(placement: .principal) {Text("Model Settings")@@ -75,7 +68,6 @@ struct ModelSettingsView: View {}}} else {- #if os(iOS)NavigationStack {content.navigationBarTitleDisplayMode(.inline)@@ -90,9 +82,6 @@ struct ModelSettingsView: View {}}}- #else- content- #endif}}.onAppear {@@ -111,32 +100,6 @@ struct ModelSettingsView: View {.transition(.move(edge: .bottom).combined(with: .opacity))}}- #if os(macOS)- .safeAreaInset(edge: .top) {- if embeddedInNavigation {- EmptyView()- } else {- MacSheetHeader(- leading: {- EmptyView()- },- center: {- Text("Model Settings")- .font(EnsuTypography.large)- .foregroundStyle(EnsuColor.textPrimary)- },- trailing: {- Button("Done") {- dismiss()- }- .font(EnsuTypography.small)- .foregroundStyle(EnsuColor.textMuted)- .buttonStyle(.plain)- }- )- }- }- #endif}private var isStoredCustomModel: Bool {@@ -281,7 +244,7 @@ struct ModelSettingsView: View {hint: String,text: Binding<String>,error: String?,- keyboardType: PlatformKeyboardType+ keyboardType: UIKeyboardType) -> some View {VStack(alignment: .leading, spacing: 6) {Text(label)diff --git a/mobile/native/apple/apps/ensu/Ensu/Services/KeychainStore.swift b/mobile/native/apple/apps/ensu/Ensu/Services/KeychainStore.swiftindex d8deb855e2..969f758013 100644--- a/mobile/native/apple/apps/ensu/Ensu/Services/KeychainStore.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Services/KeychainStore.swift@@ -30,9 +30,7 @@ final class KeychainStore {// Insert.var insertQuery = queryinsertQuery[kSecValueData as String] = data- #if os(iOS)insertQuery[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly- #endiflet addStatus = SecItemAdd(insertQuery as CFDictionary, nil)if addStatus != errSecSuccess {throw KeychainStoreError.unexpectedStatus(addStatus)diff --git a/mobile/native/apple/apps/ensu/Ensu/Services/Logging/EnsuLogging.swift b/mobile/native/apple/apps/ensu/Ensu/Services/Logging/EnsuLogging.swiftindex d7627086b6..9fc57206b1 100644--- a/mobile/native/apple/apps/ensu/Ensu/Services/Logging/EnsuLogging.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Services/Logging/EnsuLogging.swift@@ -1,7 +1,5 @@import Foundation-#if os(iOS)import UIKit-#endif#if canImport(ZIPFoundation)import ZIPFoundation#endif@@ -259,11 +257,7 @@ final class EnsuLogging {}}- #if os(iOS)parts.append("device=\(UIDevice.current.model)")- #elseif os(macOS)- parts.append("device=Mac")- #endifparts.append("os=\(ProcessInfo.processInfo.operatingSystemVersionString)")return parts.joined(separator: " ")diff --git a/mobile/native/apple/apps/ensu/Ensu/Services/ModelDownloadManager.swift b/mobile/native/apple/apps/ensu/Ensu/Services/ModelDownloadManager.swiftindex fb2f59ec3e..06fa0019e8 100644--- a/mobile/native/apple/apps/ensu/Ensu/Services/ModelDownloadManager.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Services/ModelDownloadManager.swift@@ -38,9 +38,7 @@ final class ModelDownloadManager: NSObject {private lazy var session: URLSession = {let configuration: URLSessionConfigurationconfiguration = URLSessionConfiguration.background(withIdentifier: "io.ente.ensu.model-downloads")- #if os(iOS)configuration.sessionSendsLaunchEvents = true- #endifconfiguration.isDiscretionary = falseconfiguration.waitsForConnectivity = truereturn URLSession(configuration: configuration, delegate: self, delegateQueue: delegateQueue)diff --git a/mobile/native/apple/apps/ensu/Ensu/Services/ModelSettingsStore.swift b/mobile/native/apple/apps/ensu/Ensu/Services/ModelSettingsStore.swiftindex 6bd82b343b..59bfea2244 100644--- a/mobile/native/apple/apps/ensu/Ensu/Services/ModelSettingsStore.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Services/ModelSettingsStore.swift@@ -133,23 +133,11 @@ final class ModelSettingsStore: ObservableObject {}private static var platformDefaultModel: EnsuRustModelPreset {- #if os(iOS)EnsuRustDefaults.shared.mobileDefaultModel- #else- if ProcessInfo.processInfo.physicalMemory >= highRAMThresholdBytes {- return EnsuRustDefaults.shared.desktopDefaultModel- } else {- return EnsuRustDefaults.shared.mobileDefaultModel- }- #endif}private static var platformSystemPromptBody: String {- #if os(iOS)EnsuRustDefaults.shared.mobileSystemPromptBody- #else- EnsuRustDefaults.shared.desktopSystemPromptBody- #endif}private func persist() {diff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/LogsView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/LogsView.swiftindex 0c69ae642e..5dcf91ebfc 100644--- a/mobile/native/apple/apps/ensu/Ensu/Settings/LogsView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/LogsView.swift@@ -27,9 +27,7 @@ struct LogsView: View {content}.background(EnsuColor.backgroundBase)- #if os(iOS).navigationBarTitleDisplayMode(.inline)- #endif.toolbar {toolbarContent}@@ -39,9 +37,7 @@ struct LogsView: View {content}.background(EnsuColor.backgroundBase)- #if os(iOS).navigationBarTitleDisplayMode(.inline)- #endif.toolbar {toolbarContentToolbarItem(placement: .cancellationAction) {@@ -58,14 +54,12 @@ struct LogsView: View {.onChange(of: logStore.entries) { _ inrefreshEntries()}- #if os(iOS).sheet(item: $shareArchive) { archive inActivityView(activityItems: [archive.url])}.sheet(item: $exportArchive) { archive inExportDocumentPicker(urls: [archive.url])}- #endif.sheet(item: $selectedEntry) { entry inLogDetailView(entry: entry)}@@ -117,9 +111,8 @@ struct LogsView: View {private var searchField: some View {TextField("Search logs", text: $query).font(EnsuTypography.body)- .platformTextInputAutocapitalization(.never)+ .textInputAutocapitalization(.never).autocorrectionDisabled()- .platformTextFieldStyle().padding(.horizontal, EnsuSpacing.inputHorizontal).padding(.vertical, EnsuSpacing.inputVertical).background(EnsuColor.fillFaint)@@ -226,11 +219,7 @@ struct LogsView: View {private func shareTapped() {do {let archiveURL = try EnsuLogging.shared.createLogsArchive()- #if os(iOS)shareArchive = LogArchive(url: archiveURL)- #elseif os(macOS)- MacShareSheet(items: [archiveURL]).present()- #endif} catch {logger.error("Failed to create logs archive", error)}@@ -239,33 +228,12 @@ struct LogsView: View {private func exportTapped() {do {let archiveURL = try EnsuLogging.shared.createLogsArchive()- #if os(iOS)exportArchive = LogArchive(url: archiveURL)- #elseif os(macOS)- exportOnMac(url: archiveURL)- #endif} catch {logger.error("Failed to create logs archive", error)}}- #if os(macOS)- private func exportOnMac(url archiveURL: URL) {- let panel = NSSavePanel()- panel.nameFieldStringValue = archiveURL.lastPathComponent- panel.begin { response in- guard response == .OK, let dest = panel.url else { return }- do {- if FileManager.default.fileExists(atPath: dest.path) {- try FileManager.default.removeItem(at: dest)- }- try FileManager.default.copyItem(at: archiveURL, to: dest)- } catch {- logger.error("Failed to export logs", error)- }- }- }- #endif}private struct LogArchive: Identifiable {@@ -360,9 +328,7 @@ private struct LogDetailView: View {.frame(maxWidth: .infinity, alignment: .leading)}.navigationTitle("Log details")- #if os(iOS).navigationBarTitleDisplayMode(.inline)- #endif.toolbar {ToolbarItem(placement: .cancellationAction) {Button("Close") { dismiss() }@@ -391,7 +357,6 @@ private let logLineRegex: NSRegularExpression = {return try! NSRegularExpression(pattern: pattern, options: [])}()-#if os(iOS)import UIKitstruct ActivityView: UIViewControllerRepresentable {@@ -415,23 +380,4 @@ struct ExportDocumentPicker: UIViewControllerRepresentable {func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {}}-#endif--#if os(macOS)-import AppKit-private final class MacShareSheet: NSObject {- private let items: [Any]-- init(items: [Any]) {- self.items = items- }-- func present() {- guard let keyWindow = NSApplication.shared.keyWindow,- let contentView = keyWindow.contentView else { return }- let picker = NSSharingServicePicker(items: items)- picker.show(relativeTo: .zero, of: contentView, preferredEdge: .minY)- }-}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift b/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swiftindex afbc03c073..87518d51b5 100644--- a/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Settings/SettingsView.swift@@ -77,12 +77,8 @@ struct SettingsView: View {.padding(EnsuSpacing.lg)}.background(EnsuColor.backgroundBase)- #if os(iOS).searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)).navigationBarTitleDisplayMode(.inline)- #else- .searchable(text: $query)- #endif.toolbar {ToolbarItem(placement: .principal) {Text("Settings")@@ -274,9 +270,7 @@ private struct SystemPromptSettingsView: View {Group {if embeddedInNavigation {content- #if os(iOS).navigationBarTitleDisplayMode(.inline)- #endif.toolbar {ToolbarItem(placement: .principal) {Text("System Prompt")@@ -285,7 +279,6 @@ private struct SystemPromptSettingsView: View {}}} else {- #if os(iOS)NavigationStack {content.navigationBarTitleDisplayMode(.inline)@@ -300,9 +293,6 @@ private struct SystemPromptSettingsView: View {}}}- #else- content- #endif}}.onAppear {@@ -315,32 +305,6 @@ private struct SystemPromptSettingsView: View {.transition(.move(edge: .bottom).combined(with: .opacity))}}- #if os(macOS)- .safeAreaInset(edge: .top) {- if embeddedInNavigation {- EmptyView()- } else {- MacSheetHeader(- leading: {- EmptyView()- },- center: {- Text("System Prompt")- .font(EnsuTypography.large)- .foregroundStyle(EnsuColor.textPrimary)- },- trailing: {- Button("Done") {- dismiss()- }- .font(EnsuTypography.small)- .foregroundStyle(EnsuColor.textMuted)- .buttonStyle(.plain)- }- )- }- }- #endif}private var content: some View {diff --git a/mobile/native/apple/apps/ensu/Ensu/Utils/Haptics.swift b/mobile/native/apple/apps/ensu/Ensu/Utils/Haptics.swiftindex 445469d740..e2183cae0b 100644--- a/mobile/native/apple/apps/ensu/Ensu/Utils/Haptics.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Utils/Haptics.swift@@ -1,6 +1,5 @@import Foundation-#if canImport(UIKit)import UIKitfunc hapticTap() {@@ -27,30 +26,3 @@ func hapticError() {UINotificationFeedbackGenerator().notificationOccurred(.error)}-#elseif canImport(AppKit)-import AppKit--func hapticTap() {- NSHapticFeedbackManager.defaultPerformer.perform(.generic, performanceTime: .now)-}--func hapticMedium() {- NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)-}--func hapticHeavy() {- NSHapticFeedbackManager.defaultPerformer.perform(.levelChange, performanceTime: .now)-}--func hapticSuccess() {- hapticTap()-}--func hapticWarning() {- hapticMedium()-}--func hapticError() {- hapticHeavy()-}-#endifdiff --git a/mobile/native/apple/apps/ensu/Ensu/Utils/Pasteboard.swift b/mobile/native/apple/apps/ensu/Ensu/Utils/Pasteboard.swiftindex 8fec9f9def..f28d2886d9 100644--- a/mobile/native/apple/apps/ensu/Ensu/Utils/Pasteboard.swift+++ b/mobile/native/apple/apps/ensu/Ensu/Utils/Pasteboard.swift@@ -1,17 +1,7 @@import Foundation-#if canImport(UIKit)import UIKitfunc copyToPasteboard(_ value: String) {UIPasteboard.general.string = value}-#elseif canImport(AppKit)-import AppKit--func copyToPasteboard(_ value: String) {- let pasteboard = NSPasteboard.general- pasteboard.clearContents()- pasteboard.setString(value, forType: .string)-}-#endif