Compare commits

..

No commits in common. "b9ade066e75d98b4a2f94c573be03f619fa2d9b3" and "15b5d5e13149ec75d1852e9700e0309ba23eea68" have entirely different histories.

6 changed files with 64 additions and 134 deletions

View file

@ -17,14 +17,8 @@ use crate::diags;
use core::{
action::Action,
components::{
Component,
footer::Footer,
fps::FpsCounter,
left::{Left, SelectionType},
popup,
right::Right,
state::StatefulList,
title::Title,
Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right,
state::StatefulList, title::Title,
},
config::Config,
line::{DVLine, get_disk_description_right, get_part_description},
@ -746,15 +740,15 @@ fn build_footer_string(cur_mode: Mode) -> String {
fn build_left_items(app: &App) -> Action {
let mut items = Vec::new();
let mut labels = vec![String::new(), String::new()];
let select_type: SelectionType;
let select_num: usize;
let title: String;
match app.cur_mode {
Mode::Home => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Home");
}
Mode::DiagMenu => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Troubleshooting");
app.list.items.iter().for_each(|mode| {
let (name, _) = get_mode_strings(*mode);
@ -762,7 +756,7 @@ fn build_left_items(app: &App) -> Action {
});
}
Mode::InstallDrivers => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Install Drivers");
app.clone
.driver_list
@ -770,7 +764,7 @@ fn build_left_items(app: &App) -> Action {
.for_each(|driver| items.push(driver.to_string()));
}
Mode::InjectDrivers => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Select Drivers");
app.clone
.driver_list
@ -778,7 +772,7 @@ fn build_left_items(app: &App) -> Action {
.for_each(|driver| items.push(driver.to_string()));
}
Mode::SelectDisks => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Select Disk");
let disk_list = app.clone.disk_list.lock().unwrap();
disk_list
@ -786,11 +780,11 @@ fn build_left_items(app: &App) -> Action {
.for_each(|disk| items.push(disk.description.to_string()));
}
Mode::BootScan | Mode::ScanDisks => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Processing");
}
Mode::SelectParts => {
select_type = SelectionType::Two;
select_num = 2;
title = String::from("Select Boot and OS Partitions");
labels[0] = String::from("boot");
labels[1] = String::from("os");
@ -804,7 +798,7 @@ fn build_left_items(app: &App) -> Action {
}
}
Mode::BootDiags => {
select_type = SelectionType::Loop;
select_num = 0;
let (new_title, _) = get_mode_strings(app.cur_mode);
title = new_title;
app.diag_groups.get().iter().for_each(|group| {
@ -816,19 +810,19 @@ fn build_left_items(app: &App) -> Action {
});
}
Mode::BootSetup => {
select_type = SelectionType::Loop;
select_num = 0;
let (new_title, _) = get_mode_strings(app.cur_mode);
title = new_title;
}
Mode::SetBootMode => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Set Boot Mode");
app.boot_modes.iter().for_each(|entry| {
items.push(format!("{:?} Safe Mode", entry));
});
}
Mode::Done | Mode::Failed => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Done");
}
// Invalid states
@ -841,7 +835,7 @@ fn build_left_items(app: &App) -> Action {
panic!("This shouldn't happen?")
}
};
Action::UpdateLeft(title, labels, items, select_type)
Action::UpdateLeft(title, labels, items, select_num)
}
fn build_right_items(app: &App) -> Action {

View file

@ -16,12 +16,7 @@
use serde::{Deserialize, Serialize};
use strum::Display;
use crate::{
components::{left::SelectionType, popup::Type as PopupType},
line::DVLine,
state::Mode,
system::disk::Disk,
};
use crate::{components::popup::Type, line::DVLine, state::Mode, system::disk::Disk};
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
pub enum Action {
@ -37,7 +32,11 @@ pub enum Action {
TasksComplete,
UpdateDiskList(Vec<Disk>),
UpdateFooter(String),
UpdateLeft(String, Vec<String>, Vec<String>, SelectionType), // (title, labels, items, select_type)
UpdateLeft(String, Vec<String>, Vec<String>, usize), // (title, labels, items, select_num)
// NOTE: select_num should be set to 0, 1, or 2.
// 0: For repeating selections
// 1: For a single choice
// 2: For two selections (obviously)
UpdateRight(Vec<Vec<DVLine>>, usize, Vec<Vec<DVLine>>), // (labels, start_index, items) - items before start are always shown
// App (PE-Menu)
OpenTerminal,
@ -45,7 +44,7 @@ pub enum Action {
Shutdown,
// Screens
DismissPopup,
DisplayPopup(PopupType, String),
DisplayPopup(Type, String),
NextScreen,
PrevScreen,
SetMode(Mode),

View file

@ -30,8 +30,6 @@ use crate::action::Action;
#[derive(Debug, Clone, PartialEq)]
pub struct FpsCounter {
mode: String,
last_tick_update: Instant,
tick_count: u32,
ticks_per_second: f64,
@ -51,7 +49,6 @@ impl FpsCounter {
#[must_use]
pub fn new() -> Self {
Self {
mode: String::from(""),
last_tick_update: Instant::now(),
tick_count: 0,
ticks_per_second: 0.0,
@ -91,44 +88,29 @@ impl FpsCounter {
impl Component for FpsCounter {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action {
Action::SetMode(mode) => {
self.mode = format!("{:?}", mode);
}
Action::Render => self.render_tick()?,
Action::Tick => self.app_tick()?,
Action::Render => self.render_tick()?,
_ => {}
};
Ok(None)
}
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let [column, _] =
Layout::horizontal([Constraint::Min(1), Constraint::Length(2)]).areas(area);
let [_, row, _] = Layout::vertical([
Constraint::Length(1),
Constraint::Length(1),
Constraint::Min(0),
])
.areas(area);
let [_, left, right, _] = Layout::horizontal([
Constraint::Length(2),
Constraint::Min(1),
Constraint::Min(1),
Constraint::Length(2),
])
.areas(row);
// Debug
let span = Span::styled(format!("Mode: {}", &self.mode), Style::new().dim());
let paragraph = Paragraph::new(span).left_aligned();
frame.render_widget(paragraph, left);
// FPS
.areas(column);
let message = format!(
"{:.2} ticks/sec, {:.2} FPS",
self.ticks_per_second, self.frames_per_second
);
let span = Span::styled(message, Style::new().dim());
let paragraph = Paragraph::new(span).right_aligned();
frame.render_widget(paragraph, right);
frame.render_widget(paragraph, row);
Ok(())
}
}

View file

@ -19,27 +19,18 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, HighlightSpacing, List, ListItem, Padding, Paragraph},
};
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::UnboundedSender;
use super::{Component, state::StatefulList};
use crate::{action::Action, config::Config};
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub enum SelectionType {
#[default]
Loop,
One,
Two,
}
#[derive(Default)]
pub struct Left {
command_tx: Option<UnboundedSender<Action>>,
config: Config,
labels: Vec<String>,
list: StatefulList<String>,
select_type: SelectionType,
select_num: usize,
selections: Vec<Option<usize>>,
selections_saved: Vec<Option<usize>>,
title_text: String,
@ -49,8 +40,8 @@ impl Left {
#[must_use]
pub fn new() -> Self {
Self {
select_num: 0,
labels: vec![String::from("one"), String::from("two")],
select_type: SelectionType::Loop,
selections: vec![None, None],
selections_saved: vec![None, None],
title_text: String::from("Home"),
@ -85,14 +76,14 @@ impl Component for Left {
Action::KeyUp => self.list.previous(),
Action::KeyDown => self.list.next(),
Action::Process => {
if self.select_type == SelectionType::Loop {
if self.select_num == 0 {
// Selections aren't being used so this is a no-op
} else if let Some(command_tx) = self.command_tx.clone() {
match (self.selections[0], self.selections[1]) {
(None, None) => {
// Making first selection
command_tx.send(Action::Select(self.list.selected(), None))?;
if self.select_type == SelectionType::One {
if self.select_num == 1 {
// Confirm selection
command_tx.send(Action::NextScreen)?;
}
@ -127,14 +118,14 @@ impl Component for Left {
self.selections[0] = None;
self.selections[1] = None;
}
Action::UpdateLeft(title, labels, items, select_type) => {
Action::UpdateLeft(title, labels, items, select_num) => {
self.title_text = title;
self.labels = labels
.iter()
.map(|label| format!(" ~{}~", label.to_lowercase()))
.collect();
self.list.set_items(items);
self.select_type = select_type;
self.select_num = select_num;
}
_ => {}
}

View file

@ -16,14 +16,8 @@
use core::{
action::Action,
components::{
Component,
footer::Footer,
fps::FpsCounter,
left::{Left, SelectionType},
popup,
right::Right,
state::StatefulList,
title::Title,
Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right,
state::StatefulList, title::Title,
},
config::Config,
line::{DVLine, get_disk_description_right, get_part_description},
@ -633,17 +627,17 @@ fn build_footer_string(cur_mode: Mode) -> String {
}
fn build_left_items(app: &App, cur_mode: Mode) -> Action {
let select_type: SelectionType;
let select_num: usize;
let title: String;
let mut items = Vec::new();
let mut labels: Vec<String> = Vec::new();
match cur_mode {
Mode::Home => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Home");
}
Mode::InstallDrivers => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Install Drivers");
app.clone
.driver_list
@ -651,7 +645,7 @@ fn build_left_items(app: &App, cur_mode: Mode) -> Action {
.for_each(|driver| items.push(driver.to_string()));
}
Mode::SelectDisks => {
select_type = SelectionType::Two;
select_num = 2;
title = String::from("Select Source and Destination Disks");
labels.push(String::from("source"));
labels.push(String::from("dest"));
@ -661,21 +655,21 @@ fn build_left_items(app: &App, cur_mode: Mode) -> Action {
.for_each(|disk| items.push(disk.description.to_string()));
}
Mode::SelectTableType => {
select_type = SelectionType::One;
select_num = 1;
title = String::from("Select Partition Table Type");
items.push(format!("{}", PartitionTableType::Guid));
items.push(format!("{}", PartitionTableType::Legacy));
}
Mode::Confirm => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Confirm Selections");
}
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Processing");
}
Mode::SelectParts => {
select_type = SelectionType::Two;
select_num = 2;
title = String::from("Select Boot and OS Partitions");
labels.push(String::from("boot"));
labels.push(String::from("os"));
@ -689,7 +683,7 @@ fn build_left_items(app: &App, cur_mode: Mode) -> Action {
}
}
Mode::Done | Mode::Failed => {
select_type = SelectionType::Loop;
select_num = 0;
title = String::from("Done");
}
// Invalid states
@ -701,7 +695,7 @@ fn build_left_items(app: &App, cur_mode: Mode) -> Action {
| Mode::PEMenu
| Mode::SetBootMode => panic!("This shouldn't happen?"),
};
Action::UpdateLeft(title, labels, items, select_type)
Action::UpdateLeft(title, labels, items, select_num)
}
fn build_right_items(app: &App, cur_mode: Mode) -> Action {

View file

@ -16,14 +16,8 @@
use core::{
action::Action,
components::{
Component,
footer::Footer,
fps::FpsCounter,
left::{Left, SelectionType},
popup,
right::Right,
state::StatefulList,
title::Title,
Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right,
state::StatefulList, title::Title,
},
config::Config,
line::DVLine,
@ -82,7 +76,7 @@ impl App {
let disk_list_arc = Arc::new(Mutex::new(Vec::new()));
let tasks = Tasks::new(action_tx.clone(), disk_list_arc.clone());
let mut list = StatefulList::default();
list.set_items(load_tools(action_tx.clone()));
list.set_items(load_tools());
Ok(Self {
// TUI
action_rx,
@ -417,7 +411,7 @@ fn build_left_items(app: &App) -> Action {
})
// ─
.collect();
Action::UpdateLeft(title, labels, items, SelectionType::Loop)
Action::UpdateLeft(title, labels, items, 0)
}
fn build_right_items(app: &App) -> Action {
@ -447,45 +441,21 @@ fn build_right_items(app: &App) -> Action {
Action::UpdateRight(labels, start_index, items)
}
pub fn load_tools(action_tx: mpsc::UnboundedSender<Action>) -> Vec<Tool> {
let mut entries: Vec<PathBuf>;
let mut tools: Vec<Tool> = Vec::new();
pub fn load_tools() -> Vec<Tool> {
let exe_path = env::current_exe().expect("Failed to find main executable");
let tool_config_path = exe_path.parent().unwrap().join("menu_entries");
if let Ok(read_dir) = std::fs::read_dir(tool_config_path) {
entries = read_dir
let mut entries: Vec<PathBuf> = std::fs::read_dir(tool_config_path)
.expect("Failed to find any tool configs")
.map(|res| res.map(|e| e.path()))
.filter_map(Result::ok)
.collect();
entries.sort();
} else {
action_tx
.send(Action::Error(String::from(
"Failed to find any tool configs",
)))
.unwrap();
entries = Vec::new();
}
entries.iter().for_each(|entry| {
if let Ok(toml_str) = fs::read_to_string(entry) {
if let Ok(tool) = toml::from_str(&toml_str) {
tools.push(tool);
} else {
action_tx
.send(Action::Error(format!(
"Failed to parse tool config file: {:?}",
&entry,
)))
.unwrap();
}
} else {
action_tx
.send(Action::Error(format!(
"Failed to read tool config file: {:?}",
&entry,
)))
.unwrap();
}
});
tools
entries
.iter()
.map(|entry| {
let contents = fs::read_to_string(entry).expect("Failed to read tool config file");
let tool: Tool = toml::from_str(&contents).expect("Failed to parse tool config file");
tool
})
.collect()
}