interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / ui-memory / main.swift

24 lines · 1599 bytes Raw Blame History
1import 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.
7struct Launch: Codable { var app: String; var from: String; var hour: Int; var at: Date }
8struct Entry: Codable { var path: String; var machine: String?; var count: Int; var last: Date }
9
10let dir = URL(fileURLWithPath: CommandLine.arguments[1])
11func read<T: Decodable>(_ 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}
15let now = Date()
16if 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") }
21if 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") }