Эх сурвалжийг харах

refactor(core): remove PathExt trait, add `path` function to Manager (#6670)

Lucas Fernandes Nogueira 2 жил өмнө
parent
commit
f436cf8609

+ 0 - 1
core/tauri/src/app.rs

@@ -1581,7 +1581,6 @@ impl<R: Runtime> Builder<R> {
         .windows
         .webview_install_mode
       {
-        use crate::path::PathExt;
         if let Ok(resource_dir) = app.path().resource_dir() {
           std::env::set_var(
             "WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",

+ 1 - 1
core/tauri/src/endpoints/file_system.rs

@@ -9,7 +9,7 @@ use crate::{
     dir,
     file::{self, SafePathBuf},
   },
-  path::{BaseDirectory, PathExt},
+  path::BaseDirectory,
   scope::Scopes,
   Config, Env, Manager, PackageInfo, Runtime, Window,
 };

+ 5 - 0
core/tauri/src/lib.rs

@@ -890,6 +890,11 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
   fn shell_scope(&self) -> ShellScope {
     self.state::<Scopes>().inner().shell.clone()
   }
+
+  /// The path resolver.
+  fn path(&self) -> &crate::path::PathResolver<R> {
+    self.state::<crate::path::PathResolver<R>>().inner()
+  }
 }
 
 /// Prevent implementation details from leaking out of the [`Manager`] trait.

+ 1 - 1
core/tauri/src/manager.rs

@@ -56,7 +56,7 @@ use crate::{
 };
 
 #[cfg(any(target_os = "linux", target_os = "windows"))]
-use crate::path::{BaseDirectory, PathExt};
+use crate::path::BaseDirectory;
 
 use crate::{runtime::menu::Menu, MenuEvent};
 

+ 4 - 16
core/tauri/src/path/mod.rs

@@ -25,9 +25,9 @@ mod android;
 mod desktop;
 
 #[cfg(target_os = "android")]
-use android::PathResolver;
+pub(crate) use android::PathResolver;
 #[cfg(not(target_os = "android"))]
-use desktop::PathResolver;
+pub(crate) use desktop::PathResolver;
 
 /// A base directory to be used in [`resolve_directory`].
 ///
@@ -179,25 +179,13 @@ impl BaseDirectory {
   }
 }
 
-/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the path APIs.
-pub trait PathExt<R: Runtime> {
-  /// The path resolver.
-  fn path(&self) -> &PathResolver<R>;
-}
-
-impl<R: Runtime, T: Manager<R>> PathExt<R> for T {
-  fn path(&self) -> &PathResolver<R> {
-    self.state::<PathResolver<R>>().inner()
-  }
-}
-
 impl<R: Runtime> PathResolver<R> {
   /// Resolves the path with the base directory.
   ///
   /// # Examples
   ///
   /// ```rust,no_run
-  /// use tauri::{path::{BaseDirectory, PathExt}, Manager};
+  /// use tauri::{path::BaseDirectory, Manager};
   /// tauri::Builder::default()
   ///   .setup(|app| {
   ///     let path = app.path().resolve("path/to/something", BaseDirectory::Config)?;
@@ -214,7 +202,7 @@ impl<R: Runtime> PathResolver<R> {
   /// # Examples
   ///
   /// ```rust,no_run
-  /// use tauri::{Manager, path::PathExt};
+  /// use tauri::Manager;
   /// tauri::Builder::default()
   ///   .setup(|app| {
   ///     let path = app.path().parse("$HOME/.bashrc")?;

+ 1 - 1
core/tauri/src/scope/fs.rs

@@ -13,7 +13,7 @@ pub use glob::Pattern;
 use tauri_utils::config::FsAllowlistScope;
 use uuid::Uuid;
 
-use crate::{path::PathExt, Manager, Runtime};
+use crate::{Manager, Runtime};
 
 /// Scope change event.
 #[derive(Debug, Clone)]

+ 1 - 1
core/tauri/src/scope/shell.rs

@@ -6,7 +6,7 @@
 use crate::api::process::Command;
 #[cfg(feature = "shell-open-api")]
 use crate::api::shell::Program;
-use crate::{path::PathExt, Manager, Runtime};
+use crate::{Manager, Runtime};
 
 use regex::Regex;