Split TaskType::Command into wait and no-wait variants

Allows for apps to be simply launched
This commit is contained in:
2Shirt 2025-02-22 20:44:28 -08:00
parent c5a9dc80cb
commit f1c3743584
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
5 changed files with 66 additions and 35 deletions

View file

@ -218,7 +218,7 @@ impl App {
} }
// BCD // BCD
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bcdedit.exe")), PathBuf::from(format!("{system32}/bcdedit.exe")),
vec![ vec![
String::from("/store"), String::from("/store"),
@ -235,11 +235,11 @@ impl App {
)); ));
// Bitlocker // Bitlocker
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/manage-bde.exe")), PathBuf::from(format!("{system32}/manage-bde.exe")),
vec![String::from("-status"), format!("{letter_os}:")], vec![String::from("-status"), format!("{letter_os}:")],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/manage-bde.exe")), PathBuf::from(format!("{system32}/manage-bde.exe")),
vec![ vec![
String::from("-protectors"), String::from("-protectors"),
@ -249,19 +249,19 @@ impl App {
)); ));
// DISM Health // DISM Health
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/dism.exe")), PathBuf::from(format!("{system32}/dism.exe")),
vec![format!("{letter_os}:")], vec![format!("{letter_os}:")],
)); ));
// Filesystem Health // Filesystem Health
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/chkdsk.exe")), PathBuf::from(format!("{system32}/chkdsk.exe")),
vec![format!("{letter_os}:")], vec![format!("{letter_os}:")],
)); ));
// Registry // Registry
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![ vec![
String::from("load"), String::from("load"),
@ -269,7 +269,7 @@ impl App {
format!("{letter_os}:\\Windows\\System32\\config\\SOFTWARE"), format!("{letter_os}:\\Windows\\System32\\config\\SOFTWARE"),
], ],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![ vec![
String::from("load"), String::from("load"),
@ -277,7 +277,7 @@ impl App {
format!("{letter_os}:\\Windows\\System32\\config\\SYSTEM"), format!("{letter_os}:\\Windows\\System32\\config\\SYSTEM"),
], ],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![ vec![
String::from("load"), String::from("load"),
@ -285,15 +285,15 @@ impl App {
format!("{letter_os}:\\Windows\\System32\\config\\DEFAULT"), format!("{letter_os}:\\Windows\\System32\\config\\DEFAULT"),
], ],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![String::from("unload"), String::from("HKLM\\TmpSoftware")], vec![String::from("unload"), String::from("HKLM\\TmpSoftware")],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![String::from("unload"), String::from("HKLM\\TmpSystem")], vec![String::from("unload"), String::from("HKLM\\TmpSystem")],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")), PathBuf::from(format!("{system32}/reg.exe")),
vec![String::from("unload"), String::from("HKU\\TmpDefault")], vec![String::from("unload"), String::from("HKU\\TmpDefault")],
)); ));
@ -532,7 +532,7 @@ impl App {
info!("Handling Task: {task:?}"); info!("Handling Task: {task:?}");
match self.cur_mode { match self.cur_mode {
Mode::BootScan => { Mode::BootScan => {
if let TaskType::Command(cmd_path, cmd_args) = &task.task_type { if let TaskType::CommandWait(cmd_path, _cmd_args) = &task.task_type {
let mut cmd_name = ""; let mut cmd_name = "";
if let Some(path) = cmd_path.file_name() { if let Some(path) = cmd_path.file_name() {
if let Some(cmd_str) = path.to_str() { if let Some(cmd_str) = path.to_str() {
@ -577,7 +577,9 @@ impl App {
} }
_ => { _ => {
match task.task_type { match task.task_type {
TaskType::Command(_, _) | TaskType::Diskpart(_) => { TaskType::CommandNoWait(_, _)
| TaskType::CommandWait(_, _)
| TaskType::Diskpart(_) => {
// Check result // Check result
if let Some(result) = &task.result { if let Some(result) = &task.result {
match result { match result {

View file

@ -34,7 +34,7 @@ pub fn configure_disk(
let mut tasks = Vec::new(); let mut tasks = Vec::new();
// Create // Create
tasks.push(TaskType::Command( tasks.push(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bcdboot.exe")), PathBuf::from(format!("{system32}/bcdboot.exe")),
vec![ vec![
format!("{letter_os}:\\Windows"), format!("{letter_os}:\\Windows"),
@ -50,7 +50,7 @@ pub fn configure_disk(
// Update boot sector (for legacy setups) // Update boot sector (for legacy setups)
if table_type == PartitionTableType::Legacy { if table_type == PartitionTableType::Legacy {
tasks.push(TaskType::Command( tasks.push(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bootsect.exe")), PathBuf::from(format!("{system32}/bootsect.exe")),
vec![ vec![
String::from("/nt60"), String::from("/nt60"),
@ -74,7 +74,7 @@ pub fn configure_disk(
pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result<TaskType> { pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result<TaskType> {
//if let Some(driver_path_str) = driver.path.to_str() { //if let Some(driver_path_str) = driver.path.to_str() {
let driver_path = driver.path.to_str().unwrap(); let driver_path = driver.path.to_str().unwrap();
Ok(TaskType::Command( Ok(TaskType::CommandWait(
PathBuf::from(format!("{system32}/dism.exe")), PathBuf::from(format!("{system32}/dism.exe")),
vec![ vec![
format!("/image:{letter_os}:\\"), format!("/image:{letter_os}:\\"),
@ -100,7 +100,7 @@ pub fn set_mode(
} }
}; };
// Build Command // Build CommandWait
let mut cmd_args = vec![String::from("/store"), bcd_path]; let mut cmd_args = vec![String::from("/store"), bcd_path];
match mode { match mode {
SafeMode::Disable => { SafeMode::Disable => {
@ -115,7 +115,7 @@ pub fn set_mode(
cmd_args.push(String::from("minimal")); cmd_args.push(String::from("minimal"));
} }
} }
Ok(TaskType::Command( Ok(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bcdedit.exe")), PathBuf::from(format!("{system32}/bcdedit.exe")),
cmd_args, cmd_args,
)) ))

View file

@ -16,6 +16,7 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
fmt,
path::PathBuf, path::PathBuf,
process::{Command, Stdio}, process::{Command, Stdio},
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -41,7 +42,8 @@ pub enum TaskResult {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum TaskType { pub enum TaskType {
Command(PathBuf, Vec<String>), // (command, args) CommandNoWait(PathBuf, Vec<String>), // (command, args)
CommandWait(PathBuf, Vec<String>), // (command, args)
Diskpart(String), // (script_as_string) Diskpart(String), // (script_as_string)
ScanDisks, ScanDisks,
Sleep, Sleep,
@ -49,6 +51,27 @@ pub enum TaskType {
UpdateDiskList, UpdateDiskList,
} }
impl fmt::Display for TaskType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TaskType::CommandNoWait(cmd_path, _) | TaskType::CommandWait(cmd_path, _) => {
write!(
f,
"Command(\"{}\")",
cmd_path.file_name().unwrap().to_string_lossy()
)
}
TaskType::Diskpart(_) => {
write!(f, "Diskpart")
}
TaskType::ScanDisks => write!(f, "ScanDisks"),
TaskType::Sleep => write!(f, "Sleep"),
TaskType::UpdateDestDisk(_) => write!(f, "UpdateDestDisk"),
TaskType::UpdateDiskList => write!(f, "UpdateDiskList"),
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Task { pub struct Task {
pub handle: Option<JoinHandle<()>>, pub handle: Option<JoinHandle<()>>,
@ -145,7 +168,11 @@ impl Tasks {
if let Some(task) = self.cur_task.take() { if let Some(task) = self.cur_task.take() {
let task_tx = self.task_tx.clone(); let task_tx = self.task_tx.clone();
match task.task_type { match task.task_type {
TaskType::Command(ref cmd_path, ref cmd_args) => { TaskType::CommandNoWait(ref cmd_path, ref cmd_args) => {
self.cur_handle = None;
run_task_command(cmd_path.clone(), cmd_args.clone(), task_tx);
}
TaskType::CommandWait(ref cmd_path, ref cmd_args) => {
self.cur_handle = Some(run_task_command( self.cur_handle = Some(run_task_command(
cmd_path.clone(), cmd_path.clone(),
cmd_args.clone(), cmd_args.clone(),

View file

@ -193,7 +193,7 @@ impl App {
}; };
// (Re)Enable volume mounting // (Re)Enable volume mounting
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/mountvol.exe")), PathBuf::from(format!("{system32}/mountvol.exe")),
vec![String::from("/e")], vec![String::from("/e")],
)); ));
@ -213,7 +213,7 @@ impl App {
popup::Type::Info, popup::Type::Info,
String::from("Running Clone Tool"), String::from("Running Clone Tool"),
))?; ))?;
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
self.config.clone_app_path.clone(), self.config.clone_app_path.clone(),
Vec::new(), Vec::new(),
)); ));
@ -520,13 +520,13 @@ impl App {
fn handle_task(&mut self, task: &Task) -> Result<()> { fn handle_task(&mut self, task: &Task) -> Result<()> {
match task.task_type { match task.task_type {
TaskType::Command(_, _) | TaskType::Diskpart(_) => { TaskType::CommandWait(_, _) | TaskType::Diskpart(_) => {
// Check result // Check result
if let Some(result) = &task.result { if let Some(result) = &task.result {
match result { match result {
TaskResult::Error(msg) => { TaskResult::Error(msg) => {
self.action_tx self.action_tx
.send(Action::Error(format!("{task:?} Failed: {msg}")))?; .send(Action::Error(format!("{} Failed: {msg}", task.task_type)))?;
} }
TaskResult::Output(stdout, stderr, success) => { TaskResult::Output(stdout, stderr, success) => {
if !success { if !success {
@ -537,8 +537,10 @@ impl App {
} else { } else {
String::from("Unknown Error") String::from("Unknown Error")
}; };
self.action_tx self.action_tx.send(Action::Error(format!(
.send(Action::Error(format!("{task:?} Failed: {msg}")))?; "{} Failed: {msg}",
task.task_type
)))?;
} }
} }
} }

View file

@ -230,7 +230,7 @@ impl App {
// Run selected tool // Run selected tool
if let Some(tool) = self.list.get_selected() { if let Some(tool) = self.list.get_selected() {
info!("Run tool: {:?}", &tool); info!("Run tool: {:?}", &tool);
self.tasks.add(build_command(&self, &tool)); self.tasks.add(build_tool_command(&self, &tool));
} }
} }
Action::Resize(w, h) => self.handle_resize(tui, w, h)?, Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
@ -245,7 +245,7 @@ impl App {
self.action_tx.send(Action::Select(None, None))?; self.action_tx.send(Action::Select(None, None))?;
} }
Action::OpenTerminal => { Action::OpenTerminal => {
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandNoWait(
PathBuf::from("cmd.exe"), PathBuf::from("cmd.exe"),
vec![String::from("-new_console:n")], vec![String::from("-new_console:n")],
)); ));
@ -255,11 +255,11 @@ impl App {
popup::Type::Info, popup::Type::Info,
String::from("Restarting..."), String::from("Restarting..."),
))?; ))?;
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from("X:/Windows/System32/sync64.exe"), PathBuf::from("X:/Windows/System32/sync64.exe"),
vec![String::from("-r")], vec![String::from("-r")],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from("X:/Windows/System32/wpeutil.exe"), PathBuf::from("X:/Windows/System32/wpeutil.exe"),
vec![String::from("reboot")], vec![String::from("reboot")],
)); ));
@ -270,11 +270,11 @@ impl App {
popup::Type::Info, popup::Type::Info,
String::from("Powering off..."), String::from("Powering off..."),
))?; ))?;
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from("X:/Windows/System32/sync64.exe"), PathBuf::from("X:/Windows/System32/sync64.exe"),
vec![String::from("-r")], vec![String::from("-r")],
)); ));
self.tasks.add(TaskType::Command( self.tasks.add(TaskType::CommandWait(
PathBuf::from("X:/Windows/System32/wpeutil.exe"), PathBuf::from("X:/Windows/System32/wpeutil.exe"),
vec![String::from("shutdown")], vec![String::from("shutdown")],
)); ));
@ -371,7 +371,7 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
chunks chunks
} }
pub fn build_command(app: &App, tool: &Tool) -> TaskType { pub fn build_tool_command(app: &App, tool: &Tool) -> TaskType {
let cmd_path: PathBuf; let cmd_path: PathBuf;
let mut cmd_args: Vec<String> = Vec::new(); let mut cmd_args: Vec<String> = Vec::new();
let start_index: usize; let start_index: usize;
@ -392,7 +392,7 @@ pub fn build_command(app: &App, tool: &Tool) -> TaskType {
}); });
} }
} }
TaskType::Command(cmd_path, cmd_args) TaskType::CommandNoWait(cmd_path, cmd_args)
} }
fn build_left_items(app: &App) -> Action { fn build_left_items(app: &App) -> Action {