fix:iframe切换颜色

This commit is contained in:
Rocky Kwok committed 2026-07-26 17:01:09 +08:00
1 parent 5436719bfb
commit 59f2f56124
3 files changed
+32 -3

No files matched your search

@@ -31,3 +31,20 @@ test("forces light theme for landing and chats_iframe routes only", () => {
);
assert.equal(resolveForcedThemeForPath("/page/workspace/chats/new"), undefined);
});
test("honors the dark-blue theme query on chats_iframe routes", () => {
assert.equal(
resolveForcedThemeForPath(
"/page/workspace/chats_iframe/new",
"?from=iframe&theme=dark-blue",
),
"dark",
);
assert.equal(
resolveForcedThemeForPath(
"/page/workspace/chats_iframe/new",
"?from=iframe&theme=red",
),
"light",
);
});
@@ -1,3 +1,5 @@
import { resolveEmbedThemeMode } from "@/core/embed/embed-session";
export function isChatsIframeWorkspacePath(pathname: string): boolean {
return (
pathname === "/page/workspace/chats_iframe/new" ||
@@ -7,10 +9,17 @@ export function isChatsIframeWorkspacePath(pathname: string): boolean {
export function resolveForcedThemeForPath(
pathname: string,
): "light" | undefined {
if (pathname === "/landing" || isChatsIframeWorkspacePath(pathname)) {
search = "",
): "light" | "dark" | undefined {
if (pathname === "/landing") {
return "light";
}
if (isChatsIframeWorkspacePath(pathname)) {
const normalizedSearch = search.startsWith("?") ? search : `?${search}`;
const rawTheme = new URLSearchParams(normalizedSearch).get("theme")?.trim();
return rawTheme ? resolveEmbedThemeMode(rawTheme) : "light";
}
return undefined;
}