From 04daf94057906ac499093190598f3ae5753fcb92 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 26 Jun 2026 22:55:22 +0200 Subject: [PATCH] Use native save panel for log export on macOS Replace the log-content-with-copy sheet with an NSSavePanel that writes the exported logs to a .txt file, matching the subscriptions and preset export flows. ShareSheet presentation is now iOS-only; tvOS export is unchanged. --- Yattee/Views/Settings/LogViewerView.swift | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Yattee/Views/Settings/LogViewerView.swift b/Yattee/Views/Settings/LogViewerView.swift index ce56c71e..dfe7cf37 100644 --- a/Yattee/Views/Settings/LogViewerView.swift +++ b/Yattee/Views/Settings/LogViewerView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import UniformTypeIdentifiers struct LogViewerView: View { @State private var loggingService = LoggingService.shared @@ -32,7 +33,7 @@ struct LogViewerView: View { .help(String(localized: "settings.advanced.logs.filter")) Button { - showingExportSheet = true + showMacOSSavePanel() } label: { Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up") .labelStyle(.iconOnly) @@ -69,7 +70,11 @@ struct LogViewerView: View { } Button { + #if os(macOS) + showMacOSSavePanel() + #else showingExportSheet = true + #endif } label: { Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up") } @@ -93,7 +98,7 @@ struct LogViewerView: View { .sheet(isPresented: $showingExportSheet) { LogExportOverlayView(server: logExportServer) } - #else + #elseif os(iOS) .sheet(isPresented: $showingExportSheet) { ShareSheet(items: [loggingService.exportLogs()]) } @@ -103,6 +108,22 @@ struct LogViewerView: View { } } + #if os(macOS) + private func showMacOSSavePanel() { + let panel = NSSavePanel() + panel.nameFieldStringValue = "Yattee Logs \(Date.now.formatted(.iso8601.year().month().day())).txt" + panel.allowedContentTypes = [.plainText] + + if panel.runModal() == .OK, let url = panel.url { + do { + try Data(loggingService.exportLogs().utf8).write(to: url) + } catch { + loggingService.log(level: .error, category: .general, message: "Failed to save logs export", details: error.localizedDescription) + } + } + } + #endif + private var searchBar: some View { HStack { Image(systemName: "magnifyingglass")