Enhance file browsing and handling in main.rs

This commit provides additional functionality to the file manager, allowing users to view and open files within directories. The 'get_files' command has been added to the main.rs file. This new command navigates directories and retrieves relevant details including the metadata. The metadata includes the creation, modification, and access times converted into Unix time. To handle possible errors during these operations, proper error checks have been put in place. An existing error has been rectified in the tauri.conf.json file. File scopes have been extended to ensure all directories can be
This commit is contained in:
Ian Wijma 2023-11-27 23:48:50 +11:00
parent e8969a4306
commit d2f6d1640a
2 changed files with 20 additions and 3 deletions

View File

@ -60,6 +60,22 @@ fn get_files(
} }
} }
let mut created = 0 as u64;
if let Ok(created_date) = metadata.created() {
created = created_date.duration_since(UNIX_EPOCH).unwrap().as_secs();
}
let mut modified = 0 as u64;
if let Ok(modified_date) = metadata.modified() {
modified = modified_date.duration_since(UNIX_EPOCH).unwrap().as_secs();
}
let mut accessed = 0 as u64;
if let Ok(accessed_date) = metadata.accessed() {
accessed = accessed_date.duration_since(UNIX_EPOCH).unwrap().as_secs();
}
data.push(EntryMetaData{ data.push(EntryMetaData{
name: entry.file_name().to_string_lossy().to_string(), name: entry.file_name().to_string_lossy().to_string(),
path: entry.path().to_string_lossy().to_string(), path: entry.path().to_string_lossy().to_string(),
@ -69,9 +85,9 @@ fn get_files(
is_symlink: metadata.is_symlink(), is_symlink: metadata.is_symlink(),
directory_item_count, directory_item_count,
permission, permission,
created: metadata.created().unwrap().duration_since(UNIX_EPOCH).unwrap().as_secs(), created,
modified: metadata.modified().unwrap().duration_since(UNIX_EPOCH).unwrap().as_secs(), modified,
accessed: metadata.accessed().unwrap().duration_since(UNIX_EPOCH).unwrap().as_secs(), accessed,
}); });
} }

View File

@ -20,6 +20,7 @@
"fs": { "fs": {
"all": true, "all": true,
"scope": [ "scope": [
"/",
"**", "**",
"$APP", "$APP",
"$APP/**", "$APP/**",