|
| 1 | +/// Isolated test harness for the node controller window egui components. |
| 2 | +/// This example tests the controller rendering without starting Bevy. |
| 3 | +/// |
| 4 | +/// Environment variables (all optional): |
| 5 | +/// - CONTROLLER: Controller to display (FileBrowser, Terminal, SystemInfo, PackageManager, DesktopViewer) [default: SystemInfo] |
| 6 | +/// |
| 7 | +/// Usage: cargo run --example client_gui_node_controller --features client-gui |
| 8 | +/// |
| 9 | +/// Examples: |
| 10 | +/// CONTROLLER=FileBrowser cargo run --example client_gui_node_controller --features client-gui |
| 11 | +/// CONTROLLER=Terminal cargo run --example client_gui_node_controller --features client-gui |
| 12 | +/// CONTROLLER=SystemInfo cargo run --example client_gui_node_controller --features client-gui |
| 13 | +use eframe::egui; |
| 14 | +use sandpolis::{InstanceState, config::Configuration, MODELS}; |
| 15 | +use sandpolis::client::gui::controller::ControllerType; |
| 16 | +use sandpolis_core::InstanceId; |
| 17 | +use sandpolis_database::{DatabaseLayer, config::DatabaseConfig}; |
| 18 | +use std::env; |
| 19 | + |
| 20 | +#[tokio::main] |
| 21 | +async fn main() -> eframe::Result<()> { |
| 22 | + // Set up tracing |
| 23 | + tracing_subscriber::fmt::init(); |
| 24 | + |
| 25 | + // Read configuration from environment |
| 26 | + let controller = env::var("CONTROLLER") |
| 27 | + .ok() |
| 28 | + .and_then(|s| parse_controller(&s)) |
| 29 | + .unwrap_or(ControllerType::SystemInfo); |
| 30 | + |
| 31 | + // Create minimal configuration |
| 32 | + let config = Configuration::default(); |
| 33 | + |
| 34 | + // Create in-memory database |
| 35 | + let db_config = DatabaseConfig { |
| 36 | + storage: None, |
| 37 | + ephemeral: true, |
| 38 | + }; |
| 39 | + let database = DatabaseLayer::new(db_config, &*MODELS).unwrap(); |
| 40 | + |
| 41 | + // Create instance state |
| 42 | + let state = InstanceState::new(config.clone(), database).await.unwrap(); |
| 43 | + let instance_id = state.instance.instance_id; |
| 44 | + |
| 45 | + println!("Testing node controller with:"); |
| 46 | + println!(" Controller: {:?}", controller); |
| 47 | + println!(" Instance ID: {}", instance_id); |
| 48 | + |
| 49 | + let options = eframe::NativeOptions { |
| 50 | + viewport: egui::ViewportBuilder::default() |
| 51 | + .with_inner_size([650.0, 500.0]) |
| 52 | + .with_title("Node Controller Test Harness"), |
| 53 | + ..Default::default() |
| 54 | + }; |
| 55 | + |
| 56 | + eframe::run_native( |
| 57 | + "Node Controller Test", |
| 58 | + options, |
| 59 | + Box::new(move |_cc| Ok(Box::new(NodeControllerTestApp::new(controller, instance_id, state)))), |
| 60 | + ) |
| 61 | +} |
| 62 | + |
| 63 | +fn parse_controller(s: &str) -> Option<ControllerType> { |
| 64 | + match s { |
| 65 | + "FileBrowser" => Some(ControllerType::FileBrowser), |
| 66 | + "Terminal" => Some(ControllerType::Terminal), |
| 67 | + "SystemInfo" => Some(ControllerType::SystemInfo), |
| 68 | + "PackageManager" => Some(ControllerType::PackageManager), |
| 69 | + "DesktopViewer" => Some(ControllerType::DesktopViewer), |
| 70 | + _ => None, |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +struct NodeControllerTestApp { |
| 75 | + controller_type: ControllerType, |
| 76 | + instance_id: InstanceId, |
| 77 | + state: InstanceState, |
| 78 | +} |
| 79 | + |
| 80 | +impl NodeControllerTestApp { |
| 81 | + fn new(controller_type: ControllerType, instance_id: InstanceId, state: InstanceState) -> Self { |
| 82 | + Self { |
| 83 | + controller_type, |
| 84 | + instance_id, |
| 85 | + state, |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +impl eframe::App for NodeControllerTestApp { |
| 91 | + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { |
| 92 | + egui::CentralPanel::default().show(ctx, |ui| { |
| 93 | + ui.heading("Node Controller Component Test"); |
| 94 | + ui.separator(); |
| 95 | + |
| 96 | + ui.label(format!("Controller: {}", self.controller_type.display_name())); |
| 97 | + ui.label(format!("Instance: {}", self.instance_id)); |
| 98 | + |
| 99 | + ui.add_space(20.0); |
| 100 | + |
| 101 | + // Render the actual controller component in a frame |
| 102 | + egui::Frame::new() |
| 103 | + .fill(ui.visuals().window_fill()) |
| 104 | + .stroke(ui.visuals().window_stroke()) |
| 105 | + .corner_radius(ui.visuals().window_corner_radius) |
| 106 | + .inner_margin(8.0) |
| 107 | + .show(ui, |ui| { |
| 108 | + ui.set_width(600.0); |
| 109 | + ui.set_height(400.0); |
| 110 | + |
| 111 | + // Call the actual render function with real state |
| 112 | + match self.controller_type { |
| 113 | + ControllerType::FileBrowser => { |
| 114 | + #[cfg(feature = "layer-filesystem")] |
| 115 | + sandpolis::client::gui::controller::file_browser::render( |
| 116 | + ui, |
| 117 | + &self.state, |
| 118 | + self.instance_id, |
| 119 | + ); |
| 120 | + #[cfg(not(feature = "layer-filesystem"))] |
| 121 | + ui.label("Filesystem layer not enabled"); |
| 122 | + } |
| 123 | + ControllerType::Terminal => { |
| 124 | + #[cfg(feature = "layer-shell")] |
| 125 | + sandpolis::client::gui::controller::terminal::render( |
| 126 | + ui, |
| 127 | + &self.state, |
| 128 | + self.instance_id, |
| 129 | + ); |
| 130 | + #[cfg(not(feature = "layer-shell"))] |
| 131 | + ui.label("Shell layer not enabled"); |
| 132 | + } |
| 133 | + ControllerType::SystemInfo => { |
| 134 | + #[cfg(feature = "layer-inventory")] |
| 135 | + sandpolis::client::gui::controller::system_info::render( |
| 136 | + ui, |
| 137 | + &self.state, |
| 138 | + self.instance_id, |
| 139 | + ); |
| 140 | + #[cfg(not(feature = "layer-inventory"))] |
| 141 | + ui.label("Inventory layer not enabled"); |
| 142 | + } |
| 143 | + ControllerType::PackageManager => { |
| 144 | + sandpolis::client::gui::controller::package_manager::render( |
| 145 | + ui, |
| 146 | + &self.state, |
| 147 | + self.instance_id, |
| 148 | + ); |
| 149 | + } |
| 150 | + ControllerType::DesktopViewer => { |
| 151 | + #[cfg(feature = "layer-desktop")] |
| 152 | + sandpolis::client::gui::controller::desktop_viewer::render( |
| 153 | + ui, |
| 154 | + &self.state, |
| 155 | + self.instance_id, |
| 156 | + ); |
| 157 | + #[cfg(not(feature = "layer-desktop"))] |
| 158 | + ui.label("Desktop layer not enabled"); |
| 159 | + } |
| 160 | + ControllerType::None => { |
| 161 | + ui.label("No controller selected"); |
| 162 | + } |
| 163 | + } |
| 164 | + }); |
| 165 | + }); |
| 166 | + } |
| 167 | +} |
0 commit comments