Skip to content

Commit

Permalink
use appdata when no xdg-data-dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Dec 17, 2023
1 parent 11f8b4a commit ecc83ad
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
13 changes: 7 additions & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const REQUIRED_DIRS: &[(BaseDirectory, &str)] = &[
(BaseDirectory::AppData, "db"),
(BaseDirectory::AppData, "presets"),
(BaseDirectory::AppData, "puzzles"),
(BaseDirectory::AppData, "documents"),
(BaseDirectory::Document, "EnCroissant"),
];

Expand Down Expand Up @@ -177,11 +178,12 @@ fn main() {
&app.env(),
path,
Some(*dir),
)
.unwrap();
if !Path::new(&path).exists() {
create_dir_all(&path).unwrap();
}
);
if let Ok(path) = path {
if !Path::new(&path).exists() {
create_dir_all(&path).unwrap();
}
};
}

for (dir, path) in REQUIRED_FILES.iter() {
Expand Down Expand Up @@ -243,7 +245,6 @@ fn is_bmi2_compatible() -> bool {
false
}


#[tauri::command]
#[specta::specta]
async fn is_menu_visisble(window: tauri::Window) -> bool {
Expand Down
9 changes: 7 additions & 2 deletions src/components/common/OpenFolderButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ function OpenFolderButton({
const path = await resolve(await appDataDir(), folder);
open(path);
} else if (base === "Document") {
const path = await resolve(await documentDir(), folder);
open(path);
try {
const path = await resolve(await documentDir(), folder);
open(path);
} catch {
const path = await resolve(await appDataDir(), "documents");
open(path);
}
}
}
return (
Expand Down
45 changes: 31 additions & 14 deletions src/components/files/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,37 @@ export function EditModal({
filename + ".pgn"
);

await renameFile(
"EnCroissant/" + metadata.name + ".pgn",
"EnCroissant/" + filename + ".pgn",
{
dir: BaseDirectory.Document,
}
);
await renameFile(
"EnCroissant/" + metadata.name + ".info",
"EnCroissant/" + filename + ".info",
{
dir: BaseDirectory.Document,
}
);
try {
await renameFile(
"EnCroissant/" + metadata.name + ".pgn",
"EnCroissant/" + filename + ".pgn",
{
dir: BaseDirectory.Document,
}
);
await renameFile(
"EnCroissant/" + metadata.name + ".info",
"EnCroissant/" + filename + ".info",
{
dir: BaseDirectory.Document,
}
);
} catch {
await renameFile(
"documents/" + metadata.name + ".pgn",
"documents/" + filename + ".pgn",
{
dir: BaseDirectory.AppData,
}
);
await renameFile(
"documents/" + metadata.name + ".info",
"documents/" + filename + ".info",
{
dir: BaseDirectory.AppData,
}
);
}

setFiles((files) =>
[
Expand Down

0 comments on commit ecc83ad

Please sign in to comment.