diff options
author | metamuffin <metamuffin@disroot.org> | 2022-12-11 10:40:15 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-12-11 10:40:15 +0100 |
commit | 62172003909956850879dee1252980b2547f8451 (patch) | |
tree | 9727c256127b6a55339d6dcba1b0b21bf978e4c5 /client-native-gui | |
parent | 15f22441826983120a940fda00e5cfa39dddd7b3 (diff) | |
download | keks-meet-62172003909956850879dee1252980b2547f8451.tar keks-meet-62172003909956850879dee1252980b2547f8451.tar.bz2 keks-meet-62172003909956850879dee1252980b2547f8451.tar.zst |
requestable resources (native gui)
Diffstat (limited to 'client-native-gui')
-rw-r--r-- | client-native-gui/src/main.rs | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/client-native-gui/src/main.rs b/client-native-gui/src/main.rs index c973fb6..69d1657 100644 --- a/client-native-gui/src/main.rs +++ b/client-native-gui/src/main.rs @@ -10,8 +10,7 @@ use client_native_lib::{ use eframe::egui; use egui::{Ui, Visuals}; use std::{ - collections::{HashMap, HashSet}, - ops::Deref, + collections::HashMap, sync::{Arc, RwLock}, }; use tokio::task::JoinHandle; @@ -44,6 +43,32 @@ enum App { Ingame(Ingame), } +struct Ingame { + instance: Arc<Instance>, + handler: Arc<Handler>, +} + +struct Handler { + peers: RwLock<HashMap<usize, GuiPeer>>, +} + +struct GuiPeer { + peer: Arc<Peer>, + resources: HashMap<String, GuiResource>, + username: Option<String>, +} + +struct GuiResource { + info: ProvideInfo, + state: GuiResourceState, +} + +enum GuiResourceState { + Available, + Connecting, + Connected, +} + impl App { pub fn new() -> Self { Self::Prejoin("longtest".to_string(), "blub".to_string()) @@ -83,10 +108,6 @@ impl eframe::App for App { } } -struct Ingame { - instance: Arc<Instance>, - handler: Arc<Handler>, -} impl Ingame { pub async fn new(config: Config) -> Self { let handler = Arc::new(Handler::new()); @@ -100,28 +121,46 @@ impl Ingame { } pub fn ui(&self, ui: &mut Ui) { - for (_pid, peer) in self.handler.peers.read().unwrap().deref() { + for peer in self.handler.peers.write().unwrap().values_mut() { ui.collapsing(peer.display_name(), |ui| { - for (_rid, resource) in peer.resources.iter() { - ui.label(&format!( - "{} {} {:?}", - resource.id, resource.kind, resource.label - )); - if ui.button("Request").clicked() {} + for resource in peer.resources.values_mut() { + resource.ui(ui, &peer.peer) } }); } } } - -struct Handler { - peers: RwLock<HashMap<usize, GuiPeer>>, -} - -struct GuiPeer { - peer: Arc<Peer>, - resources: HashMap<String, ProvideInfo>, - username: Option<String>, +impl GuiResource { + pub fn ui(&mut self, ui: &mut Ui, peer: &Arc<Peer>) { + ui.label(&format!( + "{} {} {:?}", + self.info.id, self.info.kind, self.info.label + )); + match self.state { + GuiResourceState::Available => { + if ui.button("Enable").clicked() { + let id = self.info.id.clone(); + let peer = peer.clone(); + self.state = GuiResourceState::Connecting; + tokio::spawn(async move { peer.request_resource(id).await }); + } + } + GuiResourceState::Connecting => { + ui.horizontal(|ui| { + ui.spinner(); + ui.label("Connecting...") + }); + } + GuiResourceState::Connected => { + if ui.button("Disable").clicked() { + let id = self.info.id.clone(); + let peer = peer.clone(); + self.state = GuiResourceState::Available; + tokio::spawn(async move { peer.request_stop_resource(id).await }); + } + } + } + } } impl Handler { @@ -170,7 +209,13 @@ impl EventHandler for Handler { info: client_native_lib::protocol::ProvideInfo, ) -> client_native_lib::DynFut<()> { if let Some(gp) = self.peers.write().unwrap().get_mut(&peer.id) { - gp.resources.insert(info.id.clone(), info); + gp.resources.insert( + info.id.clone(), + GuiResource { + info, + state: GuiResourceState::Available, + }, + ); } Box::pin(async move {}) } @@ -192,6 +237,13 @@ impl EventHandler for Handler { resource: &client_native_lib::protocol::ProvideInfo, channel: client_native_lib::peer::TransportChannel, ) -> client_native_lib::DynFut<()> { + if let Some(gp) = self.peers.write().unwrap().get_mut(&peer.id) { + if let Some(gr) = gp.resources.get_mut(&resource.id) { + gr.state = GuiResourceState::Connected + + // TODO + } + } Box::pin(async move {}) } |