Merge branch 'main' of https://github.com/Tensamin/Iota
# Conflicts: # Cargo.lock # Cargo.toml # src/auth/auth_connector.rs # src/main.rs # src/omikron/omikron_connection.rs
This commit is contained in:
commit
3d7ae99eef
7 changed files with 549 additions and 74 deletions
|
|
@ -1,4 +1,8 @@
|
|||
use std::time::Duration;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
use request::blocking::{Client, Response};
|
||||
use request::header::CONTENT_TYPE;
|
||||
use uuid::{uuid, Uuid};
|
||||
use reqwest::header::CONTENT_TYPE;
|
||||
use json::JsonValue;
|
||||
|
|
@ -43,7 +47,7 @@ impl AuthConnector {
|
|||
let json = res.text().await.ok()?;
|
||||
let cv = CommunicationValue::from_json(&json);
|
||||
Option::from(cv.is_type(CommunicationType::Success))
|
||||
|
||||
|
||||
}
|
||||
|
||||
pub async fn get_uuid(username: &str) -> Option<Uuid> {
|
||||
|
|
@ -57,13 +61,13 @@ impl AuthConnector {
|
|||
}
|
||||
Uuid::parse_str(cv.get_data(DataTypes::UserId).unwrap()).ok()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_user(user_id: Uuid) -> Option<AuthUser> {
|
||||
let url = format!("https://auth.tensamin.methanium.net/api/get/{}/", user_id);
|
||||
let client = Self::client();
|
||||
let res = client.get(&url).send().await.ok()?;
|
||||
let json = res.text().await.ok()?;
|
||||
|
||||
|
||||
let mut cv = CommunicationValue::from_json(&json);
|
||||
if cv.comm_type != CommunicationType::Success {
|
||||
return None;
|
||||
|
|
@ -152,5 +156,5 @@ impl AuthConnector {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
1
src/gui/mod.rs
Normal file
1
src/gui/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod ratatui_interface;
|
||||
57
src/gui/ratatui_interface.rs
Normal file
57
src/gui/ratatui_interface.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use color_eyre::Result;
|
||||
use crossterm::event::{self, Event};
|
||||
use ratatui::{DefaultTerminal, Frame};
|
||||
use ratatui::widgets::{Block, Paragraph,};
|
||||
use ratatui::layout::{Constraint, Layout, Direction};
|
||||
use sys_info;
|
||||
|
||||
use crate::omikron::omikron_connection::OmikronConnection;
|
||||
|
||||
pub fn launch(connection_status: bool) -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
let terminal = ratatui::init();
|
||||
let result = run(terminal, connection_status);
|
||||
ratatui::restore();
|
||||
result
|
||||
}
|
||||
|
||||
fn run(mut terminal: DefaultTerminal, connection_status: bool) -> Result<()> {
|
||||
loop {
|
||||
terminal.draw(|frame| render(frame, connection_status))?;
|
||||
if matches!(event::read()?, Event::Key(_)) {
|
||||
break Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render(frame: &mut Frame, connection_status: bool) {
|
||||
let main_layout = Layout::default().direction(Direction::Horizontal).margin(1).constraints([Constraint::Percentage((100))].as_ref());
|
||||
let main_block = Block::bordered().title("Tensamin - Iota");
|
||||
let main_chunks = main_layout.split(frame.area());
|
||||
|
||||
let [left, right] = Layout::horizontal([Constraint::Fill(1); 2]).areas(main_chunks[0]);
|
||||
let [top_right, bottom_right] = Layout::vertical([Constraint::Fill(1); 2]).areas(right);
|
||||
|
||||
let block_logs = Block::bordered().title("Logs");
|
||||
let block_systeminfo = Block::bordered().title("System Info");
|
||||
let block_ping = Block::bordered().title("Ping");
|
||||
|
||||
let mut operating_system: String;
|
||||
match sys_info::os_type() {
|
||||
Ok(os) => operating_system = os,
|
||||
Err(error) => operating_system = error.to_string(),
|
||||
}
|
||||
|
||||
let mut text_content: String = String::from("");
|
||||
text_content.push_str("Operating System: ");
|
||||
text_content.push_str(operating_system.as_str());
|
||||
text_content.push_str("\nConnection: ");
|
||||
text_content.push_str(if connection_status {"Connected"} else {"Disconnected"});
|
||||
|
||||
let paragraph_systeminfo = Paragraph::new(text_content).block(block_systeminfo);
|
||||
|
||||
frame.render_widget(Block::bordered().title("Tensamin - Iota"), frame.area());
|
||||
frame.render_widget(Block::bordered().title("Logs"), left);
|
||||
frame.render_widget(paragraph_systeminfo, top_right);
|
||||
frame.render_widget(Block::bordered().title("Ping"), bottom_right);
|
||||
}
|
||||
37
src/main.rs
37
src/main.rs
|
|
@ -1,45 +1,44 @@
|
|||
use tokio::runtime::Runtime;
|
||||
use std::process::{Command, ExitStatus};
|
||||
use json::{
|
||||
self
|
||||
};
|
||||
use futures_util::SinkExt;
|
||||
use json::{self};
|
||||
use uuid::Uuid;
|
||||
|
||||
mod data;
|
||||
mod omikron;
|
||||
mod util;
|
||||
mod users;
|
||||
mod gui {
|
||||
pub mod ratatui_interface;
|
||||
}
|
||||
mod auth;
|
||||
|
||||
use crate::auth::auth_connector::AuthConnector;
|
||||
use crate::omikron::omikron_connection::{OmikronConnection};
|
||||
use crate::data::communication::{CommunicationValue, CommunicationType, DataTypes};
|
||||
use gui::{ratatui_interface};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let alois = AuthConnector::get_uuid("aloisianer").await;
|
||||
if alois.is_none() {
|
||||
println!("No UUID");
|
||||
return
|
||||
}
|
||||
println!("{}", alois.unwrap());
|
||||
let omikron = OmikronConnection::new();
|
||||
let mut omikron: OmikronConnection = OmikronConnection::new();
|
||||
|
||||
omikron.connect().await;
|
||||
|
||||
OmikronConnection::send_message_static(
|
||||
&omikron.writer,
|
||||
omikron.send_message(
|
||||
CommunicationValue::new(
|
||||
CommunicationType::Identification
|
||||
)
|
||||
.add_data(DataTypes::UserIds, Uuid::new_v4().to_string())
|
||||
.add_data(DataTypes::IotaId, Uuid::new_v4().to_string())
|
||||
.add_data(DataTypes::UserIds, json::JsonValue::String(Uuid::new_v4().to_string()))
|
||||
.add_data(DataTypes::IotaId, json::JsonValue::String(Uuid::new_v4().to_string()))
|
||||
.to_json()
|
||||
.to_string()
|
||||
.as_mut().parse().unwrap()
|
||||
.as_mut()
|
||||
.to_string()
|
||||
).await;
|
||||
|
||||
|
||||
omikron.close().await;
|
||||
|
||||
|
||||
let mut child = Command::new("sleep").arg("2").spawn().unwrap();
|
||||
let _result = child.wait().unwrap();
|
||||
|
||||
|
||||
println!("reached end of main");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use std::io::{Read, Write};
|
|||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum MessageState {
|
||||
Read,
|
||||
Received,
|
||||
|
|
|
|||
Loading…
Reference in a new issue