Files
ShhShell/ShhShell/Views/Hosts/HostsView.swift
neon443 f19f32682f added selecting and applying themes
added selectTheme to set the selectedtheme index
added isthemeselected to check if a theme is selected
applytheme takes an index now

ui needs work lol - cant select default, and selction doesnt save between sessions
2025-06-28 16:06:11 +01:00

94 lines
2.1 KiB
Swift

//
// HostsView.swift
// ShhShell
//
// Created by neon443 on 20/06/2025.
//
import SwiftUI
struct HostsView: View {
@ObservedObject var handler: SSHHandler
@ObservedObject var hostsManager: HostsManager
@ObservedObject var keyManager: KeyManager
var body: some View {
if hostsManager.hosts.isEmpty {
Text("Add your first Host!")
}
//proves that u can connect to multiple at the same time
NavigationLink() {
ForEach(hostsManager.hosts) { host in
let miniHandler = SSHHandler(host: host)
TerminalController(handler: miniHandler, hostsManager: hostsManager)
.onAppear { miniHandler.go() }
}
} label: {
Label("multiview", systemImage: "square.split.2x2")
}
ForEach(hostsManager.hosts) { host in
NavigationLink() {
ConnectionView(
handler: SSHHandler(host: host),
hostsManager: hostsManager,
keyManager: keyManager
)
} label: {
SymbolPreview(symbol: host.symbol, label: host.label)
.frame(width: 40, height: 40)
Text(hostsManager.makeLabel(forHost: host))
}
.id(host)
.animation(.default, value: host)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
hostsManager.removeHost(host)
} label: {
Label("Delete", systemImage: "trash")
}
Button() {
hostsManager.duplicateHost(host)
} label: {
Label("Duplicate", systemImage: "square.filled.on.square")
}
}
}
.onMove(perform: {
hostsManager.moveHost(from: $0, to: $1)
})
Section() {
NavigationLink {
ThemeManagerView(hostsManager: hostsManager)
} label: {
Label("Themes", systemImage: "swatchpalette")
}
}
.transition(.opacity)
.navigationTitle("ShhShell")
.toolbar {
ToolbarItem(placement: .confirmationAction) {
NavigationLink {
ConnectionView(
handler: SSHHandler(host: Host.blank),
hostsManager: hostsManager,
keyManager: keyManager
)
} label: {
Label("Add", systemImage: "plus")
}
}
}
}
}
#Preview {
HostsView(
handler: SSHHandler(host: Host.debug),
hostsManager: HostsManager(),
keyManager: KeyManager()
)
}