Skip to content

Commit 1784a7e

Browse files
authored
Merge pull request microsoft#165049 from microsoft/hediet/narrow-llama
Fixes microsoft#156454 (ChangeObserver relauncher contrib refactoring)
2 parents 54543cf + 12c107c commit 1784a7e

File tree

1 file changed

+54
-55
lines changed

1 file changed

+54
-55
lines changed

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

Lines changed: 54 additions & 55 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,
@@ -61,49 +61,32 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
6161
private onConfigurationChange(config: IConfiguration, notify: boolean): void {
6262
let changed = false;
6363

64+
function processChanged(didChange: boolean) {
65+
changed = changed || didChange;
66+
}
67+
6468
if (isNative) {
6569

6670
// 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+
processChanged((config.window.titleBarStyle === 'native' || config.window.titleBarStyle === 'custom') && this.titleBarStyle.handleChange(config.window?.titleBarStyle));
7172

7273
// 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-
}
74+
processChanged(isWindows && this.windowControlsOverlayEnabled.handleChange(config.window?.experimental?.windowControlsOverlay?.enabled));
7775

7876
// 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-
}
77+
processChanged(this.windowSandboxEnabled.handleChange(config.window?.experimental?.useSandbox));
8378

8479
// 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-
}
80+
processChanged(isMacintosh && this.nativeTabs.handleChange(config.window?.nativeTabs));
8981

9082
// 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-
}
83+
processChanged(isMacintosh && this.nativeFullScreen.handleChange(config.window?.nativeFullScreen));
9584

9685
// 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-
}
86+
processChanged(isMacintosh && this.clickThroughInactive.handleChange(config.window?.clickThroughInactive));
10187

10288
// Update channel
103-
if (typeof config.update?.mode === 'string' && config.update.mode !== this.updateMode) {
104-
this.updateMode = config.update.mode;
105-
changed = true;
106-
}
89+
processChanged(this.updateMode.handleChange(config.update?.mode));
10790

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

11699
// 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-
}
100+
processChanged(this.workspaceTrustEnabled.handleChange(config?.security?.workspace?.trust?.enabled));
121101
}
122102

123103
// 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;
127-
}
104+
processChanged(this.productService.quality === 'stable' && this.settingsProfilesEnabled.handleChange(config.workbench?.experimental?.settingsProfiles?.enabled));
128105

129106
// Experiments
130-
if (typeof config.workbench?.enableExperiments === 'boolean' && config.workbench.enableExperiments !== this.experimentsEnabled) {
131-
this.experimentsEnabled = config.workbench.enableExperiments;
132-
changed = true;
133-
}
107+
processChanged(this.experimentsEnabled.handleChange(config.workbench?.enableExperiments));
134108

135109
// 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-
}
110+
processChanged(this.productService.quality !== 'stable' && this.enablePPEExtensionsGallery.handleChange(config._extensionsGallery?.enablePPE));
140111

141112
// Notify only when changed and we are the focused window (avoids notification spam across windows)
142113
if (notify && changed) {
@@ -165,6 +136,34 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
165136
}
166137
}
167138

139+
interface TypeNameToType {
140+
readonly boolean: boolean;
141+
readonly string: string;
142+
}
143+
144+
class ChangeObserver<T> {
145+
146+
static create<TTypeName extends 'boolean' | 'string'>(typeName: TTypeName): ChangeObserver<TypeNameToType[TTypeName]> {
147+
return new ChangeObserver(typeName);
148+
}
149+
150+
constructor(private readonly typeName: string) { }
151+
152+
private lastValue: T | undefined = undefined;
153+
154+
/**
155+
* Returns if there was a change compared to the last value
156+
*/
157+
handleChange(value: T | undefined): boolean {
158+
if (typeof value === this.typeName && value !== this.lastValue) {
159+
this.lastValue = value;
160+
return true;
161+
}
162+
163+
return false;
164+
}
165+
}
166+
168167
export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWorkbenchContribution {
169168

170169
private firstFolderResource?: URI;

0 commit comments

Comments
 (0)