Skip to content

Commit

Permalink
flatpak: Add funny directory workaround round 3
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Jun 1, 2024
1 parent c897aee commit 016dda4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ pub fn create_config(project_name: &str) -> Option<PathBuf> {
config_file = Some(res.unwrap());
}
let config_file = config_file.unwrap();
// Hacky flatpak workaround
let mut hacked_path = config_file.to_str().unwrap().to_string();
hacked_path.remove_matches("var/app/org.Xetibo.ReSet/config/ReSet.toml");
hacked_path.push_str("config/reset/ReSet.toml");
Some(PathBuf::from(hacked_path))
flatpak_fix(config_file)
}

// Hacky flatpak workaround
pub fn flatpak_fix(path_buf: PathBuf) -> Option<PathBuf> {
let hacked_path = path_buf.to_str().unwrap().to_string();
if hacked_path.contains("var/app") {
Some(PathBuf::from(hacked_path.replace(
"var/app/org.Xetibo.ReSet/config/ReSet.toml",
"config/reset/ReSet.toml",
)))
} else {
Some(path_buf)
}
}

pub fn parse_flags(flags: Vec<String>) -> Flags {
Expand Down
14 changes: 14 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ fn test_config_dir() {
assert!(create_config(project_name).is_some());
}

#[test]
fn test_flatpak_fix() {
use crate::flatpak_fix;
use std::path::PathBuf;
let flatpak = "/home/something/.var/app/org.Xetibo.ReSet/config/ReSet.toml";
assert_eq!(
flatpak_fix(PathBuf::from(flatpak))
.unwrap()
.to_str()
.unwrap(),
"/home/something/.config/reset/ReSet.toml"
);
}

#[test]
#[serial]
fn test_custom_config() {
Expand Down

0 comments on commit 016dda4

Please sign in to comment.