From fa9c39ae35fb62b964a35f92d9b8ed978604a7fe Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 27 Sep 2019 07:43:17 +0200 Subject: [PATCH] Web: update PWA theme_color dynamically based on theme --- src/vs/base/browser/dom.ts | 6 ++++++ src/vs/workbench/browser/style.ts | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index d9d424f84e4..ad076013e03 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -781,6 +781,12 @@ export function createStyleSheet(container: HTMLElement = document.getElementsBy return style; } +export function createMetaElement(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLMetaElement { + let meta = document.createElement('meta'); + container.appendChild(meta); + return meta; +} + let _sharedStyleSheet: HTMLStyleElement | null = null; function getSharedStyleSheet(): HTMLStyleElement { if (!_sharedStyleSheet) { diff --git a/src/vs/workbench/browser/style.ts b/src/vs/workbench/browser/style.ts index deaaf4953ed..54164146cd0 100644 --- a/src/vs/workbench/browser/style.ts +++ b/src/vs/workbench/browser/style.ts @@ -7,7 +7,9 @@ import 'vs/css!./media/style'; import { registerThemingParticipant, ITheme, ICssStyleCollector, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService'; import { iconForeground, foreground, selectionBackground, focusBorder, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, listHighlightForeground, inputPlaceholderForeground } from 'vs/platform/theme/common/colorRegistry'; -import { WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme'; +import { WORKBENCH_BACKGROUND, TITLE_BAR_ACTIVE_BACKGROUND } from 'vs/workbench/common/theme'; +import { isWeb } from 'vs/base/common/platform'; +import { createMetaElement } from 'vs/base/browser/dom'; registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { @@ -143,4 +145,19 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { `); } + // Update based on selected theme + if (isWeb) { + const titleBackground = theme.getColor(TITLE_BAR_ACTIVE_BACKGROUND); + if (titleBackground) { + const metaElementId = 'monaco-workbench-meta-theme-color'; + let metaElement = document.getElementById(metaElementId) as HTMLMetaElement | null; + if (!metaElement) { + metaElement = createMetaElement(); + metaElement.name = 'theme-color'; + metaElement.id = metaElementId; + } + + metaElement.content = titleBackground.toString(); + } + } });