From da1892710fb06ce23046cfc67108d5f433e9f52f Mon Sep 17 00:00:00 2001
From: 2Shirt <2xShirt@gmail.com>
Date: Sat, 11 Jan 2025 18:18:29 -0800
Subject: [PATCH 01/21] Load title from config file
---
deja_vu/.envrc | 3 ---
deja_vu/Cargo.toml | 1 -
deja_vu/config/config.json5 | 1 +
deja_vu/src/app.rs | 1 +
deja_vu/src/components/title.rs | 2 +-
deja_vu/src/config.rs | 12 +++++++-----
6 files changed, 10 insertions(+), 10 deletions(-)
delete mode 100644 deja_vu/.envrc
diff --git a/deja_vu/.envrc b/deja_vu/.envrc
deleted file mode 100644
index dd7b181..0000000
--- a/deja_vu/.envrc
+++ /dev/null
@@ -1,3 +0,0 @@
-export DEJA_VU_CONFIG=`pwd`/config
-export DEJA_VU_DATA=`pwd`/data
-export DEJA_VU_LOG_LEVEL=debug
diff --git a/deja_vu/Cargo.toml b/deja_vu/Cargo.toml
index 2a1c29a..592fcb5 100644
--- a/deja_vu/Cargo.toml
+++ b/deja_vu/Cargo.toml
@@ -21,7 +21,6 @@ edition = "2021"
license = "GPL"
version = "0.2.0"
-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diff --git a/deja_vu/config/config.json5 b/deja_vu/config/config.json5
index bb9e684..54e41f5 100644
--- a/deja_vu/config/config.json5
+++ b/deja_vu/config/config.json5
@@ -1,4 +1,5 @@
{
+ "app_title": "Deja-vu: Clone Tool",
"clone_app_path": "C:/Program Files/Some Clone Tool/app.exe",
"keybindings": {
"ScanDisks": {
diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs
index f68b066..e9c0a24 100644
--- a/deja_vu/src/app.rs
+++ b/deja_vu/src/app.rs
@@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with Deja-vu. If not, see .
//
+
use std::{
env,
iter::zip,
diff --git a/deja_vu/src/components/title.rs b/deja_vu/src/components/title.rs
index 1394186..243b064 100644
--- a/deja_vu/src/components/title.rs
+++ b/deja_vu/src/components/title.rs
@@ -56,7 +56,7 @@ impl Component for Title {
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
// Title Block
let title_text = Span::styled(
- "WizardKit: Clone Tool",
+ self.config.app_title.as_str(),
Style::default().fg(Color::LightCyan),
);
let title = Paragraph::new(Line::from(title_text).centered())
diff --git a/deja_vu/src/config.rs b/deja_vu/src/config.rs
index f21ca83..ba2daab 100644
--- a/deja_vu/src/config.rs
+++ b/deja_vu/src/config.rs
@@ -40,6 +40,8 @@ pub struct AppConfig {
#[derive(Clone, Debug, Default, Deserialize)]
pub struct Config {
+ #[serde(default)]
+ pub app_title: String,
#[serde(default)]
pub clone_app_path: PathBuf,
#[serde(default, flatten)]
@@ -68,12 +70,13 @@ impl Config {
let data_dir = get_data_dir();
let config_dir = get_config_dir();
let mut builder = config::Config::builder()
- .set_default("data_dir", data_dir.to_str().unwrap())?
- .set_default("config_dir", config_dir.to_str().unwrap())?
+ .set_default("app_title", default_config.app_title.as_str())?
.set_default(
"clone_app_path",
String::from("C:\\Program Files\\Some Clone Tool\\app.exe"),
- )?;
+ )?
+ .set_default("config_dir", config_dir.to_str().unwrap())?
+ .set_default("data_dir", data_dir.to_str().unwrap())?;
let config_files = [
("config.json5", config::FileFormat::Json5),
@@ -95,7 +98,6 @@ impl Config {
if !found_config {
error!("No configuration file found. Application may not behave as expected");
}
-
let mut cfg: Self = builder.build()?.try_deserialize()?;
for (mode, default_bindings) in default_config.keybindings.iter() {
@@ -140,7 +142,7 @@ pub fn get_config_dir() -> PathBuf {
}
fn project_directory() -> Option {
- ProjectDirs::from("com", "WizardKit", env!("CARGO_PKG_NAME"))
+ ProjectDirs::from("com", "Deja-vu", env!("CARGO_PKG_NAME"))
}
#[derive(Clone, Debug, Default, Deref, DerefMut)]
From 81aa7a8984e7fd24f7a5bd4b88d8add7cc058410 Mon Sep 17 00:00:00 2001
From: 2Shirt <2xShirt@gmail.com>
Date: Sat, 11 Jan 2025 22:38:53 -0800
Subject: [PATCH 02/21] Update pe_menu title
---
pe_menu/src/ui.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pe_menu/src/ui.rs b/pe_menu/src/ui.rs
index bdfdedf..031b48b 100644
--- a/pe_menu/src/ui.rs
+++ b/pe_menu/src/ui.rs
@@ -34,7 +34,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
.split(frame.size());
// Title Block
- let title_text = Span::styled("WizardKit: PE Menu", Style::default().fg(Color::LightCyan));
+ let title_text = Span::styled("Deja-vu: PE Menu", Style::default().fg(Color::LightCyan));
let title = Paragraph::new(Line::from(title_text).centered())
.block(Block::default().borders(Borders::ALL));
frame.render_widget(title, chunks[0]);
From 828a2736be365cf32347ed97c0e2d6d83bdd94c7 Mon Sep 17 00:00:00 2001
From: 2Shirt <2xShirt@gmail.com>
Date: Sun, 12 Jan 2025 00:17:18 -0800
Subject: [PATCH 03/21] Add support for getting Modes by name
Should support app implementations for multiple binaries
---
Cargo.lock | 2 +-
deja_vu/src/action.rs | 3 +--
deja_vu/src/app.rs | 31 ++++++++++++++++++++++++-------
deja_vu/src/components/footer.rs | 2 ++
deja_vu/src/components/left.rs | 5 +++--
deja_vu/src/components/popup.rs | 8 +++++---
deja_vu/src/components/right.rs | 5 +++--
7 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 835fa64..d1d23d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-version = 3
+version = 4
[[package]]
name = "addr2line"
diff --git a/deja_vu/src/action.rs b/deja_vu/src/action.rs
index ba18a79..8bdbb1e 100644
--- a/deja_vu/src/action.rs
+++ b/deja_vu/src/action.rs
@@ -17,7 +17,6 @@ use serde::{Deserialize, Serialize};
use strum::Display;
use crate::{
- app::Mode,
components::popup::Type,
system::{
disk::{Disk, PartitionTableType},
@@ -40,7 +39,7 @@ pub enum Action {
DisplayPopup(Type, String),
NextScreen,
PrevScreen,
- SetMode(Mode),
+ SetMode(String),
// TUI
ClearScreen,
Error(String),
diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs
index e9c0a24..7a98d36 100644
--- a/deja_vu/src/app.rs
+++ b/deja_vu/src/app.rs
@@ -17,6 +17,7 @@
use std::{
env,
iter::zip,
+ str::FromStr,
sync::{Arc, Mutex},
};
@@ -27,6 +28,7 @@ use ratatui::{
prelude::Rect,
};
use serde::{Deserialize, Serialize};
+use strum::{Display, EnumString};
use tokio::sync::mpsc;
use tracing::{debug, info};
@@ -71,7 +73,9 @@ pub struct App {
tasks: Tasks,
}
-#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[derive(
+ Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, EnumString, Display,
+)]
pub enum Mode {
#[default]
ScanDisks,
@@ -87,6 +91,13 @@ pub enum Mode {
Failed,
}
+impl Mode {
+ pub fn get_mode(mode_str: &str) -> Self {
+ let error_msg = format!("Failed to get app Mode: '{}'", mode_str);
+ Self::from_str(mode_str).expect(&error_msg)
+ }
+}
+
impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result {
let (action_tx, action_rx) = mpsc::unbounded_channel();
@@ -373,10 +384,12 @@ impl App {
Action::Error(ref msg) => {
self.action_tx
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
- self.action_tx.send(Action::SetMode(Mode::Failed))?;
+ self.action_tx
+ .send(Action::SetMode(String::from("Failed")))?;
}
Action::InstallDriver => {
- self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
+ self.action_tx
+ .send(Action::SetMode(String::from("InstallDrivers")))?;
}
Action::SelectDriver(ref driver) => {
self.driver = Some(driver.clone());
@@ -394,15 +407,17 @@ impl App {
(Mode::SelectTableType, Mode::SelectTableType) => Mode::SelectDisks,
(_, _) => self.prev_mode,
};
- self.action_tx.send(Action::SetMode(new_mode))?;
+ self.action_tx.send(Action::SetMode(new_mode.to_string()))?;
}
Action::NextScreen => {
if let Some(mode) = self.next_mode() {
self.action_tx.send(Action::DismissPopup)?;
- self.action_tx.send(Action::SetMode(mode))?;
+ self.action_tx.send(Action::SetMode(mode.to_string()))?;
}
}
- Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
+ Action::ScanDisks => self
+ .action_tx
+ .send(Action::SetMode(String::from("ScanDisks")))?,
Action::Select(one, two) => {
match self.cur_mode {
Mode::SelectDisks => {
@@ -418,7 +433,9 @@ impl App {
self.selections[0] = one;
self.selections[1] = two;
}
- Action::SetMode(new_mode) => self.set_mode(new_mode)?,
+ Action::SetMode(ref new_mode_string) => {
+ self.set_mode(Mode::get_mode(&new_mode_string))?
+ }
_ => {}
}
for component in &mut self.components {
diff --git a/deja_vu/src/components/footer.rs b/deja_vu/src/components/footer.rs
index 1530cd7..4610fe3 100644
--- a/deja_vu/src/components/footer.rs
+++ b/deja_vu/src/components/footer.rs
@@ -18,6 +18,7 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
+use std::str::FromStr;
use tokio::sync::mpsc::UnboundedSender;
use super::Component;
@@ -52,6 +53,7 @@ impl Component for Footer {
fn update(&mut self, action: Action) -> Result