LD-Uninstaller/src/pages/AppsView.tsx

314 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useMemo, useState } from 'react';
import { useAppStore } from '../store/useAppStore';
import {
RefreshCw,
Download,
Trash2,
Zap,
SearchCode,
ArrowUpDown,
Package,
} from 'lucide-react';
import { api } from '../lib/tauri';
type SortKey = 'name' | 'size' | 'publisher' | 'date';
export const AppsView: React.FC = () => {
const {
apps,
isLoadingApps,
searchQuery,
selectedAppIds,
toggleSelectApp,
selectAllApps,
clearSelectedApps,
loadApps,
uninstallSingleApp,
bulkUninstall,
isUninstalling,
startLeftoverScan,
addToast,
} = useAppStore();
const [sortKey, setSortKey] = useState<SortKey>('name');
const [sortAsc, setSortAsc] = useState<boolean>(true);
const [filterKind, setFilterKind] = useState<string>('all');
const filteredApps = useMemo(() => {
let result = apps.filter((app) => {
const matchSearch =
searchQuery.trim() === '' ||
app.display_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
app.publisher.toLowerCase().includes(searchQuery.toLowerCase());
const matchKind =
filterKind === 'all' ||
(filterKind === 'steam' && app.kind === 'Steam') ||
(filterKind === 'store' && app.kind === 'StoreApp') ||
(filterKind === 'registry' && app.kind === 'Registry');
return matchSearch && matchKind;
});
result.sort((a, b) => {
let cmp = 0;
switch (sortKey) {
case 'name':
cmp = a.display_name.localeCompare(b.display_name);
break;
case 'size':
cmp = a.estimated_size_kb - b.estimated_size_kb;
break;
case 'publisher':
cmp = a.publisher.localeCompare(b.publisher);
break;
case 'date':
cmp = a.install_date.localeCompare(b.install_date);
break;
}
return sortAsc ? cmp : -cmp;
});
return result;
}, [apps, searchQuery, filterKind, sortKey, sortAsc]);
const totalSizeMB = useMemo(() => {
const totalKB = apps.reduce((acc, a) => acc + a.estimated_size_kb, 0);
return (totalKB / 1024).toFixed(1);
}, [apps]);
const toggleSort = (key: SortKey) => {
if (sortKey === key) {
setSortAsc(!sortAsc);
} else {
setSortKey(key);
setSortAsc(true);
}
};
const formatSize = (kb: number) => {
if (kb >= 1024 * 1024) return `${(kb / 1024 / 1024).toFixed(2)} GB`;
if (kb >= 1024) return `${(kb / 1024).toFixed(1)} MB`;
if (kb > 0) return `${kb} KB`;
return '-';
};
const handleExportCsv = async () => {
try {
const savedPath = await api.exportAppsCsv('');
addToast('Dışa Aktarıldı', `Uygulama listesi kaydedildi: ${savedPath}`, 'success');
} catch (e: any) {
addToast('Hata', String(e), 'error');
}
};
return (
<div className="flex-1 flex flex-col h-full overflow-hidden bg-ld-bg pt-10">
{/* Üst İşlem Çubuğu */}
<div className="p-3.5 border-b border-ld-border bg-ld-surface/80 flex items-center justify-between gap-3">
<div className="flex items-center gap-2">
<button
onClick={() => loadApps()}
disabled={isLoadingApps}
className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-300 hover:text-white hover:bg-white/5 transition-colors disabled:opacity-50"
>
<RefreshCw className={`w-3.5 h-3.5 ${isLoadingApps ? 'animate-spin text-sky-400' : ''}`} />
Yenile
</button>
<select
value={filterKind}
onChange={(e) => setFilterKind(e.target.value)}
className="bg-ld-card border border-ld-border rounded-lg px-2.5 py-1.5 text-xs text-slate-300 focus:outline-none focus:border-sky-500/50"
>
<option value="all">Tüm Kaynaklar</option>
<option value="registry">Kayıt Defteri</option>
<option value="steam">Steam Oyunları</option>
<option value="store">Windows Store</option>
</select>
<button
onClick={handleExportCsv}
title="CSV Olarak Dışa Aktar"
className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-ld-card border border-ld-border text-slate-400 hover:text-slate-200 hover:bg-white/5 transition-colors"
>
<Download className="w-3.5 h-3.5" />
CSV
</button>
</div>
{/* Seçim İşlemleri */}
<div className="flex items-center gap-2">
{selectedAppIds.length > 0 && (
<>
<button
disabled={isUninstalling}
onClick={() => bulkUninstall(true)}
className="flex items-center gap-1.5 px-3.5 py-1.5 rounded-lg text-xs font-semibold bg-emerald-600 text-white hover:bg-emerald-500 shadow-sm shadow-emerald-600/20 transition-all cursor-pointer disabled:opacity-50"
>
<Zap className="w-3.5 h-3.5" />
Sessiz Kaldır ({selectedAppIds.length})
</button>
<button
disabled={isUninstalling}
onClick={() => bulkUninstall(false)}
className="flex items-center gap-1.5 px-3.5 py-1.5 rounded-lg text-xs font-semibold bg-rose-600 text-white hover:bg-rose-500 shadow-sm shadow-rose-600/20 transition-all cursor-pointer disabled:opacity-50"
>
<Trash2 className="w-3.5 h-3.5" />
Normal Kaldır ({selectedAppIds.length})
</button>
</>
)}
</div>
</div>
{/* Tablo Başlığı */}
<div className="grid grid-cols-12 px-4 py-2 border-b border-ld-border/70 text-[11px] font-semibold text-slate-400 bg-ld-card/40 select-none">
<div className="col-span-1 flex items-center">
<input
type="checkbox"
checked={apps.length > 0 && selectedAppIds.length === apps.length}
onChange={(e) => (e.target.checked ? selectAllApps() : clearSelectedApps())}
className="rounded border-slate-700 bg-slate-900 text-sky-500 focus:ring-0 cursor-pointer"
/>
</div>
<div
onClick={() => toggleSort('name')}
className="col-span-5 flex items-center gap-1 cursor-pointer hover:text-slate-200"
>
<span>Uygulama Adı</span>
<ArrowUpDown className="w-3 h-3 text-slate-500" />
</div>
<div
onClick={() => toggleSort('publisher')}
className="col-span-2 flex items-center gap-1 cursor-pointer hover:text-slate-200"
>
<span>Yayımcı</span>
<ArrowUpDown className="w-3 h-3 text-slate-500" />
</div>
<div
onClick={() => toggleSort('size')}
className="col-span-2 flex items-center justify-end gap-1 cursor-pointer hover:text-slate-200 pr-2"
>
<span>Boyut</span>
<ArrowUpDown className="w-3 h-3 text-slate-500" />
</div>
<div className="col-span-2 text-right pr-2">İşlemler</div>
</div>
{/* Uygulama Listesi */}
<div className="flex-1 overflow-y-auto divide-y divide-ld-border/30">
{isLoadingApps ? (
<div className="py-24 flex flex-col items-center justify-center text-center space-y-3">
<RefreshCw className="w-8 h-8 text-sky-400 animate-spin" />
<p className="text-xs font-semibold text-slate-200">Kayıt defteri ve mağaza uygulamaları taranıyor...</p>
</div>
) : filteredApps.length === 0 ? (
<div className="py-24 text-center space-y-2">
<Package className="w-8 h-8 text-slate-600 mx-auto" />
<h4 className="text-xs font-semibold text-slate-400">Uygulama bulunamadı</h4>
<p className="text-[11px] text-slate-500">Arama filtrenizi değiştirmeyi deneyin.</p>
</div>
) : (
filteredApps.map((app) => {
const isSelected = selectedAppIds.includes(app.id);
return (
<div
key={app.id}
onClick={() => toggleSelectApp(app.id)}
className={`grid grid-cols-12 px-4 py-2.5 items-center text-xs transition-colors cursor-pointer select-none ${
isSelected ? 'bg-sky-500/10 hover:bg-sky-500/15' : 'hover:bg-white/[0.03]'
}`}
>
<div className="col-span-1 flex items-center" onClick={(e) => e.stopPropagation()}>
<input
type="checkbox"
checked={isSelected}
onChange={() => toggleSelectApp(app.id)}
className="rounded border-slate-700 bg-slate-900 text-sky-500 focus:ring-0 cursor-pointer"
/>
</div>
<div className="col-span-5 flex items-center gap-2.5 min-w-0 pr-2">
<div className="w-6 h-6 rounded bg-ld-card border border-ld-border flex items-center justify-center shrink-0">
<Package className="w-3.5 h-3.5 text-slate-400" />
</div>
<div className="min-w-0">
<p className="font-medium text-slate-200 truncate" title={app.display_name}>
{app.display_name}
</p>
<div className="flex items-center gap-1.5 text-[10px] text-slate-500">
<span>{app.display_version || 'v1.0'}</span>
{app.kind === 'Steam' && (
<span className="px-1 rounded bg-sky-500/20 text-sky-400 font-mono">Steam</span>
)}
{app.kind === 'StoreApp' && (
<span className="px-1 rounded bg-purple-500/20 text-purple-400 font-mono">Store</span>
)}
</div>
</div>
</div>
<div className="col-span-2 text-slate-400 truncate text-[11px]" title={app.publisher}>
{app.publisher || 'Bilinmiyor'}
</div>
<div className="col-span-2 text-right pr-2 font-mono text-[11px] text-slate-300">
{formatSize(app.estimated_size_kb)}
</div>
<div className="col-span-2 flex items-center justify-end gap-1.5" onClick={(e) => e.stopPropagation()}>
{/* Sessiz Kaldır */}
<button
onClick={() => uninstallSingleApp(app, true)}
title="Sessiz Kaldır"
className="p-1 rounded text-slate-400 hover:text-emerald-400 hover:bg-emerald-500/10 transition-colors"
>
<Zap className="w-3.5 h-3.5" />
</button>
{/* Kalıntı Tara */}
<button
onClick={() => startLeftoverScan(app)}
title="Kalıntı Ara"
className="p-1 rounded text-slate-400 hover:text-sky-400 hover:bg-sky-500/10 transition-colors"
>
<SearchCode className="w-3.5 h-3.5" />
</button>
{/* Normal Kaldır */}
<button
onClick={() => uninstallSingleApp(app, false)}
title="Kaldır"
className="p-1 rounded text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 transition-colors"
>
<Trash2 className="w-3.5 h-3.5" />
</button>
</div>
</div>
);
})
)}
</div>
{/* Alt Bilgi Çubuğu */}
<div className="px-4 py-2 border-t border-ld-border bg-ld-surface flex items-center justify-between text-[11px] text-slate-400">
<div className="flex items-center gap-3">
<span>Toplam: <strong className="text-slate-200 font-mono">{apps.length}</strong> uygulama</span>
<span>•</span>
<span>Tahmini Alan: <strong className="text-slate-200 font-mono">{totalSizeMB} MB</strong></span>
{selectedAppIds.length > 0 && (
<>
<span>•</span>
<span className="text-sky-400 font-semibold">{selectedAppIds.length} seçili</span>
</>
)}
</div>
<div className="text-slate-500">
İpucu: Birden fazla uygulamayı seçip tek tıkla toplu kaldırabilirsiniz.
</div>
</div>
</div>
);
};