@@ -13,61 +13,94 @@ use crate::{Config, Env, PackageInfo};
1313
1414use serde_repr:: { Deserialize_repr , Serialize_repr } ;
1515
16- /// A base directory to be used in [`resolve_path`].
17- ///
18- /// The base directory is the optional root of a file system operation.
19- /// If informed by the API call, all paths will be relative to the path of the given directory.
20- ///
21- /// For more information, check the [`dirs_next` documentation](https://docs.rs/dirs_next/).
22- #[ derive( Serialize_repr , Deserialize_repr , Clone , Copy , Debug ) ]
23- #[ repr( u16 ) ]
24- #[ non_exhaustive]
25- pub enum BaseDirectory {
26- /// The Audio directory.
27- Audio = 1 ,
28- /// The Cache directory.
29- Cache ,
30- /// The Config directory.
31- Config ,
32- /// The Data directory.
33- Data ,
34- /// The LocalData directory.
35- LocalData ,
36- /// The Desktop directory.
37- Desktop ,
38- /// The Document directory.
39- Document ,
40- /// The Download directory.
41- Download ,
42- /// The Executable directory.
43- Executable ,
44- /// The Font directory.
45- Font ,
46- /// The Home directory.
47- Home ,
48- /// The Picture directory.
49- Picture ,
50- /// The Public directory.
51- Public ,
52- /// The Runtime directory.
53- Runtime ,
54- /// The Template directory.
55- Template ,
56- /// The Video directory.
57- Video ,
58- /// The Resource directory.
59- Resource ,
60- /// The default App config directory.
61- /// Resolves to [`BaseDirectory::Config`].
62- App ,
63- /// The Log directory.
64- /// Resolves to `BaseDirectory::Home/Library/Logs/{bundle_identifier}` on macOS
65- /// and `BaseDirectory::Config/{bundle_identifier}/logs` on linux and windows.
66- Log ,
67- /// A temporary directory.
68- /// Resolves to [`temp_dir`].
69- Temp ,
16+ // we have to wrap the BaseDirectory enum in a module for #[allow(deprecated)]
17+ // to work, because the procedural macros on the enum prevent it from working directly
18+ // TODO: remove this workaround in v2 along with deprecated variants
19+ #[ allow( deprecated) ]
20+ mod base_directory {
21+ use super :: * ;
22+
23+ /// A base directory to be used in [`resolve_path`].
24+ ///
25+ /// The base directory is the optional root of a file system operation.
26+ /// If informed by the API call, all paths will be relative to the path of the given directory.
27+ ///
28+ /// For more information, check the [`dirs_next` documentation](https://docs.rs/dirs_next/).
29+ #[ derive( Serialize_repr , Deserialize_repr , Clone , Copy , Debug ) ]
30+ #[ repr( u16 ) ]
31+ #[ non_exhaustive]
32+ pub enum BaseDirectory {
33+ /// The Audio directory.
34+ Audio = 1 ,
35+ /// The Cache directory.
36+ Cache ,
37+ /// The Config directory.
38+ Config ,
39+ /// The Data directory.
40+ Data ,
41+ /// The LocalData directory.
42+ LocalData ,
43+ /// The Desktop directory.
44+ Desktop ,
45+ /// The Document directory.
46+ Document ,
47+ /// The Download directory.
48+ Download ,
49+ /// The Executable directory.
50+ Executable ,
51+ /// The Font directory.
52+ Font ,
53+ /// The Home directory.
54+ Home ,
55+ /// The Picture directory.
56+ Picture ,
57+ /// The Public directory.
58+ Public ,
59+ /// The Runtime directory.
60+ Runtime ,
61+ /// The Template directory.
62+ Template ,
63+ /// The Video directory.
64+ Video ,
65+ /// The Resource directory.
66+ Resource ,
67+ /// The default app config directory.
68+ /// Resolves to [`BaseDirectory::Config`]`/{bundle_identifier}`.
69+ #[ deprecated(
70+ since = "1.2.0" ,
71+ note = "Will be removed in 2.0.0. Use `BaseDirectory::AppConfig` or BaseDirectory::AppData` instead."
72+ ) ]
73+ App ,
74+ /// The default app log directory.
75+ /// Resolves to [`BaseDirectory::Home`]`/Library/Logs/{bundle_identifier}` on macOS
76+ /// and [`BaseDirectory::Config`]`/{bundle_identifier}/logs` on linux and Windows.
77+ #[ deprecated(
78+ since = "1.2.0" ,
79+ note = "Will be removed in 2.0.0. Use `BaseDirectory::AppLog` instead."
80+ ) ]
81+ Log ,
82+ /// A temporary directory.
83+ /// Resolves to [`temp_dir`].
84+ Temp ,
85+ /// The default app config directory.
86+ /// Resolves to [`BaseDirectory::Config`]`/{bundle_identifier}`.
87+ AppConfig ,
88+ /// The default app data directory.
89+ /// Resolves to [`BaseDirectory::Data`]`/{bundle_identifier}`.
90+ AppData ,
91+ /// The default app local data directory.
92+ /// Resolves to [`BaseDirectory::LocalData`]`/{bundle_identifier}`.
93+ AppLocalData ,
94+ /// The default app cache directory.
95+ /// Resolves to [`BaseDirectory::Cache`]`/{bundle_identifier}`.
96+ AppCache ,
97+ /// The default app log directory.
98+ /// Resolves to [`BaseDirectory::Home`]`/Library/Logs/{bundle_identifier}` on macOS
99+ /// and [`BaseDirectory::Config`]`/{bundle_identifier}/logs` on linux and Windows.
100+ AppLog ,
101+ }
70102}
103+ pub use base_directory:: BaseDirectory ;
71104
72105impl BaseDirectory {
73106 /// Gets the variable that represents this [`BaseDirectory`] for string paths.
@@ -90,9 +123,16 @@ impl BaseDirectory {
90123 Self :: Template => "$TEMPLATE" ,
91124 Self :: Video => "$VIDEO" ,
92125 Self :: Resource => "$RESOURCE" ,
126+ #[ allow( deprecated) ]
93127 Self :: App => "$APP" ,
128+ #[ allow( deprecated) ]
94129 Self :: Log => "$LOG" ,
95130 Self :: Temp => "$TEMP" ,
131+ Self :: AppConfig => "$APPCONFIG" ,
132+ Self :: AppData => "$APPDATA" ,
133+ Self :: AppLocalData => "$APPLOCALDATA" ,
134+ Self :: AppCache => "$APPCACHE" ,
135+ Self :: AppLog => "$APPLOG" ,
96136 }
97137 }
98138
@@ -116,9 +156,16 @@ impl BaseDirectory {
116156 "$TEMPLATE" => Self :: Template ,
117157 "$VIDEO" => Self :: Video ,
118158 "$RESOURCE" => Self :: Resource ,
159+ #[ allow( deprecated) ]
119160 "$APP" => Self :: App ,
161+ #[ allow( deprecated) ]
120162 "$LOG" => Self :: Log ,
121163 "$TEMP" => Self :: Temp ,
164+ "$APPCONFIG" => Self :: AppConfig ,
165+ "$APPDATA" => Self :: AppData ,
166+ "$APPLOCALDATA" => Self :: AppLocalData ,
167+ "$APPCACHE" => Self :: AppCache ,
168+ "$APPLOG" => Self :: AppLog ,
122169 _ => return None ,
123170 } ;
124171 Some ( res)
@@ -192,7 +239,7 @@ pub fn parse<P: AsRef<Path>>(
192239/// context.package_info(),
193240/// &Env::default(),
194241/// "db/tauri.sqlite",
195- /// Some(BaseDirectory::App ))
242+ /// Some(BaseDirectory::AppData ))
196243/// .expect("failed to resolve path");
197244/// assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/com.tauri.app/db/tauri.sqlite");
198245///
@@ -242,9 +289,16 @@ pub fn resolve_path<P: AsRef<Path>>(
242289 BaseDirectory :: Template => template_dir ( ) ,
243290 BaseDirectory :: Video => video_dir ( ) ,
244291 BaseDirectory :: Resource => resource_dir ( package_info, env) ,
245- BaseDirectory :: App => app_dir ( config) ,
246- BaseDirectory :: Log => log_dir ( config) ,
292+ #[ allow( deprecated) ]
293+ BaseDirectory :: App => app_config_dir ( config) ,
294+ #[ allow( deprecated) ]
295+ BaseDirectory :: Log => app_log_dir ( config) ,
247296 BaseDirectory :: Temp => Some ( temp_dir ( ) ) ,
297+ BaseDirectory :: AppConfig => app_config_dir ( config) ,
298+ BaseDirectory :: AppData => app_data_dir ( config) ,
299+ BaseDirectory :: AppLocalData => app_local_data_dir ( config) ,
300+ BaseDirectory :: AppCache => app_cache_dir ( config) ,
301+ BaseDirectory :: AppLog => app_log_dir ( config) ,
248302 } ;
249303 if let Some ( mut base_dir_path_value) = base_dir_path {
250304 // use the same path resolution mechanism as the bundler's resource injection algorithm
@@ -459,25 +513,52 @@ pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> Option<PathBuf> {
459513 crate :: utils:: platform:: resource_dir ( package_info, env) . ok ( )
460514}
461515
462- /// Returns the path to the suggested directory for your app config files.
516+ /// Returns the path to the suggested directory for your app's config files.
463517///
464- /// Resolves to `${ config_dir} /${bundle_identifier}`.
518+ /// Resolves to [` config_dir`]` /${bundle_identifier}`.
465519///
466- /// See [`PathResolver::app_dir `](crate::PathResolver#method.app_dir ) for a more convenient helper function.
467- pub fn app_dir ( config : & Config ) -> Option < PathBuf > {
520+ /// See [`PathResolver::app_config_dir `](crate::PathResolver#method.app_config_dir ) for a more convenient helper function.
521+ pub fn app_config_dir ( config : & Config ) -> Option < PathBuf > {
468522 dirs_next:: config_dir ( ) . map ( |dir| dir. join ( & config. tauri . bundle . identifier ) )
469523}
470524
471- /// Returns the path to the suggested log directory.
525+ /// Returns the path to the suggested directory for your app's data files.
526+ ///
527+ /// Resolves to [`data_dir`]`/${bundle_identifier}`.
528+ ///
529+ /// See [`PathResolver::app_data_dir`](crate::PathResolver#method.app_data_dir) for a more convenient helper function.
530+ pub fn app_data_dir ( config : & Config ) -> Option < PathBuf > {
531+ dirs_next:: data_dir ( ) . map ( |dir| dir. join ( & config. tauri . bundle . identifier ) )
532+ }
533+
534+ /// Returns the path to the suggested directory for your app's local data files.
535+ ///
536+ /// Resolves to [`local_data_dir`]`/${bundle_identifier}`.
537+ ///
538+ /// See [`PathResolver::app_data_dir`](crate::PathResolver#method.app_data_dir) for a more convenient helper function.
539+ pub fn app_local_data_dir ( config : & Config ) -> Option < PathBuf > {
540+ dirs_next:: data_local_dir ( ) . map ( |dir| dir. join ( & config. tauri . bundle . identifier ) )
541+ }
542+
543+ /// Returns the path to the suggested directory for your app's cache files.
544+ ///
545+ /// Resolves to [`cache_dir`]`/${bundle_identifier}`.
546+ ///
547+ /// See [`PathResolver::app_cache_dir`](crate::PathResolver#method.app_cache_dir) for a more convenient helper function.
548+ pub fn app_cache_dir ( config : & Config ) -> Option < PathBuf > {
549+ dirs_next:: cache_dir ( ) . map ( |dir| dir. join ( & config. tauri . bundle . identifier ) )
550+ }
551+
552+ /// Returns the path to the suggested directory for your app's log files.
472553///
473554/// ## Platform-specific
474555///
475- /// - **Linux:** Resolves to `${ config_dir} /${bundle_identifier}/logs`.
476- /// - **macOS:** Resolves to `${ home_dir}// Library/Logs/{bundle_identifier}`
477- /// - **Windows:** Resolves to `${ config_dir} /${bundle_identifier}/logs`.
556+ /// - **Linux:** Resolves to [` config_dir`]` /${bundle_identifier}/logs`.
557+ /// - **macOS:** Resolves to [` home_dir`]`/ Library/Logs/$ {bundle_identifier}`
558+ /// - **Windows:** Resolves to [` config_dir`]` /${bundle_identifier}/logs`.
478559///
479- /// See [`PathResolver::log_dir `](crate::PathResolver#method.log_dir ) for a more convenient helper function.
480- pub fn log_dir ( config : & Config ) -> Option < PathBuf > {
560+ /// See [`PathResolver::app_log_dir `](crate::PathResolver#method.app_log_dir ) for a more convenient helper function.
561+ pub fn app_log_dir ( config : & Config ) -> Option < PathBuf > {
481562 #[ cfg( target_os = "macos" ) ]
482563 let path = dirs_next:: home_dir ( ) . map ( |dir| {
483564 dir
@@ -491,3 +572,33 @@ pub fn log_dir(config: &Config) -> Option<PathBuf> {
491572
492573 path
493574}
575+
576+ /// Returns the path to the suggested directory for your app's config files.
577+ ///
578+ /// Resolves to [`config_dir`]`/${bundle_identifier}`.
579+ ///
580+ /// See [`PathResolver::app_config_dir`](crate::PathResolver#method.app_config_dir) for a more convenient helper function.
581+ #[ deprecated(
582+ since = "1.2.0" ,
583+ note = "Will be removed in 2.0.0. Use `app_config_dir` or `app_data_dir` instead."
584+ ) ]
585+ pub fn app_dir ( config : & Config ) -> Option < PathBuf > {
586+ app_config_dir ( config)
587+ }
588+
589+ /// Returns the path to the suggested directory for your app's log files.
590+ ///
591+ /// ## Platform-specific
592+ ///
593+ /// - **Linux:** Resolves to [`config_dir`]`/${bundle_identifier}`.
594+ /// - **macOS:** Resolves to [`home_dir`]`/Library/Logs/${bundle_identifier}`
595+ /// - **Windows:** Resolves to [`config_dir`]`/${bundle_identifier}`.
596+ ///
597+ /// See [`PathResolver::app_log_dir`](crate::PathResolver#method.app_log_dir) for a more convenient helper function.
598+ #[ deprecated(
599+ since = "1.2.0" ,
600+ note = "Will be removed in 2.0.0. Use `app_log_dir` instead."
601+ ) ]
602+ pub fn log_dir ( config : & Config ) -> Option < PathBuf > {
603+ app_log_dir ( config)
604+ }
0 commit comments