-
Notifications
You must be signed in to change notification settings - Fork 21
Feature/vscode-theming #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nasdan
merged 6 commits into
feature/#812-implement-vscode-ext-and-mcp
from
feature/vscode-theming
May 8, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c4cdd9
feat(vscode-theming): implement theme synchronization and update styl…
Ivanruii c0575fe
fix(vscode-theming): refine background CSS variable mapping
Ivanruii 4ca0046
fix(vscode-theming): debounce theme updates to improve performance
Ivanruii c7c082f
fix(vscode-theming): standardize background and foreground style prop…
Ivanruii a726ee1
fix(vscode-theming): remove unused cleanup function from setupThemeSync
Ivanruii 57dc5c1
fix: remove unnecessary file extensions in import statements
Ivanruii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { isVSCodeEnv } from '#common/utils/env.utils'; | ||
| import { onMessage } from '#common/utils/vscode-bridge.utils'; | ||
| import { | ||
| HOST_MESSAGE_TYPE, | ||
| type ThemePayload, | ||
| } from '@lemoncode/quickmock-bridge-protocol'; | ||
| import { useEffect } from 'react'; | ||
|
|
||
| const CSS_VAR_MAP: Record<keyof ThemePayload, readonly string[]> = { | ||
| background: ['--primary-100', '--primary-200'], | ||
| backgroundSecondary: ['--pure-white'], | ||
| foreground: ['--primary-700'], | ||
| }; | ||
|
|
||
| const applyTheme = (theme: ThemePayload): void => { | ||
| const root = document.documentElement; | ||
| for (const [key, cssVars] of Object.entries(CSS_VAR_MAP)) { | ||
| const value = theme[key as keyof ThemePayload]; | ||
| if (!value) continue; | ||
| for (const cssVar of cssVars) { | ||
| root.style.setProperty(cssVar, value); | ||
| } | ||
| } | ||
| if (theme.background) | ||
| document.body.style.setProperty('background-color', theme.background); | ||
| if (theme.foreground) | ||
| document.body.style.setProperty('color', theme.foreground); | ||
| }; | ||
|
|
||
| export const useVSCodeTheme = (): void => { | ||
| useEffect(() => { | ||
| if (!isVSCodeEnv()) return; | ||
| return onMessage(HOST_MESSAGE_TYPE.THEME, applyTheme); | ||
| }, []); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| APP_MESSAGE_TYPE, | ||
| HOST_MESSAGE_TYPE, | ||
| type ThemePayload, | ||
| } from '@lemoncode/quickmock-bridge-protocol'; | ||
|
|
||
| const readVar = (style: CSSStyleDeclaration, name: string): string => | ||
| style.getPropertyValue(name).trim(); | ||
|
|
||
| export const extractTheme = (): ThemePayload => { | ||
| const style = getComputedStyle(document.documentElement); | ||
| return { | ||
| background: readVar(style, '--vscode-editor-background'), | ||
| backgroundSecondary: readVar(style, '--vscode-sideBar-background'), | ||
| foreground: readVar(style, '--vscode-editor-foreground'), | ||
| }; | ||
| }; | ||
|
|
||
| const IFRAME_READY_TYPES: ReadonlySet<string> = new Set([ | ||
| APP_MESSAGE_TYPE.WEBVIEW_READY, | ||
| APP_MESSAGE_TYPE.READY, | ||
| ]); | ||
|
|
||
| export const setupThemeSync = ( | ||
| iframe: HTMLIFrameElement, | ||
| appOrigin: string | ||
| ): void => { | ||
| const sendTheme = (): void => { | ||
| iframe.contentWindow?.postMessage( | ||
| { type: HOST_MESSAGE_TYPE.THEME, payload: extractTheme() }, | ||
| appOrigin | ||
| ); | ||
| }; | ||
|
|
||
| const onIframeReady = (event: MessageEvent): void => { | ||
| if (event.origin !== appOrigin) return; | ||
| const type = (event.data as { type?: string } | undefined)?.type; | ||
| if (type && IFRAME_READY_TYPES.has(type)) sendTheme(); | ||
| }; | ||
| window.addEventListener('message', onIframeReady); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
let rafId = 0;
const sendThemeDebounced = () => {
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(sendTheme);
};
const observer = new MutationObserver(sendThemeDebounced); |
||
| let rafId = 0; | ||
| const sendThemeDebounced = (): void => { | ||
| cancelAnimationFrame(rafId); | ||
| rafId = requestAnimationFrame(sendTheme); | ||
| }; | ||
|
|
||
| const observer = new MutationObserver(sendThemeDebounced); | ||
| observer.observe(document.body, { | ||
| attributes: true, | ||
| attributeFilter: ['class', 'style'], | ||
| }); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El retorno de
setupThemeSync(función de cleanup que elimina el listener y desconecta elMutationObserver) se descarta. Para un webview cuyo ciclo de vida es el de la página es tolerable, pero es preferible guardar la referencia para hacer explícita la intención: