-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tim Bert <[email protected]>
- Loading branch information
Showing
10 changed files
with
218 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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 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([])) | ||
// } | ||
|
||
import Foundation | ||
import OpenHABCore | ||
import OSLog | ||
import SwiftUI | ||
|
||
// swiftlint:disable:next file_types_order | ||
struct LogsViewer: View { | ||
let template = NSPredicate( | ||
format: "(subsystem BEGINSWITH $PREFIX)" | ||
) | ||
let myFont = Font | ||
.system(size: 10) | ||
.monospaced() | ||
|
||
var logService: LogServiceProtocol | ||
|
||
var body: some View { | ||
List { | ||
Text(text) | ||
.font(myFont) | ||
} | ||
.toolbar { | ||
ToolbarItem(placement: .primaryAction) { | ||
ShareLink( | ||
item: text, | ||
preview: SharePreview("Logs", image: Image(.openHABIcon)) | ||
) { | ||
Label("Share Logs", systemSymbol: .squareAndArrowUp) | ||
} | ||
} | ||
} | ||
.navigationTitle("Logs") | ||
.task { | ||
text = await logService.fetchLogs(with: template) | ||
} | ||
} | ||
|
||
@State private var text = "Loading..." | ||
} | ||
|
||
#if DEBUG | ||
struct MockLogService: LogServiceProtocol { | ||
func fetchLogs(with template: NSPredicate) async -> String { | ||
""" | ||
Mocked Data | ||
Test data | ||
""" | ||
} | ||
} | ||
#endif | ||
|
||
#Preview { | ||
LogsViewer(logService: MockLogService()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 OpenHABCore | ||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@ObservedObject var viewModel: UserData | ||
@EnvironmentObject var settings: ObservableOpenHABDataObject | ||
@State var title = "openHAB" | ||
|
||
var body: some View { | ||
TabView { | ||
NavigationStack { | ||
SitemapView(viewModel: viewModel) | ||
} | ||
.tabItem { | ||
Label("Sitemap", systemSymbol: .circleFill) | ||
} | ||
NavigationStack { | ||
PreferencesSwiftUIView() | ||
} | ||
.tabItem { | ||
Label("Preferences", systemSymbol: .circleFill) | ||
} | ||
NavigationStack { | ||
LogsViewer(logService: LogService()) | ||
} | ||
.tabItem { | ||
Label("Debug", systemSymbol: .circleFill) | ||
} | ||
} | ||
.tabViewStyle(.page) | ||
} | ||
} | ||
|
||
#Preview { | ||
ContentView(viewModel: .init()) | ||
.environmentObject(ObservableOpenHABDataObject()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.