mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-05 18:47:50 +03:00
feat: add current working directory to path api module (#1375)
This commit is contained in:
parent
5b3d9b2c07
commit
52c2baf940
5
.changes/api-path-cwd.md
Normal file
5
.changes/api-path-cwd.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": minor
|
||||
"tauri-api": minor
|
||||
---
|
||||
Add current working directory to the path api module.
|
@ -18,7 +18,8 @@ export enum BaseDirectory {
|
||||
Template,
|
||||
Video,
|
||||
Resource,
|
||||
App
|
||||
App,
|
||||
Current
|
||||
}
|
||||
|
||||
export interface FsOptions {
|
||||
|
@ -289,6 +289,22 @@ async function videoDir(): Promise<string> {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @name currentDir
|
||||
* @descriptionReturns Returns the path to the current working dir.
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
async function currentDir(): Promise<string> {
|
||||
return invokeTauriCommand<string>({
|
||||
__tauriModule: 'Fs',
|
||||
message: {
|
||||
cmd: 'resolvePath',
|
||||
path: '',
|
||||
directory: BaseDirectory.Current
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @name resolvePath
|
||||
* @descriptionReturns Resolves the path with the optional base directory.
|
||||
@ -327,5 +343,6 @@ export {
|
||||
runtimeDir,
|
||||
templateDir,
|
||||
videoDir,
|
||||
currentDir,
|
||||
resolvePath
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{
|
||||
env,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
|
||||
@ -47,6 +50,8 @@ pub enum BaseDirectory {
|
||||
/// The default App config directory.
|
||||
/// Resolves to ${CONFIG_DIR}/${APP_NAME}
|
||||
App,
|
||||
/// The current working directory.
|
||||
Current,
|
||||
}
|
||||
|
||||
/// Resolves the path with the optional base directory.
|
||||
@ -79,6 +84,7 @@ pub fn resolve_path<P: AsRef<Path>>(path: P, dir: Option<BaseDirectory>) -> crat
|
||||
BaseDirectory::Video => video_dir(),
|
||||
BaseDirectory::Resource => resource_dir(),
|
||||
BaseDirectory::App => app_dir(),
|
||||
BaseDirectory::Current => Some(env::current_dir()?),
|
||||
};
|
||||
if let Some(mut base_dir_path_value) = base_dir_path {
|
||||
base_dir_path_value.push(path);
|
||||
|
Loading…
Reference in New Issue
Block a user