skeleton code for fetching channel data
Ready for open_channel to be implemented
This commit is contained in:
parent
c32afc6dab
commit
9b4909963d
@ -1,8 +1,9 @@
|
|||||||
|
use cursive::Cursive;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use crate::types::Channel;
|
use crate::types::Channel;
|
||||||
|
|
||||||
pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
|
pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
|
||||||
if let Ok(resp) = reqwest::get(format!("{}/channels/list", domain)).await {
|
if let Ok(resp) = reqwest::get(&format!("{}/channels/list", domain)).await {
|
||||||
let bytes = resp.bytes().await.unwrap();
|
let bytes = resp.bytes().await.unwrap();
|
||||||
let res: Result<Vec<Channel>, serde_json::Error> = serde_json::from_slice(&bytes);
|
let res: Result<Vec<Channel>, serde_json::Error> = serde_json::from_slice(&bytes);
|
||||||
return match res {
|
return match res {
|
||||||
@ -11,4 +12,14 @@ pub async fn fetch_channels(domain: &str) -> Option<Vec<Channel>>{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub mod sync {
|
||||||
|
use cursive::Cursive;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
|
pub fn open_channel(ip: Ipv4Addr, name: &str, s: &mut Cursive) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,7 +10,8 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use clap::{Arg, App};
|
use clap::{Arg, App};
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
use cursive::views::Dialog;
|
use cursive::views::{Dialog, TextView};
|
||||||
|
use cursive::menu::MenuTree;
|
||||||
use cursive::event::Key;
|
use cursive::event::Key;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
@ -66,6 +67,7 @@ async fn main() {
|
|||||||
|
|
||||||
app.add_global_callback('q', Cursive::quit);
|
app.add_global_callback('q', Cursive::quit);
|
||||||
app.add_global_callback(Key::Esc, |s| s.select_menubar());
|
app.add_global_callback(Key::Esc, |s| s.select_menubar());
|
||||||
|
app.set_autohide_menu(false); // don't hide the menubar all the time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -73,23 +75,24 @@ async fn main() {
|
|||||||
for server in config.servers.iter() {
|
for server in config.servers.iter() {
|
||||||
let name = match &server.name {
|
let name = match &server.name {
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
None => String::from("None")
|
//None => String::from(&format!("{}", server.ip))
|
||||||
|
None => String::from("None")
|
||||||
};
|
};
|
||||||
|
|
||||||
match http::fetch_channels(&server.ip).await {
|
app.menubar().add_subtree(&name, MenuTree::new()); // add server name
|
||||||
Some(channels) => {
|
// on action:
|
||||||
// add the channels to the current sub tree
|
// open up search able list of channels
|
||||||
for channel in channels {
|
// choose from that list of channels which one you want to see
|
||||||
app.menubar().add_leaf(&name, move |appref| {
|
|
||||||
let address = format!("{}", channel.ip);
|
|
||||||
appref.add_layer(Dialog::info(address));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
app.menubar().add_leaf(name, |_| {/* */});
|
if let Some(channels) = http::fetch_channels(&server.ip).await {
|
||||||
|
// add a bunch of actionable leafs to our sub tree
|
||||||
|
for channel in channels {
|
||||||
|
app.menubar().find_subtree(name.as_ref()).unwrap().add_leaf(channel.name.clone(), move |s| {
|
||||||
|
let (ip, name) = channel.parts();
|
||||||
|
http::sync::open_channel(ip, name, s);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
|
Loading…
Reference in New Issue
Block a user