import Foundation import ParcelIPC import ParcelUI @MainActor final class AppFeedback { let controller: FeedbackController let model: FeedbackModel init( sensory: FeedbackSensory = FeedbackSensory(), onFailure: @escaping @MainActor (any Error) -> Void ) { model = FeedbackModel() controller = FeedbackController(model: model, sensory: sensory, onFailure: onFailure) } func run(_ args: [String]) async throws -> JSONValue { if args.isEmpty || args == ["list"] { return .object([ "current": try model.current.map(Self.json) ?? .null, "visible": .bool(controller.isVisible), "key": .bool(controller.isKeyWindow), "recent": try Self.json(model.recent), ]) } if args == ["show-current"], model.current != nil { controller.showCurrent() } else if args == ["dismiss"] { if let current = model.current { model.dismiss(current.id) } } else { throw IPCError( code: "invalid_command", message: AppText.string("Use feedback list, show-current, or dismiss.")) } return .object(["accepted": .bool(true)]) } private static func json(_ value: Value) throws -> JSONValue { try JSONDecoder().decode(JSONValue.self, from: JSONEncoder().encode(value)) } }