Introduce addMatchMediaChangeListener
with support for Safari 13.x
This commit is contained in:
parent
db5cb92a74
commit
2abf8d3779
3 changed files with 18 additions and 19 deletions
|
@ -1600,3 +1600,13 @@ export function getCookieValue(name: string): string | undefined {
|
|||
|
||||
return match ? match.pop() : undefined;
|
||||
}
|
||||
|
||||
export function addMatchMediaChangeListener(query: string, callback: () => void): void {
|
||||
const mediaQueryList = window.matchMedia(query);
|
||||
if (typeof mediaQueryList.addEventListener === 'function') {
|
||||
mediaQueryList.addEventListener('change', callback);
|
||||
} else {
|
||||
// Safari 13.x
|
||||
mediaQueryList.addListener(callback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,15 +233,9 @@ export class StandaloneThemeServiceImpl extends Disposable implements IStandalon
|
|||
this._updateCSS();
|
||||
});
|
||||
|
||||
const matchForcedColors = window.matchMedia('(forced-colors: active)');
|
||||
const matchForcedColorsListener = () => {
|
||||
dom.addMatchMediaChangeListener('(forced-colors: active)', () => {
|
||||
this._updateActualTheme();
|
||||
};
|
||||
if (typeof matchForcedColors.addEventListener === 'function') {
|
||||
matchForcedColors.addEventListener('change', matchForcedColorsListener);
|
||||
} else {
|
||||
matchForcedColors.addListener(matchForcedColorsListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public registerEditorContainer(domNode: HTMLElement): IDisposable {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
|
@ -25,18 +26,12 @@ export class BrowserHostColorSchemeService extends Disposable implements IHostCo
|
|||
|
||||
private registerListeners(): void {
|
||||
|
||||
const matchPrefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
const matchForcedColors = window.matchMedia('(forced-colors: active)');
|
||||
const listener = () => {
|
||||
dom.addMatchMediaChangeListener('(prefers-color-scheme: dark)', () => {
|
||||
this._onDidSchemeChangeEvent.fire();
|
||||
};
|
||||
if (typeof matchForcedColors.addEventListener === 'function') {
|
||||
matchPrefersColorSchemeDark.addEventListener('change', listener);
|
||||
matchForcedColors.addEventListener('change', listener);
|
||||
} else {
|
||||
matchPrefersColorSchemeDark.addListener(listener);
|
||||
matchForcedColors.addListener(listener);
|
||||
}
|
||||
});
|
||||
dom.addMatchMediaChangeListener('(forced-colors: active)', () => {
|
||||
this._onDidSchemeChangeEvent.fire();
|
||||
});
|
||||
}
|
||||
|
||||
get onDidChangeColorScheme(): Event<void> {
|
||||
|
|
Loading…
Reference in a new issue