Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Dec 5, 2023
1 parent f64f66c commit 0a37146
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 42 deletions.
6 changes: 2 additions & 4 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Build

This will depend on the host platform

### Build Linux on Linux
### Linux
```
sudo apt install make bison flex clang -y
make libsensors
cargo run --release
```
### Build Windows on Windows
### Windows
1. install [dotnet 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
2. run these commands
```
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
- [x] theme (from Cosmic)
- [x] impl UI for managing configs
- [x] impl UI for removing nodes
- [ ] impl UI for adding nodes
- [x] impl UI settings page
- [ ] impl UI for adding nodes
- [ ] impl UI for removing config
- [ ] CustomDropDown widget
- [ ] FloatingElement witget
- [ ] impl UI graph behavior
- [x] icons
- [ ] tray icon support (not yet available on [Iced](https://whimsical.com/roadmap-iced-7vhq6R35Lp3TmYH4WeYwLM))
Expand Down
28 changes: 25 additions & 3 deletions data/src/dir_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use directories::ProjectDirs;
use hardware::Hardware;

use crate::{
cli::Args, config::Config, fl, name_sorter, serde_helper, settings::Settings, utils::RemoveElem,
Expand Down Expand Up @@ -76,15 +77,15 @@ impl DirManager {
}
}

pub fn settings_file_path(&self) -> PathBuf {
fn settings_file_path(&self) -> PathBuf {
self.config_dir_path.join(SETTINGS_FILENAME)
}

pub fn hardware_file_path(&self) -> PathBuf {
fn hardware_file_path(&self) -> PathBuf {
self.config_dir_path.join(HARDWARE_FILENAME)
}

pub fn config_file_path(&self, name: &str) -> PathBuf {
fn config_file_path(&self, name: &str) -> PathBuf {
self.config_dir_path.join(add_toml_ext(name).into_owned())
}

Expand All @@ -99,6 +100,27 @@ impl DirManager {
error!("{e}");
}
}

pub fn get_config(&self) -> Option<Config> {
match &self.settings().current_config {
Some(config_name) => {
match serde_helper::deserialize::<Config>(&self.config_file_path(config_name)) {
Ok(config) => Some(config),
Err(e) => {
warn!("{:?}", e);
None
}
}
}
None => None,
}
}

pub fn serialize_hardware(&self, hardware: &Hardware) {
if let Err(e) = serde_helper::serialize(&self.hardware_file_path(), hardware) {
warn!("{}", e);
}
}
}

impl DirManager {
Expand Down
22 changes: 11 additions & 11 deletions src/integrated_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ use std::path::PathBuf;
use std::thread;
use std::time::Duration;

use data::directories::DirManager;
use data::app_graph::AppGraph;
use data::cli::Args;
use data::dir_manager::DirManager;

use data::{config::Config, node::AppGraph, update::Update, AppState};
use data::{update::Update, AppState};
use hardware::{fake_hardware, HardwareBridge};

#[test]
fn test_config() {
env_logger::init();

let dir_manager = DirManager::new(Some(PathBuf::from("./.config")));
let settings = dir_manager.init_settings();
let args = Args {
config_dir_path: Some(PathBuf::from("./.config")),
config_name: Some("fake".into()),
};

let dir_manager = DirManager::new(args);

let (hardware, bridge) = fake_hardware::FakeHardwareBridge::generate_hardware();
DirManager::serialize(&dir_manager.hardware_file_path(), &hardware).unwrap();

let config = DirManager::deserialize::<Config>(
&dir_manager.config_file_path(&settings.current_config.clone().unwrap()),
true,
)
.unwrap();
let config = dir_manager.get_config().unwrap();

let app_graph = AppGraph::from_config(config, &hardware);

let mut app_state = AppState {
dir_manager,
settings,
hardware,
app_graph,
update: Update::new(),
Expand Down
27 changes: 4 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use clap::Parser;
use data::{
app_graph::AppGraph, cli::Args, config::Config, dir_manager::DirManager, serde_helper,
update::Update, AppState,
};
use data::{app_graph::AppGraph, cli::Args, dir_manager::DirManager, update::Update, AppState};
use hardware::{self, HardwareBridge};

use ui::run_ui;

#[allow(unused_imports)]
#[macro_use]
extern crate log;

Expand All @@ -31,26 +29,9 @@ fn main() {
#[cfg(all(not(feature = "fake_hardware"), target_os = "windows"))]
let (hardware, bridge) = hardware::windows::WindowsBridge::generate_hardware();

let hardware_file_path = dir_manager.hardware_file_path();
dir_manager.serialize_hardware(&hardware);

if let Err(e) = serde_helper::serialize(&hardware_file_path, &hardware) {
warn!("{}", e);
}

let config = match &dir_manager.settings().current_config {
Some(config_name) => {
match serde_helper::deserialize::<Config>(&dir_manager.config_file_path(config_name)) {
Ok(config) => Some(config),
Err(e) => {
warn!("{:?}", e);
None
}
}
}
None => None,
};

let app_graph = match config {
let app_graph = match dir_manager.get_config() {
Some(config) => AppGraph::from_config(config, &hardware),
None => AppGraph::default(&hardware),
};
Expand Down

0 comments on commit 0a37146

Please sign in to comment.