chore(rust): added functions to detect file type
mellbacon committed
Jun 25, 2023 at 15:44 UTC
ef143b95d1c11e08105319352033955747db2772
1 file changed
+13
-3
src-tauri/src/main.rs
+13
-3
@@ -21,15 +21,25 @@ fn open_in_explorer(path: &str) {
21
}
22
}
23
24
+#[tauri::command]
25
+fn is_file(path: &str) -> bool {
26
+ fs::metadata(path).unwrap().is_file()
27
+}
28
+
29
+#[tauri::command]
30
+fn is_folder(path: &str) -> bool {
31
+ fs::metadata(path).unwrap().is_dir()
32
+}
33
+
34
#[tauri::command]
35
fn attempt_file_access(app_handle: tauri::AppHandle, p: &str) {
36
app_handle.fs_scope().allow_directory(p, true).unwrap();
37
}
38
39
#[tauri::command]
30
-fn delete_file(path: &str, perm: bool, is_file: bool) {
40
+fn delete_file(path: &str, perm: bool) {
41
if perm {
32
- if is_file {
42
+ if is_file(path) {
43
fs::remove_file(path).unwrap();
44
}
45
else {
@@ -43,7 +53,7 @@ fn delete_file(path: &str, perm: bool, is_file: bool) {
53
54
fn main() {
55
tauri::Builder::default()
46
- .invoke_handler(tauri::generate_handler![open_in_explorer, delete_file, attempt_file_access])
56
+ .invoke_handler(tauri::generate_handler![open_in_explorer, delete_file, attempt_file_access, is_file, is_folder])
57
.plugin(tauri_plugin_fs_watch::init())
58
.run(tauri::generate_context!())
59
.expect("error while running tauri application");