mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-08-15 14:35:33 +08:00
9453006310
从 v5.0 cherry-pick 的开源项目基础设施改进: 新增配置文件: - .editorconfig, .gitattributes, .prettierrc, .markdownlint.json - commitlint.config.js 新增 GitHub 社区文件: - .github/dependabot.yml — 依赖自动更新 - .github/CODEOWNERS — 自动 PR 审查分配 - .github/FUNDING.yml — 开源赞助入口 新增文档: - ROADMAP.md — 路线图 - SUPPORT.md — 帮助指南 - docs/screenshots/ — 应用截图 新增 Git Hooks: - .husky/pre-commit — lint-staged 自动格式化+修复 - .husky/commit-msg — commitlint 校验 CI 强化: - 新增 Prettier 格式检查 - 新增 Vitest 覆盖率 + Codecov 上报 - 保留 v5.1 已有的 rust-cache + jsdom 全局环境 修复: - index.html 标题 v4.0 → v5.1 - PathEditDialog set-state-in-effect 改用 useRef prevOpen 守卫 - merge-preview.test.tsx no-explicit-any 修复 - 所有 TS/TSX 文件 Prettier 格式化统一 v5.1 保留特性: - @tanstack/react-virtual 虚拟滚动 - jsdom 全局测试环境 - Swatinem/rust-cache CI 加速 - 105 测试全部通过
231 lines
7.0 KiB
TypeScript
231 lines
7.0 KiB
TypeScript
import { useState, useEffect, useMemo, useRef } from 'react';
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Modal } from '@/components/ui/Modal';
|
|
import { useAppStore } from '@/store/app-store';
|
|
|
|
interface ConflictLocation {
|
|
dir: string;
|
|
priority: number;
|
|
}
|
|
|
|
interface ConflictEntry {
|
|
name: string;
|
|
locations: ConflictLocation[];
|
|
}
|
|
|
|
interface ToolGroup {
|
|
dir: string;
|
|
exists: boolean;
|
|
exes: string[];
|
|
}
|
|
|
|
type TabType = 'conflicts' | 'tools';
|
|
|
|
interface Props {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export function AnalyzeDialog({ open, onClose }: Props) {
|
|
const { t } = useTranslation();
|
|
const [tab, setTab] = useState<TabType>('conflicts');
|
|
const [loading, setLoading] = useState(false);
|
|
const [conflicts, setConflicts] = useState<ConflictEntry[]>([]);
|
|
const [toolGroups, setToolGroups] = useState<ToolGroup[]>([]);
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
|
|
const prevOpen = useRef(false);
|
|
useEffect(() => {
|
|
if (!open) {
|
|
prevOpen.current = false;
|
|
return;
|
|
}
|
|
if (prevOpen.current) return;
|
|
prevOpen.current = true;
|
|
setLoading(true);
|
|
const paths = getEnabledPaths();
|
|
Promise.all([
|
|
invoke<ConflictEntry[]>('scan_conflicts', { paths }),
|
|
invoke<ToolGroup[]>('scan_tools', { paths, query: '' }),
|
|
])
|
|
.then(([c, t]) => {
|
|
setConflicts(c);
|
|
setToolGroups(t);
|
|
})
|
|
.catch(console.error)
|
|
.finally(() => setLoading(false));
|
|
}, [open]);
|
|
|
|
// 搜索的工具清单
|
|
const filteredTools = useMemo(() => {
|
|
if (!searchQuery.trim()) return toolGroups;
|
|
const q = searchQuery.toLowerCase();
|
|
return toolGroups
|
|
.map((g) => ({ ...g, exes: g.exes.filter((e) => e.toLowerCase().includes(q)) }))
|
|
.filter((g) => g.exes.length > 0);
|
|
}, [toolGroups, searchQuery]);
|
|
|
|
return (
|
|
<Modal open={open} onClose={onClose}>
|
|
<div className="flex flex-col" style={{ width: 680, maxHeight: '75vh' }}>
|
|
{/* 标题栏 */}
|
|
<div
|
|
className="flex items-center justify-between px-5 py-3 border-b"
|
|
style={{ borderColor: 'var(--app-border)' }}
|
|
>
|
|
<h2 className="text-base font-semibold">{t('analyze.title')}</h2>
|
|
<div className="flex gap-1">
|
|
{(['conflicts', 'tools'] as TabType[]).map((tb) => (
|
|
<button
|
|
key={tb}
|
|
onClick={() => setTab(tb)}
|
|
className="px-3 py-1 text-sm rounded transition-colors"
|
|
style={{
|
|
backgroundColor: tab === tb ? '#3b82f6' : 'transparent',
|
|
color: tab === tb ? '#fff' : 'var(--app-fg)',
|
|
}}
|
|
>
|
|
{tb === 'conflicts' ? t('analyze.conflicts') : t('analyze.tools')}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* 内容 */}
|
|
<div className="flex-1 overflow-auto p-4">
|
|
{loading ? (
|
|
<div
|
|
className="flex items-center justify-center py-12 text-sm"
|
|
style={{ color: 'var(--app-fg)', opacity: 0.6 }}
|
|
>
|
|
{t('analyze.scanning')}
|
|
</div>
|
|
) : tab === 'conflicts' ? (
|
|
<ConflictsTab conflicts={conflicts} />
|
|
) : (
|
|
<ToolsTab groups={filteredTools} query={searchQuery} onQueryChange={setSearchQuery} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
function ConflictsTab({ conflicts }: { conflicts: ConflictEntry[] }) {
|
|
const { t } = useTranslation();
|
|
if (conflicts.length === 0) {
|
|
return <EmptyHint text={t('analyze.noConflicts')} />;
|
|
}
|
|
return (
|
|
<div>
|
|
<p className="text-sm mb-2" style={{ color: 'var(--app-fg)', opacity: 0.7 }}>
|
|
{t('analyze.conflictCount', { count: conflicts.length })}
|
|
</p>
|
|
<table className="w-full text-sm border-collapse">
|
|
<thead>
|
|
<tr className="border-b" style={{ borderColor: 'var(--app-border)' }}>
|
|
<th className="text-left py-1.5 pr-3 font-medium">EXE</th>
|
|
<th className="text-left py-1.5 font-medium">{t('analyze.priority')}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{conflicts.map((c) => (
|
|
<tr key={c.name} className="border-b" style={{ borderColor: 'var(--app-border)' }}>
|
|
<td className="py-1.5 pr-3 font-mono">{c.name}</td>
|
|
<td className="py-1.5">
|
|
{c.locations.map((loc, i) => (
|
|
<div
|
|
key={i}
|
|
className="text-xs py-0.5"
|
|
style={{ color: i === 0 ? '#22c55e' : '#ef4444' }}
|
|
>
|
|
{i === 0 ? '✓' : '✗'} {loc.dir}
|
|
{i > 0 && (
|
|
<span className="ml-1" style={{ opacity: 0.5 }}>
|
|
({t('analyze.shadowed')})
|
|
</span>
|
|
)}
|
|
</div>
|
|
))}
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ToolsTab({
|
|
groups,
|
|
query,
|
|
onQueryChange,
|
|
}: {
|
|
groups: ToolGroup[];
|
|
query: string;
|
|
onQueryChange: (q: string) => void;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<div>
|
|
<input
|
|
type="text"
|
|
value={query}
|
|
onChange={(e) => onQueryChange(e.target.value)}
|
|
placeholder={t('analyze.searchPlaceholder')}
|
|
className="w-full px-3 py-1.5 text-sm rounded mb-3 border outline-none"
|
|
style={{
|
|
backgroundColor: 'var(--app-list-bg)',
|
|
color: 'var(--app-fg)',
|
|
borderColor: 'var(--app-border)',
|
|
}}
|
|
/>
|
|
{groups.length === 0 ? (
|
|
<EmptyHint text={t('analyze.noTools')} />
|
|
) : (
|
|
groups.map((g) => (
|
|
<div key={g.dir} className="mb-3">
|
|
<div
|
|
className="text-xs font-mono py-1 px-2 rounded"
|
|
style={{
|
|
backgroundColor: g.exists ? 'transparent' : 'rgba(239,68,68,0.1)',
|
|
color: g.exists ? 'var(--app-fg)' : '#ef4444',
|
|
opacity: g.exists ? 1 : 0.6,
|
|
}}
|
|
>
|
|
{g.dir} {!g.exists && t('analyze.notExists')}
|
|
</div>
|
|
<div className="flex flex-wrap gap-1 mt-1 ml-2">
|
|
{g.exes.map((exe) => (
|
|
<span
|
|
key={exe}
|
|
className="text-xs font-mono px-1.5 py-0.5 rounded"
|
|
style={{ backgroundColor: 'var(--app-list-bg)', color: 'var(--app-fg)' }}
|
|
>
|
|
{exe}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</div>
|
|
))
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function EmptyHint({ text }: { text: string }) {
|
|
return (
|
|
<div className="text-center py-12 text-sm" style={{ color: 'var(--app-fg)', opacity: 0.5 }}>
|
|
{text}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function getEnabledPaths(): string[] {
|
|
const { sysPaths, userPaths } = useAppStore.getState();
|
|
return [...sysPaths.filter((e) => e.enabled), ...userPaths.filter((e) => e.enabled)].map(
|
|
(e) => e.path,
|
|
);
|
|
}
|