Add support for tvOS

This commit is contained in:
世界
2023-07-29 09:44:31 +08:00
parent 5a8f3a770f
commit bb0385f53c
63 changed files with 1542 additions and 389 deletions
@@ -34,12 +34,15 @@ public struct ServiceLogView: View {
}
}
}
#if !os(tvOS)
.toolbar {
Button("Export") {
fileExporterPresented = true
}
.disabled(content.isEmpty)
}
#endif
#if !os(tvOS)
.fileExporter(
isPresented: $fileExporterPresented,
document: LogDocument(content),
@@ -47,10 +50,14 @@ public struct ServiceLogView: View {
defaultFilename: "service-log.txt",
onCompletion: { _ in }
)
#endif
.navigationTitle("Service Log")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
#if os(tvOS)
.focusable()
#endif
}
private func loadContent() {
@@ -65,25 +72,27 @@ public struct ServiceLogView: View {
isLoading = false
}
private struct LogDocument: FileDocument {
static var readableContentTypes = [UTType.text]
#if !os(tvOS)
private struct LogDocument: FileDocument {
static var readableContentTypes = [UTType.text]
let content: String
let content: String
init(_ content: String) {
self.content = content
}
init(_ content: String) {
self.content = content
}
init(configuration: ReadConfiguration) throws {
if let data = configuration.file.regularFileContents {
content = String(decoding: data, as: UTF8.self)
} else {
content = ""
init(configuration: ReadConfiguration) throws {
if let data = configuration.file.regularFileContents {
content = String(decoding: data, as: UTF8.self)
} else {
content = ""
}
}
func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
FileWrapper(regularFileWithContents: Data(content.utf8))
}
}
func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
FileWrapper(regularFileWithContents: Data(content.utf8))
}
}
#endif
}
@@ -95,7 +95,7 @@ public struct SettingView: View {
Section("Core") {
FormTextItem("Version", version)
FormTextItem("Data Size", dataSize)
#if os(iOS)
#if os(iOS) || os(tvOS)
NavigationLink(destination: ServiceLogView()) {
Text("View Service Log")
}