epiphany 8 месяцев назад
Родитель
Сommit
efc80394d5
2 измененных файлов с 10 добавлено и 0 удалено
  1. 9 0
      bin/fud/fud/src/event.rs
  2. 1 0
      bin/fud/fud/src/tasks.rs

+ 9 - 0
bin/fud/fud/src/event.rs

@@ -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;

+ 1 - 0
bin/fud/fud/src/tasks.rs

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