mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-07 11:48:46 +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,
|
Template,
|
||||||
Video,
|
Video,
|
||||||
Resource,
|
Resource,
|
||||||
App
|
App,
|
||||||
|
Current
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FsOptions {
|
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
|
* @name resolvePath
|
||||||
* @descriptionReturns Resolves the path with the optional base directory.
|
* @descriptionReturns Resolves the path with the optional base directory.
|
||||||
@ -327,5 +343,6 @@ export {
|
|||||||
runtimeDir,
|
runtimeDir,
|
||||||
templateDir,
|
templateDir,
|
||||||
videoDir,
|
videoDir,
|
||||||
|
currentDir,
|
||||||
resolvePath
|
resolvePath
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
env,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
@ -47,6 +50,8 @@ pub enum BaseDirectory {
|
|||||||
/// The default App config directory.
|
/// The default App config directory.
|
||||||
/// Resolves to ${CONFIG_DIR}/${APP_NAME}
|
/// Resolves to ${CONFIG_DIR}/${APP_NAME}
|
||||||
App,
|
App,
|
||||||
|
/// The current working directory.
|
||||||
|
Current,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the path with the optional base directory.
|
/// 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::Video => video_dir(),
|
||||||
BaseDirectory::Resource => resource_dir(),
|
BaseDirectory::Resource => resource_dir(),
|
||||||
BaseDirectory::App => app_dir(),
|
BaseDirectory::App => app_dir(),
|
||||||
|
BaseDirectory::Current => Some(env::current_dir()?),
|
||||||
};
|
};
|
||||||
if let Some(mut base_dir_path_value) = base_dir_path {
|
if let Some(mut base_dir_path_value) = base_dir_path {
|
||||||
base_dir_path_value.push(path);
|
base_dir_path_value.push(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user