Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(apps): open the app connect flow in the browser on Desktop (MUL-8964) (#10332)

Jiayuan Zhang0d2366164b1e
diff --git a/packages/views/common/app-requests.tsx b/packages/views/common/app-requests.tsx
index b9971a5609..4921673272 100644
--- a/packages/views/common/app-requests.tsx
+++ b/packages/views/common/app-requests.tsx
@@ -24,6 +24,7 @@ import { useActorName } from "@multica/core/workspace/hooks";
import type { AppRequest } from "@multica/core/types";
import { useLocale, useT } from "../i18n";
import { currentPath, useNavigation } from "../navigation";
+import { isDesktopShell, openExternal } from "../platform";
const CONNECTED_PARAM = "app_connected";
const CONNECT_ERROR_PARAM = "app_connect_error";
@@ -254,7 +255,10 @@ function AppRequestCard({
// The callback appends its own query, so the fragment stays behind.
const returnTo = currentPath({ ...navigation, hash: "" });
const { redirect_url } = await api.connectApp("personal", app, returnTo);
- window.location.href = redirect_url;
+ openExternal(redirect_url, { webTarget: "same-tab" });
+ // Desktop opens the hosted flow in the system browser and stays here;
+ // the card resolves through the request's realtime update.
+ if (isDesktopShell()) setConnecting(false);
} catch {
toast.error(t(($) => $.connected_apps.toast_failed));
setConnecting(false);
diff --git a/packages/views/settings/components/add-app-dialog.test.tsx b/packages/views/settings/components/add-app-dialog.test.tsx
index e24f02d6d9..f1cfede1dc 100644
--- a/packages/views/settings/components/add-app-dialog.test.tsx
+++ b/packages/views/settings/components/add-app-dialog.test.tsx
@@ -20,7 +20,11 @@ const catalog = [
];
beforeEach(() => { vi.mocked(api.connectApp).mockRejectedValue(new Error("offline")); });
-afterEach(() => { cleanup(); vi.clearAllMocks(); });
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+ delete (window as { desktopAPI?: unknown }).desktopAPI;
+});
function renderDialog(scope: AppAccountScope, canManage = true) {
render(<I18nProvider locale="en" resources={{ en: { common: enCommon, settings: enSettings } }}>
@@ -71,4 +75,19 @@ describe("AddAppDialog", () => {
await waitFor(() => expect(api.connectApp).toHaveBeenCalledTimes(2));
expect(api.connectApp).toHaveBeenLastCalledWith("team", "notion");
});
+
+ it("hands the hosted flow to the system browser on Desktop and frees the row", async () => {
+ // Desktop blocks same-window navigation to another origin, so assigning
+ // the location left the row on "Connecting..." forever.
+ const openExternal = vi.fn();
+ (window as { desktopAPI?: unknown }).desktopAPI = { openExternal, pickDirectory: vi.fn() };
+ vi.mocked(api.connectApp).mockResolvedValue({ redirect_url: "https://connect.example.test/flow" });
+ const user = userEvent.setup();
+ renderDialog("team");
+ const connect = screen.getByRole("button", { name: "Connect" });
+ await user.click(connect);
+ await waitFor(() => expect(openExternal).toHaveBeenCalledWith("https://connect.example.test/flow"));
+ await waitFor(() => expect(connect).toBeEnabled());
+ expect(connect).toHaveTextContent("Connect");
+ });
});
diff --git a/packages/views/settings/components/add-app-dialog.tsx b/packages/views/settings/components/add-app-dialog.tsx
index a0997a3ab9..ce4c1b1242 100644
--- a/packages/views/settings/components/add-app-dialog.tsx
+++ b/packages/views/settings/components/add-app-dialog.tsx
@@ -17,6 +17,7 @@ import { api } from "@multica/core/api";
import type { AppAccountScope, AppCatalogEntry, AppsOverview } from "@multica/core/types";
import { ComposioToolkitLogo } from "../../common/composio-toolkit-logo";
import { useT } from "../../i18n";
+import { isDesktopShell, openExternal } from "../../platform";
/**
* The add-app dialog: every app the workspace allows, curated ones first.
@@ -67,7 +68,10 @@ export function AddAppDialog({
setConnecting(app.slug);
try {
const { redirect_url } = await api.connectApp(scope, app.slug);
- window.location.href = redirect_url;
+ openExternal(redirect_url, { webTarget: "same-tab" });
+ // The web tab leaves for the hosted flow. Desktop opens it in the system
+ // browser and stays here, so the row must become clickable again.
+ if (isDesktopShell()) setConnecting(null);
} catch (e) {
toast.error(e instanceof Error && e.message ? e.message : t(($) => $.connected_apps.toast_failed));
setConnecting(null);
diff --git a/packages/views/settings/components/apps-settings.test.tsx b/packages/views/settings/components/apps-settings.test.tsx
index 56ff25c61d..2d906c1591 100644
--- a/packages/views/settings/components/apps-settings.test.tsx
+++ b/packages/views/settings/components/apps-settings.test.tsx
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
-import { cleanup, render, screen, waitFor, within } from "@testing-library/react";
+import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { api } from "@multica/core/api";
@@ -34,7 +34,11 @@ beforeEach(() => {
return { rules: [] };
});
});
-afterEach(() => { cleanup(); vi.clearAllMocks(); });
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+ delete (window as { desktopAPI?: unknown }).desktopAPI;
+});
function renderSettings() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
@@ -98,3 +102,20 @@ it("only offers members the personal connection entry", async () => {
expect(await screen.findByRole("button", { name: "Connect my account" })).toBeVisible();
expect(screen.queryByRole("button", { name: "Connect team account" })).not.toBeInTheDocument();
});
+
+it("reloads accounts when the Desktop window is focused again after connecting in the browser", async () => {
+ (window as { desktopAPI?: unknown }).desktopAPI = { pickDirectory: vi.fn() };
+ renderSettings();
+ await screen.findByText("A saved app list is hiding other apps.");
+ expect(api.getAppsOverview).toHaveBeenCalledTimes(1);
+ fireEvent.focus(window);
+ await waitFor(() => expect(api.getAppsOverview).toHaveBeenCalledTimes(2));
+});
+
+it("does not reload on focus on the web, where the flow returns to this tab", async () => {
+ renderSettings();
+ await screen.findByText("A saved app list is hiding other apps.");
+ fireEvent.focus(window);
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(api.getAppsOverview).toHaveBeenCalledTimes(1);
+});
diff --git a/packages/views/settings/components/apps-settings.tsx b/packages/views/settings/components/apps-settings.tsx
index e6bdc32668..ac42f5a24a 100644
--- a/packages/views/settings/components/apps-settings.tsx
+++ b/packages/views/settings/components/apps-settings.tsx
@@ -35,6 +35,7 @@ import { ComposioToolkitLogo } from "../../common/composio-toolkit-logo";
import { SavedAppRestriction } from "../../common/saved-app-restriction";
import { useT, useTimeAgo } from "../../i18n";
import { useNavigation } from "../../navigation";
+import { isDesktopShell } from "../../platform";
import { AddAppDialog } from "./add-app-dialog";
import { AppAccountDialog } from "./app-account-dialog";
import { SettingsCard, SettingsSection } from "./settings-layout";
@@ -83,6 +84,15 @@ export function AppsSettings() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [connectedParam, errorParam]);
+ // Desktop finishes the hosted flow in the system browser, so that return
+ // never reaches this window. Reload the accounts when it is focused again.
+ useEffect(() => {
+ if (!isDesktopShell()) return;
+ const refresh = () => void qc.invalidateQueries({ queryKey: connectedAppsKeys.overview(wsId) });
+ window.addEventListener("focus", refresh);
+ return () => window.removeEventListener("focus", refresh);
+ }, [qc, wsId]);
+
const appBySlug = useMemo(() => {
const m = new Map<string, AppCatalogEntry>();
for (const app of catalog.data?.apps ?? []) m.set(app.slug, app);