1- import { workspace } from "vscode" ;
1+ import { workspace , window , ColorThemeKind } from "vscode" ;
22import { Disposable } from "@hediet/std/disposable" ;
33import { observable } from "mobx" ;
44import { DataExtractorId } from "@hediet/debug-visualizer-data-extraction" ;
5-
6- const useChromeKioskModeKey = "debugVisualizer.useChromeKioskMode" ;
7- const debugAdapterConfigsKey = "debugVisualizer.debugAdapterConfigurations" ;
5+ import { VsCodeSetting , serializerWithDefault } from "./utils/VsCodeSettings" ;
86
97export class Config {
108 public dispose = Disposable . fn ( ) ;
119
12- @observable
13- private _useChromeKioskMode ! : boolean ;
14-
15- @observable
16- private _debugAdapterConfigs ! : DebugAdapterConfigs ;
10+ private readonly _useChromeKioskMode = new VsCodeSetting (
11+ "debugVisualizer.useChromeKioskMode" ,
12+ { serializer : serializerWithDefault < boolean > ( true ) }
13+ ) ;
1714
1815 public get useChromeKioskMode ( ) : boolean {
19- return this . _useChromeKioskMode ;
16+ return this . _useChromeKioskMode . get ( ) ;
2017 }
2118
22- public get debugAdapterConfigs ( ) : DebugAdapterConfigs {
23- return this . _debugAdapterConfigs ;
19+ private readonly _debugAdapterConfigs = new VsCodeSetting (
20+ "debugVisualizer.debugAdapterConfigurations" ,
21+ { serializer : serializerWithDefault < DebugAdapterConfigs > ( { } ) }
22+ ) ;
23+
24+ @observable
25+ private _vsCodeTheme = window . activeColorTheme ;
26+
27+ public get theme ( ) : "light" | "dark" {
28+ if ( this . _vsCodeTheme . kind === ColorThemeKind . Light ) {
29+ return "light" ;
30+ } else if ( this . _vsCodeTheme . kind === ColorThemeKind . Dark ) {
31+ return "dark" ;
32+ }
33+ return "light" ;
2434 }
2535
2636 constructor ( ) {
27- this . updateConfig ( ) ;
2837 this . dispose . track (
29- workspace . onDidChangeConfiguration ( ( ) => {
30- this . updateConfig ( ) ;
38+ window . onDidChangeActiveColorTheme ( ( ) => {
39+ this . _vsCodeTheme = window . activeColorTheme ;
3140 } )
3241 ) ;
3342 }
3443
35- private updateConfig ( ) : void {
36- const c = workspace . getConfiguration ( ) ;
37-
38- this . _useChromeKioskMode = mapUndefined (
39- c . get < boolean > ( useChromeKioskModeKey ) ,
40- true
41- ) ;
42-
43- this . _debugAdapterConfigs = mapUndefined (
44- c . get < DebugAdapterConfigs > ( debugAdapterConfigsKey ) ,
45- { }
46- ) ;
47- }
48-
4944 public getDebugAdapterConfig (
5045 debugAdapterType : string
5146 ) : DebugAdapterConfig | undefined {
52- const c = this . debugAdapterConfigs [ debugAdapterType ] ;
47+ const c = this . _debugAdapterConfigs . get ( ) [ debugAdapterType ] ;
5348 if ( ! c ) {
5449 return undefined ;
5550 }
@@ -65,13 +60,6 @@ export class Config {
6560 }
6661}
6762
68- function mapUndefined < T > ( val : T | undefined , defaultVal : T ) {
69- if ( val === undefined ) {
70- return defaultVal ;
71- }
72- return val ;
73- }
74-
7563type DebugAdapterConfigs = {
7664 [ debugAdapter : string ] : {
7765 context ?: "watch" | "repl" ;
0 commit comments