mirror of
https://github.com/yattee/yattee.git
synced 2026-07-19 22:02:10 +00:00
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.
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user