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 host: Host
|
||||||
var count: Int
|
var count: Int
|
||||||
|
var lastConnect: Date = .now
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
|||||||
func addToHistory(_ host: Host) {
|
func addToHistory(_ host: Host) {
|
||||||
history.append(History(host: host, count: 1))
|
history.append(History(host: host, count: 1))
|
||||||
formatHistory()
|
formatHistory()
|
||||||
|
saveHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatHistory() {
|
func formatHistory() {
|
||||||
@@ -55,6 +56,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
|||||||
if result.last?.host == item.host {
|
if result.last?.host == item.host {
|
||||||
guard var lastOne = result.popLast() else { continue }
|
guard var lastOne = result.popLast() else { continue }
|
||||||
lastOne.count += 1
|
lastOne.count += 1
|
||||||
|
lastOne.lastConnect = .now
|
||||||
result.append(lastOne)
|
result.append(lastOne)
|
||||||
} else {
|
} else {
|
||||||
result.append(History(host: item.host, count: 1))
|
result.append(History(host: item.host, count: 1))
|
||||||
@@ -68,7 +70,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
|||||||
userDefaults.set(data, forKey: "history")
|
userDefaults.set(data, forKey: "history")
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeFromHistory(_ toRemove: Host) {
|
func removeFromHistory(_ toRemove: History) {
|
||||||
history.removeAll(where: { $0.id == toRemove.id })
|
history.removeAll(where: { $0.id == toRemove.id })
|
||||||
saveHistory()
|
saveHistory()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ struct RecentsView: View {
|
|||||||
@ObservedObject var hostsManager: HostsManager
|
@ObservedObject var hostsManager: HostsManager
|
||||||
@ObservedObject var keyManager: KeyManager
|
@ObservedObject var keyManager: KeyManager
|
||||||
|
|
||||||
|
@State var historyCount: Int = 1
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if !hostsManager.history.isEmpty {
|
if !hostsManager.history.isEmpty {
|
||||||
Section("Recents") {
|
Section("Recents") {
|
||||||
ForEach(hostsManager.history) { history in
|
ForEach(0..<historyCount, id: \.self) { index in
|
||||||
|
let history = hostsManager.history[index]
|
||||||
NavigationLink() {
|
NavigationLink() {
|
||||||
ConnectionView(
|
ConnectionView(
|
||||||
handler: SSHHandler(
|
handler: SSHHandler(
|
||||||
@@ -25,16 +28,54 @@ struct RecentsView: View {
|
|||||||
keyManager: keyManager
|
keyManager: keyManager
|
||||||
)
|
)
|
||||||
} label: {
|
} label: {
|
||||||
Text(history.host.description)
|
|
||||||
Text("\(history.count)")
|
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 {
|
.swipeActions {
|
||||||
Button("Remove", systemImage: "trash", role: .destructive) {
|
Button("Remove", systemImage: "trash", role: .destructive) {
|
||||||
hostsManager.removeFromHistory(history.host)
|
hostsManager.removeFromHistory(history)
|
||||||
}
|
}
|
||||||
.tint(.red)
|
.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 {
|
var body: some View {
|
||||||
if small {
|
if small {
|
||||||
HStack(alignment: .center, spacing: 5) {
|
HStack(alignment: .center, spacing: 5) {
|
||||||
|
if !label.isEmpty {
|
||||||
Text(label)
|
Text(label)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
}
|
||||||
symbol.image
|
symbol.image
|
||||||
.resizable().scaledToFit()
|
.resizable().scaledToFit()
|
||||||
.symbolRenderingMode(.monochrome)
|
.symbolRenderingMode(.monochrome)
|
||||||
@@ -30,12 +32,14 @@ struct HostSymbolPreview: View {
|
|||||||
symbol.image
|
symbol.image
|
||||||
.resizable().scaledToFit()
|
.resizable().scaledToFit()
|
||||||
.symbolRenderingMode(.monochrome)
|
.symbolRenderingMode(.monochrome)
|
||||||
|
if !label.isEmpty {
|
||||||
Text(label)
|
Text(label)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
.offset(symbol.offset)
|
.offset(symbol.offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
Reference in New Issue
Block a user