From 135873a3e72c35787ea1c57ac3ea99ee5df23751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=9A=E5=AD=90?= <40852301+uiYzzi@users.noreply.github.com> Date: Fri, 7 Mar 2025 02:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E6=A3=80=E6=B5=8B=E5=92=8C=E5=90=AF=E5=8A=A8=E5=BA=94?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src-tauri/src/handlers/deb.rs | 22 +++++ src-tauri/src/handlers/mod.rs | 1 + src-tauri/src/lib.rs | 2 + src/features/app-detail/AppDetail.tsx | 126 ++++++++++++++++---------- src/lib/api/deb.ts | 9 ++ 6 files changed, 111 insertions(+), 50 deletions(-) create mode 100644 src-tauri/src/handlers/deb.rs create mode 100644 src/lib/api/deb.ts diff --git a/README.md b/README.md index 648e2c1..7a95582 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ This template should help get you started developing with Tauri, Solid and Types ## Recommended IDE Setup - [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) +##### 1.2 其他依赖 diff --git a/src-tauri/src/handlers/deb.rs b/src-tauri/src/handlers/deb.rs new file mode 100644 index 0000000..9ecc5ef --- /dev/null +++ b/src-tauri/src/handlers/deb.rs @@ -0,0 +1,22 @@ +use std::process::Command; + +#[tauri::command] +pub async fn check_is_installed(pkgname: String) -> Result { + let output = Command::new("/opt/durapps/spark-store/bin/store-helper/check-is-installed") + .arg(&pkgname) + .output() + .map_err(|e| format!("执行命令失败: {}", e))?; + + Ok(output.status.success()) +} + +#[tauri::command] +pub async fn launch_app(pkgname: String) -> Result<(), String> { + Command::new("/opt/durapps/spark-store/bin/store-helper/ss-launcher") + .arg(&pkgname) + .spawn() + .map_err(|e| format!("启动应用失败: {}", e))?; + + Ok(()) +} + diff --git a/src-tauri/src/handlers/mod.rs b/src-tauri/src/handlers/mod.rs index 261a1d4..31ed4db 100644 --- a/src-tauri/src/handlers/mod.rs +++ b/src-tauri/src/handlers/mod.rs @@ -4,3 +4,4 @@ pub mod app; pub mod home; pub mod file; pub mod download; +pub mod deb; \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 6e2d13d..2dd03e6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -30,6 +30,8 @@ pub fn run() { handlers::download::pause_download, handlers::download::resume_download, handlers::download::cancel_download, + handlers::deb::check_is_installed, + handlers::deb::launch_app, utils::get_user_agent, ]) .on_window_event(|window, event| match event { diff --git a/src/features/app-detail/AppDetail.tsx b/src/features/app-detail/AppDetail.tsx index a9aed0c..05f9879 100644 --- a/src/features/app-detail/AppDetail.tsx +++ b/src/features/app-detail/AppDetail.tsx @@ -1,4 +1,4 @@ -import { Component, createSignal } from 'solid-js'; +import { Component, createSignal, onMount } from 'solid-js'; import { useParams } from '@solidjs/router'; import { useAppDetailStore } from './store'; import './AppDetail.css'; @@ -16,6 +16,7 @@ import { useCollectionStore } from '@/features/collection/store'; import { useDownloadsStore } from '@/features/downloads/store'; import { Progress } from '@/components/ui/progress'; import { X } from 'lucide-solid'; +import { checkIsInstalled, launchApp } from '@/lib/api/deb'; const AppDetail: Component = () => { const params = useParams(); @@ -26,6 +27,7 @@ const AppDetail: Component = () => { const [newCollectionDesc, setNewCollectionDesc] = createSignal(''); const [showNewCollectionDialog, setShowNewCollectionDialog] = createSignal(false); const [showCollectionDialog, setShowCollectionDialog] = createSignal(false); + const [isInstalled, setIsInstalled] = createSignal(false); const [selectedCollections, setSelectedCollections] = createSignal([]); const handleCreateCollection = () => { @@ -45,6 +47,11 @@ const AppDetail: Component = () => { showToast({ description: '收藏单创建成功', variant: "success" }); }; + onMount(async () => { + const installed = await checkIsInstalled(params.pkgname); + setIsInstalled(installed); + }); + return (
{loading() ? ( @@ -110,56 +117,75 @@ const AppDetail: Component = () => {

{app()?.Name}

- {downloads().some(task => task.category === params.category && task.pkgname === params.pkgname) ? ( -
- {downloads().map(download => { - if (download.category === params.category && download.pkgname === params.pkgname) { - return ( -
- -
- {download.progress}% - {download.speed && ( - {download.speed} - )} -
- + {(() => { + const downloadTask = downloads().find(task => + task.category === params.category && + task.pkgname === params.pkgname + ); + + if (downloadTask?.status === 'installed' || isInstalled()) { + return ( + + ); + } + + if (downloadTask) { + return ( +
+
+ +
+ {downloadTask.progress}% + {downloadTask.speed && ( + {downloadTask.speed} + )}
- ); - } - return null; - })} -
- ) : ( - - )} + +
+
+ ); + } + + return ( + + ); + })()} diff --git a/src/lib/api/deb.ts b/src/lib/api/deb.ts new file mode 100644 index 0000000..8186137 --- /dev/null +++ b/src/lib/api/deb.ts @@ -0,0 +1,9 @@ +import { invoke } from "@tauri-apps/api/core"; + +export async function checkIsInstalled(pkgname: string): Promise { + return await invoke('check_is_installed', { pkgname }); +} + +export async function launchApp(pkgname: string) { + await invoke('launch_app', { pkgname }); +} \ No newline at end of file