Skip to content

Commit 52c2baf

Browse files
authored
feat: add current working directory to path api module (#1375)
1 parent 5b3d9b2 commit 52c2baf

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.changes/api-path-cwd.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": minor
3+
"tauri-api": minor
4+
---
5+
Add current working directory to the path api module.

api/src/fs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export enum BaseDirectory {
1818
Template,
1919
Video,
2020
Resource,
21-
App
21+
App,
22+
Current
2223
}
2324

2425
export interface FsOptions {

api/src/path.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,22 @@ async function videoDir(): Promise<string> {
289289
})
290290
}
291291

292+
/**
293+
* @name currentDir
294+
* @descriptionReturns Returns the path to the current working dir.
295+
* @return {Promise<string>}
296+
*/
297+
async function currentDir(): Promise<string> {
298+
return invokeTauriCommand<string>({
299+
__tauriModule: 'Fs',
300+
message: {
301+
cmd: 'resolvePath',
302+
path: '',
303+
directory: BaseDirectory.Current
304+
}
305+
})
306+
}
307+
292308
/**
293309
* @name resolvePath
294310
* @descriptionReturns Resolves the path with the optional base directory.
@@ -327,5 +343,6 @@ export {
327343
runtimeDir,
328344
templateDir,
329345
videoDir,
346+
currentDir,
330347
resolvePath
331348
}

tauri-api/src/path.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::path::{Path, PathBuf};
1+
use std::{
2+
env,
3+
path::{Path, PathBuf},
4+
};
25

36
use serde_repr::{Deserialize_repr, Serialize_repr};
47

@@ -47,6 +50,8 @@ pub enum BaseDirectory {
4750
/// The default App config directory.
4851
/// Resolves to ${CONFIG_DIR}/${APP_NAME}
4952
App,
53+
/// The current working directory.
54+
Current,
5055
}
5156

5257
/// 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
7984
BaseDirectory::Video => video_dir(),
8085
BaseDirectory::Resource => resource_dir(),
8186
BaseDirectory::App => app_dir(),
87+
BaseDirectory::Current => Some(env::current_dir()?),
8288
};
8389
if let Some(mut base_dir_path_value) = base_dir_path {
8490
base_dir_path_value.push(path);

0 commit comments

Comments
 (0)