mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): add path resolver API to the App and AppHandle structs (#2015)
This commit is contained in:
committed by
GitHub
parent
86d0aaa021
commit
5ca462f6cc
5
.changes/path-resolver.md
Normal file
5
.changes/path-resolver.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Adds a `PathResolver` struct to simplify the usage of the `tauri::api::path::{app_dir, resource_dir}` APIs, accessible through the `App` and `AppHandle` `path_resolver` methods.
|
||||
@@ -8,7 +8,7 @@ pub(crate) mod tray;
|
||||
|
||||
use crate::{
|
||||
api::assets::Assets,
|
||||
api::config::WindowUrl,
|
||||
api::config::{Config, WindowUrl},
|
||||
hooks::{InvokeHandler, OnPageLoad, PageLoadPayload, SetupHook},
|
||||
manager::{Args, WindowManager},
|
||||
plugin::{Plugin, PluginStore},
|
||||
@@ -22,7 +22,9 @@ use crate::{
|
||||
Context, Invoke, Manager, StateManager, Window,
|
||||
};
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use tauri_utils::PackageInfo;
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||
|
||||
#[cfg(feature = "menu")]
|
||||
use crate::runtime::menu::Menu;
|
||||
@@ -85,6 +87,25 @@ impl<P: Params> GlobalWindowEvent<P> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The path resolver is a helper for the application-specific [`crate::api::path`] APIs.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PathResolver {
|
||||
config: Arc<Config>,
|
||||
package_info: PackageInfo,
|
||||
}
|
||||
|
||||
impl PathResolver {
|
||||
/// Returns the path to the resource directory of this app.
|
||||
pub fn resource_dir(&self) -> Option<PathBuf> {
|
||||
crate::api::path::resource_dir(&self.package_info)
|
||||
}
|
||||
|
||||
/// Returns the path to the suggested directory for your app config files.
|
||||
pub fn app_dir(&self) -> Option<PathBuf> {
|
||||
crate::api::path::app_dir(&self.config)
|
||||
}
|
||||
}
|
||||
|
||||
crate::manager::default_args! {
|
||||
/// A handle to the currently running application.
|
||||
///
|
||||
@@ -187,6 +208,14 @@ macro_rules! shared_app_impl {
|
||||
.clone()
|
||||
.expect("tray not configured; use the `Builder#system_tray` API first.")
|
||||
}
|
||||
|
||||
/// The path resolver for the application.
|
||||
pub fn path_resolver(&self) -> PathResolver {
|
||||
PathResolver {
|
||||
config: self.manager.config(),
|
||||
package_info: self.manager.package_info().clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user