From 44a118605f8a9ab035e6f7bef27eb41b98de1d8a Mon Sep 17 00:00:00 2001 From: lanyeeee Date: Sun, 3 Aug 2025 05:56:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97Dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 14 +++ package.json | 1 + pnpm-lock.yaml | 13 +++ src-tauri/src/commands.rs | 31 ++++++ src-tauri/src/lib.rs | 2 + src/App.vue | 217 ++++++++------------------------------ src/AppContent.vue | 59 +++++++++++ src/bindings.ts | 16 +++ src/dialogs/LogDialog.vue | 205 +++++++++++++++++++++++++++++++++++ src/store.ts | 6 +- 10 files changed, 389 insertions(+), 175 deletions(-) create mode 100644 src/AppContent.vue create mode 100644 src/dialogs/LogDialog.vue diff --git a/components.d.ts b/components.d.ts index 09c6b47..8cfac07 100644 --- a/components.d.ts +++ b/components.d.ts @@ -9,5 +9,19 @@ export {} declare module 'vue' { export interface GlobalComponents { NButton: typeof import('naive-ui')['NButton'] + NCheckbox: typeof import('naive-ui')['NCheckbox'] + NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + NDialog: typeof import('naive-ui')['NDialog'] + NDialogProvider: typeof import('naive-ui')['NDialogProvider'] + NIcon: typeof import('naive-ui')['NIcon'] + NInput: typeof import('naive-ui')['NInput'] + NInputGroup: typeof import('naive-ui')['NInputGroup'] + NMessageProvider: typeof import('naive-ui')['NMessageProvider'] + NModal: typeof import('naive-ui')['NModal'] + NModalProvider: typeof import('naive-ui')['NModalProvider'] + NNotificationProvider: typeof import('naive-ui')['NNotificationProvider'] + NSelect: typeof import('naive-ui')['NSelect'] + NTooltip: typeof import('naive-ui')['NTooltip'] + NVirtualList: typeof import('naive-ui')['NVirtualList'] } } diff --git a/package.json b/package.json index bdd50aa..e0eef49 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "tauri": "tauri" }, "dependencies": { + "@phosphor-icons/vue": "^2.2.1", "@tauri-apps/api": "^2", "@tauri-apps/plugin-opener": "^2", "naive-ui": "^2.42.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6fadcd4..8b0b49d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@phosphor-icons/vue': + specifier: ^2.2.1 + version: 2.2.1(vue@3.5.17(typescript@5.6.3)) '@tauri-apps/api': specifier: ^2 version: 2.6.0 @@ -493,6 +496,12 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@phosphor-icons/vue@2.2.1': + resolution: {integrity: sha512-3RNg1utc2Z5RwPKWFkW3eXI/0BfQAwXgtFxPUPeSzi55jGYUq16b+UqcgbKLazWFlwg5R92OCLKjDiJjeiJcnA==} + engines: {node: '>=14'} + peerDependencies: + vue: '>=3.2.39' + '@polka/url@1.0.0-next.29': resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==} @@ -2381,6 +2390,10 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.19.1 + '@phosphor-icons/vue@2.2.1(vue@3.5.17(typescript@5.6.3))': + dependencies: + vue: 3.5.17(typescript@5.6.3) + '@polka/url@1.0.0-next.29': {} '@quansync/fs@0.1.3': diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index c30dce1..74361a8 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -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 CommandResult { + 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::(); + 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(()) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8ba3d07..89d3b4f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -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]); diff --git a/src/App.vue b/src/App.vue index f3d47ad..50aa4b8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,180 +1,49 @@ - - - - diff --git a/src/AppContent.vue b/src/AppContent.vue new file mode 100644 index 0000000..a0484ad --- /dev/null +++ b/src/AppContent.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/src/bindings.ts b/src/bindings.ts index 843d85c..2e20dcd 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -161,6 +161,22 @@ async search(params: SearchParams) : Promise> if(e instanceof Error) throw e; else return { status: "error", error: e as any }; } +}, +async getLogsDirSize() : Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_logs_dir_size") }; +} catch (e) { + if(e instanceof Error) throw e; + else return { status: "error", error: e as any }; +} +}, +async showPathInFileManager(path: string) : Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("show_path_in_file_manager", { path }) }; +} catch (e) { + if(e instanceof Error) throw e; + else return { status: "error", error: e as any }; +} } } diff --git a/src/dialogs/LogDialog.vue b/src/dialogs/LogDialog.vue new file mode 100644 index 0000000..54cae42 --- /dev/null +++ b/src/dialogs/LogDialog.vue @@ -0,0 +1,205 @@ + + + diff --git a/src/store.ts b/src/store.ts index 456213e..986b160 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,5 +1,9 @@ import { defineStore } from 'pinia' +import { ref } from 'vue' +import { Config } from './bindings.ts' export const useStore = defineStore('store', () => { - return {} + const config = ref() + + return { config } })