Skip to content

Commit

Permalink
Add ShareLink on watch app
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Bert <[email protected]>
  • Loading branch information
timbms committed Nov 1, 2024
1 parent 974c9e9 commit 91922f6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
4 changes: 4 additions & 0 deletions openHAB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -348,6 +349,7 @@
DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderRow.swift; sourceTree = "<group>"; };
DA15BFBC23C6726400BD8ADA /* ObservableOpenHABDataObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableOpenHABDataObject.swift; sourceTree = "<group>"; };
DA162BEB2CD3B53E0040DAE5 /* LogsViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogsViewer.swift; sourceTree = "<group>"; };
DA162BEF2CD4CC730040DAE5 /* LogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogView.swift; sourceTree = "<group>"; };
DA19E25A22FD801D002F8F2F /* OpenHABGeneralTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenHABGeneralTests.swift; sourceTree = "<group>"; };
DA1C2E4B230DC28F00FACFB0 /* Appfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Appfile; sourceTree = "<group>"; };
DA1C2E4C230DC28F00FACFB0 /* SnapshotHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotHelper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
34 changes: 34 additions & 0 deletions openHAB/LogView.swift
Original file line number Diff line number Diff line change
@@ -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([]))
}
15 changes: 15 additions & 0 deletions openHAB/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 10 additions & 4 deletions openHABWatch/Views/LogsViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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)
Expand Down

0 comments on commit 91922f6

Please sign in to comment.