mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-01 11:13:40 +03:00
feat: add tempDir
to path plugin (#7144)
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
f2d68cf7d4
commit
4652c446b3
5
.changes/tempdir-api.md
Normal file
5
.changes/tempdir-api.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@tauri-apps/api': 'patch'
|
||||
---
|
||||
|
||||
Add `tempDir` function to `path` module
|
5
.changes/tempdir-core.md
Normal file
5
.changes/tempdir-core.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'patch'
|
||||
---
|
||||
|
||||
Add `temp_dir` method to `PathResolver`
|
File diff suppressed because one or more lines are too long
@ -112,4 +112,9 @@ impl<R: Runtime> PathResolver<R> {
|
||||
.call_resolve("getConfigDir")
|
||||
.map(|dir| dir.join("logs"))
|
||||
}
|
||||
|
||||
/// A temporary directory. Resolves to [`std::env::temp_dir`].
|
||||
pub fn temp_dir(&self) -> Result<PathBuf> {
|
||||
Ok(std::env::temp_dir())
|
||||
}
|
||||
}
|
||||
|
@ -254,4 +254,9 @@ impl<R: Runtime> PathResolver<R> {
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
/// A temporary directory. Resolves to [`std::env::temp_dir`].
|
||||
pub fn temp_dir(&self) -> Result<PathBuf> {
|
||||
Ok(std::env::temp_dir())
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::{
|
||||
env::temp_dir,
|
||||
path::{Component, Display, Path, PathBuf},
|
||||
};
|
||||
use std::path::{Component, Display, Path, PathBuf};
|
||||
|
||||
use crate::{
|
||||
plugin::{Builder, TauriPlugin},
|
||||
@ -26,9 +23,9 @@ mod android;
|
||||
mod desktop;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub(crate) use android::PathResolver;
|
||||
pub use android::PathResolver;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub(crate) use desktop::PathResolver;
|
||||
pub use desktop::PathResolver;
|
||||
|
||||
/// A wrapper for [`PathBuf`] that prevents path traversal.
|
||||
#[derive(Clone, Debug)]
|
||||
@ -100,8 +97,7 @@ pub enum BaseDirectory {
|
||||
Video,
|
||||
/// The Resource directory.
|
||||
Resource,
|
||||
/// A temporary directory.
|
||||
/// Resolves to [`temp_dir`].
|
||||
/// A temporary directory. Resolves to [`std::env::temp_dir`].
|
||||
Temp,
|
||||
/// The default app config directory.
|
||||
/// Resolves to [`BaseDirectory::Config`]`/{bundle_identifier}`.
|
||||
@ -293,7 +289,7 @@ fn resolve_path<R: Runtime>(
|
||||
BaseDirectory::Public => resolver.public_dir(),
|
||||
BaseDirectory::Video => resolver.video_dir(),
|
||||
BaseDirectory::Resource => resolver.resource_dir(),
|
||||
BaseDirectory::Temp => Ok(temp_dir()),
|
||||
BaseDirectory::Temp => resolver.temp_dir(),
|
||||
BaseDirectory::AppConfig => resolver.app_config_dir(),
|
||||
BaseDirectory::AppData => resolver.app_data_dir(),
|
||||
BaseDirectory::AppLocalData => resolver.app_local_data_dir(),
|
||||
|
File diff suppressed because one or more lines are too long
@ -524,6 +524,22 @@ async function appLogDir(): Promise<string> {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary directory.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { tempDir } from '@tauri-apps/api/path';
|
||||
* const temp = await tempDir();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
async function tempDir(path: string): Promise<string> {
|
||||
return invoke('plugin:path|resolve_directory', {
|
||||
directory: BaseDirectory.Temp
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the platform-specific path segment separator:
|
||||
* - `\` on Windows
|
||||
@ -683,5 +699,6 @@ export {
|
||||
dirname,
|
||||
extname,
|
||||
basename,
|
||||
isAbsolute
|
||||
isAbsolute,
|
||||
tempDir
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user