-
Notifications
You must be signed in to change notification settings - Fork 736
Expand file tree
/
Copy paththemeWatcher.ts
More file actions
41 lines (35 loc) · 1.37 KB
/
themeWatcher.ts
File metadata and controls
41 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Disposable } from './common/lifecycle';
import { COLOR_THEME, WORKBENCH } from './common/settingKeys';
import { loadCurrentThemeData, ThemeData } from './view/theme';
export interface IThemeWatcher {
readonly onDidChangeTheme: vscode.Event<ThemeData | undefined>;
readonly themeData: ThemeData | undefined;
}
export class ThemeWatcher extends Disposable implements IThemeWatcher {
private _themeData: ThemeData | undefined;
private _onDidChangeTheme = this._register(new vscode.EventEmitter<ThemeData | undefined>());
readonly onDidChangeTheme = this._onDidChangeTheme.event;
constructor() {
super();
this._register(
vscode.workspace.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(`${WORKBENCH}.${COLOR_THEME}`)) {
await this.updateTheme();
}
}),
);
this.updateTheme();
}
private async updateTheme() {
this._themeData = await loadCurrentThemeData();
this._onDidChangeTheme.fire(this._themeData);
}
get themeData() {
return this._themeData;
}
}