import Foundation /// Launch counts per app, persisted to ~/Library/Application Support/FreeLaunch/usage.json. final class Usage { private var counts: [String: Int] = [:] private let file: URL init() { let support = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] let dir = support.appendingPathComponent("FreeLaunch", isDirectory: true) try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) file = dir.appendingPathComponent("usage.json") if let data = try? Data(contentsOf: file), let stored = try? JSONDecoder().decode([String: Int].self, from: data) { counts = stored } } func count(for entry: AppEntry) -> Int { counts[entry.url.path] ?? 0 } func record(_ entry: AppEntry) { counts[entry.url.path, default: 0] += 1 if let data = try? JSONEncoder().encode(counts) { try? data.write(to: file, options: .atomic) } } }