From 3ba5577b87357d8f1428944c229c325e0085f76b Mon Sep 17 00:00:00 2001 From: Michael Mikovsky <77305074+Astatin3@users.noreply.github.com> Date: Tue, 16 Dec 2025 22:23:54 -0700 Subject: [PATCH] Work on customizable config tool --- unshell-gui/src/payload_config/mod.rs | 21 +++- unshell-gui/src/payload_config/structs.rs | 129 ++++++++++++++++++++++ unshell-server/Cargo.toml | 19 ---- unshell-server/src/config/mod.rs | 1 + unshell-server/src/lib.rs | 1 + 5 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 unshell-gui/src/payload_config/structs.rs create mode 100644 unshell-server/src/config/mod.rs diff --git a/unshell-gui/src/payload_config/mod.rs b/unshell-gui/src/payload_config/mod.rs index aa9d412..fcee4b2 100644 --- a/unshell-gui/src/payload_config/mod.rs +++ b/unshell-gui/src/payload_config/mod.rs @@ -1,18 +1,27 @@ -#[derive(serde::Deserialize, serde::Serialize)] -pub struct PayloadConfig {} +// use crate::payload_config::structs::ConfigStructField; -struct ServerConfigState { - // config: Vec +mod structs; + +#[derive(serde::Deserialize, serde::Serialize)] +pub struct PayloadConfig { + config_struct: structs::Config, } +// struct ServerConfigState { +// // config: Vec +// } + impl PayloadConfig { pub fn update(&mut self, ui: &mut egui::Ui) { - ui.heading("Test"); + // ui.heading("Test"); + self.config_struct.update(ui); } } impl Default for PayloadConfig { fn default() -> Self { - Self {} + Self { + config_struct: structs::default_configurable(), + } } } diff --git a/unshell-gui/src/payload_config/structs.rs b/unshell-gui/src/payload_config/structs.rs new file mode 100644 index 0000000..de7d633 --- /dev/null +++ b/unshell-gui/src/payload_config/structs.rs @@ -0,0 +1,129 @@ +use std::collections::HashMap; + +use egui::TextEdit; + +#[derive(serde::Deserialize, serde::Serialize)] +enum ConfigStructField { + Header(String), + Text(String), + String { + default: Option, + max_length: Option, + protected: bool, + }, + Integer { + default: i32, + min: Option, + max: Option, + }, +} + +#[derive(serde::Deserialize, serde::Serialize)] +enum ConfigStructValue { + String(String), + Integer(i32), +} + +// #[derive(serde::Deserialize, serde::Serialize)] +// struct ConfigStruct { +// id: String, +// field: ConfigStructField, +// } + +#[derive(serde::Deserialize, serde::Serialize)] +pub struct Config { + config: Vec<(String, ConfigStructField)>, + state: HashMap, +} + +impl Config { + fn new(config: Vec<(String, ConfigStructField)>) -> Self { + Self { + config, + state: HashMap::default(), + } + } + + pub fn update(&mut self, ui: &mut egui::Ui) { + for (id, field) in &self.config { + match field { + ConfigStructField::Header(text) => { + ui.heading(text); + } + ConfigStructField::Text(text) => { + ui.label(text); + } + ConfigStructField::String { + default, + max_length, + protected, + } => { + let value = + if let Some(ConfigStructValue::String(value)) = self.state.get_mut(id) { + value + } else { + self.state.insert( + id.clone(), + ConfigStructValue::String(default.clone().unwrap_or(String::new())), + ); + if let Some(ConfigStructValue::String(value)) = self.state.get_mut(id) { + value + } else { + unreachable!() + } + }; + + let mut widget = TextEdit::singleline(value).password(*protected); + + if let Some(limit) = &max_length { + widget = widget.char_limit(*limit); + } + + ui.add(widget); + } + _ => {} // ConfigStructField::Integer { default, min, max } => todo!(), + } + } + + // match &self.field { + // ConfigStructField::Header(text) => { + // ui.heading(text); + // } + // ConfigStructField::Text(text) => { + // ui.label(text); + // } + // ConfigStructField::String { + // default, + // max_length, + // protected, + // } => ui.text_edit_singleline(), + // ConfigStructField::Integer { default, min, max } => todo!(), + // } + } +} + +pub fn default_configurable() -> Config { + Config::new(vec![ + ( + "Header".into(), + ConfigStructField::Header("Test Header!".into()), + ), + ("text".into(), ConfigStructField::Text("Test Text!".into())), + ( + "Config".into(), + ConfigStructField::String { + default: Some("Test String".into()), + max_length: Some(30), + protected: false, + }, + ), + ( + "Protected".into(), + ConfigStructField::String { + default: Some("Protected String".into()), + max_length: None, + protected: true, + }, + ), + ]) +} diff --git a/unshell-server/Cargo.toml b/unshell-server/Cargo.toml index a3a975a..dc579da 100644 --- a/unshell-server/Cargo.toml +++ b/unshell-server/Cargo.toml @@ -6,8 +6,6 @@ edition = "2024" [features] log_debug = ["unshell-lib/log_debug"] - - [dependencies] unshell-lib = {path = "../unshell-lib"} @@ -24,20 +22,3 @@ chrono = "0.4.42" static_init = "1.0.4" clap = {version = "4.5.53", features = ["derive"]} sled = "0.34.7" - -# tracing = "0.1.43" -# tracing-subscriber = {version="0.3.22", features = ["env-filter"] } - - -# async-trait = "0.1.89" -# axum = "0.8.7" -# axum-extra = "0.12.2" -# axum-login = "0.18.0" -# bcrypt = "0.17.1" -# jsonwebtoken = "10.2.0" -# serde = "1.0.228" -# serde_json = "1.0.145" -# tokio = {version = "1.48.0", features=["rt-multi-thread"]} -# tower-sessions = "0.14.0" -# tracing = "0.1.43" -# tracing-subscriber = "0.3.22" diff --git a/unshell-server/src/config/mod.rs b/unshell-server/src/config/mod.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/unshell-server/src/config/mod.rs @@ -0,0 +1 @@ + diff --git a/unshell-server/src/lib.rs b/unshell-server/src/lib.rs index 3789df1..0d1abcb 100644 --- a/unshell-server/src/lib.rs +++ b/unshell-server/src/lib.rs @@ -1,6 +1,7 @@ // #![macro_use] mod api; +mod config; pub mod logger; mod modules; mod server;