Refactor application structure and simplify implementation

This commit is contained in:
2026-07-22 00:08:09 +03:00
parent dbba3806cc
commit 90b2eb507c
74 changed files with 11362 additions and 6814 deletions
+70 -36
View File
@@ -1,25 +1,47 @@
import type { ProxiFyreSetupProgress, ProxiFyreSetupStatus } from '../../api/tauriCommands';
import type {
ProxiFyreSetupProgress,
ProxiFyreSetupStatus,
} from "../../api/tauriCommands";
interface ProxiFyreSetupStripProps {
setupStatus: ProxiFyreSetupStatus | null;
progress: ProxiFyreSetupProgress | null;
}
const SETUP_PLACEHOLDERS: ProxiFyreSetupStatus['items'] = [
{ id: 'vc-runtime', name: 'Среда запуска', installed: false, details: 'Проверяю' },
{ id: 'packet-filter', name: 'Сетевой драйвер', installed: false, details: 'Проверяю' },
{ id: 'proxifyre', name: 'Клиент ProxiFyre', installed: false, details: 'Проверяю' },
const SETUP_PLACEHOLDERS: ProxiFyreSetupStatus["items"] = [
{
id: "vc-runtime",
name: "Среда запуска",
installed: false,
details: "Проверяю",
},
{
id: "packet-filter",
name: "Сетевой драйвер",
installed: false,
details: "Проверяю",
},
{
id: "proxifyre",
name: "Клиент ProxiFyre",
installed: false,
details: "Проверяю",
},
];
export function ProxiFyreSetupStrip({ setupStatus, progress }: ProxiFyreSetupStripProps) {
export function ProxiFyreSetupStrip({
setupStatus,
progress,
}: ProxiFyreSetupStripProps) {
const stripItems = setupStatus?.items ?? SETUP_PLACEHOLDERS;
const visibleProgress = isVisibleProgress(progress) ? progress : null;
const progressTone = visibleProgress?.status === 'failed' ? 'failed' : 'running';
const progressTone =
visibleProgress?.status === "failed" ? "failed" : "running";
const percent = clampPercent(visibleProgress?.percent ?? 0);
return (
<div
className={`setup-strip ${setupStatus?.ready ? 'ready' : 'attention'} ${visibleProgress ? 'with-progress' : ''}`}
className={`setup-strip ${setupStatus?.ready ? "ready" : "attention"} ${visibleProgress ? "with-progress" : ""}`}
aria-label="Состав ProxiFyre"
>
<span className="setup-strip-title">Состав</span>
@@ -45,9 +67,14 @@ export function ProxiFyreSetupStrip({ setupStatus, progress }: ProxiFyreSetupStr
aria-valuenow={percent}
aria-label={visibleProgress.message}
>
<span className="setup-progress-fill" style={{ width: `${percent}%` }} />
<span
className="setup-progress-fill"
style={{ width: `${percent}%` }}
/>
</div>
<span className="setup-progress-message">{visibleProgress.message}</span>
<span className="setup-progress-message">
{visibleProgress.message}
</span>
</div>
) : null}
</div>
@@ -55,52 +82,59 @@ export function ProxiFyreSetupStrip({ setupStatus, progress }: ProxiFyreSetupStr
}
function setupItemClass(
item: ProxiFyreSetupStatus['items'][number],
item: ProxiFyreSetupStatus["items"][number],
progress: ProxiFyreSetupProgress | null,
) {
if (progress?.activeStep === item.id) {
if (progress.status === 'failed') return 'failed';
return 'active';
if (progress.status === "failed") return "failed";
return "active";
}
if (item.installed) return 'installed';
return 'missing';
if (item.installed) return "installed";
return "missing";
}
function setupItemUserName(id: string, fallbackName: string) {
if (id === 'vc-runtime') return 'Среда запуска';
if (id === 'packet-filter') return 'Сетевой драйвер';
if (id === 'proxifyre') return 'Клиент ProxiFyre';
if (id === "vc-runtime") return "Среда запуска";
if (id === "packet-filter") return "Сетевой драйвер";
if (id === "proxifyre") return "Клиент ProxiFyre";
return fallbackName;
}
function setupItemShortStatus(
item: ProxiFyreSetupStatus['items'][number],
item: ProxiFyreSetupStatus["items"][number],
progress: ProxiFyreSetupProgress | null,
) {
if (progress?.activeStep === item.id) {
if (progress.status === 'failed') return 'ошибка';
if (progress.status === 'succeeded') return progress.operation === 'uninstall' ? 'удалено' : 'готово';
return 'в процессе';
if (progress.status === "failed") return "ошибка";
if (progress.status === "succeeded")
return progress.operation === "uninstall" ? "удалено" : "готово";
return "в процессе";
}
if (item.details === 'Проверяю') return 'проверяю';
if (!item.installed) return progress?.operation === 'uninstall' && progress.status === 'succeeded'
? 'удалено'
: 'нужно установить';
if (item.id === 'proxifyre') return proxifyreSetupServiceSummary(item.version);
return 'готово';
if (item.details === "Проверяю") return "проверяю";
if (!item.installed)
return progress?.operation === "uninstall" &&
progress.status === "succeeded"
? "удалено"
: "нужно установить";
if (item.id === "proxifyre")
return proxifyreSetupServiceSummary(item.version);
return "готово";
}
function proxifyreSetupServiceSummary(version: string | undefined) {
const normalized = version?.trim().toLowerCase() ?? '';
if (normalized.includes('не установлена')) return 'служба не установлена';
if (normalized.includes('остановлена') || normalized.includes('не запущена')) return 'служба остановлена';
if (normalized.includes('запущена')) return 'служба запущена';
return 'готово';
const normalized = version?.trim().toLowerCase() ?? "";
if (normalized.includes("не установлена")) return "служба не установлена";
if (normalized.includes("остановлена") || normalized.includes("не запущена"))
return "служба остановлена";
if (normalized.includes("запущена")) return "служба запущена";
return "готово";
}
function isVisibleProgress(progress: ProxiFyreSetupProgress | null): progress is ProxiFyreSetupProgress {
if (!progress || progress.status === 'idle') return false;
return progress.status === 'running' || progress.status === 'failed';
function isVisibleProgress(
progress: ProxiFyreSetupProgress | null,
): progress is ProxiFyreSetupProgress {
if (!progress || progress.status === "idle") return false;
return progress.status === "running" || progress.status === "failed";
}
function clampPercent(value: number) {