Skip to content

Commit fa9c39a

Browse files
author
Benjamin Pasero
committed
Web: update PWA theme_color dynamically based on theme
1 parent e0762af commit fa9c39a

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/vs/base/browser/dom.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ export function createStyleSheet(container: HTMLElement = document.getElementsBy
781781
return style;
782782
}
783783

784+
export function createMetaElement(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLMetaElement {
785+
let meta = document.createElement('meta');
786+
container.appendChild(meta);
787+
return meta;
788+
}
789+
784790
let _sharedStyleSheet: HTMLStyleElement | null = null;
785791
function getSharedStyleSheet(): HTMLStyleElement {
786792
if (!_sharedStyleSheet) {

src/vs/workbench/browser/style.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import 'vs/css!./media/style';
77

88
import { registerThemingParticipant, ITheme, ICssStyleCollector, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService';
99
import { iconForeground, foreground, selectionBackground, focusBorder, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, listHighlightForeground, inputPlaceholderForeground } from 'vs/platform/theme/common/colorRegistry';
10-
import { WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme';
10+
import { WORKBENCH_BACKGROUND, TITLE_BAR_ACTIVE_BACKGROUND } from 'vs/workbench/common/theme';
11+
import { isWeb } from 'vs/base/common/platform';
12+
import { createMetaElement } from 'vs/base/browser/dom';
1113

1214
registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
1315

@@ -143,4 +145,19 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
143145
`);
144146
}
145147

148+
// Update <meta name="theme-color" content=""> based on selected theme
149+
if (isWeb) {
150+
const titleBackground = theme.getColor(TITLE_BAR_ACTIVE_BACKGROUND);
151+
if (titleBackground) {
152+
const metaElementId = 'monaco-workbench-meta-theme-color';
153+
let metaElement = document.getElementById(metaElementId) as HTMLMetaElement | null;
154+
if (!metaElement) {
155+
metaElement = createMetaElement();
156+
metaElement.name = 'theme-color';
157+
metaElement.id = metaElementId;
158+
}
159+
160+
metaElement.content = titleBackground.toString();
161+
}
162+
}
146163
});

0 commit comments

Comments
 (0)