Skip to content

Commit 06a874d

Browse files
committed
1 parent 9059a3b commit 06a874d

File tree

1 file changed

+49
-65
lines changed

1 file changed

+49
-65
lines changed

src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ interface IConfiguration extends IWindowsConfiguration {
3333

3434
export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution {
3535

36-
private titleBarStyle: 'native' | 'custom' | undefined;
37-
private windowControlsOverlayEnabled: boolean | undefined;
38-
private windowSandboxEnabled: boolean | undefined;
39-
private nativeTabs: boolean | undefined;
40-
private nativeFullScreen: boolean | undefined;
41-
private clickThroughInactive: boolean | undefined;
42-
private updateMode: string | undefined;
36+
private readonly titleBarStyle = new ChangeObserver<'native' | 'custom'>('string');
37+
private readonly windowControlsOverlayEnabled = new ChangeObserver('boolean');
38+
private readonly windowSandboxEnabled = new ChangeObserver('boolean');
39+
private readonly nativeTabs = new ChangeObserver('boolean');
40+
private readonly nativeFullScreen = new ChangeObserver('boolean');
41+
private readonly clickThroughInactive = new ChangeObserver('boolean');
42+
private readonly updateMode = new ChangeObserver('string');
4343
private accessibilitySupport: 'on' | 'off' | 'auto' | undefined;
44-
private workspaceTrustEnabled: boolean | undefined;
45-
private settingsProfilesEnabled: boolean | undefined;
46-
private experimentsEnabled: boolean | undefined;
47-
private enablePPEExtensionsGallery: boolean | undefined;
44+
private readonly workspaceTrustEnabled = new ChangeObserver('boolean');
45+
private readonly settingsProfilesEnabled = new ChangeObserver('boolean');
46+
private readonly experimentsEnabled = new ChangeObserver('boolean');
47+
private readonly enablePPEExtensionsGallery = new ChangeObserver('boolean');
4848

4949
constructor(
5050
@IHostService private readonly hostService: IHostService,
@@ -62,48 +62,20 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
6262
let changed = false;
6363

6464
if (isNative) {
65-
6665
// Titlebar style
67-
if (typeof config.window?.titleBarStyle === 'string' && config.window?.titleBarStyle !== this.titleBarStyle && (config.window.titleBarStyle === 'native' || config.window.titleBarStyle === 'custom')) {
68-
this.titleBarStyle = config.window.titleBarStyle;
69-
changed = true;
70-
}
71-
66+
changed = changed || (config.window.titleBarStyle === 'native' || config.window.titleBarStyle === 'custom') && this.titleBarStyle.handleChange(config.window?.titleBarStyle);
7267
// Windows: Window Controls Overlay
73-
if (isWindows && typeof config.window?.experimental?.windowControlsOverlay?.enabled === 'boolean' && config.window.experimental.windowControlsOverlay.enabled !== this.windowControlsOverlayEnabled) {
74-
this.windowControlsOverlayEnabled = config.window.experimental.windowControlsOverlay.enabled;
75-
changed = true;
76-
}
77-
68+
changed = changed || isWindows && this.windowControlsOverlayEnabled.handleChange(config.window?.experimental?.windowControlsOverlay?.enabled);
7869
// Windows: Sandbox
79-
if (typeof config.window?.experimental?.useSandbox === 'boolean' && config.window.experimental.useSandbox !== this.windowSandboxEnabled) {
80-
this.windowSandboxEnabled = config.window.experimental.useSandbox;
81-
changed = true;
82-
}
83-
70+
changed = changed || this.windowSandboxEnabled.handleChange(config.window?.experimental?.useSandbox);
8471
// macOS: Native tabs
85-
if (isMacintosh && typeof config.window?.nativeTabs === 'boolean' && config.window.nativeTabs !== this.nativeTabs) {
86-
this.nativeTabs = config.window.nativeTabs;
87-
changed = true;
88-
}
89-
72+
changed = changed || isMacintosh && this.nativeTabs.handleChange(config.window?.nativeTabs);
9073
// macOS: Native fullscreen
91-
if (isMacintosh && typeof config.window?.nativeFullScreen === 'boolean' && config.window.nativeFullScreen !== this.nativeFullScreen) {
92-
this.nativeFullScreen = config.window.nativeFullScreen;
93-
changed = true;
94-
}
95-
74+
changed = changed || isMacintosh && this.nativeFullScreen.handleChange(config.window?.nativeFullScreen);
9675
// macOS: Click through (accept first mouse)
97-
if (isMacintosh && typeof config.window?.clickThroughInactive === 'boolean' && config.window.clickThroughInactive !== this.clickThroughInactive) {
98-
this.clickThroughInactive = config.window.clickThroughInactive;
99-
changed = true;
100-
}
101-
76+
changed = changed || isMacintosh && this.clickThroughInactive.handleChange(config.window?.clickThroughInactive);
10277
// Update channel
103-
if (typeof config.update?.mode === 'string' && config.update.mode !== this.updateMode) {
104-
this.updateMode = config.update.mode;
105-
changed = true;
106-
}
78+
changed = changed || this.updateMode.handleChange(config.update?.mode);
10779

10880
// On linux turning on accessibility support will also pass this flag to the chrome renderer, thus a restart is required
10981
if (isLinux && typeof config.editor?.accessibilitySupport === 'string' && config.editor.accessibilitySupport !== this.accessibilitySupport) {
@@ -114,29 +86,15 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
11486
}
11587

11688
// Workspace trust
117-
if (typeof config?.security?.workspace?.trust?.enabled === 'boolean' && config.security?.workspace.trust.enabled !== this.workspaceTrustEnabled) {
118-
this.workspaceTrustEnabled = config.security.workspace.trust.enabled;
119-
changed = true;
120-
}
121-
}
89+
changed = changed || this.workspaceTrustEnabled.handleChange(config?.security?.workspace?.trust?.enabled);
12290

123-
// Profiles
124-
if (this.productService.quality === 'stable' && typeof config.workbench?.experimental?.settingsProfiles?.enabled === 'boolean' && config.workbench.experimental.settingsProfiles.enabled !== this.settingsProfilesEnabled) {
125-
this.settingsProfilesEnabled = config.workbench.experimental.settingsProfiles.enabled;
126-
changed = true;
12791
}
128-
92+
// Profiles
93+
changed = changed || this.productService.quality === 'stable' && this.settingsProfilesEnabled.handleChange(config.workbench?.experimental?.settingsProfiles?.enabled);
12994
// Experiments
130-
if (typeof config.workbench?.enableExperiments === 'boolean' && config.workbench.enableExperiments !== this.experimentsEnabled) {
131-
this.experimentsEnabled = config.workbench.enableExperiments;
132-
changed = true;
133-
}
134-
95+
changed = changed || this.experimentsEnabled.handleChange(config.workbench?.enableExperiments);
13596
// Profiles
136-
if (this.productService.quality !== 'stable' && typeof config._extensionsGallery?.enablePPE === 'boolean' && config._extensionsGallery?.enablePPE !== this.enablePPEExtensionsGallery) {
137-
this.enablePPEExtensionsGallery = config._extensionsGallery?.enablePPE;
138-
changed = true;
139-
}
97+
changed = changed || this.productService.quality !== 'stable' && this.enablePPEExtensionsGallery.handleChange(config._extensionsGallery?.enablePPE);
14098

14199
// Notify only when changed and we are the focused window (avoids notification spam across windows)
142100
if (notify && changed) {
@@ -165,6 +123,32 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
165123
}
166124
}
167125

126+
interface TypeNameToType {
127+
boolean: boolean;
128+
string: string;
129+
}
130+
131+
class ChangeObserver<T> {
132+
public static create<TTypeName extends 'boolean' | 'string'>(typeName: TTypeName): ChangeObserver<TypeNameToType[TTypeName]> {
133+
return new ChangeObserver(typeName);
134+
}
135+
136+
constructor(private readonly typeName: string) { }
137+
138+
private lastValue: T | undefined = undefined;
139+
140+
/**
141+
* Returns if there was a change compared to the last value
142+
*/
143+
handleChange(value: T | undefined): boolean {
144+
if (typeof value === this.typeName && value !== this.lastValue) {
145+
this.lastValue = value;
146+
return true;
147+
}
148+
return false;
149+
}
150+
}
151+
168152
export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWorkbenchContribution {
169153

170154
private firstFolderResource?: URI;

0 commit comments

Comments
 (0)