mirror of
https://github.com/yattee/yattee.git
synced 2026-07-20 14:22:02 +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 SwiftUI
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct LogViewerView: View {
|
struct LogViewerView: View {
|
||||||
@State private var loggingService = LoggingService.shared
|
@State private var loggingService = LoggingService.shared
|
||||||
@@ -32,7 +33,7 @@ struct LogViewerView: View {
|
|||||||
.help(String(localized: "settings.advanced.logs.filter"))
|
.help(String(localized: "settings.advanced.logs.filter"))
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
showingExportSheet = true
|
showMacOSSavePanel()
|
||||||
} label: {
|
} label: {
|
||||||
Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up")
|
Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up")
|
||||||
.labelStyle(.iconOnly)
|
.labelStyle(.iconOnly)
|
||||||
@@ -69,7 +70,11 @@ struct LogViewerView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
|
#if os(macOS)
|
||||||
|
showMacOSSavePanel()
|
||||||
|
#else
|
||||||
showingExportSheet = true
|
showingExportSheet = true
|
||||||
|
#endif
|
||||||
} label: {
|
} label: {
|
||||||
Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up")
|
Label(String(localized: "settings.advanced.logs.export"), systemImage: "square.and.arrow.up")
|
||||||
}
|
}
|
||||||
@@ -93,7 +98,7 @@ struct LogViewerView: View {
|
|||||||
.sheet(isPresented: $showingExportSheet) {
|
.sheet(isPresented: $showingExportSheet) {
|
||||||
LogExportOverlayView(server: logExportServer)
|
LogExportOverlayView(server: logExportServer)
|
||||||
}
|
}
|
||||||
#else
|
#elseif os(iOS)
|
||||||
.sheet(isPresented: $showingExportSheet) {
|
.sheet(isPresented: $showingExportSheet) {
|
||||||
ShareSheet(items: [loggingService.exportLogs()])
|
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 {
|
private var searchBar: some View {
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "magnifyingglass")
|
Image(systemName: "magnifyingglass")
|
||||||
|
|||||||
Reference in New Issue
Block a user