Skip to content

Commit

Permalink
Align vscode: Set theme attributes to webview body element
Browse files Browse the repository at this point in the history
Signed-off-by: Esther Perelman <[email protected]>
  • Loading branch information
EstherPerelman committed Dec 14, 2021
1 parent 858bda8 commit cb7fb70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- [terminal] removed deprecated `activateTerminal` method in favor of `open`. [#10529](https://github.com/eclipse-theia/theia/pull/10529)
- [core] removed deprecated `activeChanged` signal emitter in favor of `onDidChangeActiveWidget` [#10515](https://github.com/eclipse-theia/theia/pull/10515)
- [core] removed deprecated `currentChanged` signal emitter in favor of `onDidChangeCurrentWidget` [#10515](https://github.com/eclipse-theia/theia/pull/10515)
- [plugin] changed return type of `WebviewThemeDataProvider.getActiveTheme()` to `Theme` instead of `WebviewThemeType` [#10493](https://github.com/eclipse-theia/theia/pull/10493)
- [plugin] renamed `WebviewThemeData.activeTheme` to `activeThemeType` [#10493](https://github.com/eclipse-theia/theia/pull/10493)

## v1.20.0 - 11/25/2021

Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-ext/src/main/browser/webview/pre/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@

if (body) {
body.classList.remove('vscode-light', 'vscode-dark', 'vscode-high-contrast');
body.classList.add(initData.activeTheme);
body.classList.add(initData.activeThemeType);
body.setAttribute('data-vscode-theme-kind', initData.activeThemeType);
body.setAttribute('data-vscode-theme-name', initData.activeThemeName);
}

if (initData.styles) {
Expand Down Expand Up @@ -409,7 +411,8 @@

host.onMessage('styles', (_event, data) => {
initData.styles = data.styles;
initData.activeTheme = data.activeTheme;
initData.activeThemeType = data.activeThemeType;
initData.activeThemeName = data.activeThemeName;

const target = getActiveFrame();
if (!target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import { inject, postConstruct, injectable } from '@theia/core/shared/inversify';
import { Emitter } from '@theia/core/lib/common/event';
import { EditorPreferences, EditorConfiguration } from '@theia/editor/lib/browser/editor-preferences';
import { ThemeService } from '@theia/core/lib/browser/theming';
import { Theme, ThemeService } from '@theia/core/lib/browser/theming';
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { ColorApplicationContribution } from '@theia/core/lib/browser/color-application-contribution';

export type WebviewThemeType = 'vscode-light' | 'vscode-dark' | 'vscode-high-contrast';
export interface WebviewThemeData {
readonly activeTheme: WebviewThemeType;
readonly activeThemeName: string;
readonly activeThemeType: WebviewThemeType;
readonly styles: { readonly [key: string]: string | number; };
}

Expand Down Expand Up @@ -104,11 +105,18 @@ export class WebviewThemeDataProvider {
}

const activeTheme = this.getActiveTheme();
return { styles, activeTheme };
return {
styles,
activeThemeName: activeTheme.label,
activeThemeType: this.getThemeType(activeTheme)
};
}

protected getActiveTheme(): Theme {
return ThemeService.get().getCurrentTheme();
}

protected getActiveTheme(): WebviewThemeType {
const theme = ThemeService.get().getCurrentTheme();
protected getThemeType(theme: Theme): WebviewThemeType {
switch (theme.type) {
case 'light': return 'vscode-light';
case 'dark': return 'vscode-dark';
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/main/browser/webview/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget {
}

protected style(): void {
const { styles, activeTheme } = this.themeDataProvider.getThemeData();
this.doSend('styles', { styles, activeTheme });
const { styles, activeThemeType, activeThemeName } = this.themeDataProvider.getThemeData();
this.doSend('styles', { styles, activeThemeType, activeThemeName });
}

protected openLink(link: URI): void {
Expand Down

0 comments on commit cb7fb70

Please sign in to comment.