mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Start to make dynamic interfaces work
This commit is contained in:
Generated
+18
-69
@@ -37,26 +37,6 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
|
||||
dependencies = [
|
||||
"bincode_derive",
|
||||
"serde",
|
||||
"unty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode_derive"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
|
||||
dependencies = [
|
||||
"virtue",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@@ -98,9 +78,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
version = "3.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
@@ -113,9 +93,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.45"
|
||||
version = "1.2.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe"
|
||||
checksum = "9f50d563227a1c37cc0a263f64eca3334388c01c5e4c4861a9def205c614383c"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
@@ -177,21 +157,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
@@ -214,9 +179,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
@@ -303,9 +268,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.82"
|
||||
version = "0.3.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
|
||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
@@ -328,9 +293,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.28"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -640,11 +605,7 @@ dependencies = [
|
||||
name = "unshell-lib"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"libc",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"unshell-obfuscate",
|
||||
@@ -662,24 +623,12 @@ dependencies = [
|
||||
"unshell-crypt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unty"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
@@ -691,9 +640,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
|
||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -704,9 +653,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
|
||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -714,9 +663,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
|
||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -727,9 +676,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.105"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
|
||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
@@ -17,13 +17,13 @@ obfuscate = ["unshell-obfuscate/obfuscate"]
|
||||
[dependencies]
|
||||
# Base dependencies
|
||||
# libloading = {version = "0.8.9"}
|
||||
bincode = "2.0.1"
|
||||
# bincode = "2.0.1"
|
||||
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
||||
chrono = "0.4.42"
|
||||
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.145"
|
||||
|
||||
libc = "0.2.177"
|
||||
rand = "0.9.2"
|
||||
crossbeam-channel = "0.5.15"
|
||||
# libc = "0.2.177"
|
||||
# rand = "0.9.2"
|
||||
# crossbeam-channel = "0.5.15"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use bincode::{Decode, Encode};
|
||||
// use bincode::{Decode, Encode};
|
||||
|
||||
/// Mostly temporary server message type
|
||||
#[derive(Clone, Debug, Encode, Decode)]
|
||||
// #[derive(Clone, Debug, Encode, Decode)]
|
||||
pub enum Announcement {
|
||||
TestAnnouncement(String),
|
||||
// GetRuntimes,
|
||||
@@ -11,18 +11,18 @@ pub enum Announcement {
|
||||
// StartRuntimeAck(bool),
|
||||
}
|
||||
|
||||
const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
|
||||
// const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
|
||||
|
||||
impl Announcement {
|
||||
pub fn encode(&self) -> Vec<u8> {
|
||||
bincode::encode_to_vec(self, BINCODE_CONFIG).unwrap()
|
||||
}
|
||||
// impl Announcement {
|
||||
// pub fn encode(&self) -> Vec<u8> {
|
||||
// bincode::encode_to_vec(self, BINCODE_CONFIG).unwrap()
|
||||
// }
|
||||
|
||||
pub fn decode(bytes: &[u8]) -> Option<Self> {
|
||||
if let Ok((decoded, _)) = bincode::decode_from_slice(&bytes[..], BINCODE_CONFIG) {
|
||||
Some(decoded)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
// pub fn decode(bytes: &[u8]) -> Option<Self> {
|
||||
// if let Ok((decoded, _)) = bincode::decode_from_slice(&bytes[..], BINCODE_CONFIG) {
|
||||
// Some(decoded)
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
pub type ConfigStructKeys = Vec<ConfigStructField>;
|
||||
pub type ConfigStructValues = Vec<Value>;
|
||||
|
||||
pub struct Config {
|
||||
keys: ConfigStructKeys,
|
||||
values: ConfigStructValues,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum ConfigStructField {
|
||||
Header(String),
|
||||
Text(String),
|
||||
String {
|
||||
// Default value of string edit in struct
|
||||
#[serde(default)]
|
||||
default: String,
|
||||
max_length: Option<usize>,
|
||||
// Display string edit as password
|
||||
#[serde(default)]
|
||||
protected: Option<bool>,
|
||||
},
|
||||
Integer {
|
||||
// Default value of integer in struct
|
||||
#[serde(default)]
|
||||
default: i32,
|
||||
min: Option<i32>,
|
||||
max: Option<i32>,
|
||||
},
|
||||
// Checkbox
|
||||
// Dropdown
|
||||
// Collapsing header
|
||||
// Slider
|
||||
// ...
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
pub mod config_struct;
|
||||
mod tree;
|
||||
|
||||
pub use tree::{InterfaceData, InterfaceStruct, Tree, TreeMessage};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{ModuleError, Result, config::config_struct};
|
||||
|
||||
pub trait Tree {
|
||||
fn is_folder() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn get_children_string(&self) -> Vec<String> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn select_child(&self, child: &str, _message: TreeMessage) -> Result<TreeMessage>;
|
||||
|
||||
fn get_value(&self, _message: TreeMessage) -> TreeMessage {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn get_path(&self, elements: &mut Vec<&str>, message: TreeMessage) -> Result<TreeMessage> {
|
||||
if elements.is_empty() {
|
||||
return if Self::is_folder() {
|
||||
Ok(TreeMessage::Folder(self.get_children_string()))
|
||||
} else {
|
||||
Ok(self.get_value(message))
|
||||
};
|
||||
}
|
||||
|
||||
let child = elements.remove(0);
|
||||
|
||||
if Self::is_folder() {
|
||||
self.select_child(child, message)
|
||||
} else {
|
||||
Err(ModuleError::TreeMessageError(
|
||||
"This is a folder, not a file".into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self, path: &str, message: TreeMessage) -> Result<TreeMessage> {
|
||||
let mut path = if path.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
path.split("/").collect::<Vec<&str>>()
|
||||
};
|
||||
|
||||
self.get_path(&mut path, message)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub enum TreeMessage {
|
||||
RequestState,
|
||||
RequestStruct,
|
||||
RequestStructAndValue,
|
||||
|
||||
State(Value),
|
||||
Interface(InterfaceStruct),
|
||||
InterfaceAndValue(InterfaceStruct, InterfaceData),
|
||||
|
||||
Folder(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub enum InterfaceStruct {
|
||||
ConfigStruct(config_struct::ConfigStructKeys),
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub enum InterfaceData {
|
||||
ConfigStruct(config_struct::ConfigStructValues),
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
///Generic error type for module-related operations.
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ModuleError {
|
||||
LibLoadingError(String),
|
||||
// LogError(log::SetLoggerError),
|
||||
LinkError(String),
|
||||
CryptError(String),
|
||||
DatabaseError(String),
|
||||
SerdeJsonError(String),
|
||||
|
||||
TreeMessageError(String),
|
||||
|
||||
Error(String),
|
||||
}
|
||||
|
||||
impl From<&str> for ModuleError {
|
||||
fn from(value: &str) -> Self {
|
||||
Self::Error(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for ModuleError {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
Self::SerdeJsonError(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn std::error::Error>> for ModuleError {
|
||||
fn from(value: Box<dyn std::error::Error>) -> Self {
|
||||
ModuleError::Error(value.to_string())
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -1,25 +1,18 @@
|
||||
#![no_main]
|
||||
|
||||
pub mod config;
|
||||
mod error;
|
||||
pub mod logger;
|
||||
|
||||
mod announcement;
|
||||
use std::fmt::{self, Debug};
|
||||
|
||||
pub use error::ModuleError;
|
||||
|
||||
pub use announcement::Announcement;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, ModuleError>;
|
||||
|
||||
///Generic error type for module-related operations.
|
||||
#[derive(Debug)]
|
||||
pub enum ModuleError {
|
||||
LibLoadingError(String),
|
||||
// LogError(log::SetLoggerError),
|
||||
LinkError(String),
|
||||
CryptError(String),
|
||||
Error(String),
|
||||
}
|
||||
|
||||
impl std::error::Error for ModuleError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user