fix: sync context panel iframe themes

Keeps embedded sessions aligned with parent theme
Prevents iframe reloads on theme changes
Supports theme hotkeys from focused iframes
This commit is contained in:
Bohdan Triapitsyn
2026-06-16 23:33:29 +03:00
parent 91e8e94961
commit 0fef61e25f
12 changed files with 484 additions and 118 deletions
@@ -0,0 +1,23 @@
export const readEmbeddedThemeSearchParams = (): URLSearchParams | null => {
if (typeof window === 'undefined') {
return null;
}
const params = new URLSearchParams(window.location.search);
return params.get('ocPanel') === 'session-chat' ? params : null;
};
const getSystemPreference = (): boolean => {
if (typeof window === 'undefined') {
return true;
}
return window.matchMedia('(prefers-color-scheme: dark)').matches;
};
export const getInitialSystemPreference = (): boolean => {
const embeddedParams = readEmbeddedThemeSearchParams();
const embeddedVariant = embeddedParams?.get('themeVariant');
if (embeddedVariant === 'dark' || embeddedVariant === 'light') {
return embeddedVariant === 'dark';
}
return getSystemPreference();
};