@@ -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 ,
@@ -62,48 +62,20 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
62
62
let changed = false ;
63
63
64
64
if ( isNative ) {
65
-
66
65
// 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 ) ;
72
67
// 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 ) ;
78
69
// 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 ) ;
84
71
// 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 ) ;
90
73
// 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 ) ;
96
75
// 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 ) ;
102
77
// 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 ) ;
107
79
108
80
// On linux turning on accessibility support will also pass this flag to the chrome renderer, thus a restart is required
109
81
if ( isLinux && typeof config . editor ?. accessibilitySupport === 'string' && config . editor . accessibilitySupport !== this . accessibilitySupport ) {
@@ -114,29 +86,15 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
114
86
}
115
87
116
88
// 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 ) ;
122
90
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 ;
127
91
}
128
-
92
+ // Profiles
93
+ changed = changed || this . productService . quality === 'stable' && this . settingsProfilesEnabled . handleChange ( config . workbench ?. experimental ?. settingsProfiles ?. enabled ) ;
129
94
// 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 ) ;
135
96
// 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 ) ;
140
98
141
99
// Notify only when changed and we are the focused window (avoids notification spam across windows)
142
100
if ( notify && changed ) {
@@ -165,6 +123,32 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
165
123
}
166
124
}
167
125
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
+
168
152
export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWorkbenchContribution {
169
153
170
154
private firstFolderResource ?: URI ;
0 commit comments