Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): use shared switch in plugin details

kirozeng49eba7a2fb03
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
index 423c425a93..059f850065 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx
@@ -4,11 +4,11 @@ import { shouldShowOpenPathError } from '../../../shared/openPathResult';
*
* Inputs: the renderer-safe Plugin detail model plus the installed Ghost when available.
* Outputs: accessible detail interactions, Host-owned configuration rows, a single-row responsive
- * action hero, and the sticky top bar carrying the back affordance and macOS window-drag region.
+ * action hero with the shared Switch, and the sticky top bar with back and macOS window dragging.
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
*/
-import { useLayoutEffect, useRef, useState, type ReactNode } from 'react';
+import { useId, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
import * as Dialog from '@radix-ui/react-dialog';
import {
AppWindow,
@@ -178,6 +178,7 @@ export function GhostPluginDetailView({
}: GhostPluginDetailViewProps) {
const { t } = useTranslation();
const { scrolled, onScroll } = usePluginDetailScrolled();
+ const enableSwitchId = useId();
const [descriptionExpanded, setDescriptionExpanded] = useState(false);
const [descriptionOverflows, setDescriptionOverflows] = useState(false);
const descriptionRef = useRef<HTMLParagraphElement>(null);
@@ -359,25 +360,18 @@ export function GhostPluginDetailView({
</button>
) : null}
{/* 启用开关带明确文字(设计定稿):状态一目了然,点文字同样可切换。 */}
- <button
- type="button"
- role="switch"
- onClick={() => {
- // 未批准的安装不可切换启用(点了 Main 也会拒);与 updateBusy 同级门控。
- if (!toggleDisabled && !needsReapproval) onToggle(!enabled);
- }}
- disabled={toggleDisabled || needsReapproval}
- aria-checked={enabled}
- aria-label={t('settings.ghosts.enableAria', { name: detail.name })}
+ <label
+ htmlFor={enableSwitchId}
className={cn(
'flex shrink-0 items-center gap-2 rounded-full py-1 pl-3 pr-1 transition-colors duration-150',
- 'hover:bg-[var(--surface-hover-soft)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',
- 'disabled:cursor-not-allowed disabled:opacity-60',
+ 'hover:bg-[var(--surface-hover-soft)]',
+ toggleDisabled || needsReapproval ? 'cursor-not-allowed' : 'cursor-pointer',
)}
>
<span
className={cn(
'text-12',
+ (toggleDisabled || needsReapproval) && 'opacity-60',
enabled ? 'text-[var(--text-secondary)]' : 'text-[var(--text-tertiary)]',
)}
>
@@ -387,25 +381,14 @@ export function GhostPluginDetailView({
: 'settings.ghosts.detail.disabledLabel',
)}
</span>
- <span
- aria-hidden="true"
- className={cn(
- 'inline-flex h-5 w-9 shrink-0 items-center rounded-full border-2 border-transparent transition-colors',
- enabled
- ? 'bg-[var(--switch-track-on)]'
- : 'bg-[var(--switch-track-off)]',
- )}
- >
- <span
- className={cn(
- 'block h-4 w-4 rounded-full ring-0 transition-transform',
- enabled
- ? 'translate-x-4 bg-background'
- : 'translate-x-0 bg-[var(--switch-thumb-off)]',
- )}
- />
- </span>
- </button>
+ <Switch
+ id={enableSwitchId}
+ checked={enabled}
+ disabled={toggleDisabled || needsReapproval}
+ onCheckedChange={onToggle}
+ aria-label={t('settings.ghosts.enableAria', { name: detail.name })}
+ />
+ </label>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
index 9d9c1e9c56..8e32defe59 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginDetailSections.test.tsx
@@ -1,5 +1,5 @@
/**
- * Regression coverage for Plugin detail section content and interaction behavior.
+ * Regression coverage for Plugin detail sections, shared Switch wiring and interaction behavior.
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
* @vitest-environment jsdom
*/
@@ -179,6 +179,50 @@ afterEach(() => {
});
describe('Ghost plugin detail sections', () => {
+ it('uses the shared Cindy Switch for the plugin enabled control', () => {
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ const onToggle = vi.fn();
+ const view = (disabled = false) => (
+ <GhostPluginDetailView
+ ghost={null}
+ detail={detail}
+ panelStatus="Docked"
+ onBack={vi.fn()}
+ onToggle={onToggle}
+ onUse={vi.fn()}
+ onUpdate={vi.fn()}
+ onUpdateFromFile={vi.fn()}
+ onUninstall={vi.fn()}
+ toggleDisabled={disabled}
+ />
+ );
+ const { rerender } = render(view());
+
+ const toggle = screen.getByRole('switch', {
+ name: 'settings.ghosts.enableAria',
+ });
+ expect(toggle.className).toContain('cindy-switch');
+ expect(toggle.className).toContain('data-[state=checked]:bg-[var(--switch-track-on)]');
+ expect(toggle.firstElementChild?.className).toContain(
+ 'data-[state=checked]:bg-[var(--switch-thumb-on)]',
+ );
+ fireEvent.click(toggle);
+ expect(onToggle.mock.calls).toEqual([[false]]);
+ fireEvent.click(screen.getByText('settings.ghosts.detail.enabledLabel'));
+ expect(onToggle.mock.calls).toEqual([[false], [false]]);
+ rerender(view(true));
+ fireEvent.click(toggle);
+ fireEvent.click(screen.getByText('settings.ghosts.detail.enabledLabel'));
+ expect(onToggle).toHaveBeenCalledTimes(2);
+ });
+
it('shows the main-view preference alongside the plugin settings UI', () => {
vi.stubGlobal(
'ResizeObserver',
@@ -565,7 +609,7 @@ describe('Ghost plugin detail sections', () => {
).disabled,
).toBe(true);
- // 启用区域是单个 switch 按钮;点文字或轨道都由同一交互处理。
+ // 共享 Switch 和关联文字标签遵循同一禁用门控。
const toggle = screen.getByRole('switch', {
name: 'settings.ghosts.enableAria',
}) as HTMLButtonElement;