mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-07-01 03:25:54 +08:00
Compare commits
5 Commits
49ef9c0cff
...
v4.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 26f6953919 | |||
| 5ed15535e7 | |||
| 230fb5d741 | |||
| d7d11480b8 | |||
| 7869886670 |
@@ -1,5 +1,7 @@
|
||||
pub mod registry;
|
||||
pub mod system;
|
||||
pub mod backup;
|
||||
pub mod fs;
|
||||
pub mod disabled;
|
||||
pub mod fs;
|
||||
pub mod profiles;
|
||||
pub mod registry;
|
||||
pub mod scanner;
|
||||
pub mod system;
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn profiles_dir() -> PathBuf {
|
||||
dirs::home_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join(".patheditor")
|
||||
.join("profiles")
|
||||
}
|
||||
|
||||
fn profile_path(name: &str) -> PathBuf {
|
||||
profiles_dir().join(format!("{}.json", name))
|
||||
}
|
||||
|
||||
/// 内部用的 PathEntry(与前端 PathEntry 字段一致)
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct ProfilePathEntry {
|
||||
pub path: String,
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileMeta {
|
||||
pub name: String,
|
||||
pub created: String,
|
||||
pub modified: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ProfileData {
|
||||
pub name: String,
|
||||
pub sys: Vec<ProfilePathEntry>,
|
||||
pub user: Vec<ProfilePathEntry>,
|
||||
pub created: String,
|
||||
pub modified: String,
|
||||
}
|
||||
|
||||
/// 列出所有配置文件的元数据
|
||||
#[tauri::command]
|
||||
pub fn list_profiles() -> Result<Vec<ProfileMeta>, String> {
|
||||
let dir = profiles_dir();
|
||||
if !dir.exists() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let mut profiles: Vec<ProfileMeta> = Vec::new();
|
||||
let entries = fs::read_dir(&dir).map_err(|e| format!("无法读取配置目录: {}", e))?;
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.extension().map_or(true, |e| e != "json") {
|
||||
continue;
|
||||
}
|
||||
let content = fs::read_to_string(&path)
|
||||
.map_err(|e| format!("无法读取 {}: {}", path.display(), e))?;
|
||||
if let Ok(data) = serde_json::from_str::<ProfileData>(&content) {
|
||||
profiles.push(ProfileMeta {
|
||||
name: data.name,
|
||||
created: data.created,
|
||||
modified: data.modified,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
profiles.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
Ok(profiles)
|
||||
}
|
||||
|
||||
/// 保存当前 PATH 为配置文件
|
||||
#[tauri::command]
|
||||
pub fn save_profile(
|
||||
name: String,
|
||||
sys: Vec<ProfilePathEntry>,
|
||||
user: Vec<ProfilePathEntry>,
|
||||
) -> Result<(), String> {
|
||||
let dir = profiles_dir();
|
||||
fs::create_dir_all(&dir).map_err(|e| format!("无法创建配置目录: {}", e))?;
|
||||
|
||||
let path = profile_path(&name);
|
||||
let now = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S").to_string();
|
||||
|
||||
let data = ProfileData {
|
||||
name,
|
||||
sys,
|
||||
user,
|
||||
created: now.clone(),
|
||||
modified: now,
|
||||
};
|
||||
|
||||
let json =
|
||||
serde_json::to_string_pretty(&data).map_err(|e| format!("JSON 序列化失败: {}", e))?;
|
||||
fs::write(&path, &json).map_err(|e| format!("无法写入配置文件: {}", e))?;
|
||||
|
||||
log::info!("已保存配置: {}", path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 加载配置文件
|
||||
#[tauri::command]
|
||||
pub fn load_profile(name: String) -> Result<ProfileData, String> {
|
||||
let path = profile_path(&name);
|
||||
if !path.exists() {
|
||||
return Err(format!("配置文件不存在: {}", name));
|
||||
}
|
||||
let content = fs::read_to_string(&path)
|
||||
.map_err(|e| format!("无法读取配置文件: {}", e))?;
|
||||
serde_json::from_str(&content)
|
||||
.map_err(|e| format!("JSON 解析失败: {}", e))
|
||||
}
|
||||
|
||||
/// 删除配置文件
|
||||
#[tauri::command]
|
||||
pub fn delete_profile(name: String) -> Result<(), String> {
|
||||
let path = profile_path(&name);
|
||||
fs::remove_file(&path).map_err(|e| format!("无法删除配置文件: {}", e))?;
|
||||
log::info!("已删除配置: {}", path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 重命名配置文件
|
||||
#[tauri::command]
|
||||
pub fn rename_profile(old_name: String, new_name: String) -> Result<(), String> {
|
||||
let old_path = profile_path(&old_name);
|
||||
if !old_path.exists() {
|
||||
return Err(format!("配置文件不存在: {}", old_name));
|
||||
}
|
||||
|
||||
let mut data: ProfileData =
|
||||
serde_json::from_str(&fs::read_to_string(&old_path).map_err(|e| format!("无法读取配置文件: {}", e))?).map_err(|e| format!("JSON 解析失败: {}", e))?;
|
||||
|
||||
data.name = new_name.clone();
|
||||
data.modified = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S").to_string();
|
||||
|
||||
let new_path = profile_path(&new_name);
|
||||
let json =
|
||||
serde_json::to_string_pretty(&data).map_err(|e| format!("JSON 序列化失败: {}", e))?;
|
||||
fs::write(&new_path, &json).map_err(|e| format!("无法写入配置文件: {}", e))?;
|
||||
|
||||
if old_path != new_path {
|
||||
fs::remove_file(&old_path).map_err(|e| format!("无法删除旧配置文件: {}", e))?;
|
||||
}
|
||||
|
||||
log::info!("已重命名配置: {} -> {}", old_name, new_name);
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
const EXECUTABLE_EXTENSIONS: &[&str] = &["exe", "bat", "cmd", "com", "ps1"];
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
pub struct ConflictLocation {
|
||||
pub dir: String,
|
||||
pub priority: usize,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone)]
|
||||
pub struct ConflictEntry {
|
||||
pub name: String,
|
||||
pub locations: Vec<ConflictLocation>,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct ToolGroup {
|
||||
pub dir: String,
|
||||
pub exists: bool,
|
||||
pub exes: Vec<String>,
|
||||
}
|
||||
|
||||
/// 扫描 PATH 中的可执行文件冲突
|
||||
///
|
||||
/// 遍历每个 PATH 目录,查找 .exe/.bat/.cmd/.com/.ps1 文件,
|
||||
/// 标记出现在多个目录中的同名文件(后面的目录会被前面的「遮蔽」)
|
||||
#[tauri::command]
|
||||
pub fn scan_conflicts(paths: Vec<String>) -> Result<Vec<ConflictEntry>, String> {
|
||||
// exe_name (小写) → [(priority, dir)]
|
||||
let mut map: HashMap<String, Vec<(usize, String)>> = HashMap::new();
|
||||
|
||||
for (priority, dir) in paths.iter().enumerate() {
|
||||
let p = Path::new(dir);
|
||||
if !p.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let entries = fs::read_dir(p).map_err(|e| format!("无法读取目录 {}: {}", dir, e))?;
|
||||
for entry in entries.flatten() {
|
||||
let fname = entry.file_name();
|
||||
let name = fname.to_string_lossy();
|
||||
if let Some(ext) = Path::new(name.as_ref()).extension() {
|
||||
let ext_lower = ext.to_ascii_lowercase();
|
||||
if EXECUTABLE_EXTENSIONS.contains(&ext_lower.to_str().unwrap_or("")) {
|
||||
let key = name.to_lowercase();
|
||||
map.entry(key).or_default().push((priority, dir.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut results: Vec<ConflictEntry> = map
|
||||
.into_iter()
|
||||
.filter(|(_, locs)| locs.len() >= 2)
|
||||
.map(|(name, locs)| ConflictEntry {
|
||||
name,
|
||||
locations: locs
|
||||
.into_iter()
|
||||
.map(|(priority, dir)| ConflictLocation { dir, priority })
|
||||
.collect(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
results.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
Ok(results)
|
||||
}
|
||||
|
||||
/// 扫描 PATH 中各目录提供的可执行文件
|
||||
///
|
||||
/// query 非空时只返回文件名包含关键词的结果
|
||||
#[tauri::command]
|
||||
pub fn scan_tools(paths: Vec<String>, query: String) -> Result<Vec<ToolGroup>, String> {
|
||||
let query_lower = query.to_lowercase();
|
||||
let mut groups: Vec<ToolGroup> = Vec::new();
|
||||
|
||||
for dir in &paths {
|
||||
let p = Path::new(dir);
|
||||
if !p.is_dir() {
|
||||
groups.push(ToolGroup {
|
||||
dir: dir.clone(),
|
||||
exists: false,
|
||||
exes: vec![],
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
let entries = fs::read_dir(p).map_err(|e| format!("无法读取目录 {}: {}", dir, e))?;
|
||||
let mut exes: Vec<String> = Vec::new();
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let fname = entry.file_name();
|
||||
let name = fname.to_string_lossy();
|
||||
if let Some(ext) = Path::new(name.as_ref()).extension() {
|
||||
let ext_lower = ext.to_ascii_lowercase();
|
||||
if EXECUTABLE_EXTENSIONS.contains(&ext_lower.to_str().unwrap_or("")) {
|
||||
if query_lower.is_empty() || name.to_lowercase().contains(&query_lower) {
|
||||
exes.push(name.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exes.sort();
|
||||
groups.push(ToolGroup {
|
||||
dir: dir.clone(),
|
||||
exists: true,
|
||||
exes,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(groups)
|
||||
}
|
||||
@@ -28,6 +28,13 @@ pub fn run() {
|
||||
commands::fs::read_text_file,
|
||||
commands::disabled::save_disabled_state,
|
||||
commands::disabled::load_disabled_state,
|
||||
commands::scanner::scan_conflicts,
|
||||
commands::scanner::scan_tools,
|
||||
commands::profiles::list_profiles,
|
||||
commands::profiles::save_profile,
|
||||
commands::profiles::load_profile,
|
||||
commands::profiles::delete_profile,
|
||||
commands::profiles::rename_profile,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
import { useState, useEffect, useMemo } 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('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
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 && '(不存在)'}
|
||||
</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);
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
import { useState, useEffect, useCallback } 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';
|
||||
import type { PathEntry } from '@/core/path-entry';
|
||||
|
||||
interface ProfileMeta {
|
||||
name: string;
|
||||
created: string;
|
||||
modified: string;
|
||||
}
|
||||
|
||||
interface ProfileData {
|
||||
name: string;
|
||||
sys: PathEntry[];
|
||||
user: PathEntry[];
|
||||
created: string;
|
||||
modified: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function ProfileDialog({ open, onClose }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [profiles, setProfiles] = useState<ProfileMeta[]>([]);
|
||||
const [newName, setNewName] = useState('');
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
const [selectedData, setSelectedData] = useState<ProfileData | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [renameOpen, setRenameOpen] = useState(false);
|
||||
const [renameValue, setRenameValue] = useState('');
|
||||
|
||||
const refreshProfiles = useCallback(async () => {
|
||||
const list = await invoke<ProfileMeta[]>('list_profiles');
|
||||
setProfiles(list);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) refreshProfiles();
|
||||
}, [open, refreshProfiles]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!newName.trim()) return;
|
||||
setSaving(true);
|
||||
const { sysPaths, userPaths } = useAppStore.getState();
|
||||
await invoke('save_profile', { name: newName.trim(), sys: sysPaths, user: userPaths });
|
||||
setNewName('');
|
||||
setSaving(false);
|
||||
refreshProfiles();
|
||||
};
|
||||
|
||||
const handleLoad = async (name: string) => {
|
||||
const data = await invoke<ProfileData>('load_profile', { name });
|
||||
setSelected(name);
|
||||
setSelectedData(data);
|
||||
};
|
||||
|
||||
const handleApply = async () => {
|
||||
if (!selected || !selectedData) return;
|
||||
if (!window.confirm(t('profile.applyConfirm', { name: selected }))) return;
|
||||
useAppStore.getState().replaceBothPaths(
|
||||
selectedData.sys.map(e => e.path),
|
||||
selectedData.user.map(e => e.path),
|
||||
);
|
||||
// 同步 disabled 状态
|
||||
await invoke('save_disabled_state', {
|
||||
system: selectedData.sys.filter(e => !e.enabled).map(e => e.path),
|
||||
user: selectedData.user.filter(e => !e.enabled).map(e => e.path),
|
||||
});
|
||||
await useAppStore.getState().savePaths();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleDelete = async (name: string) => {
|
||||
if (!window.confirm(`删除配置文件 "${name}"?`)) return;
|
||||
await invoke('delete_profile', { name });
|
||||
if (selected === name) { setSelected(null); setSelectedData(null); }
|
||||
refreshProfiles();
|
||||
};
|
||||
|
||||
const handleRename = async () => {
|
||||
if (!selected || !renameValue.trim()) return;
|
||||
await invoke('rename_profile', { oldName: selected, newName: renameValue.trim() });
|
||||
setRenameOpen(false);
|
||||
setSelected(renameValue.trim());
|
||||
refreshProfiles();
|
||||
};
|
||||
|
||||
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('profile.title')}</h2>
|
||||
<div className="flex gap-2 items-center">
|
||||
<input
|
||||
type="text"
|
||||
value={newName}
|
||||
onChange={e => setNewName(e.target.value)}
|
||||
placeholder={t('profile.namePlaceholder')}
|
||||
className="px-2 py-1 text-sm rounded border outline-none w-44"
|
||||
style={{ backgroundColor: 'var(--app-list-bg)', color: 'var(--app-fg)', borderColor: 'var(--app-border)' }}
|
||||
/>
|
||||
<button
|
||||
className="px-3 py-1 text-sm rounded text-white"
|
||||
style={{ backgroundColor: '#3b82f6' }}
|
||||
disabled={saving || !newName.trim()}
|
||||
onClick={handleSave}
|
||||
>
|
||||
{t('profile.save')}
|
||||
</button>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="px-2 py-1 text-sm rounded hover:opacity-70 transition-opacity"
|
||||
style={{ color: 'var(--app-fg)' }}
|
||||
title="关闭"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
{/* 左侧:列表 */}
|
||||
<div className="w-48 border-r overflow-auto p-2" style={{ borderColor: 'var(--app-border)' }}>
|
||||
{profiles.length === 0 ? (
|
||||
<div className="text-xs text-center py-6" style={{ opacity: 0.5 }}>{t('profile.noProfiles')}</div>
|
||||
) : (
|
||||
profiles.map(p => (
|
||||
<div
|
||||
key={p.name}
|
||||
onClick={() => handleLoad(p.name)}
|
||||
className="px-2 py-1.5 text-sm rounded cursor-pointer mb-0.5"
|
||||
style={{
|
||||
backgroundColor: selected === p.name ? 'rgba(59,130,246,0.15)' : 'transparent',
|
||||
color: selected === p.name ? '#3b82f6' : 'var(--app-fg)',
|
||||
}}
|
||||
>
|
||||
{p.name}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 右侧:详情 */}
|
||||
<div className="flex-1 p-3 overflow-auto">
|
||||
{!selectedData ? (
|
||||
<div className="text-center py-10 text-sm" style={{ opacity: 0.4 }}>
|
||||
{profiles.length === 0 ? t('profile.noProfiles') : '选择一个配置文件'}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<span className="font-semibold text-sm">{selectedData.name}</span>
|
||||
<span className="text-xs" style={{ opacity: 0.5 }}>{selectedData.modified}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-1.5 mb-3">
|
||||
<button
|
||||
className="px-3 py-1 text-xs rounded text-white"
|
||||
style={{ backgroundColor: '#3b82f6' }}
|
||||
onClick={handleApply}
|
||||
>
|
||||
{t('profile.apply')}
|
||||
</button>
|
||||
<button
|
||||
className="px-3 py-1 text-xs rounded"
|
||||
style={{ backgroundColor: 'var(--app-list-bg)', color: 'var(--app-fg)' }}
|
||||
onClick={() => { setRenameOpen(true); setRenameValue(selectedData.name); }}
|
||||
>
|
||||
{t('profile.rename')}
|
||||
</button>
|
||||
<button
|
||||
className="px-3 py-1 text-xs rounded text-white"
|
||||
style={{ backgroundColor: '#ef4444' }}
|
||||
onClick={() => handleDelete(selectedData.name)}
|
||||
>
|
||||
{t('profile.delete')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{renameOpen && (
|
||||
<div className="flex gap-2 mb-2">
|
||||
<input
|
||||
type="text"
|
||||
value={renameValue}
|
||||
onChange={e => setRenameValue(e.target.value)}
|
||||
className="px-2 py-1 text-xs rounded border outline-none"
|
||||
style={{ backgroundColor: 'var(--app-list-bg)', color: 'var(--app-fg)', borderColor: 'var(--app-border)' }}
|
||||
/>
|
||||
<button className="px-2 py-1 text-xs rounded text-white" style={{ backgroundColor: '#3b82f6' }} onClick={handleRename}>
|
||||
确认
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<PathSection title={`系统 PATH (${selectedData.sys.length})`} paths={selectedData.sys} />
|
||||
<PathSection title={`用户 PATH (${selectedData.user.length})`} paths={selectedData.user} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
function PathSection({ title, paths }: { title: string; paths: PathEntry[] }) {
|
||||
return (
|
||||
<div className="mb-2">
|
||||
<div className="text-xs font-medium mb-1" style={{ opacity: 0.7 }}>{title}</div>
|
||||
{paths.length === 0 ? (
|
||||
<div className="text-xs" style={{ opacity: 0.4 }}>(空)</div>
|
||||
) : (
|
||||
<div className="space-y-0.5 max-h-48 overflow-auto">
|
||||
{paths.map((e, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="text-xs font-mono px-2 py-0.5 rounded flex items-center gap-1.5"
|
||||
style={{
|
||||
backgroundColor: 'var(--app-list-bg)',
|
||||
color: e.enabled ? 'var(--app-fg)' : '#ef4444',
|
||||
textDecoration: e.enabled ? 'none' : 'line-through',
|
||||
opacity: e.enabled ? 1 : 0.5,
|
||||
}}
|
||||
>
|
||||
<span style={{ color: e.enabled ? '#22c55e' : '#ef4444', fontSize: 10 }}>
|
||||
{e.enabled ? '●' : '○'}
|
||||
</span>
|
||||
{e.path}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import { MergePreview } from '@/components/path-list/MergePreview';
|
||||
import { PathEditDialog } from '@/components/dialogs/PathEditDialog';
|
||||
import { HelpDialog } from '@/components/dialogs/HelpDialog';
|
||||
import { ImportDialog } from '@/components/dialogs/ImportDialog';
|
||||
import { AnalyzeDialog } from '@/components/dialogs/AnalyzeDialog';
|
||||
import { ProfileDialog } from '@/components/dialogs/ProfileDialog';
|
||||
import { useAppActions, type DialogState } from '@/hooks/use-app-actions';
|
||||
|
||||
/** Tauri's File object includes the native filesystem path */
|
||||
@@ -33,10 +35,12 @@ export function AppShell() {
|
||||
const [importDialog, setImportDialog] = useState<DialogState['importDialog']>({
|
||||
open: false, system: [], user: [],
|
||||
});
|
||||
const [analyzeOpen, setAnalyzeOpen] = useState(false);
|
||||
const [profilesOpen, setProfilesOpen] = useState(false);
|
||||
|
||||
const actions = useAppActions(activeTab, {
|
||||
editDialog, newDialog, helpOpen, importDialog,
|
||||
setEditDialog, setNewDialog, setHelpOpen, setImportDialog,
|
||||
setEditDialog, setNewDialog, setHelpOpen, setImportDialog, setAnalyzeOpen, setProfilesOpen,
|
||||
});
|
||||
|
||||
const tabConfig: { id: TabId; label: string }[] = [
|
||||
@@ -84,6 +88,8 @@ export function AppShell() {
|
||||
const current = localStorage.getItem('i18nextLng') || 'zh-CN';
|
||||
i18n.changeLanguage(current === 'zh-CN' ? 'en' : 'zh-CN');
|
||||
}}
|
||||
onProfiles={() => setProfilesOpen(true)}
|
||||
onAnalyze={() => setAnalyzeOpen(true)}
|
||||
onDarkMode={() => useThemeStore.getState().toggle()}
|
||||
/>
|
||||
</div>
|
||||
@@ -112,6 +118,8 @@ export function AppShell() {
|
||||
<PathEditDialog open={editDialog.open} title={t('dialog.editPath')} initialValue={editDialog.value} onConfirm={actions.handleEditConfirm} onCancel={() => setEditDialog({ open: false, index: -1, value: '', target: TargetType.SYSTEM })} />
|
||||
<HelpDialog open={helpOpen} onClose={() => setHelpOpen(false)} />
|
||||
<ImportDialog open={importDialog.open} systemCount={importDialog.system.length} userCount={importDialog.user.length} onSelect={actions.handleImportSelect} onCancel={() => setImportDialog({ open: false, system: [], user: [] })} />
|
||||
<AnalyzeDialog open={analyzeOpen} onClose={() => setAnalyzeOpen(false)} />
|
||||
<ProfileDialog open={profilesOpen} onClose={() => setProfilesOpen(false)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ export function PathTable({ tabId }: PathTableProps) {
|
||||
className="cursor-pointer select-none"
|
||||
style={{
|
||||
backgroundColor: isSelected
|
||||
? 'rgba(59, 130, 246, 0.3)'
|
||||
? 'var(--app-select-row)'
|
||||
: rowIdx % 2 === 0
|
||||
? 'var(--app-list-bg)'
|
||||
: 'var(--app-list-alt)',
|
||||
|
||||
@@ -20,6 +20,8 @@ interface ToolBarProps {
|
||||
onHelp: () => void;
|
||||
onLanguage: () => void;
|
||||
onDarkMode: () => void;
|
||||
onAnalyze: () => void;
|
||||
onProfiles: () => void;
|
||||
}
|
||||
|
||||
export function ToolBar(props: ToolBarProps) {
|
||||
@@ -66,6 +68,12 @@ export function ToolBar(props: ToolBarProps) {
|
||||
<button className={btnClass} style={btnStyle} onClick={props.onLanguage}>
|
||||
{t('button.language')}
|
||||
</button>
|
||||
<button className={btnClass} style={btnStyle} onClick={props.onAnalyze}>
|
||||
{t('button.analyze')}
|
||||
</button>
|
||||
<button className={btnClass} style={btnStyle} onClick={props.onProfiles}>
|
||||
{t('button.profiles')}
|
||||
</button>
|
||||
<button className={btnClass} style={btnStyle} onClick={props.onDarkMode}>
|
||||
{t('button.darkMode')}
|
||||
</button>
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface DialogState {
|
||||
setNewDialog: (v: boolean) => void;
|
||||
setHelpOpen: (v: boolean) => void;
|
||||
setImportDialog: (v: DialogState['importDialog']) => void;
|
||||
setAnalyzeOpen: (v: boolean) => void;
|
||||
setProfilesOpen: (v: boolean) => void;
|
||||
}
|
||||
|
||||
export function useAppActions(activeTab: TabId, dialogs: DialogState) {
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
"save": "OK",
|
||||
"cancel": "Cancel",
|
||||
"help": "Help",
|
||||
"analyze": "Analyze",
|
||||
"profiles": "Profiles",
|
||||
"undo": "Undo",
|
||||
"redo": "Redo",
|
||||
"darkMode": "Dark Mode",
|
||||
@@ -70,6 +72,31 @@
|
||||
"cancel": "Cancel",
|
||||
"search": "Search paths..."
|
||||
},
|
||||
"analyze": {
|
||||
"title": "PATH Analysis",
|
||||
"conflicts": "Conflicts",
|
||||
"tools": "Tools",
|
||||
"scanning": "Scanning...",
|
||||
"noConflicts": "No executable conflicts found",
|
||||
"noTools": "No matching executables found",
|
||||
"priority": "Prioritized",
|
||||
"shadowed": "Shadowed",
|
||||
"searchPlaceholder": "Search executable name...",
|
||||
"conflictCount": "{{count}} file conflict(s) found"
|
||||
},
|
||||
"profile": {
|
||||
"title": "PATH Profiles",
|
||||
"saveCurrent": "Save Current as Profile",
|
||||
"namePlaceholder": "Profile name...",
|
||||
"save": "Save",
|
||||
"load": "Load",
|
||||
"apply": "Apply",
|
||||
"delete": "Delete",
|
||||
"rename": "Rename",
|
||||
"noProfiles": "No saved profiles",
|
||||
"applyConfirm": "This will overwrite current PATH with profile \"{{name}}\" and write to registry. Confirm?",
|
||||
"deleted": "Profile \"{{name}}\" deleted"
|
||||
},
|
||||
"help": {
|
||||
"content": "PathEditor v4.0 — Windows System Environment Variable (PATH) Editor\n\nFeatures:\n• Create/Edit/Delete path entries\n• Move Up/Down to adjust priority\n• One-click cleanup of invalid & duplicate paths\n• Import/Export JSON, CSV, TXT formats\n• Full Undo/Redo support\n\nShortcuts:\n• Ctrl+N New\n• Ctrl+S Save\n• Ctrl+Z Undo\n• Ctrl+Y Redo\n• Ctrl+F Search\n• Delete Delete selected\n• F1 Help\n\nAuthor: 刘航宇\nGitHub: https://github.com/LHY0125/PathEditor"
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
"save": "确定",
|
||||
"cancel": "取消",
|
||||
"help": "帮助",
|
||||
"analyze": "分析",
|
||||
"profiles": "配置",
|
||||
"undo": "撤销",
|
||||
"redo": "重做",
|
||||
"darkMode": "深色模式",
|
||||
@@ -70,6 +72,31 @@
|
||||
"cancel": "取消",
|
||||
"search": "搜索路径..."
|
||||
},
|
||||
"analyze": {
|
||||
"title": "PATH 分析",
|
||||
"conflicts": "冲突检测",
|
||||
"tools": "工具清单",
|
||||
"scanning": "正在扫描...",
|
||||
"noConflicts": "未发现可执行文件冲突",
|
||||
"noTools": "未找到匹配的可执行文件",
|
||||
"priority": "优先执行",
|
||||
"shadowed": "被遮蔽",
|
||||
"searchPlaceholder": "搜索可执行文件名...",
|
||||
"conflictCount": "发现 {{count}} 个文件冲突"
|
||||
},
|
||||
"profile": {
|
||||
"title": "PATH 配置文件",
|
||||
"saveCurrent": "保存当前 PATH 为配置",
|
||||
"namePlaceholder": "配置名称...",
|
||||
"save": "保存",
|
||||
"load": "加载",
|
||||
"apply": "应用",
|
||||
"delete": "删除",
|
||||
"rename": "重命名",
|
||||
"noProfiles": "暂无配置文件",
|
||||
"applyConfirm": "将用配置 \"{{name}}\" 覆盖当前 PATH 并写入注册表,确定吗?",
|
||||
"deleted": "已删除配置 \"{{name}}\""
|
||||
},
|
||||
"help": {
|
||||
"content": "PathEditor v4.0 — Windows 系统环境变量 (PATH) 编辑器\n\n功能:\n• 新建/编辑/删除路径条目\n• 上移/下移调整优先级\n• 一键清理无效和重复路径\n• 导入/导出 JSON、CSV、TXT 格式\n• 完整撤销/重做支持\n\n快捷键:\n• Ctrl+N 新建\n• Ctrl+S 保存\n• Ctrl+Z 撤销\n• Ctrl+Y 重做\n• Ctrl+F 搜索\n• Delete 删除选中\n• F1 帮助\n\n作者: 刘航宇\nGitHub: https://github.com/LHY0125/PathEditor"
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ body {
|
||||
--app-fg: var(--color-light-fg);
|
||||
--app-border: var(--color-light-border);
|
||||
--app-hover: var(--color-light-hover);
|
||||
--app-select-row: rgba(59, 130, 246, 0.18);
|
||||
}
|
||||
|
||||
/* 深色模式 */
|
||||
@@ -51,6 +52,7 @@ body {
|
||||
--app-fg: var(--color-dark-fg);
|
||||
--app-border: var(--color-dark-border);
|
||||
--app-hover: var(--color-dark-hover);
|
||||
--app-select-row: rgba(96, 165, 250, 0.35);
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
|
||||
Reference in New Issue
Block a user