LD-Uninstaller/src/components/Titlebar.tsx

137 lines
5.2 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, { useEffect, useState } from 'react';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { Minus, Square, X, RefreshCw } from 'lucide-react';
import { useAppStore } from '../store/useAppStore';
export const Titlebar: React.FC = () => {
const [isMaximized, setIsMaximized] = useState(false);
const appWindow = getCurrentWindow();
const {
searchQuery,
setSearchQuery,
availableUpdate,
setShowUpdateModal,
isCheckingUpdate,
checkForUpdatesOTA,
isElevated,
relaunchAsAdmin,
} = useAppStore();
useEffect(() => {
const updateMaximized = async () => {
const max = await appWindow.isMaximized();
setIsMaximized(max);
};
updateMaximized();
const unlisten = appWindow.onResized(updateMaximized);
return () => {
unlisten.then((fn) => fn()).catch(() => {});
};
}, []);
const handleMinimize = () => {
appWindow.minimize().catch((e) => console.error('minimize failed', e));
};
const handleMaximize = async () => {
try {
await appWindow.toggleMaximize();
setIsMaximized(await appWindow.isMaximized());
} catch (e) {
console.error('toggleMaximize failed', e);
}
};
const handleClose = () => {
appWindow.close().catch(() => {
// close() bir olay dinleyicisi tarafından engellenirse pencereyi doğrudan yok et
appWindow.destroy().catch((e) => console.error('close failed', e));
});
};
return (
<div
data-tauri-drag-region
className="h-10 bg-ld-surface border-b border-ld-border flex items-center justify-between px-3 select-none z-50 fixed top-0 left-0 right-0"
>
{/* Sol: Logo ve İsim */}
<div data-tauri-drag-region className="flex items-center gap-2.5">
<img
src="/logo.png"
alt="LD Uninstaller"
data-tauri-drag-region
className="w-5 h-5 rounded object-cover shadow-sm shadow-sky-500/20"
/>
<span data-tauri-drag-region className="text-xs font-semibold tracking-wider text-slate-200">
LD UNINSTALLER
</span>
<span className="text-[10px] px-1.5 py-0.5 rounded bg-sky-500/10 text-sky-400 font-mono border border-sky-500/20">
v3.0.2
</span>
{isElevated ? (
<span className="text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/15 text-emerald-400 font-semibold border border-emerald-500/30 flex items-center gap-1">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse" />
ADMIN
</span>
) : (
<button
onClick={() => relaunchAsAdmin()}
title="Tüm sistem dosyalarını ve HKLM kayıtlarını yönetebilmek için Yönetici yetkisiyle yeniden başlat"
className="text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-300 font-medium border border-amber-500/30 hover:bg-amber-500/25 transition-colors cursor-pointer flex items-center gap-1"
>
YÖNETİCİ BAŞLAT
</button>
)}
</div>
{/* Orta: Hızlı Arama & Güncelleme Bildirimi */}
<div className="flex items-center gap-3 w-1/3 max-w-sm">
<input
type="text"
placeholder="Uygulama veya kalıntı ara... (Ctrl+F)"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full bg-ld-card/80 border border-ld-border rounded-md px-2.5 py-1 text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-sky-500/50 transition-colors"
/>
{availableUpdate && (
<button
onClick={() => setShowUpdateModal(true)}
className="flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 text-[11px] font-medium hover:bg-emerald-500/30 transition-all cursor-pointer whitespace-nowrap animate-pulse"
>
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
v{availableUpdate.version} Hazır
</button>
)}
</div>
{/* Sağ: Pencere Butonları */}
<div className="flex items-center gap-1">
<button
onClick={() => checkForUpdatesOTA(true)}
title="Güncellemeleri Denetle"
className="p-1.5 text-slate-400 hover:text-slate-200 hover:bg-white/5 rounded transition-colors cursor-pointer"
>
<RefreshCw className={`w-3.5 h-3.5 ${isCheckingUpdate ? 'animate-spin text-sky-400' : ''}`} />
</button>
<button
onClick={handleMinimize}
className="p-1.5 text-slate-400 hover:text-slate-200 hover:bg-white/5 rounded transition-colors"
>
<Minus className="w-3.5 h-3.5" />
</button>
<button
onClick={handleMaximize}
title={isMaximized ? "Geri Yükle" : "Ekranı Kapla"}
className="p-1.5 text-slate-400 hover:text-slate-200 hover:bg-white/5 rounded transition-colors"
>
<Square className="w-3 h-3" />
</button>
<button
onClick={handleClose}
className="p-1.5 text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 rounded transition-colors"
>
<X className="w-3.5 h-3.5" />
</button>
</div>
</div>
);
};