Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: implement AppPaths trait and DesktopPaths struct for file path management

Tonho54cb49ea1b6d
diff --git a/src-tauri/omniget-core/src/fs_paths.rs b/src-tauri/omniget-core/src/fs_paths.rs
new file mode 100644
index 00000000..c726d8eb
--- /dev/null
+++ b/src-tauri/omniget-core/src/fs_paths.rs
@@ -0,0 +1,32 @@
+use std::path::PathBuf;
+
+pub trait AppPaths: Send + Sync {
+ fn downloads_dir(&self) -> PathBuf;
+ fn data_dir(&self) -> PathBuf;
+ fn cache_dir(&self) -> PathBuf;
+ fn bin_dir(&self) -> Option<PathBuf>;
+}
+
+pub struct DesktopPaths;
+
+impl AppPaths for DesktopPaths {
+ fn downloads_dir(&self) -> PathBuf {
+ dirs::download_dir().unwrap_or_else(|| PathBuf::from("."))
+ }
+
+ fn data_dir(&self) -> PathBuf {
+ dirs::data_dir()
+ .map(|d| d.join("omniget"))
+ .unwrap_or_else(|| PathBuf::from("."))
+ }
+
+ fn cache_dir(&self) -> PathBuf {
+ dirs::cache_dir()
+ .map(|d| d.join("omniget"))
+ .unwrap_or_else(|| PathBuf::from("."))
+ }
+
+ fn bin_dir(&self) -> Option<PathBuf> {
+ dirs::data_dir().map(|d| d.join("omniget").join("bin"))
+ }
+}