diff --git a/ShhShell/Host/History.swift b/ShhShell/Host/History.swift index bcc1091..53354b8 100644 --- a/ShhShell/Host/History.swift +++ b/ShhShell/Host/History.swift @@ -12,4 +12,5 @@ struct History: Identifiable, Codable { var host: Host var count: Int + var lastConnect: Date = .now } diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 0a67ce3..0e25ef7 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -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() } diff --git a/ShhShell/Views/Hosts/RecentsView.swift b/ShhShell/Views/Hosts/RecentsView.swift index 46e42f3..e2b3469 100644 --- a/ShhShell/Views/Hosts/RecentsView.swift +++ b/ShhShell/Views/Hosts/RecentsView.swift @@ -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..