Skip to content

Commit

Permalink
Use XDG directories
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Dec 16, 2024
1 parent 20ccec3 commit 1b2204f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/tanoshi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mime_guess = { version = "2", default-features = false }
clap = { version = "4", features = ["derive"] }
bytes = { version = "1", default-features = false }
dirs = "5"
directories = "5"
base64 = { version = "0.22", default-features = false }
sqlx = { version = "0.8", features = [
"runtime-tokio",
Expand Down
20 changes: 17 additions & 3 deletions crates/tanoshi/src/infrastructure/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::{iter, path::PathBuf};
use directories::ProjectDirs;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TelegramConfig {
Expand Down Expand Up @@ -109,10 +110,23 @@ impl Default for Config {
}

fn tanoshi_home() -> PathBuf {
match std::env::var("TANOSHI_HOME") {
Ok(path) => PathBuf::from(path),
Err(_) => dirs::home_dir().expect("should have home").join(".tanoshi"),
// If TANOSHI_HOME is explicitly set, prefer that
if let Ok(path) = std::env::var("TANOSHI_HOME") {
return PathBuf::from(path);
}

// Check for legacy directory ~/.tanoshi
let legacy_dir = dirs::home_dir()
.expect("Home directory should exist")
.join(".tanoshi");
if legacy_dir.exists() {
return legacy_dir;
}

// Use XDG directories
let proj_dirs = ProjectDirs::from("org", "luigi311", "tanoshi")
.expect("Could not determine project directory");
proj_dirs.data_dir().to_path_buf()
}

fn default_port() -> u16 {
Expand Down
2 changes: 1 addition & 1 deletion org.luigi311.tanoshi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ finish-args:
- --device=dri # OpenGL, not necessary for all projects
- --share=ipc
- --share=network
- --filesystem=home/.tanoshi
- --filesystem=xdg-data/tanoshi:rw

cleanup:
- "/include"
Expand Down

0 comments on commit 1b2204f

Please sign in to comment.