fixed issues

This commit is contained in:
cranci1 2025-01-24 14:40:01 +01:00
parent ce29144951
commit 58c3642dc1
2 changed files with 16 additions and 17 deletions

View file

@ -10,7 +10,7 @@ import SwiftUI
struct SettingsViewLogger: View {
@State private var logs: String = ""
@StateObject private var filterViewModel = LogFilterViewModel.shared
var body: some View {
VStack {
ScrollView {
@ -29,9 +29,6 @@ struct SettingsViewLogger: View {
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
HStack {
NavigationLink(destination: SettingsViewLoggerFilter(viewModel: filterViewModel)) {
Image(systemName: "gearshape")
Menu {
Button(action: {
UIPasteboard.general.string = logs
@ -49,6 +46,9 @@ struct SettingsViewLogger: View {
.resizable()
.frame(width: 20, height: 20)
}
NavigationLink(destination: SettingsViewLoggerFilter(viewModel: filterViewModel)) {
Image(systemName: "slider.horizontal.3")
}
}
}

View file

@ -14,10 +14,9 @@ struct LogFilter: Identifiable, Hashable {
let description: String
}
class LogFilterViewModel: ObservableObject {
static let shared = LogFilterViewModel() // Singleton instance
static let shared = LogFilterViewModel()
@Published var filters: [LogFilter] = [] {
didSet {
saveFiltersToUserDefaults()
@ -26,10 +25,10 @@ class LogFilterViewModel: ObservableObject {
private let userDefaultsKey = "LogFilterStates"
private let hardcodedFilters: [(type: String, description: String, defaultState: Bool)] = [
("General", "Logs for general events and activities.", true),
("Stream", "Logs for streaming and video playback.", true),
("Error", "Logs for errors and critical issues.", true),
("Debug", "Logs for debugging and troubleshooting.", false)
("General", "General events and activities.", true),
("Stream", "Streaming and video playback.", true),
("Error", "Errors and critical issues.", true),
("Debug", "Debugging and troubleshooting.", false)
]
private init() {
@ -70,21 +69,21 @@ class LogFilterViewModel: ObservableObject {
}
}
struct SettingsViewLoggerFilter: View {
@ObservedObject var viewModel = LogFilterViewModel.shared
var body: some View {
List {
ForEach($viewModel.filters) { $filter in
VStack(alignment: .leading, spacing: 5) {
Toggle(filter.type, isOn: $filter.isEnabled)
.font(.headline)
VStack(alignment: .leading, spacing: 0) {
HStack {
Toggle(filter.type, isOn: $filter.isEnabled)
Spacer()
}
Text(filter.description)
.font(.subheadline)
.foregroundColor(.secondary)
.padding(.leading, 5)
}
.padding(.vertical, 5)
}