Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Nov 7, 2024
1 parent f0f6dc6 commit db7fa33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions data/src/dir_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ impl DirManager {
self.config_dir_path.join(SETTINGS_FILENAME)
}

fn cached_config_file_path(&self) -> PathBuf {
self.cache_dir_path.join(CACHED_CONFIG_FILENAME)
}

fn hardware_file_path(&self) -> PathBuf {
self.config_dir_path.join(HARDWARE_FILENAME)
}
Expand Down Expand Up @@ -202,17 +206,23 @@ impl DirManager {
}

pub fn get_config_cached(&self) -> Option<Config> {
deserialize::<Config>(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME)).ok()
deserialize::<Config>(&self.cached_config_file_path())
.ok()
.inspect(|_| info!("load cached config"))
}

pub fn save_config_cached(&self, config: &Config) -> Result<()> {
serialize(&self.cache_dir_path.join(CACHED_CONFIG_FILENAME), config)?;
serialize(&self.cached_config_file_path(), config)?;

Ok(())
}

pub fn remove_config_cached(&self) {
let _ = fs::remove_file(self.cache_dir_path.join(CACHED_CONFIG_FILENAME));
pub fn remove_config_cached(&self) -> Result<()> {
if fs::exists(self.cached_config_file_path())? {
fs::remove_file(self.cached_config_file_path())?;
info!("cached config removed successfully");
}
Ok(())
}

pub fn serialize_hardware(&self, hardware: &Hardware) {
Expand Down
4 changes: 3 additions & 1 deletion ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ impl<H: HardwareBridge + 'static> cosmic::Application for Ui<H> {
info!("cached config saved successfully");
}
} else {
self.app_state.dir_manager.remove_config_cached();
if let Err(err) = self.app_state.dir_manager.remove_config_cached() {
error!("{err}")
}
}

None
Expand Down

0 comments on commit db7fa33

Please sign in to comment.