Files
phbar/Sources/phbar/Models/Event/PHEvent.swift
T
2026-07-12 00:50:11 +02:00

25 lines
929 B
Swift

import Foundation
/// A subscribable event that drives block refreshes.
///
/// Modeled as a `String`-backed value so it decodes straight from the TOML
/// config (e.g. `events = ["volume", "network"]`). phbar ships **no compiled
/// event sources**: every name resolves at runtime to an external recognizer
/// loaded from `~/.config/phbar/events/<name>/` a `dlopen`'d library whose
/// root object conforms to `PHEventRecognizer`. To add an event, install a
/// recognizer folder; no host code change is required.
struct PHEvent: Hashable, Sendable {
let rawValue: String
init(rawValue: String) { self.rawValue = rawValue }
/// Convenience initializer for ad-hoc event names.
init(_ rawValue: String) { self.rawValue = rawValue }
}
extension PHEvent: Decodable {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.init(rawValue: try container.decode(String.self))
}
}