added full expand and full close buttons, with new symbols that support ios 13+

added historylimitdisplay computed property
made disconnect synchronous
This commit is contained in:
neon443
2025-09-01 17:46:43 +01:00
parent efb6072af8
commit 7c28cc79da
2 changed files with 72 additions and 49 deletions

View File

@@ -140,11 +140,9 @@ class SSHHandler: @unchecked Sendable, ObservableObject {
} }
func disconnect() { func disconnect() {
Task { @MainActor in self.hostkeyChanged = false
self.hostkeyChanged = false withAnimation { self.state = .idle }
withAnimation { self.state = .idle } withAnimation { self.testSuceeded = nil }
withAnimation { self.testSuceeded = nil }
}
if let sessionID { if let sessionID {
Task { @MainActor in Task { @MainActor in

View File

@@ -11,12 +11,22 @@ struct RecentsView: View {
@ObservedObject var hostsManager: HostsManager @ObservedObject var hostsManager: HostsManager
@ObservedObject var keyManager: KeyManager @ObservedObject var keyManager: KeyManager
@State var historyCount: Int = 1 @State var historyLimit: Int = 1
var historyLimitDisplay: String {
let count = hostsManager.history.count
if historyLimit == 0 {
return "\(count) item\(plural(count))"
} else if historyLimit > count {
return "\(count)/\(count)"
} else {
return "\(historyLimit)/\(count)"
}
}
var body: some View { var body: some View {
if !hostsManager.history.isEmpty { if !hostsManager.history.isEmpty {
Section("Recents") { Section("Recents") {
ForEach(hostsManager.history.reversed().prefix(historyCount)) { history in ForEach(hostsManager.history.reversed().prefix(historyLimit)) { history in
NavigationLink() { NavigationLink() {
ConnectionView( ConnectionView(
handler: SSHHandler( handler: SSHHandler(
@@ -46,51 +56,66 @@ struct RecentsView: View {
.tint(.red) .tint(.red)
} }
} }
// if historyCount <= hostsManager.history.count { HStack(alignment: .center) {
HStack(alignment: .center) { Button() {
Button() { var decrement: Int = 2
var increment = 2 if historyLimit < 2 { decrement = 1 }
if historyCount+2 > hostsManager.history.count { withAnimation(.spring) { historyLimit -= decrement }
increment = 1 } label: {
} Image(systemName: "chevron.up")
withAnimation(.spring) { historyCount += increment } .resizable().scaledToFit()
} label: { .frame(width: 20)
Image(systemName: "chevron.down") .foregroundStyle(hostsManager.tint)
.resizable().scaledToFit()
.frame(width: 20)
.foregroundStyle(hostsManager.tint)
}
.buttonStyle(.plain)
.disabled(historyCount == hostsManager.history.count)
Spacer()
Text(
historyCount == 0 ?
"\(hostsManager.history.count) item\(plural(hostsManager.history.count))" :
"\(historyCount)/\(hostsManager.history.count)"
)
.foregroundStyle(.gray)
.font(.caption)
.contentTransition(.numericText())
Spacer()
Button {
withAnimation(.spring) { historyCount = 0 }
} label: {
Image(systemName: "chevron.up.2")
.resizable().scaledToFit()
.frame(width: 20)
.foregroundStyle(hostsManager.tint)
}
.buttonStyle(.plain)
.disabled(historyCount == 0)
} }
// } .buttonStyle(.plain)
.disabled(historyLimit == 0)
.padding(.trailing, 10)
Button() {
withAnimation(.spring) { historyLimit += 2 }
} label: {
Image(systemName: "chevron.down")
.resizable().scaledToFit()
.frame(width: 20)
.foregroundStyle(hostsManager.tint)
}
.buttonStyle(.plain)
.disabled(historyLimit >= hostsManager.history.count)
Spacer()
Text(historyLimitDisplay)
.foregroundStyle(.gray)
.font(.caption)
.contentTransition(.numericText())
Spacer()
Button {
withAnimation(.spring) { historyLimit = Int.max }
} label: {
Image(systemName: "rectangle.expand.vertical")
.resizable().scaledToFit()
.frame(width: 20)
.foregroundStyle(hostsManager.tint)
}
.buttonStyle(.plain)
.disabled(historyLimit != 0)
.padding(.trailing, 10)
Button {
withAnimation(.spring) { historyLimit = 0 }
} label: {
Image(systemName: "rectangle.compress.vertical")
.resizable().scaledToFit()
.frame(width: 20)
.foregroundStyle(hostsManager.tint)
}
.buttonStyle(.plain)
.disabled(historyLimit == 0)
}
} }
.transition(.opacity) .transition(.opacity)
} }
} }
} }
#Preview { #Preview {