@@ -33,18 +33,18 @@ interface IConfiguration extends IWindowsConfiguration {
33
33
34
34
export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution {
35
35
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' ) ;
43
43
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' ) ;
48
48
49
49
constructor (
50
50
@IHostService private readonly hostService : IHostService ,
@@ -61,49 +61,32 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
61
61
private onConfigurationChange ( config : IConfiguration , notify : boolean ) : void {
62
62
let changed = false ;
63
63
64
+ function processChanged ( didChange : boolean ) {
65
+ changed = changed || didChange ;
66
+ }
67
+
64
68
if ( isNative ) {
65
69
66
70
// 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 ) ) ;
71
72
72
73
// 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 ) ) ;
77
75
78
76
// 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 ) ) ;
83
78
84
79
// 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 ) ) ;
89
81
90
82
// 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 ) ) ;
95
84
96
85
// 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 ) ) ;
101
87
102
88
// 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 ) ) ;
107
90
108
91
// On linux turning on accessibility support will also pass this flag to the chrome renderer, thus a restart is required
109
92
if ( isLinux && typeof config . editor ?. accessibilitySupport === 'string' && config . editor . accessibilitySupport !== this . accessibilitySupport ) {
@@ -114,29 +97,17 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
114
97
}
115
98
116
99
// 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 ) ) ;
121
101
}
122
102
123
103
// 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 ) ) ;
128
105
129
106
// 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 ) ) ;
134
108
135
109
// 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 ) ) ;
140
111
141
112
// Notify only when changed and we are the focused window (avoids notification spam across windows)
142
113
if ( notify && changed ) {
@@ -165,6 +136,34 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
165
136
}
166
137
}
167
138
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
+
168
167
export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWorkbenchContribution {
169
168
170
169
private firstFolderResource ?: URI ;
0 commit comments