fud/event: add Ready event

This commit is contained in:
epiphany
2025-12-03 11:34:12 +00:00
parent 4e16964d8e
commit efc80394d5
2 changed files with 10 additions and 0 deletions

View File

@@ -94,6 +94,7 @@ pub struct SeedersFound {
#[derive(Clone, Debug)]
pub enum FudEvent {
Ready,
DownloadStarted(DownloadStarted),
ChunkDownloadCompleted(ChunkDownloadCompleted),
MetadataDownloadCompleted(MetadataDownloadCompleted),
@@ -217,6 +218,7 @@ impl From<SeedersFound> for JsonValue {
impl From<FudEvent> for JsonValue {
fn from(event: FudEvent) -> JsonValue {
match event {
FudEvent::Ready => json_map([("event", json_str("ready"))]),
FudEvent::DownloadStarted(info) => {
json_map([("event", json_str("download_started")), ("info", info.into())])
}
@@ -282,5 +284,12 @@ macro_rules! notify_event {
}))
.await;
};
// This is for `FudEvent`s with no fields
($fud:expr, $event:ident) => {
$fud
.event_publisher
.notify(FudEvent::$event)
.await;
};
}
pub(crate) use notify_event;

View File

@@ -50,6 +50,7 @@ pub async fn handle_dht_events(fud: Arc<Fud>) -> Result<()> {
}
DhtEvent::BootstrapCompleted => {
let _ = fud.init().await;
notify_event!(fud, Ready);
}
_ => {}
}