Show VM status, use separate threads for VM operations
This commit is contained in:
15
src/gui.rs
15
src/gui.rs
@@ -89,7 +89,7 @@ pub struct AppState {
|
|||||||
pub node: String,
|
pub node: String,
|
||||||
pub nodes: Vec<String>,
|
pub nodes: Vec<String>,
|
||||||
pub vms: Vec<(u32, String)>,
|
pub vms: Vec<(u32, String)>,
|
||||||
pub vm_status: String,
|
pub vm_statuses: std::collections::HashMap<u32, String>,
|
||||||
pub log_buffer: Vec<String>,
|
pub log_buffer: Vec<String>,
|
||||||
pub is_connected: bool,
|
pub is_connected: bool,
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ impl AppState {
|
|||||||
node: config.node.clone(),
|
node: config.node.clone(),
|
||||||
nodes: Vec::new(),
|
nodes: Vec::new(),
|
||||||
vms: Vec::new(),
|
vms: Vec::new(),
|
||||||
vm_status: "未知".to_string(),
|
vm_statuses: std::collections::HashMap::new(),
|
||||||
log_buffer: log,
|
log_buffer: log,
|
||||||
is_connected: false,
|
is_connected: false,
|
||||||
}
|
}
|
||||||
@@ -299,6 +299,11 @@ impl eframe::App for App {
|
|||||||
state.vms = vms.clone();
|
state.vms = vms.clone();
|
||||||
state.vm_id = vms[0].0;
|
state.vm_id = vms[0].0;
|
||||||
state.add_log(&format!("✓ 找到 {} 台虚拟机", vms.len()));
|
state.add_log(&format!("✓ 找到 {} 台虚拟机", vms.len()));
|
||||||
|
for (vid, _) in vms {
|
||||||
|
if let Ok(status) = c.get_vm_status(&node, vid).await {
|
||||||
|
state.vm_statuses.insert(vid, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
state.add_log("未找到虚拟机");
|
state.add_log("未找到虚拟机");
|
||||||
}
|
}
|
||||||
@@ -319,6 +324,7 @@ impl eframe::App for App {
|
|||||||
// 虚拟机列表(每行带操作按钮)
|
// 虚拟机列表(每行带操作按钮)
|
||||||
ui.label("虚拟机列表:");
|
ui.label("虚拟机列表:");
|
||||||
let vms_list = st.vms.clone();
|
let vms_list = st.vms.clone();
|
||||||
|
let statuses = st.vm_statuses.clone();
|
||||||
let client_ref = st.client.clone();
|
let client_ref = st.client.clone();
|
||||||
let node_ref = st.node.clone();
|
let node_ref = st.node.clone();
|
||||||
egui::ScrollArea::vertical().max_height(180.0).stick_to_bottom(true).show(ui, |ui| {
|
egui::ScrollArea::vertical().max_height(180.0).stick_to_bottom(true).show(ui, |ui| {
|
||||||
@@ -327,8 +333,13 @@ impl eframe::App for App {
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
for (_, (id, name)) in vms_list.iter().enumerate() {
|
for (_, (id, name)) in vms_list.iter().enumerate() {
|
||||||
|
let status = statuses.get(id).cloned().unwrap_or_else(|| "未知".to_string());
|
||||||
|
let status_color = if status == "running" { egui::Color32::GREEN } else { egui::Color32::GRAY };
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
ui.colored_label(status_color, format!("●"));
|
||||||
ui.label(format!("{} ({})", name, id));
|
ui.label(format!("{} ({})", name, id));
|
||||||
|
ui.colored_label(egui::Color32::LIGHT_BLUE, format!("[{}]", status));
|
||||||
ui.add_space(10.0);
|
ui.add_space(10.0);
|
||||||
|
|
||||||
let client = client_ref.clone();
|
let client = client_ref.clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user