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"
1124source = "registry+https://github.com/rust-lang/crates.io-index" 1124source = "registry+https://github.com/rust-lang/crates.io-index"
1125checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 1125checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
1126 1126
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
1136[[package]] 1127[[package]]
1137name = "http" 1128name = "http"
1138version = "1.4.0" 1129version = "1.4.0"
@@ -4226,7 +4217,6 @@ dependencies = [
4226 "dirs", 4217 "dirs",
4227 "dyn-clone", 4218 "dyn-clone",
4228 "futures", 4219 "futures",
4229 "home",
4230 "http_req 0.14.4", 4220 "http_req 0.14.4",
4231 "invidious", 4221 "invidious",
4232 "libmpv-sirno", 4222 "libmpv-sirno",
Cargo.toml −1
@@ -28,7 +28,6 @@ rustypipe = []
28serde = {version = "1.0", default-features = false, features = ["derive"]} 28serde = {version = "1.0", default-features = false, features = ["derive"]}
29crossterm = {version = "0.29", default-features = false, features = ["serde"]} 29crossterm = {version = "0.29", default-features = false, features = ["serde"]}
30viuer = {version = "0.11", default-features = false, optional = true, features = ["print-file"]} 30viuer = {version = "0.11", default-features = false, optional = true, features = ["print-file"]}
31home = "0.5"
32dirs = "5" 31dirs = "5"
33chrono = {version = "0.4", default-features = false, features = ["clock"]} 32chrono = {version = "0.4", default-features = false, features = ["clock"]}
34typemap = {version = "0.3", default-features = false} 33typemap = {version = "0.3", default-features = false}
src/config/main.rs +1 −2
@@ -287,10 +287,9 @@ const fn write_to_config_default() -> WriteConfig {
287} 287}
288 288
289fn default_env() -> HashMap<String, String> { 289fn default_env() -> HashMap<String, String> {
290 use crate::global::functions::paths;
291
292 #[cfg(target_os = "windows")] 290 #[cfg(target_os = "windows")]
293 { 291 {
292 use crate::global::functions::paths;
294 HashMap::from([ 293 HashMap::from([
295 (String::from("video-player"), String::from("mpv")), 294 (String::from("video-player"), String::from("mpv")),
296 (String::from("browser"), String::from("explorer")), 295 (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> {
9 9
10 // Resolve save-path: handle tilde expansion for backward compatibility 10 // Resolve save-path: handle tilde expansion for backward compatibility
11 let save_path = if save_path_str.starts_with("~/") || save_path_str.starts_with("~\\") { 11 let save_path = if save_path_str.starts_with("~/") || save_path_str.starts_with("~\\") {
12 home::home_dir() 12 dirs::home_dir()
13 .unwrap() 13 .unwrap()
14 .join(&save_path_str[2..]) 14 .join(&save_path_str[2..])
15 } else { 15 } else {
src/global/functions/paths.rs +27 −15
@@ -5,30 +5,43 @@ use std::path::PathBuf;
5/// On Linux this is handled by `dirs` already. On Windows and macOS, `dirs` 5/// On Linux this is handled by `dirs` already. On Windows and macOS, `dirs`
6/// ignores XDG env vars, so we check manually first. This lets Windows users 6/// ignores XDG env vars, so we check manually first. This lets Windows users
7/// keep their config in `~/.config` by setting `XDG_CONFIG_HOME`. 7/// keep their config in `~/.config` by setting `XDG_CONFIG_HOME`.
8fn xdg_config_base() -> PathBuf { 8fn sys_config_base() -> PathBuf {
9 std::env::var("XDG_CONFIG_HOME") 9 std::env::var("YOUTUBETUI_CONFIG_HOME")
10 .map(PathBuf::from) 10 .map(PathBuf::from)
11 .unwrap_or_else(|_| { 11 .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")
13 }) 14 })
14} 15}
15 16
16/// Returns the base data directory, respecting XDG_DATA_HOME on all platforms. 17/// Returns the base data directory, respecting XDG_DATA_HOME on all platforms.
17fn xdg_data_base() -> PathBuf { 18fn sys_data_base() -> PathBuf {
18 std::env::var("XDG_DATA_HOME") 19 std::env::var("YOUTUBETUI_DATA_HOME")
19 .map(PathBuf::from) 20 .map(PathBuf::from)
20 .unwrap_or_else(|_| { 21 .unwrap_or_else(|_| {
21 dirs::data_local_dir() 22 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")
23 }) 24 })
24} 25}
25 26
26/// Returns the base cache directory, respecting XDG_CACHE_HOME on all platforms. 27/// Returns the base cache directory, respecting XDG_CACHE_HOME on all platforms.
27fn xdg_cache_base() -> PathBuf { 28fn sys_cache_base() -> PathBuf {
28 std::env::var("XDG_CACHE_HOME") 29 std::env::var("YOUTUBETUI_CACHE_HOME")
29 .map(PathBuf::from) 30 .map(PathBuf::from)
30 .unwrap_or_else(|_| { 31 .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 )
32 }) 45 })
33} 46}
34 47
@@ -39,7 +52,7 @@ fn xdg_cache_base() -> PathBuf {
39/// - Windows: `%APPDATA%\youtube-tui\` (or `~/.config/youtube-tui/` if XDG_CONFIG_HOME is set) 52/// - Windows: `%APPDATA%\youtube-tui\` (or `~/.config/youtube-tui/` if XDG_CONFIG_HOME is set)
40/// - macOS: `~/Library/Application Support/youtube-tui/` 53/// - macOS: `~/Library/Application Support/youtube-tui/`
41pub fn config_dir() -> PathBuf { 54pub fn config_dir() -> PathBuf {
42 xdg_config_base().join("youtube-tui") 55 sys_config_base().join("youtube-tui")
43} 56}
44 57
45/// Returns the data directory for youtube-tui. 58/// Returns the data directory for youtube-tui.
@@ -49,7 +62,7 @@ pub fn config_dir() -> PathBuf {
49/// - Windows: `%LOCALAPPDATA%\youtube-tui\` 62/// - Windows: `%LOCALAPPDATA%\youtube-tui\`
50/// - macOS: `~/Library/Application Support/youtube-tui/` 63/// - macOS: `~/Library/Application Support/youtube-tui/`
51pub fn data_dir() -> PathBuf { 64pub fn data_dir() -> PathBuf {
52 xdg_data_base().join("youtube-tui") 65 sys_data_base().join("youtube-tui")
53} 66}
54 67
55/// Returns the cache directory for youtube-tui. 68/// Returns the cache directory for youtube-tui.
@@ -59,14 +72,14 @@ pub fn data_dir() -> PathBuf {
59/// - Windows: `%LOCALAPPDATA%\youtube-tui\cache\` 72/// - Windows: `%LOCALAPPDATA%\youtube-tui\cache\`
60/// - macOS: `~/Library/Caches/youtube-tui/` 73/// - macOS: `~/Library/Caches/youtube-tui/`
61pub fn cache_dir() -> PathBuf { 74pub fn cache_dir() -> PathBuf {
62 xdg_cache_base().join("youtube-tui") 75 sys_cache_base().join("youtube-tui")
63} 76}
64 77
65/// Returns the storage directory for rustypipe. 78/// Returns the storage directory for rustypipe.
66/// 79///
67/// Respects `XDG_DATA_HOME` on all platforms. 80/// Respects `XDG_DATA_HOME` on all platforms.
68pub fn rustypipe_dir() -> PathBuf { 81pub fn rustypipe_dir() -> PathBuf {
69 xdg_data_base().join("rustypipe") 82 sys_data_base().join("rustypipe")
70} 83}
71 84
72/// Returns the default save path string for the `save-path` env variable. 85/// Returns the default save path string for the `save-path` env variable.
@@ -81,8 +94,7 @@ pub fn default_save_path() -> String {
81 94
82/// Returns the default download path string for the `download-path` env variable. 95/// Returns the default download path string for the `download-path` env variable.
83pub fn default_download_path() -> String { 96pub fn default_download_path() -> String {
84 let downloads = 97 let downloads = sys_download_base();
85 dirs::download_dir().unwrap_or_else(|| home::home_dir().unwrap().join("Downloads"));
86 let mut s = downloads.to_string_lossy().to_string(); 98 let mut s = downloads.to_string_lossy().to_string();
87 if !s.ends_with(std::path::MAIN_SEPARATOR) { 99 if !s.ends_with(std::path::MAIN_SEPARATOR) {
88 s.push(std::path::MAIN_SEPARATOR); 100 s.push(std::path::MAIN_SEPARATOR);