From 91922f66750257b2ced04d70a23cb576408ccf16 Mon Sep 17 00:00:00 2001 From: Tim Bert <5411131+timbms@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:02:34 +0100 Subject: [PATCH] Add ShareLink on watch app Signed-off-by: Tim Bert <5411131+timbms@users.noreply.github.com> --- openHAB.xcodeproj/project.pbxproj | 4 ++++ openHAB/LogView.swift | 34 +++++++++++++++++++++++++++++ openHAB/SettingsView.swift | 15 +++++++++++++ openHABWatch/Views/LogsViewer.swift | 14 ++++++++---- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 openHAB/LogView.swift diff --git a/openHAB.xcodeproj/project.pbxproj b/openHAB.xcodeproj/project.pbxproj index 5e733355..0836d0c3 100644 --- a/openHAB.xcodeproj/project.pbxproj +++ b/openHAB.xcodeproj/project.pbxproj @@ -80,6 +80,7 @@ DA0F37D023D4ACC7007EAB48 /* SliderRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */; }; DA15BFBD23C6726400BD8ADA /* ObservableOpenHABDataObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA15BFBC23C6726400BD8ADA /* ObservableOpenHABDataObject.swift */; }; DA162BEC2CD3B53E0040DAE5 /* LogsViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA162BEB2CD3B53E0040DAE5 /* LogsViewer.swift */; }; + DA162BF02CD4CC730040DAE5 /* LogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA162BEF2CD4CC730040DAE5 /* LogView.swift */; }; DA19E25B22FD801D002F8F2F /* OpenHABGeneralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA19E25A22FD801D002F8F2F /* OpenHABGeneralTests.swift */; }; DA21EAE22339621C001AB415 /* Throttler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA21EAE12339621C001AB415 /* Throttler.swift */; }; DA242C622C83588600AFB10D /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA242C612C83588600AFB10D /* SettingsView.swift */; }; @@ -348,6 +349,7 @@ DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderRow.swift; sourceTree = ""; }; DA15BFBC23C6726400BD8ADA /* ObservableOpenHABDataObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableOpenHABDataObject.swift; sourceTree = ""; }; DA162BEB2CD3B53E0040DAE5 /* LogsViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogsViewer.swift; sourceTree = ""; }; + DA162BEF2CD4CC730040DAE5 /* LogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogView.swift; sourceTree = ""; }; DA19E25A22FD801D002F8F2F /* OpenHABGeneralTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenHABGeneralTests.swift; sourceTree = ""; }; DA1C2E4B230DC28F00FACFB0 /* Appfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Appfile; sourceTree = ""; }; DA1C2E4C230DC28F00FACFB0 /* SnapshotHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotHelper.swift; sourceTree = ""; }; @@ -871,6 +873,7 @@ 653B54BF285C0AC700298ECD /* OpenHABRootViewController.swift */, 65570A7C2476D16A00D524EA /* OpenHABWebViewController.swift */, DFB2624318830A3600D3244D /* OpenHABSitemapViewController.swift */, + DA162BEF2CD4CC730040DAE5 /* LogView.swift */, DAC65FC6236EDF3900F4501E /* SpinnerViewController.swift */, DA6B2EF62C8B92E800DF77CF /* SelectionView.swift */, DA242C612C83588600AFB10D /* SettingsView.swift */, @@ -1558,6 +1561,7 @@ 1224F78F228A89FD00750965 /* WatchMessageService.swift in Sources */, DAA42BAC21DC984A00244B2A /* WebUITableViewCell.swift in Sources */, DF4B84131886DAC400F34902 /* FrameUITableViewCell.swift in Sources */, + DA162BF02CD4CC730040DAE5 /* LogView.swift in Sources */, DF4B84161886EACA00F34902 /* GenericUITableViewCell.swift in Sources */, 935B484625342B8E00E44CF0 /* URL+Static.swift in Sources */, B7D5ECE121499E55001B0EC6 /* MapViewTableViewCell.swift in Sources */, diff --git a/openHAB/LogView.swift b/openHAB/LogView.swift new file mode 100644 index 00000000..62bc4177 --- /dev/null +++ b/openHAB/LogView.swift @@ -0,0 +1,34 @@ +// Copyright (c) 2010-2024 Contributors to the openHAB project +// +// See the NOTICE file(s) distributed with this work for additional +// information. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0 +// +// SPDX-License-Identifier: EPL-2.0 + +import Foundation +import OSLog +import SwiftUI + +struct LogView: View { + let logs: [OSLogEntryLog] + + var body: some View { + List(logs, id: \.self) { log in + VStack(alignment: .leading) { + Text(log.composedMessage) + HStack { + Text(log.subsystem) + Text(log.date, format: .dateTime) + }.bold() + } + } + } +} + +#Preview { + LogView(logs: .init([])) +} diff --git a/openHAB/SettingsView.swift b/openHAB/SettingsView.swift index cd728014..6729a9e2 100644 --- a/openHAB/SettingsView.swift +++ b/openHAB/SettingsView.swift @@ -43,6 +43,8 @@ struct SettingsView: View { @State private var sitemaps: [OpenHABSitemap] = [] + @State private var exportShown = false + @Environment(\.dismiss) private var dismiss var appData: OpenHABDataObject? { @@ -287,6 +289,19 @@ struct SettingsView: View { } } +// Section(header: Text(LocalizedStringKey("debug"))) { +// ShareLink(items: [logs.entries.joined(separator: "\n")]) { +// Text("Share Logs") +// } +// Button("exportLogs") { +// logs.export() +// exportShown.toggle() +// } +// .sheet(isPresented: $exportShown) { +// ShareView(items: [logs.entries.joined(separator: "\n")]) +// } +// } + Section(header: Text(LocalizedStringKey("about_settings"))) { LabeledContent("App Version", value: appVersion) diff --git a/openHABWatch/Views/LogsViewer.swift b/openHABWatch/Views/LogsViewer.swift index 9e0549b4..916ef5b0 100644 --- a/openHABWatch/Views/LogsViewer.swift +++ b/openHABWatch/Views/LogsViewer.swift @@ -16,6 +16,7 @@ import SwiftUI // Thanks to https://useyourloaf.com/blog/fetching-oslog-messages-in-swift/ +// swiftlint:disable:next file_types_order struct LogsViewer: View { let template = NSPredicate( format: "(subsystem BEGINSWITH $PREFIX)" @@ -27,10 +28,15 @@ struct LogsViewer: View { var logService: LogServiceProtocol var body: some View { - ScrollView { - Text(text) - .font(myFont) - .padding() + VStack { + ShareLink(item: text) { + Label("Share Logs", systemSymbol: .squareAndArrowUp) + } + ScrollView { + Text(text) + .font(myFont) + .padding() + } } .task { text = await logService.fetchLogs(with: template)