diff --git a/boot_diags/src/app.rs b/boot_diags/src/app.rs
index 220e587..6854bf8 100644
--- a/boot_diags/src/app.rs
+++ b/boot_diags/src/app.rs
@@ -27,7 +27,7 @@ use core::{
cpu::get_cpu_name,
drivers,
},
- tasks::{Task, Tasks},
+ tasks::{TaskType, Tasks},
tui::{Event, Tui},
};
use std::{
@@ -178,7 +178,7 @@ impl App {
Mode::InjectDrivers | Mode::InstallDrivers => self.clone.scan_drivers(),
Mode::ScanDisks => {
if self.tasks.idle() {
- self.tasks.add(Task::ScanDisks);
+ self.tasks.add(TaskType::ScanDisks);
}
self.action_tx.send(Action::DisplayPopup(
popup::Type::Info,
@@ -297,7 +297,7 @@ impl App {
match self.cur_mode {
Mode::BootDiags => {
// Check result of background task (if finished)
- if let Some(handle) = self.tasks.poll()? {
+ if let Some(task) = self.tasks.poll()? {
// TODO: Impl logic
}
}
diff --git a/core/src/system/boot.rs b/core/src/system/boot.rs
index 5dfd4dd..97862ef 100644
--- a/core/src/system/boot.rs
+++ b/core/src/system/boot.rs
@@ -14,7 +14,7 @@
// along with Deja-Vu. If not, see .
//
use super::{disk::PartitionTableType, drivers::Driver};
-use crate::tasks::Task;
+use crate::tasks::TaskType;
use color_eyre::Result;
use std::path::PathBuf;
@@ -30,11 +30,11 @@ pub fn configure_disk(
letter_os: &str,
system32: &str,
table_type: PartitionTableType,
-) -> Vec {
+) -> Vec {
let mut tasks = Vec::new();
// Create
- tasks.push(Task::Command(
+ tasks.push(TaskType::Command(
PathBuf::from(format!("{system32}/bcdboot.exe")),
vec![
format!("{letter_os}:\\Windows"),
@@ -50,7 +50,7 @@ pub fn configure_disk(
// Update boot sector (for legacy setups)
if table_type == PartitionTableType::Legacy {
- tasks.push(Task::Command(
+ tasks.push(TaskType::Command(
PathBuf::from(format!("{system32}/bootsect.exe")),
vec![
String::from("/nt60"),
@@ -71,10 +71,10 @@ pub fn configure_disk(
tasks
}
-pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result {
+pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result {
//if let Some(driver_path_str) = driver.path.to_str() {
let driver_path = driver.path.to_str().unwrap();
- Ok(Task::Command(
+ Ok(TaskType::Command(
PathBuf::from(format!("{system32}/dism.exe")),
vec![
format!("/image:{letter_os}:\\"),
@@ -90,7 +90,7 @@ pub fn set_mode(
mode: SafeMode,
system32: &str,
table_type: &PartitionTableType,
-) -> Result {
+) -> Result {
let bcd_path = match table_type {
PartitionTableType::Guid => {
format!("{letter_boot}:\\EFI\\Microsoft\\Boot\\BCD")
@@ -115,7 +115,7 @@ pub fn set_mode(
cmd_args.push(String::from("minimal"));
}
}
- Ok(Task::Command(
+ Ok(TaskType::Command(
PathBuf::from(format!("{system32}/bcdedit.exe")),
cmd_args,
))
diff --git a/core/src/tasks.rs b/core/src/tasks.rs
index 7e885e5..13ba8d5 100644
--- a/core/src/tasks.rs
+++ b/core/src/tasks.rs
@@ -34,7 +34,7 @@ use crate::{
};
#[derive(Clone, Debug)]
-pub enum Task {
+pub enum TaskType {
Command(PathBuf, Vec), // (command, args)
Diskpart(String), // (script_as_string)
ScanDisks,
@@ -44,16 +44,26 @@ pub enum Task {
}
#[derive(Debug)]
-pub struct TaskHandle {
- task: Task,
- handle: JoinHandle<()>,
+pub struct Task {
+ pub handle: Option>,
+ pub task_type: TaskType,
+}
+
+impl Task {
+ pub fn new(task_type: TaskType) -> Task {
+ Task {
+ handle: None,
+ task_type,
+ }
+ }
}
#[derive(Debug)]
pub struct Tasks {
action_tx: mpsc::UnboundedSender,
disk_list: Arc>>,
- handle: Option,
+ cur_handle: Option>,
+ cur_task: Option,
task_list: VecDeque,
task_rx: mpsc::UnboundedReceiver, // Used to forward Actions from Tasks to App
task_tx: mpsc::UnboundedSender, // Used to forward Actions from Tasks to App
@@ -68,24 +78,25 @@ impl Tasks {
Tasks {
action_tx,
disk_list: disk_list_arc,
- handle: None,
+ cur_handle: None,
+ cur_task: None,
task_list: VecDeque::new(),
task_rx,
task_tx,
}
}
- pub fn add(&mut self, task: Task) {
- info!("Adding task: {:?}", &task);
- self.task_list.push_back(task);
+ pub fn add(&mut self, task_type: TaskType) {
+ info!("Adding task: {:?}", &task_type);
+ self.task_list.push_back(Task::new(task_type));
}
pub fn idle(&self) -> bool {
- self.handle.is_none()
+ self.cur_handle.is_none()
}
- pub fn poll(&mut self) -> Result