feat(layout):完成基本界面布局以及文件夹扫描功能。

This commit is contained in:
徐涛
2023-03-08 14:02:17 +08:00
parent ebc7c26522
commit 848c8c01e7
15 changed files with 367 additions and 24 deletions

View File

@@ -0,0 +1,36 @@
use anyhow::anyhow;
use serde::Serialize;
use walkdir::WalkDir;
#[derive(Debug, Clone, Serialize)]
pub struct FileItem {
pub filename: String,
pub path: String,
}
#[tauri::command]
pub fn scan_directory(target: String) -> Result<Vec<FileItem>, String> {
WalkDir::new(target)
.into_iter()
.filter_map(|f| f.ok())
.filter(|f| f.path().is_file())
.map(|f| {
Ok(FileItem {
filename: f
.path()
.file_name()
.ok_or(anyhow!("不能获取到文件名。"))?
.to_owned()
.into_string()
.unwrap(),
path: f
.path()
.clone()
.to_str()
.ok_or(anyhow!("不能获取到文件路径。"))?
.to_string(),
})
})
.collect::<Result<Vec<FileItem>, anyhow::Error>>()
.map_err(|e| e.to_string())
}

View File

@@ -1,5 +1,11 @@
use tauri::{App, AppHandle, Runtime, Window};
mod files;
pub mod prelude {
pub use super::files::*;
}
/// 用于持有应用实例,可存放不同的应用实例。
pub enum AppHold<'a, R: Runtime> {
Instance(&'a App<R>),

View File

@@ -8,7 +8,7 @@ use tauri::Manager;
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![])
.invoke_handler(tauri::generate_handler![commands::prelude::scan_directory])
.setup(|app| {
let main_window = app.get_window("main").unwrap();
#[cfg(debug_assertions)]