tidy
This commit is contained in:
@@ -5,7 +5,7 @@ use client_network::{
|
|||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, CentralPanel, CollapsingHeader, Color32, Context, CornerRadius, Frame, Id, Layout,
|
Align, CentralPanel, CollapsingHeader, Color32, Context, CornerRadius, Frame, Id, Layout,
|
||||||
ProgressBar, Response, ScrollArea, SidePanel, Stroke, TopBottomPanel, Ui, ViewportCommand,
|
ProgressBar, ScrollArea, SidePanel, Stroke, TopBottomPanel, Ui, ViewportCommand,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@@ -278,6 +278,7 @@ impl eframe::App for P2PClientApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.remaining_chunks.is_empty() {
|
if self.remaining_chunks.is_empty() {
|
||||||
|
self.current_total_chunks = None;
|
||||||
self.current_received_chunks = 0;
|
self.current_received_chunks = 0;
|
||||||
println!("bigfile téléchargé");
|
println!("bigfile téléchargé");
|
||||||
}
|
}
|
||||||
@@ -431,12 +432,17 @@ impl eframe::App for P2PClientApp {
|
|||||||
if ui.button("Connect").clicked() {
|
if ui.button("Connect").clicked() {
|
||||||
let addr = self.connect_address_input.clone();
|
let addr = self.connect_address_input.clone();
|
||||||
let name = self.connect_name_input.clone();
|
let name = self.connect_name_input.clone();
|
||||||
let _ = self
|
let _ = self.network_cmd_tx.send(
|
||||||
.network_cmd_tx
|
NetworkCommand::ConnectToServerPut(
|
||||||
.send(NetworkCommand::ConnectToServerPut(addr, name));
|
addr,
|
||||||
|
name.to_string(),
|
||||||
|
),
|
||||||
|
);
|
||||||
self.server_status = ServerStatus::Loading;
|
self.server_status = ServerStatus::Loading;
|
||||||
ui.close();
|
ui.close();
|
||||||
self.show_network_window = false;
|
self.show_network_window = false;
|
||||||
|
self.loaded_fs
|
||||||
|
.insert(name.to_string(), self.shared_tree.clone());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -520,56 +526,69 @@ impl eframe::App for P2PClientApp {
|
|||||||
for peer in &self.known_peers {
|
for peer in &self.known_peers {
|
||||||
let is_active =
|
let is_active =
|
||||||
self.active_peer.as_ref().map_or(false, |id| id == &peer.0); // if peer.id == self.active_peer_id
|
self.active_peer.as_ref().map_or(false, |id| id == &peer.0); // if peer.id == self.active_peer_id
|
||||||
|
//
|
||||||
// place spinner to the right of the label
|
if peer.0.eq(&self.connect_name_input) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let resp = if &self.active_server == &peer.0 {
|
let resp = ui.selectable_label(
|
||||||
let frame = Frame {
|
is_active,
|
||||||
fill: Color32::DARK_BLUE,
|
format!("{} (you)", peer.0),
|
||||||
stroke: Stroke::default(),
|
|
||||||
corner_radius: CornerRadius::from(0.5),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
frame
|
|
||||||
.show(ui, |ui| {
|
|
||||||
ui.selectable_label(
|
|
||||||
is_active,
|
|
||||||
format!("{}", peer.0),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.inner
|
|
||||||
} else {
|
|
||||||
ui.selectable_label(is_active, format!("{}", peer.0))
|
|
||||||
};
|
|
||||||
|
|
||||||
ui.add_space(4.0); // small gap
|
|
||||||
|
|
||||||
if self.loading_peers.contains(&peer.0) {
|
|
||||||
ui.with_layout(
|
|
||||||
Layout::right_to_left(Align::Center),
|
|
||||||
|ui| {
|
|
||||||
ui.spinner();
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if resp.clicked() {
|
if resp.clicked() {
|
||||||
self.active_peer = Some(peer.0.clone());
|
self.active_peer = Some(peer.0.clone());
|
||||||
// Request root content if not loaded
|
|
||||||
if !self
|
|
||||||
.loaded_fs
|
|
||||||
.contains_key(self.active_peer.as_ref().unwrap())
|
|
||||||
{
|
|
||||||
//todo!();
|
|
||||||
let _ =
|
|
||||||
self.network_cmd_tx.send(NetworkCommand::Discover(
|
|
||||||
peer.0.clone(),
|
|
||||||
"root".to_string(),
|
|
||||||
self.connected_address.clone(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
resp.context_menu(|ui| {
|
} else {
|
||||||
|
// place spinner to the right of the label
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
let resp = if &self.active_server == &peer.0 {
|
||||||
|
let frame = Frame {
|
||||||
|
fill: Color32::DARK_BLUE,
|
||||||
|
stroke: Stroke::default(),
|
||||||
|
corner_radius: CornerRadius::from(0.5),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
frame
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.selectable_label(
|
||||||
|
is_active,
|
||||||
|
format!("{}", peer.0),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.inner
|
||||||
|
} else {
|
||||||
|
ui.selectable_label(is_active, format!("{}", peer.0))
|
||||||
|
};
|
||||||
|
|
||||||
|
ui.add_space(4.0); // small gap
|
||||||
|
|
||||||
|
if self.loading_peers.contains(&peer.0) {
|
||||||
|
ui.with_layout(
|
||||||
|
Layout::right_to_left(Align::Center),
|
||||||
|
|ui| {
|
||||||
|
ui.spinner();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.clicked() {
|
||||||
|
self.active_peer = Some(peer.0.clone());
|
||||||
|
// Request root content if not loaded
|
||||||
|
if !self
|
||||||
|
.loaded_fs
|
||||||
|
.contains_key(self.active_peer.as_ref().unwrap())
|
||||||
|
{
|
||||||
|
//todo!();
|
||||||
|
let _ = self.network_cmd_tx.send(
|
||||||
|
NetworkCommand::Discover(
|
||||||
|
peer.0.clone(),
|
||||||
|
"root".to_string(),
|
||||||
|
self.connected_address.clone(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.context_menu(|ui| {
|
||||||
match self.server_status {
|
match self.server_status {
|
||||||
ServerStatus::Connected => {
|
ServerStatus::Connected => {
|
||||||
if ui
|
if ui
|
||||||
@@ -624,75 +643,8 @@ impl eframe::App for P2PClientApp {
|
|||||||
|
|
||||||
// ... autres boutons
|
// ... autres boutons
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// if self.loading_peers.contains(&peer.0) {
|
|
||||||
// ui.spinner();
|
|
||||||
// }
|
|
||||||
|
|
||||||
//if selectable.clicked() {
|
|
||||||
// switch to displaying this peer's tree
|
|
||||||
//self.active_peer = Some(peer.0.clone());
|
|
||||||
//// Request root content if not loaded
|
|
||||||
//if !self
|
|
||||||
// .loaded_fs
|
|
||||||
// .contains_key(self.active_peer.as_ref().unwrap())
|
|
||||||
//{
|
|
||||||
// //todo!();
|
|
||||||
// let _ = self.network_cmd_tx.send(NetworkCommand::Discover(
|
|
||||||
// peer.0.clone(),
|
|
||||||
// "root".to_string(),
|
|
||||||
// self.connected_address.clone(),
|
|
||||||
// ));
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//selectable.context_menu(|ui| {
|
|
||||||
// // ... action
|
|
||||||
// match self.server_status {
|
|
||||||
// ServerStatus::Connected => {
|
|
||||||
// if ui
|
|
||||||
// .button("Utiliser le peer en tant que serveur")
|
|
||||||
// .clicked()
|
|
||||||
// {
|
|
||||||
// self.active_server = peer.0.to_string();
|
|
||||||
// let res = self.network_cmd_tx.send(
|
|
||||||
// NetworkCommand::ServerHandshake(
|
|
||||||
// peer.0.to_string(),
|
|
||||||
// self.connected_address.clone(),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// _ => {}
|
|
||||||
// }
|
|
||||||
// if ui.button("Send Ping").clicked() {
|
|
||||||
// let res = self.network_cmd_tx.send(NetworkCommand::Ping(
|
|
||||||
// peer.0.to_string(),
|
|
||||||
// self.connected_address.clone(),
|
|
||||||
// ));
|
|
||||||
|
|
||||||
// self.loading_peers.push(peer.0.to_owned());
|
|
||||||
// }
|
|
||||||
// if ui.button("Send Nat Traversal Request").clicked() {
|
|
||||||
// match self.network_cmd_tx.send(NetworkCommand::NatTraversal(
|
|
||||||
// peer.0.to_string(),
|
|
||||||
// self.connected_address.clone(),
|
|
||||||
// )) {
|
|
||||||
// Ok(_) => {
|
|
||||||
// print!("[+] successfully sent nat traversal request")
|
|
||||||
// }
|
|
||||||
// Err(_) => {
|
|
||||||
// print!("[-] failed to send nat traversal request")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if ui.button("Infos").clicked() {
|
|
||||||
// // action 3
|
|
||||||
// ui.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // ... autres boutons
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user