Skip to content

Commit

Permalink
use proper settings indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nnyyxxxx committed Oct 16, 2024
1 parent 0c1ab13 commit 4708777
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fs;
use std::path::PathBuf;
use std::rc::Rc;
use shellexpand;
use std::io::Read;

const CONFIG_FILE: &str = "~/.config/hyprwall/config.ini";

Expand Down Expand Up @@ -121,13 +122,25 @@ fn load_images(folder: &PathBuf, flowbox: &Rc<RefCell<FlowBox>>) {

fn load_last_path() -> Option<PathBuf> {
let config_path = shellexpand::tilde(CONFIG_FILE).into_owned();
fs::read_to_string(config_path).ok().map(PathBuf::from)
if let Ok(mut file) = fs::File::open(config_path) {
let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() {
for line in contents.lines() {
if line.starts_with("folder = ") {
let path = line.trim_start_matches("folder = ");
return Some(PathBuf::from(shellexpand::tilde(path).into_owned()));
}
}
}
}
None
}

fn save_last_path(path: &PathBuf) {
let config_path = shellexpand::tilde(CONFIG_FILE).into_owned();
if let Some(parent) = PathBuf::from(&config_path).parent() {
fs::create_dir_all(parent).ok();
}
fs::write(config_path, path.to_str().unwrap_or("")).ok();
let content = format!("[Settings]\nfolder = {}", path.to_str().unwrap_or(""));
fs::write(config_path, content).ok();
}

0 comments on commit 4708777

Please sign in to comment.