Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(settings): install or turn on the My browser plugin in place
Dash78f3820f862e
diff --git a/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx b/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsxindex c6d993ca50..24435cb741 100644--- a/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx+++ b/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx@@ -31,8 +31,10 @@ interface BrowserBackendSubsectionProps {onRecover: () => void;/** 推荐的页面控制插件已装在本机(可能未启用);决定第 1 步写「安装」还是「启用」。 */userBrowserPluginInstalled?: boolean;- /** 打开推荐插件(未装时进入市场安装;已装时进入它的详情与设置,里面有装浏览器扩展的入口)。 */+ /** 第 1 步就地安装或启用推荐插件;第 2 步打开插件详情,里面有装浏览器扩展的入口。 */onSetUpUserBrowser?: () => void;+ /** 正在就地安装或启用插件。 */+ userBrowserSetupBusy?: boolean;}function healthReasonKey(reason: BrowserBackendHealthReason | undefined): string {@@ -64,6 +66,7 @@ export function BrowserBackendSubsection({onRecover,userBrowserPluginInstalled = false,onSetUpUserBrowser,+ userBrowserSetupBusy = false,}: BrowserBackendSubsectionProps) {const { t } = useTranslation();const embeddedHealth =@@ -144,7 +147,10 @@ export function BrowserBackendSubsection({userBrowserHealth.reason === 'extension-disconnected') ? (// 「我的浏览器」还差一步:说清缺的是哪一步,并给出直接去做的按钮;连上后父组件轮询会自动变绿。<div className="flex flex-wrap items-center justify-between gap-3 border-t border-[var(--settings-theme-card-border)] px-4 py-[14px]">- <div className="flex min-w-0 flex-1 basis-[280px] items-start gap-2 text-12 leading-[1.5]" role="status">+ <div+ className="flex min-w-0 flex-1 basis-[280px] items-start gap-2 text-12 leading-[1.5]"+ role="status"+ >{userBrowserHealth.reason === 'plugin-missing' ? (<Puzzle size={14} className="mt-0.5 shrink-0 text-[var(--settings-section-desc)]" />) : (@@ -168,7 +174,13 @@ export function BrowserBackendSubsection({</div></div>{onSetUpUserBrowser ? (- <Button variant="secondary" type="button" onClick={onSetUpUserBrowser} disabled={pending}>+ <Button+ variant="secondary"+ type="button"+ loading={userBrowserSetupBusy}+ onClick={onSetUpUserBrowser}+ disabled={pending || userBrowserSetupBusy}+ >{userBrowserHealth.reason === 'plugin-missing'? t(userBrowserPluginInstalleddiff --git a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsxindex c5ead7d90f..5d05dbdaff 100644--- a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx+++ b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx@@ -46,6 +46,9 @@ import {DropdownMenuTrigger,} from '@/components/ui/dropdown-menu';import { createLogger } from '@/lib/logger';+import { extractIpcError } from '@/utils/ipcError';+import { ghostInstallErrorKey } from '@/cindy-brain/installErrorKey';+import { pluginMarketErrorKey } from '@/features/plugin/lib/pluginMarketErrorKey';import { BrowserBackendSubsection } from './BrowserBackendSubsection';import { useAutomationSettingsRead } from './useAutomationSettingsRead';import { ComputerPermissionRow } from './ComputerPermissionRow';@@ -55,6 +58,8 @@ import {REAL_PROFILE_READ_DENIED,type BrowserBackendHealth,} from '../../../shared/browserBackend';+import { ghostInstallApprovalToken } from '../../../shared/ghost';+import { installedGhostStoragePart } from '../../../shared/pluginIdentity';import {browserOpenForLoginErrorCode,browserOpenForLoginToastKey,@@ -453,27 +458,63 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {[setBackendConfig],);const navigate = useNavigate();- const userBrowserPluginInstalled = useInstalledGhosts().some(- (ghost) => ghost.manifest.id === RECOMMENDED_PAGE_CONTROL_PLUGIN_ID,- );+ const userBrowserPlugin =+ useInstalledGhosts().find((ghost) => ghost.manifest.id === RECOMMENDED_PAGE_CONTROL_PLUGIN_ID) ??+ null;+ const [userBrowserSetupBusy, setUserBrowserSetupBusy] = useState(false);+ const refreshUserBrowserHealth = useCallback(async () => {+ const next = await window.electronAPI.browserBackend?.getHealth?.().catch(() => null);+ if (next?.active === 'user-browser') setBrowserBackendHealth(next);+ }, []);+ // Step 1 happens right here: install the plugin from the market (Main still shows its usual+ // permission confirmation) or turn it on, then re-check so the guidance moves on to step 2.+ // Step 2 and anything unexpected open the plugin's own page, which has the extension install entry.+ const handleSetUpUserBrowser = useCallback(async () => {+ const openPluginPage = () =>+ navigate(`/plugins?market=${encodeURIComponent(RECOMMENDED_PAGE_CONTROL_PLUGIN_ID)}`);+ if (browserBackendHealth?.reason !== 'plugin-missing' || userBrowserPlugin?.enabled) {+ openPluginPage();+ return;+ }+ setUserBrowserSetupBusy(true);+ try {+ if (userBrowserPlugin) {+ await window.electronAPI.ghosts.setEnabled(+ installedGhostStoragePart(userBrowserPlugin),+ true,+ ghostInstallApprovalToken(userBrowserPlugin.approval),+ );+ } else {+ const detail = await window.electronAPI.pluginMarket.detail(RECOMMENDED_PAGE_CONTROL_PLUGIN_ID);+ if (detail.installState !== 'not-installed') {+ openPluginPage();+ return;+ }+ const result = await window.electronAPI.pluginMarket.install(detail.pluginId, {+ expectedReleaseId: detail.releaseId,+ expectedManifest: detail.manifest,+ allowSourceReplacement: false,+ });+ toast.success(t('settings.ghosts.toast.installed', { name: result.ghost.manifest.name }));+ }+ await refreshUserBrowserHealth();+ } catch (error) {+ const code = extractIpcError(error)?.code;+ // Cancelling the install confirmation is not a failure.+ if (code !== 'MUTATION_CANCELLED') {+ toast.error(t(userBrowserPlugin ? ghostInstallErrorKey(code) : pluginMarketErrorKey(error)));+ }+ } finally {+ setUserBrowserSetupBusy(false);+ }+ }, [browserBackendHealth?.reason, navigate, refreshUserBrowserHealth, t, userBrowserPlugin]);// While "My browser" still lacks its plugin or extension, check again every few seconds so the// guidance turns into "connected" as soon as the user finishes a step elsewhere.useEffect(() => {if (browserBackendKind !== 'user-browser' || browserBackendHealth?.status !== 'error') return;- let cancelled = false;- const timer = setInterval(() => {- void window.electronAPI.browserBackend- ?.getHealth?.()- .then((next) => {- if (!cancelled && next?.active === 'user-browser') setBrowserBackendHealth(next);- })- .catch(() => {});- }, 3000);- return () => {- cancelled = true;- clearInterval(timer);- };- }, [browserBackendKind, browserBackendHealth?.status]);+ const timer = setInterval(() => void refreshUserBrowserHealth(), 3000);+ return () => clearInterval(timer);+ }, [browserBackendKind, browserBackendHealth?.status, refreshUserBrowserHealth]);const [useRealProfilePending, setUseRealProfilePending] = useState(false);const confirmDialog = useOptionalConfirmDialog();// Health can include an automatic embedded-browser recovery and therefore@@ -1489,10 +1530,9 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {health={browserBackendHealth}onSelect={(kind) => void handleSelectBackend(kind)}onRecover={() => void handleRecoverBrowserBackend()}- userBrowserPluginInstalled={userBrowserPluginInstalled}- onSetUpUserBrowser={() =>- navigate(`/plugins?market=${encodeURIComponent(RECOMMENDED_PAGE_CONTROL_PLUGIN_ID)}`)- }+ userBrowserPluginInstalled={userBrowserPlugin !== null}+ userBrowserSetupBusy={userBrowserSetupBusy}+ onSetUpUserBrowser={() => void handleSetUpUserBrowser()}/>) : null}{browserBackendKind !== null ? (diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsxindex 55d8237565..c98151e3f9 100644--- a/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx+++ b/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx@@ -521,4 +521,44 @@ describe('ComputerUseSection browser backend health loading', () => {'settings.computerUse.browserBackend.health.ready',);});++ // My browser without its plugin: step 1 installs the plugin in place (no trip to the market page)+ // and the guidance moves on to step 2 as soon as the host reports the extension as the gap.+ it('installs the My browser plugin from settings and moves on to the extension step', async () => {+ const detail = {+ pluginId: 'my-browser',+ releaseId: 'release-1',+ manifest: { id: 'my-browser' },+ installState: 'not-installed',+ };+ const marketDetail = vi.fn().mockResolvedValue(detail);+ const install = vi.fn().mockResolvedValue({ ghost: { manifest: { name: 'Cindy Chrome' } } });+ Object.assign(window.electronAPI, { pluginMarket: { detail: marketDetail, install } });+ api.getBackendState.mockResolvedValue({ active: 'user-browser' });+ api.getBackendHealth+ .mockResolvedValueOnce({ active: 'user-browser', status: 'error', reason: 'plugin-missing', canRecover: false })+ .mockResolvedValue({+ active: 'user-browser',+ status: 'error',+ reason: 'extension-disconnected',+ canRecover: false,+ });++ render(<ComputerUseSection workingDir="/tmp/project" />);+ fireEvent.click(+ await screen.findByRole('button', {+ name: 'settings.computerUse.browserBackend.userBrowserSetup.installPlugin',+ }),+ );++ expect(+ await screen.findByText('settings.computerUse.browserBackend.userBrowserSetup.installExtensionTitle'),+ ).toBeTruthy();+ expect(install).toHaveBeenCalledWith('my-browser', {+ expectedReleaseId: 'release-1',+ expectedManifest: { id: 'my-browser' },+ allowSourceReplacement: false,+ });+ expect(api.successToast).toHaveBeenCalledWith('settings.ghosts.toast.installed');+ });});