-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add component uninstall support #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -70,6 +70,32 @@ pub(super) async fn install_component( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Uninstall unified Python component (3.10 + 3.12). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub(super) fn uninstall_component() -> Result<String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let py310_dir = get_python_runtime_dir(RUNTIME_PY310); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let py312_dir = get_python_runtime_dir(RUNTIME_PY312); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut removed = Vec::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for dir in [&py310_dir, &py312_dir] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if dir.exists() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::fs::remove_dir_all(dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map_err(|e| AppError::io(format!("Failed to remove Python runtime: {}", e)))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| removed.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir.file_name() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .to_string_lossy() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Include more specific context in Python uninstall error messages and logs Since you already compute separate dirs for
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if removed.is_empty() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok("Python 组件未安装".to_string()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Ok(format!("已卸载 Python: {}", removed.join(", "))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Reinstall unified Python component (3.10 + 3.12). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub(super) async fn reinstall_component( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| client: &Client, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,11 @@ export default function Versions() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [detailOpen, setDetailOpen] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [uninstallOpen, setUninstallOpen] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [versionToUninstall, setVersionToUninstall] = useState<InstalledVersion | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [componentUninstallOpen, setComponentUninstallOpen] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [componentToUninstall, setComponentToUninstall] = useState<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [releases, setReleases] = useState<GitHubRelease[]>([]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const releasesLoading = operations[OPERATION_KEYS.fetchReleases] || false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -145,6 +150,23 @@ export default function Versions() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [runOperation, clearDownloadProgress] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleComponentUninstall = useCallback(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!componentToUninstall) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const key = OPERATION_KEYS.uninstallComponent(componentToUninstall.id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await runOperation({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task: () => api.uninstallComponent(componentToUninstall.id), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: (result) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message.success(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onError: (error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleApiError(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentUninstallOpen(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentToUninstall(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [componentToUninstall, runOperation]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+153
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Consider not closing the uninstall modal when the uninstall operation fails Because
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isInstalled = (tagName: string) => versions.some((v) => v.version === tagName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const availableReleases = releases.filter((r) => !isInstalled(r.tag_name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getInstalledRelease = (version: string) => releases.find((r) => r.tag_name === version); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -211,6 +233,21 @@ export default function Versions() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => runComponentInstallAction(comp.id, 'reinstall')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Tooltip>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Tooltip title="卸载" key="uninstall"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type="text" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| danger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={<DeleteOutlined />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled={isComponentOperating} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentToUninstall({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: comp.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name: comp.display_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentUninstallOpen(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Tooltip>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ].filter(Boolean) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| downloading && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -437,6 +474,31 @@ export default function Versions() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setVersionToUninstall(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/* Component Uninstall Modal */} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ConfirmModal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| open={componentUninstallOpen} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title="确认卸载组件" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| danger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content={ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p>确定卸载此组件?卸载后需重新下载才能使用。</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {componentToUninstall && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Text type="secondary">组件: {componentToUninstall.display_name}</Text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loading={ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| componentToUninstall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? operations[OPERATION_KEYS.uninstallComponent(componentToUninstall.id)] || false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onConfirm={handleComponentUninstall} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onCancel={() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentUninstallOpen(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setComponentToUninstall(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninstalling a core component (such as Python, Node.js, or uv) while there are active instances running can lead to application crashes, corrupted environments, or file lock errors (especially on Windows).\n\nIt is highly recommended to check if any instances are currently running and return an error if so, similar to how it is handled in other commands.