Move clone settings to separate struct
The App struct had too many fields IMO
This commit is contained in:
parent
fc0b82418b
commit
253385c2a7
2 changed files with 48 additions and 34 deletions
|
|
@ -35,12 +35,11 @@ use crate::{
|
||||||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
state::Mode,
|
state::{CloneSettings, Mode},
|
||||||
system::{
|
system::{
|
||||||
boot,
|
boot,
|
||||||
disk::{Disk, PartitionTableType},
|
|
||||||
diskpart::build_dest_format_script,
|
diskpart::build_dest_format_script,
|
||||||
drivers::{self, Driver},
|
drivers::{self},
|
||||||
},
|
},
|
||||||
tasks::{Task, Tasks},
|
tasks::{Task, Tasks},
|
||||||
tui::{Event, Tui},
|
tui::{Event, Tui},
|
||||||
|
|
@ -58,16 +57,10 @@ pub struct App {
|
||||||
should_suspend: bool,
|
should_suspend: bool,
|
||||||
tick_rate: f64,
|
tick_rate: f64,
|
||||||
// App
|
// App
|
||||||
|
clone: CloneSettings,
|
||||||
cur_mode: Mode,
|
cur_mode: Mode,
|
||||||
disk_index_dest: Option<usize>,
|
|
||||||
disk_index_source: Option<usize>,
|
|
||||||
disk_list: Arc<Mutex<Vec<Disk>>>,
|
|
||||||
part_index_boot: Option<usize>,
|
|
||||||
part_index_os: Option<usize>,
|
|
||||||
driver: Option<Driver>,
|
|
||||||
prev_mode: Mode,
|
prev_mode: Mode,
|
||||||
selections: Vec<Option<usize>>,
|
selections: Vec<Option<usize>>,
|
||||||
table_type: Option<PartitionTableType>,
|
|
||||||
tasks: Tasks,
|
tasks: Tasks,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,16 +89,10 @@ impl App {
|
||||||
should_suspend: false,
|
should_suspend: false,
|
||||||
tick_rate,
|
tick_rate,
|
||||||
// App
|
// App
|
||||||
|
clone: CloneSettings::new(disk_list_arc),
|
||||||
cur_mode: Mode::ScanDisks,
|
cur_mode: Mode::ScanDisks,
|
||||||
disk_index_dest: None,
|
|
||||||
disk_index_source: None,
|
|
||||||
disk_list: disk_list_arc,
|
|
||||||
driver: None,
|
|
||||||
part_index_boot: None,
|
|
||||||
part_index_os: None,
|
|
||||||
prev_mode: Mode::ScanDisks,
|
prev_mode: Mode::ScanDisks,
|
||||||
selections: vec![None, None],
|
selections: vec![None, None],
|
||||||
table_type: None,
|
|
||||||
tasks,
|
tasks,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -165,10 +152,10 @@ impl App {
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
// Build Diskpart script to format destination disk
|
// Build Diskpart script to format destination disk
|
||||||
let disk_list = self.disk_list.lock().unwrap();
|
let disk_list = self.clone.disk_list.lock().unwrap();
|
||||||
if let Some(disk_index) = self.disk_index_dest {
|
if let Some(disk_index) = self.clone.disk_index_dest {
|
||||||
if let Some(disk) = disk_list.get(disk_index) {
|
if let Some(disk) = disk_list.get(disk_index) {
|
||||||
let table_type = self.table_type.clone().unwrap();
|
let table_type = self.clone.table_type.clone().unwrap();
|
||||||
let diskpart_script = build_dest_format_script(disk.id, &table_type);
|
let diskpart_script = build_dest_format_script(disk.id, &table_type);
|
||||||
self.tasks.add(Task::Diskpart(diskpart_script));
|
self.tasks.add(Task::Diskpart(diskpart_script));
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +170,7 @@ impl App {
|
||||||
self.config.clone_app_path.clone(),
|
self.config.clone_app_path.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
if let Some(dest_index) = self.disk_index_dest {
|
if let Some(dest_index) = self.clone.disk_index_dest {
|
||||||
self.tasks.add(Task::UpdateDestDisk(dest_index));
|
self.tasks.add(Task::UpdateDestDisk(dest_index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -208,12 +195,12 @@ impl App {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add actions
|
// Add actions
|
||||||
let disk_list = self.disk_list.lock().unwrap();
|
let disk_list = self.clone.disk_list.lock().unwrap();
|
||||||
if let Some(disk_index) = self.disk_index_dest {
|
if let Some(disk_index) = self.clone.disk_index_dest {
|
||||||
if let Some(disk) = disk_list.get(disk_index) {
|
if let Some(disk) = disk_list.get(disk_index) {
|
||||||
let table_type = self.table_type.clone().unwrap();
|
let table_type = self.clone.table_type.clone().unwrap();
|
||||||
let letter_boot = disk.get_part_letter(self.part_index_boot.unwrap());
|
let letter_boot = disk.get_part_letter(self.clone.part_index_boot.unwrap());
|
||||||
let letter_os = disk.get_part_letter(self.part_index_os.unwrap());
|
let letter_os = disk.get_part_letter(self.clone.part_index_os.unwrap());
|
||||||
|
|
||||||
// Safety check
|
// Safety check
|
||||||
if letter_boot.is_empty() || letter_os.is_empty() {
|
if letter_boot.is_empty() || letter_os.is_empty() {
|
||||||
|
|
@ -231,8 +218,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject driver(s) (if selected)
|
// Inject driver(s) (if selected)
|
||||||
if let Some(driver) = &self.driver {
|
if let Some(driver) = &self.clone.driver {
|
||||||
if let Ok(task) = boot::inject_driver(&driver, &letter_os, &system32) {
|
if let Ok(task) = boot::inject_driver(driver, &letter_os, &system32) {
|
||||||
self.tasks.add(task);
|
self.tasks.add(task);
|
||||||
} else {
|
} else {
|
||||||
self.action_tx.send(Action::Error(format!(
|
self.action_tx.send(Action::Error(format!(
|
||||||
|
|
@ -363,12 +350,12 @@ impl App {
|
||||||
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
||||||
}
|
}
|
||||||
Action::SelectDriver(ref driver) => {
|
Action::SelectDriver(ref driver) => {
|
||||||
self.driver = Some(driver.clone());
|
self.clone.driver = Some(driver.clone());
|
||||||
drivers::load(&driver.inf_paths);
|
drivers::load(&driver.inf_paths);
|
||||||
self.action_tx.send(Action::NextScreen)?;
|
self.action_tx.send(Action::NextScreen)?;
|
||||||
}
|
}
|
||||||
Action::SelectTableType(ref table_type) => {
|
Action::SelectTableType(ref table_type) => {
|
||||||
self.table_type = Some(table_type.clone());
|
self.clone.table_type = Some(table_type.clone());
|
||||||
self.action_tx.send(Action::NextScreen)?;
|
self.action_tx.send(Action::NextScreen)?;
|
||||||
}
|
}
|
||||||
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
||||||
|
|
@ -390,12 +377,12 @@ impl App {
|
||||||
Action::Select(one, two) => {
|
Action::Select(one, two) => {
|
||||||
match self.cur_mode {
|
match self.cur_mode {
|
||||||
Mode::SelectDisks => {
|
Mode::SelectDisks => {
|
||||||
self.disk_index_source = one;
|
self.clone.disk_index_source = one;
|
||||||
self.disk_index_dest = two;
|
self.clone.disk_index_dest = two;
|
||||||
}
|
}
|
||||||
Mode::SelectParts => {
|
Mode::SelectParts => {
|
||||||
self.part_index_boot = one;
|
self.clone.part_index_boot = one;
|
||||||
self.part_index_os = two;
|
self.clone.part_index_os = two;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,15 @@
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::system::{
|
||||||
|
disk::{Disk, PartitionTableType},
|
||||||
|
drivers::Driver,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
#[default]
|
#[default]
|
||||||
|
|
@ -31,3 +38,23 @@ pub enum Mode {
|
||||||
Done,
|
Done,
|
||||||
Failed,
|
Failed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct CloneSettings {
|
||||||
|
pub disk_index_dest: Option<usize>,
|
||||||
|
pub disk_index_source: Option<usize>,
|
||||||
|
pub disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||||
|
pub part_index_boot: Option<usize>,
|
||||||
|
pub part_index_os: Option<usize>,
|
||||||
|
pub driver: Option<Driver>,
|
||||||
|
pub table_type: Option<PartitionTableType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CloneSettings {
|
||||||
|
pub fn new(disk_list: Arc<Mutex<Vec<Disk>>>) -> Self {
|
||||||
|
CloneSettings {
|
||||||
|
disk_list,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue