feat: 日志Dialog

This commit is contained in:
lanyeeee
2025-08-03 05:56:45 +08:00
parent 7b9fe63799
commit 44a118605f
10 changed files with 389 additions and 175 deletions
+31
View File
@@ -1,5 +1,7 @@
use anyhow::Context;
use parking_lot::RwLock;
use tauri::AppHandle;
use tauri_plugin_opener::OpenerExt;
use crate::{
config::Config,
@@ -387,3 +389,32 @@ pub async fn search(app: AppHandle, params: SearchParams) -> CommandResult<Searc
};
Ok(search_result)
}
#[allow(clippy::needless_pass_by_value)]
#[tauri::command(async)]
#[specta::specta]
pub fn get_logs_dir_size(app: AppHandle) -> CommandResult<u64> {
let logs_dir = logger::logs_dir(&app)
.context("获取日志目录失败")
.map_err(|err| CommandError::from("获取日志目录大小失败", err))?;
let logs_dir_size = std::fs::read_dir(&logs_dir)
.context(format!("读取日志目录`{}`失败", logs_dir.display()))
.map_err(|err| CommandError::from("获取日志目录大小失败", err))?
.filter_map(Result::ok)
.filter_map(|entry| entry.metadata().ok())
.map(|metadata| metadata.len())
.sum::<u64>();
tracing::debug!("获取日志目录大小成功");
Ok(logs_dir_size)
}
#[allow(clippy::needless_pass_by_value)]
#[tauri::command(async)]
#[specta::specta]
pub fn show_path_in_file_manager(app: AppHandle, path: &str) -> CommandResult<()> {
app.opener()
.reveal_item_in_dir(path)
.context(format!("在文件管理器中打开`{path}`失败"))
.map_err(|err| CommandError::from("在文件管理器中打开失败", err))?;
Ok(())
}
+2
View File
@@ -58,6 +58,8 @@ pub fn run() {
restart_download_tasks,
restore_download_tasks,
search,
get_logs_dir_size,
show_path_in_file_manager,
])
.events(tauri_specta::collect_events![LogEvent, DownloadEvent]);