Code improvements.
This commit is contained in:
@@ -1,55 +1,50 @@
|
||||
import { workspace } from "vscode";
|
||||
import { workspace, window, ColorThemeKind } from "vscode";
|
||||
import { Disposable } from "@hediet/std/disposable";
|
||||
import { observable } from "mobx";
|
||||
import { DataExtractorId } from "@hediet/debug-visualizer-data-extraction";
|
||||
|
||||
const useChromeKioskModeKey = "debugVisualizer.useChromeKioskMode";
|
||||
const debugAdapterConfigsKey = "debugVisualizer.debugAdapterConfigurations";
|
||||
import { VsCodeSetting, serializerWithDefault } from "./utils/VsCodeSettings";
|
||||
|
||||
export class Config {
|
||||
public dispose = Disposable.fn();
|
||||
|
||||
@observable
|
||||
private _useChromeKioskMode!: boolean;
|
||||
|
||||
@observable
|
||||
private _debugAdapterConfigs!: DebugAdapterConfigs;
|
||||
private readonly _useChromeKioskMode = new VsCodeSetting(
|
||||
"debugVisualizer.useChromeKioskMode",
|
||||
{ serializer: serializerWithDefault<boolean>(true) }
|
||||
);
|
||||
|
||||
public get useChromeKioskMode(): boolean {
|
||||
return this._useChromeKioskMode;
|
||||
return this._useChromeKioskMode.get();
|
||||
}
|
||||
|
||||
public get debugAdapterConfigs(): DebugAdapterConfigs {
|
||||
return this._debugAdapterConfigs;
|
||||
private readonly _debugAdapterConfigs = new VsCodeSetting(
|
||||
"debugVisualizer.debugAdapterConfigurations",
|
||||
{ serializer: serializerWithDefault<DebugAdapterConfigs>({}) }
|
||||
);
|
||||
|
||||
@observable
|
||||
private _vsCodeTheme = window.activeColorTheme;
|
||||
|
||||
public get theme(): "light" | "dark" {
|
||||
if (this._vsCodeTheme.kind === ColorThemeKind.Light) {
|
||||
return "light";
|
||||
} else if (this._vsCodeTheme.kind === ColorThemeKind.Dark) {
|
||||
return "dark";
|
||||
}
|
||||
return "light";
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.updateConfig();
|
||||
this.dispose.track(
|
||||
workspace.onDidChangeConfiguration(() => {
|
||||
this.updateConfig();
|
||||
window.onDidChangeActiveColorTheme(() => {
|
||||
this._vsCodeTheme = window.activeColorTheme;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private updateConfig(): void {
|
||||
const c = workspace.getConfiguration();
|
||||
|
||||
this._useChromeKioskMode = mapUndefined(
|
||||
c.get<boolean>(useChromeKioskModeKey),
|
||||
true
|
||||
);
|
||||
|
||||
this._debugAdapterConfigs = mapUndefined(
|
||||
c.get<DebugAdapterConfigs>(debugAdapterConfigsKey),
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
public getDebugAdapterConfig(
|
||||
debugAdapterType: string
|
||||
): DebugAdapterConfig | undefined {
|
||||
const c = this.debugAdapterConfigs[debugAdapterType];
|
||||
const c = this._debugAdapterConfigs.get()[debugAdapterType];
|
||||
if (!c) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -65,13 +60,6 @@ export class Config {
|
||||
}
|
||||
}
|
||||
|
||||
function mapUndefined<T>(val: T | undefined, defaultVal: T) {
|
||||
if (val === undefined) {
|
||||
return defaultVal;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
type DebugAdapterConfigs = {
|
||||
[debugAdapter: string]: {
|
||||
context?: "watch" | "repl";
|
||||
|
||||
Reference in New Issue
Block a user