Minor improvements

This commit is contained in:
世界
2023-08-14 09:40:21 +08:00
parent 736bbc81e9
commit 1ac5df7f72
6 changed files with 86 additions and 63 deletions
@@ -8,6 +8,7 @@ public struct ServiceLogView: View {
public static let windowID = "service-log"
#endif
@Environment(\.dismiss) private var dismiss
@State private var isLoading = true
@State private var content = ""
@State private var fileExporterPresented = false
@@ -28,7 +29,9 @@ public struct ServiceLogView: View {
Text("Empty content")
} else {
ScrollView {
Text(content).font(logFont)
Text(content)
.font(logFont)
.frame(maxWidth: .infinity, alignment: .topLeading)
}
.padding()
}
@@ -36,10 +39,16 @@ public struct ServiceLogView: View {
}
#if !os(tvOS)
.toolbar {
Button("Export") {
fileExporterPresented = true
if !content.isEmpty {
Button("Export") {
fileExporterPresented = true
}
Button("Delete", role: .destructive) {
Task.detached {
deleteContent()
}
}
}
.disabled(content.isEmpty)
}
#endif
#if !os(tvOS)
@@ -52,11 +61,8 @@ public struct ServiceLogView: View {
)
#endif
.navigationTitle("Service Log")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
#if os(tvOS)
.focusable()
.focusable()
#endif
}
@@ -67,11 +73,21 @@ public struct ServiceLogView: View {
if content.isEmpty {
do {
content = try String(contentsOf: FilePath.cacheDirectory.appendingPathComponent("stderr.log.old"))
} catch {}
} catch {
}
}
isLoading = false
}
private func deleteContent() {
try? FileManager.default.removeItem(at: FilePath.cacheDirectory.appendingPathComponent("stderr.log"))
try? FileManager.default.removeItem(at: FilePath.cacheDirectory.appendingPathComponent("stderr.log.old"))
DispatchQueue.main.async {
dismiss()
}
}
#if !os(tvOS)
private struct LogDocument: FileDocument {
static var readableContentTypes = [UTType.text]