mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-27 04:56:20 +02:00
* fix(desktop): open in-app links in a tab instead of the browser (MUL-5208) A link written as an absolute URL on this deployment's own origin (`https://<app-host>/acme/issues/1` — what "copy link" produces, and what agents paste into chat) fell through openLink's external branch to window.open, which Electron routes to shell.openExternal. Clicking an issue link in Desktop chat therefore opened a browser window instead of a tab. openLink now resolves such a URL back to its in-app path and takes the same route a relative path does. Backend-served prefixes (/api/, /_next/) stay external so attachment downloads keep working. Two supporting fixes the change depends on: - The `multica:navigate` event had no listener on web, so in-app paths in content were dead links there; normalizing app URLs would have extended that to every pasted app URL. The web platform layer now answers the event with a router push. - The desktop handler opened every path inside the active workspace's tab group. A cross-workspace link now goes through switchWorkspace, matching what the navigation adapter already does for pushes. Co-authored-by: multica-agent <github@multica.ai> * fix(desktop): scope in-app link conversion to workspace pages, answer it in issue windows Review follow-ups on MUL-5208. 1. The non-page exclusion list only covered /api/ and /_next/, so a same-origin /uploads/* link — local-storage attachments, served by the backend and proxied by web — was routed as an app page, opening a dead tab instead of the file. Replaced the deny-list with the app's own routing model: an absolute URL converts to an in-app path only when its first segment is a slug a workspace could own, which the existing reserved-slug list (shared with the backend) already answers. /api, /uploads, /_next, /favicon.ico and the pre-workspace routes all stay external without a second list to keep in sync. 2. A dedicated issue window derives the same app origin from its adapter but had no multica:navigate listener, so a same-origin link there became a silent no-op (it used to reach the browser). The window now answers the event: another issue opens in place — matching what its adapter push and mention chips already do — and any other app page, which this single-route window cannot host, goes to the browser. Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: J <agent@multica.ai> Co-authored-by: multica-agent <github@multica.ai>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import { Suspense, useEffect } from "react";
|
|
import { useRouter, usePathname, useSearchParams } from "next/navigation";
|
|
import {
|
|
NavigationProvider,
|
|
type NavigationAdapter,
|
|
} from "@multica/views/navigation";
|
|
|
|
/**
|
|
* Web half of the `multica:navigate` bridge — the event shared content
|
|
* (comments, chat, issue descriptions) fires when a link resolves to an in-app
|
|
* destination. Desktop's shell answers it by opening a tab; on the web the
|
|
* equivalent is a router push in place. Without this the event has no listener
|
|
* and such links do nothing at all.
|
|
*/
|
|
function useInternalLinkHandler(router: ReturnType<typeof useRouter>) {
|
|
useEffect(() => {
|
|
const handler = (e: Event) => {
|
|
const path = (e as CustomEvent<{ path?: string }>).detail?.path;
|
|
if (!path) return;
|
|
router.push(path);
|
|
};
|
|
window.addEventListener("multica:navigate", handler);
|
|
return () => window.removeEventListener("multica:navigate", handler);
|
|
}, [router]);
|
|
}
|
|
|
|
function NavigationProviderInner({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const searchParams = useSearchParams();
|
|
useInternalLinkHandler(router);
|
|
|
|
const adapter: NavigationAdapter = {
|
|
push: router.push,
|
|
replace: router.replace,
|
|
back: router.back,
|
|
pathname,
|
|
searchParams: new URLSearchParams(searchParams.toString()),
|
|
getShareableUrl: (path: string) =>
|
|
typeof window === "undefined" ? path : window.location.origin + path,
|
|
// router.prefetch is a no-op in dev mode by Next.js design; in production
|
|
// it warms the RSC payload + route chunk so the next push() commits with
|
|
// no network round-trip. Safe to call repeatedly — Next dedupes internally.
|
|
prefetch: (path: string) => {
|
|
router.prefetch(path);
|
|
},
|
|
};
|
|
|
|
return <NavigationProvider value={adapter}>{children}</NavigationProvider>;
|
|
}
|
|
|
|
export function WebNavigationProvider({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
return (
|
|
<Suspense>
|
|
<NavigationProviderInner>{children}</NavigationProviderInner>
|
|
</Suspense>
|
|
);
|
|
}
|