Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/hop/blob/main/Omega/tests/ui-memory/main.swift # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Omega / tests / ui-memory / main.swift` 24 lines ยท 1599 bytes Raw Blame History 1 import Foundation 2 3 // Reads habits.json and recents.json of the folder given, exactly as Hop does (the two Codable shapes are copied 4 // from Sources/Smart.swift and Sources/Recents.swift), and prints what it found. Omega/tests/check-ui.sh uses it 5 // to see that what the Omega panel wrote is something Hop can read back: a file Hop cannot decode is one Hop 6 // would start over from. 7 struct Launch: Codable { var app: String; var from: String; var hour: Int; var at: Date } 8 struct Entry: Codable { var path: String; var machine: String?; var count: Int; var last: Date } 9 10 let dir = URL(fileURLWithPath: CommandLine.arguments[1]) 11 func read(_ name: String, _ t: T.Type) -> T? { 12 guard let d = try? Data(contentsOf: dir.appendingPathComponent(name)) else { return nil } 13 return try? JSONDecoder().decode(t, from: d) 14 } 15 let now = Date() 16 if let h = read("habits.json", [Launch].self) { 17 let fresh = h.filter { abs($0.at.timeIntervalSince(now)) < 300 } 18 let hourNow = Calendar.current.component(.hour, from: now) 19 print("habits \(h.count) fresh \(fresh.count) last \(h.last.map { "\($0.app) from [\($0.from)] hour-now \(abs($0.hour - hourNow) <= 1 || abs($0.hour - hourNow) == 23)" } ?? "none")") 20 } else { print("habits unreadable") } 21 if let r = read("recents.json", [String: Entry].self) { 22 let rows = r.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value.count)\($0.value.machine.map { "@" + $0 } ?? "")\(abs($0.value.last.timeIntervalSince(now)) < 300 ? "*" : "")" } 23 print("recents \(r.count) \(rows.joined(separator: " "))") 24 } else { print("recents unreadable") }