Commit f1f21a7889

f1f21a7889b4d8ba602b1ee9c6731b34af12a550

parent: 07f019f64d

Unsigned

Siriusmart <sirius@siri.ws> · 2026-05-04 19:45 UTC

paths env change

Layout: unified · split

Cargo.lock −10
@@ -1124,15 +1124,6 @@ version = "0.4.3"
11241124source = "registry+https://github.com/rust-lang/crates.io-index"
11251125checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
11261126
1127[[package]]
1128name = "home"
1129version = "0.5.12"
1130source = "registry+https://github.com/rust-lang/crates.io-index"
1131checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d"
1132dependencies = [
1133 "windows-sys 0.61.2",
1134]
1135
11361127[[package]]
11371128name = "http"
11381129version = "1.4.0"
@@ -4226,7 +4217,6 @@ dependencies = [
42264217 "dirs",
42274218 "dyn-clone",
42284219 "futures",
4229 "home",
42304220 "http_req 0.14.4",
42314221 "invidious",
42324222 "libmpv-sirno",
Cargo.toml −1
@@ -28,7 +28,6 @@ rustypipe = []
2828serde = {version = "1.0", default-features = false, features = ["derive"]}
2929crossterm = {version = "0.29", default-features = false, features = ["serde"]}
3030viuer = {version = "0.11", default-features = false, optional = true, features = ["print-file"]}
31home = "0.5"
3231dirs = "5"
3332chrono = {version = "0.4", default-features = false, features = ["clock"]}
3433typemap = {version = "0.3", default-features = false}
src/config/main.rs +1 −2
@@ -287,10 +287,9 @@ const fn write_to_config_default() -> WriteConfig {
287287}
288288
289289fn default_env() -> HashMap<String, String> {
290 use crate::global::functions::paths;
291
292290 #[cfg(target_os = "windows")]
293291 {
292 use crate::global::functions::paths;
294293 HashMap::from([
295294 (String::from("video-player"), String::from("mpv")),
296295 (String::from("browser"), String::from("explorer")),
src/global/functions/find_library.rs +1 −1
@@ -9,7 +9,7 @@ pub fn find_library_item(id: &str, mainconfig: &MainConfig) -> Option<PathBuf> {
99
1010 // Resolve save-path: handle tilde expansion for backward compatibility
1111 let save_path = if save_path_str.starts_with("~/") || save_path_str.starts_with("~\\") {
12 home::home_dir()
12 dirs::home_dir()
1313 .unwrap()
1414 .join(&save_path_str[2..])
1515 } else {
src/global/functions/paths.rs +27 −15
@@ -5,30 +5,43 @@ use std::path::PathBuf;
55/// On Linux this is handled by `dirs` already. On Windows and macOS, `dirs`
66/// ignores XDG env vars, so we check manually first. This lets Windows users
77/// keep their config in `~/.config` by setting `XDG_CONFIG_HOME`.
8fn xdg_config_base() -> PathBuf {
9 std::env::var("XDG_CONFIG_HOME")
8fn sys_config_base() -> PathBuf {
9 std::env::var("YOUTUBETUI_CONFIG_HOME")
1010 .map(PathBuf::from)
1111 .unwrap_or_else(|_| {
12 dirs::config_dir().unwrap_or_else(|| home::home_dir().unwrap().join(".config"))
12 dirs::config_dir()
13 .expect("no config dir, set the YOUTUBETUI_CONFIG_HOME variable to set a directory")
1314 })
1415}
1516
1617/// Returns the base data directory, respecting XDG_DATA_HOME on all platforms.
17fn xdg_data_base() -> PathBuf {
18 std::env::var("XDG_DATA_HOME")
18fn sys_data_base() -> PathBuf {
19 std::env::var("YOUTUBETUI_DATA_HOME")
1920 .map(PathBuf::from)
2021 .unwrap_or_else(|_| {
2122 dirs::data_local_dir()
22 .unwrap_or_else(|| home::home_dir().unwrap().join(".local").join("share"))
23 .expect("no data dir, set the YOUTUBETUI_DATA_HOME variable to set a directory")
2324 })
2425}
2526
2627/// Returns the base cache directory, respecting XDG_CACHE_HOME on all platforms.
27fn xdg_cache_base() -> PathBuf {
28 std::env::var("XDG_CACHE_HOME")
28fn sys_cache_base() -> PathBuf {
29 std::env::var("YOUTUBETUI_CACHE_HOME")
2930 .map(PathBuf::from)
3031 .unwrap_or_else(|_| {
31 dirs::cache_dir().unwrap_or_else(|| home::home_dir().unwrap().join(".cache"))
32 dirs::cache_dir()
33 .expect("no cache dir, set the YOUTUBETUI_CACHE_HOME variable to set a directory")
34 })
35}
36
37/// Returns the base cache directory, respecting XDG_CACHE_HOME on all platforms.
38fn sys_download_base() -> PathBuf {
39 std::env::var("YOUTUBETUI_DOWNLOAD_HOME")
40 .map(PathBuf::from)
41 .unwrap_or_else(|_| {
42 dirs::cache_dir().expect(
43 "no cache dir, set the YOUTUBETUI_DOWNLOAD_HOME variable to set a directory",
44 )
3245 })
3346}
3447
@@ -39,7 +52,7 @@ fn xdg_cache_base() -> PathBuf {
3952/// - Windows: `%APPDATA%\youtube-tui\` (or `~/.config/youtube-tui/` if XDG_CONFIG_HOME is set)
4053/// - macOS: `~/Library/Application Support/youtube-tui/`
4154pub fn config_dir() -> PathBuf {
42 xdg_config_base().join("youtube-tui")
55 sys_config_base().join("youtube-tui")
4356}
4457
4558/// Returns the data directory for youtube-tui.
@@ -49,7 +62,7 @@ pub fn config_dir() -> PathBuf {
4962/// - Windows: `%LOCALAPPDATA%\youtube-tui\`
5063/// - macOS: `~/Library/Application Support/youtube-tui/`
5164pub fn data_dir() -> PathBuf {
52 xdg_data_base().join("youtube-tui")
65 sys_data_base().join("youtube-tui")
5366}
5467
5568/// Returns the cache directory for youtube-tui.
@@ -59,14 +72,14 @@ pub fn data_dir() -> PathBuf {
5972/// - Windows: `%LOCALAPPDATA%\youtube-tui\cache\`
6073/// - macOS: `~/Library/Caches/youtube-tui/`
6174pub fn cache_dir() -> PathBuf {
62 xdg_cache_base().join("youtube-tui")
75 sys_cache_base().join("youtube-tui")
6376}
6477
6578/// Returns the storage directory for rustypipe.
6679///
6780/// Respects `XDG_DATA_HOME` on all platforms.
6881pub fn rustypipe_dir() -> PathBuf {
69 xdg_data_base().join("rustypipe")
82 sys_data_base().join("rustypipe")
7083}
7184
7285/// Returns the default save path string for the `save-path` env variable.
@@ -81,8 +94,7 @@ pub fn default_save_path() -> String {
8194
8295/// Returns the default download path string for the `download-path` env variable.
8396pub fn default_download_path() -> String {
84 let downloads =
85 dirs::download_dir().unwrap_or_else(|| home::home_dir().unwrap().join("Downloads"));
97 let downloads = sys_download_base();
8698 let mut s = downloads.to_string_lossy().to_string();
8799 if !s.ends_with(std::path::MAIN_SEPARATOR) {
88100 s.push(std::path::MAIN_SEPARATOR);