updated the ui for the settings, made it actually link to the settings

add a load/savesettings function
This commit is contained in:
neon443
2025-08-20 16:32:24 +01:00
parent 2338d0d108
commit 0b16e15044
3 changed files with 37 additions and 16 deletions

View File

@@ -25,12 +25,14 @@ class HostsManager: ObservableObject, @unchecked Sendable {
@Published var snippets: [Snippet] = [] @Published var snippets: [Snippet] = []
@Published var history: [History] = [] @Published var history: [History] = []
@Published var settings: AppSettings = AppSettings()
var tint: SwiftUI.Color { var tint: SwiftUI.Color {
selectedTheme.ansi[selectedAnsi].suiColor selectedTheme.ansi[selectedAnsi].suiColor
} }
init(previews: Bool = false) { init(previews: Bool = false) {
loadSettings()
loadHosts() loadHosts()
exportHosts() exportHosts()
loadThemes() loadThemes()
@@ -45,6 +47,17 @@ class HostsManager: ObservableObject, @unchecked Sendable {
} }
} }
func loadSettings() {
guard let data = userDefaults.data(forKey: "settings") else { return }
guard let decoded = try? JSONDecoder().decode(AppSettings.self, from: data) else { return }
self.settings = decoded
}
func saveSettings() {
guard let encoded = try? JSONEncoder().encode(settings) else { return }
userDefaults.set(encoded, forKey: "settings")
}
func loadHistory() { func loadHistory() {
guard let data = userDefaults.data(forKey: "history") else { return } guard let data = userDefaults.data(forKey: "history") else { return }
guard let decoded = try? JSONDecoder().decode([History].self, from: data) else { return } guard let decoded = try? JSONDecoder().decode([History].self, from: data) else { return }

View File

@@ -9,7 +9,7 @@ import Foundation
import SwiftUI import SwiftUI
struct AppSettings: Codable, Sendable { struct AppSettings: Codable, Sendable {
var scrollback: Int = 1_000 var scrollback: CGFloat = 1_000
var cursorStyle: CursorStyle = .block var cursorStyle: CursorStyle = .block
var locationPersist: Bool = false var locationPersist: Bool = false
var bellSound: Bool = false var bellSound: Bool = false

View File

@@ -17,40 +17,48 @@ struct SettingsView: View {
.ignoresSafeArea(.all) .ignoresSafeArea(.all)
List { List {
Section("Terminal") { Section("Terminal") {
Label("Scrollback", systemImage: "scroll") VStack(alignment: .leading) {
HStack { HStack {
Slider(value: .constant(0), in: 1_000...50_000, step: 1_000) Label("Scrollback", systemImage: "scroll")
Text("hi") Spacer()
Text("\(Int(hostsManager.settings.scrollback))")
.contentTransition(.numericText())
}
Slider(
value: $hostsManager.settings.scrollback,
in: 1_000...50_000,
step: 1_000.0
)
} }
Picker("Cursor", selection: .constant(CursorStyle.bar)) { Picker("Cursor", selection: $hostsManager.settings.cursorStyle) {
ForEach(CursorStyle.allCases, id: \.self) { type in ForEach(CursorStyle.allCases, id: \.self) { type in
Text("\(type)").tag(type) Text("\(type)").tag(type)
} }
} }
.pickerStyle(.inline)
} }
Toggle("location persistence", isOn: .constant(false))
Toggle("bell sound", isOn: .constant(false)) Toggle("location persistence", systemImage: "location.fill", isOn: $hostsManager.settings.locationPersist)
Toggle("bell haptic", isOn: .constant(false))
Toggle("keep screen awake", isOn: .constant(false)) Toggle("bell sound", systemImage: "bell.and.waves.left.and.right", isOn: $hostsManager.settings.bellSound)
Toggle("bell haptic",systemImage: "iphone.homebutton.radiowaves.left.and.right", isOn: $hostsManager.settings.bellHaptic)
Picker("terminal filter", selection: .constant(TerminalFilter.crt)) { Toggle("keep screen awake", systemImage: "cup.and.saucer.fill", isOn: $hostsManager.settings.caffeinate)
Picker("terminal filter", selection: $hostsManager.settings.filter) {
ForEach(TerminalFilter.allCases, id: \.self) { filter in ForEach(TerminalFilter.allCases, id: \.self) { filter in
Text("\(filter)").tag(filter) Text("\(filter)").tag(filter)
} }
} }
Picker("appicon", selection: .constant(AppIcon.regular)) { Picker("appicon", selection: $hostsManager.settings.appIcon) {
ForEach(AppIcon.allCases, id: \.self) { icon in ForEach(AppIcon.allCases, id: \.self) { icon in
Text("\(icon)").tag(icon) Text("\(icon)").tag(icon)
icon.image icon.image
} }
}.pickerStyle(.menu) }
.pickerStyle(.inline)
} }
.listStyle(.sidebar) .listStyle(.sidebar)
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)