Skip to content

Commit

Permalink
Add listener skeleton for logging on the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofl committed Feb 9, 2024
1 parent 650b243 commit 5b8aadb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/servers/tftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_trait::async_trait;
use async_tftp::server::TftpServerBuilder;
use std::path::PathBuf;
use crate::utils::validation;
use std::{sync::Arc};
use std::sync::Arc;

#[async_trait]
pub trait TFTPServerRunner {
Expand Down Expand Up @@ -80,4 +80,4 @@ mod tests {

test_server_e2e(proto, port, dl_cmd, file_in, file_out);
}
}
}
22 changes: 22 additions & 0 deletions src/ui/listener.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::ui::window::UI;
use async_trait::async_trait;
use std::sync::Arc;

#[async_trait]
pub trait Logger {
async fn logger(self: Arc<Self>);
}

#[async_trait]
impl Logger for UI {
async fn logger(self: Arc<Self>) {
tokio::spawn(async move {
let mut receiver = self.sender.subscribe();

loop {
let m = receiver.recv().await.unwrap();
print!("{m}");
};
});
}
}
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod window;
pub mod toggle_switch;
pub mod listener;
17 changes: 15 additions & 2 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::default;
use std::sync::Arc;

use eframe::egui;
use egui::DragValue;
Expand All @@ -7,6 +8,12 @@ use crate::servers::server::Protocol;
use tokio::sync::broadcast;



use crate::ui::listener;

use super::listener::Logger;


pub struct UI {
pub sender: broadcast::Sender<String>,

Expand Down Expand Up @@ -46,8 +53,14 @@ impl Default for UI {


impl UI {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
UI::default()
pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
let d = UI::default();
let e = Arc::new(&d);

// UI::logger()
// d.logger();
// d
d
}
}

Expand Down

0 comments on commit 5b8aadb

Please sign in to comment.