mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
added collapsible recents
added last connect date added more and collapse button added a thingy that says how many are displayed and the total updated funcs
This commit is contained in:
@@ -12,4 +12,5 @@ struct History: Identifiable, Codable {
|
||||
|
||||
var host: Host
|
||||
var count: Int
|
||||
var lastConnect: Date = .now
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
func addToHistory(_ host: Host) {
|
||||
history.append(History(host: host, count: 1))
|
||||
formatHistory()
|
||||
saveHistory()
|
||||
}
|
||||
|
||||
func formatHistory() {
|
||||
@@ -55,6 +56,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
if result.last?.host == item.host {
|
||||
guard var lastOne = result.popLast() else { continue }
|
||||
lastOne.count += 1
|
||||
lastOne.lastConnect = .now
|
||||
result.append(lastOne)
|
||||
} else {
|
||||
result.append(History(host: item.host, count: 1))
|
||||
@@ -68,7 +70,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
||||
userDefaults.set(data, forKey: "history")
|
||||
}
|
||||
|
||||
func removeFromHistory(_ toRemove: Host) {
|
||||
func removeFromHistory(_ toRemove: History) {
|
||||
history.removeAll(where: { $0.id == toRemove.id })
|
||||
saveHistory()
|
||||
}
|
||||
|
||||
@@ -11,10 +11,13 @@ struct RecentsView: View {
|
||||
@ObservedObject var hostsManager: HostsManager
|
||||
@ObservedObject var keyManager: KeyManager
|
||||
|
||||
@State var historyCount: Int = 1
|
||||
|
||||
var body: some View {
|
||||
if !hostsManager.history.isEmpty {
|
||||
Section("Recents") {
|
||||
ForEach(hostsManager.history) { history in
|
||||
ForEach(0..<historyCount, id: \.self) { index in
|
||||
let history = hostsManager.history[index]
|
||||
NavigationLink() {
|
||||
ConnectionView(
|
||||
handler: SSHHandler(
|
||||
@@ -25,16 +28,54 @@ struct RecentsView: View {
|
||||
keyManager: keyManager
|
||||
)
|
||||
} label: {
|
||||
Text(history.host.description)
|
||||
Text("\(history.count)")
|
||||
.foregroundStyle(.gray)
|
||||
.padding(.trailing, 10)
|
||||
.font(.caption)
|
||||
VStack(alignment: .leading) {
|
||||
Text(history.host.description)
|
||||
.font(.body)
|
||||
Text("Last connected at " + history.lastConnect.formatted())
|
||||
.font(.caption)
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
}
|
||||
.swipeActions {
|
||||
Button("Remove", systemImage: "trash", role: .destructive) {
|
||||
hostsManager.removeFromHistory(history.host)
|
||||
hostsManager.removeFromHistory(history)
|
||||
}
|
||||
.tint(.red)
|
||||
}
|
||||
}
|
||||
if historyCount != hostsManager.history.count {
|
||||
HStack(alignment: .center) {
|
||||
Button() {
|
||||
withAnimation { historyCount += 2 }
|
||||
} label: {
|
||||
Image(systemName: "chevron.down")
|
||||
.resizable().scaledToFit()
|
||||
.frame(width: 20)
|
||||
.foregroundStyle(hostsManager.tint)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
Spacer()
|
||||
Text("\(historyCount)/\(hostsManager.history.count)")
|
||||
.foregroundStyle(.gray)
|
||||
.font(.caption)
|
||||
.contentTransition(.numericText())
|
||||
Spacer()
|
||||
Button {
|
||||
withAnimation { historyCount = 2 }
|
||||
} label: {
|
||||
Image(systemName: "chevron.up.2")
|
||||
.resizable().scaledToFit()
|
||||
.frame(width: 20)
|
||||
.foregroundStyle(hostsManager.tint)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ struct HostSymbolPreview: View {
|
||||
var body: some View {
|
||||
if small {
|
||||
HStack(alignment: .center, spacing: 5) {
|
||||
if !label.isEmpty {
|
||||
Text(label)
|
||||
.font(.headline)
|
||||
}
|
||||
symbol.image
|
||||
.resizable().scaledToFit()
|
||||
.symbolRenderingMode(.monochrome)
|
||||
@@ -30,12 +32,14 @@ struct HostSymbolPreview: View {
|
||||
symbol.image
|
||||
.resizable().scaledToFit()
|
||||
.symbolRenderingMode(.monochrome)
|
||||
if !label.isEmpty {
|
||||
Text(label)
|
||||
.font(.headline)
|
||||
.offset(symbol.offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
Reference in New Issue
Block a user