✨ 添加安装检测和启动应用
This commit is contained in:
@@ -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<string[]>([]);
|
||||
|
||||
const handleCreateCollection = () => {
|
||||
@@ -45,6 +47,11 @@ const AppDetail: Component = () => {
|
||||
showToast({ description: '收藏单创建成功', variant: "success" });
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
const installed = await checkIsInstalled(params.pkgname);
|
||||
setIsInstalled(installed);
|
||||
});
|
||||
|
||||
return (
|
||||
<div class="w-full h-full">
|
||||
{loading() ? (
|
||||
@@ -110,56 +117,75 @@ const AppDetail: Component = () => {
|
||||
<h2 class="app-name text-2xl font-bold pt-2">{app()?.Name}</h2>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 w-[120px]">
|
||||
{downloads().some(task => task.category === params.category && task.pkgname === params.pkgname) ? (
|
||||
<div class="flex flex-col gap-2 w-full pb-2">
|
||||
{downloads().map(download => {
|
||||
if (download.category === params.category && download.pkgname === params.pkgname) {
|
||||
return (
|
||||
<div class="flex items-center gap-2 group relative">
|
||||
<Progress value={download.progress} class="flex-1" />
|
||||
<div class="flex items-center gap-2 group-hover:opacity-0 transition-opacity">
|
||||
<span class="text-sm text-muted-foreground">{download.progress}%</span>
|
||||
{download.speed && (
|
||||
<span class="text-sm text-muted-foreground">{download.speed}</span>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
class="absolute right-1 bg-red-500 rounded-full w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center text-white hover:bg-red-600"
|
||||
onClick={() => {
|
||||
cancelDownload(params.category, params.pkgname);
|
||||
}}
|
||||
>
|
||||
<X />
|
||||
</button>
|
||||
{(() => {
|
||||
const downloadTask = downloads().find(task =>
|
||||
task.category === params.category &&
|
||||
task.pkgname === params.pkgname
|
||||
);
|
||||
|
||||
if (downloadTask?.status === 'installed' || isInstalled()) {
|
||||
return (
|
||||
<Button
|
||||
size="lg"
|
||||
class='w-full'
|
||||
onClick={() => {
|
||||
launchApp(params.pkgname)
|
||||
showToast({ description: '正在启动应用...' });
|
||||
}}
|
||||
>
|
||||
启动
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
if (downloadTask) {
|
||||
return (
|
||||
<div class="flex flex-col gap-2 w-full pb-2">
|
||||
<div class="flex items-center gap-2 group relative">
|
||||
<Progress value={downloadTask.progress} class="flex-1" />
|
||||
<div class="flex items-center gap-2 group-hover:opacity-0 transition-opacity">
|
||||
<span class="text-sm text-muted-foreground">{downloadTask.progress}%</span>
|
||||
{downloadTask.speed && (
|
||||
<span class="text-sm text-muted-foreground">{downloadTask.speed}</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
size="lg"
|
||||
class='w-full'
|
||||
onClick={() => {
|
||||
const currentApp = app();
|
||||
if (!currentApp) {
|
||||
showToast({ description: '获取应用信息失败', variant: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentApp.Filename) {
|
||||
showToast({ description: '获取应用下载信息失败', variant: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
addDownload(params.category, params.pkgname, currentApp.Filename, currentApp.Name || '');
|
||||
showToast({ description: '已添加到下载队列', variant: "success" });
|
||||
}}
|
||||
>
|
||||
安装
|
||||
</Button>
|
||||
)}
|
||||
<button
|
||||
class="absolute right-1 bg-red-500 rounded-full w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center text-white hover:bg-red-600"
|
||||
onClick={() => {
|
||||
cancelDownload(params.category, params.pkgname);
|
||||
}}
|
||||
>
|
||||
<X />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
size="lg"
|
||||
class='w-full'
|
||||
onClick={() => {
|
||||
const currentApp = app();
|
||||
if (!currentApp) {
|
||||
showToast({ description: '获取应用信息失败', variant: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentApp.Filename) {
|
||||
showToast({ description: '获取应用下载信息失败', variant: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
addDownload(params.category, params.pkgname, currentApp.Filename, currentApp.Name || '');
|
||||
showToast({ description: '已添加到下载队列', variant: "success" });
|
||||
}}
|
||||
>
|
||||
安装
|
||||
</Button>
|
||||
);
|
||||
})()}
|
||||
<Dialog open={showCollectionDialog()} onOpenChange={setShowCollectionDialog}>
|
||||
<DialogTrigger>
|
||||
<Button variant="secondary" size="lg" class='w-full'>收藏</Button>
|
||||
|
||||
9
src/lib/api/deb.ts
Normal file
9
src/lib/api/deb.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export async function checkIsInstalled(pkgname: string): Promise<boolean> {
|
||||
return await invoke('check_is_installed', { pkgname });
|
||||
}
|
||||
|
||||
export async function launchApp(pkgname: string) {
|
||||
await invoke('launch_app', { pkgname });
|
||||
}
|
||||
Reference in New Issue
Block a user