1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, dispose, Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContributionsRegistry, IWorkbenchContribution, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWindowsConfiguration, IWindowSettings } from 'vs/platform/window/common/window';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { localize } from 'vs/nls';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { RunOnceScheduler } from 'vs/base/common/async';
import { URI } from 'vs/base/common/uri';
import { isEqual } from 'vs/base/common/resources';
import { isMacintosh, isNative, isLinux, isWindows } from 'vs/base/common/platform';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IProductService } from 'vs/platform/product/common/productService';
interface IConfiguration extends IWindowsConfiguration {
update?: { mode?: string };
debug?: { console?: { wordWrap?: boolean } };
editor?: { accessibilitySupport?: 'on' | 'off' | 'auto' };
security?: { workspace?: { trust?: { enabled?: boolean } } };
window: IWindowSettings & { experimental?: { windowControlsOverlay?: { enabled?: boolean }; useSandbox?: boolean } };
workbench?: { experimental?: { settingsProfiles?: { enabled?: boolean } } };
}
export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution {
private titleBarStyle: 'native' | 'custom' | undefined;
private windowControlsOverlayEnabled: boolean | undefined;
private windowSandboxEnabled: boolean | undefined;
private nativeTabs: boolean | undefined;
private nativeFullScreen: boolean | undefined;
private clickThroughInactive: boolean | undefined;
private updateMode: string | undefined;
private accessibilitySupport: 'on' | 'off' | 'auto' | undefined;
private workspaceTrustEnabled: boolean | undefined;
private settingsProfilesEnabled: boolean | undefined;
constructor(
@IHostService private readonly hostService: IHostService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IProductService private readonly productService: IProductService,
@IDialogService private readonly dialogService: IDialogService
) {
super();
this.onConfigurationChange(configurationService.getValue<IConfiguration>(), false);
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChange(this.configurationService.getValue<IConfiguration>(), true)));
}
private onConfigurationChange(config: IConfiguration, notify: boolean): void {
let changed = false;
if (isNative) {
// Titlebar style
if (typeof config.window?.titleBarStyle === 'string' && config.window?.titleBarStyle !== this.titleBarStyle && (config.window.titleBarStyle === 'native' || config.window.titleBarStyle === 'custom')) {
this.titleBarStyle = config.window.titleBarStyle;
changed = true;
}
// Windows: Window Controls Overlay
if (isWindows && typeof config.window?.experimental?.windowControlsOverlay?.enabled === 'boolean' && config.window.experimental.windowControlsOverlay.enabled !== this.windowControlsOverlayEnabled) {
this.windowControlsOverlayEnabled = config.window.experimental.windowControlsOverlay.enabled;
changed = true;
}
// Windows: Sandbox
if (typeof config.window?.experimental?.useSandbox === 'boolean' && config.window.experimental.useSandbox !== this.windowSandboxEnabled) {
this.windowSandboxEnabled = config.window.experimental.useSandbox;
changed = true;
}
// macOS: Native tabs
if (isMacintosh && typeof config.window?.nativeTabs === 'boolean' && config.window.nativeTabs !== this.nativeTabs) {
this.nativeTabs = config.window.nativeTabs;
changed = true;
}
// macOS: Native fullscreen
if (isMacintosh && typeof config.window?.nativeFullScreen === 'boolean' && config.window.nativeFullScreen !== this.nativeFullScreen) {
this.nativeFullScreen = config.window.nativeFullScreen;
changed = true;
}
// macOS: Click through (accept first mouse)
if (isMacintosh && typeof config.window?.clickThroughInactive === 'boolean' && config.window.clickThroughInactive !== this.clickThroughInactive) {
this.clickThroughInactive = config.window.clickThroughInactive;
changed = true;
}
// Update channel
if (typeof config.update?.mode === 'string' && config.update.mode !== this.updateMode) {
this.updateMode = config.update.mode;
changed = true;
}
// Profiles
if (typeof config.workbench?.experimental?.settingsProfiles?.enabled === 'boolean' && config.workbench.experimental.settingsProfiles.enabled !== this.settingsProfilesEnabled) {
this.settingsProfilesEnabled = config.workbench.experimental.settingsProfiles.enabled;
changed = true;
}
// On linux turning on accessibility support will also pass this flag to the chrome renderer, thus a restart is required
if (isLinux && typeof config.editor?.accessibilitySupport === 'string' && config.editor.accessibilitySupport !== this.accessibilitySupport) {
this.accessibilitySupport = config.editor.accessibilitySupport;
if (this.accessibilitySupport === 'on') {
changed = true;
}
}
// Workspace trust
if (typeof config?.security?.workspace?.trust?.enabled === 'boolean' && config.security?.workspace.trust.enabled !== this.workspaceTrustEnabled) {
this.workspaceTrustEnabled = config.security.workspace.trust.enabled;
changed = true;
}
}
// Notify only when changed and we are the focused window (avoids notification spam across windows)
if (notify && changed) {
this.doConfirm(
isNative ?
localize('relaunchSettingMessage', "A setting has changed that requires a restart to take effect.") :
localize('relaunchSettingMessageWeb', "A setting has changed that requires a reload to take effect."),
isNative ?
localize('relaunchSettingDetail', "Press the restart button to restart {0} and enable the setting.", this.productService.nameLong) :
localize('relaunchSettingDetailWeb', "Press the reload button to reload {0} and enable the setting.", this.productService.nameLong),
isNative ?
localize('restart', "&&Restart") :
localize('restartWeb', "&&Reload"),
() => this.hostService.restart()
);
}
}
private async doConfirm(message: string, detail: string, primaryButton: string, confirmed: () => void): Promise<void> {
if (this.hostService.hasFocus) {
const res = await this.dialogService.confirm({ type: 'info', message, detail, primaryButton });
if (res.confirmed) {
confirmed();
}
}
}
}
export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWorkbenchContribution {
private firstFolderResource?: URI;
private extensionHostRestarter: RunOnceScheduler;
private onDidChangeWorkspaceFoldersUnbind: IDisposable | undefined;
constructor(
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IExtensionService extensionService: IExtensionService,
@IHostService hostService: IHostService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService
) {
super();
this.extensionHostRestarter = this._register(new RunOnceScheduler(() => {
if (!!environmentService.extensionTestsLocationURI) {
return; // no restart when in tests: see https://github.com/microsoft/vscode/issues/66936
}
if (environmentService.remoteAuthority) {
hostService.reload(); // TODO@aeschli, workaround
} else if (isNative) {
extensionService.restartExtensionHost();
}
}, 10));
this.contextService.getCompleteWorkspace()
.then(workspace => {
this.firstFolderResource = workspace.folders.length > 0 ? workspace.folders[0].uri : undefined;
this.handleWorkbenchState();
this._register(this.contextService.onDidChangeWorkbenchState(() => setTimeout(() => this.handleWorkbenchState())));
});
this._register(toDisposable(() => {
if (this.onDidChangeWorkspaceFoldersUnbind) {
this.onDidChangeWorkspaceFoldersUnbind.dispose();
}
}));
}
private handleWorkbenchState(): void {
// React to folder changes when we are in workspace state
if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) {
// Update our known first folder path if we entered workspace
const workspace = this.contextService.getWorkspace();
this.firstFolderResource = workspace.folders.length > 0 ? workspace.folders[0].uri : undefined;
// Install workspace folder listener
if (!this.onDidChangeWorkspaceFoldersUnbind) {
this.onDidChangeWorkspaceFoldersUnbind = this.contextService.onDidChangeWorkspaceFolders(() => this.onDidChangeWorkspaceFolders());
}
}
// Ignore the workspace folder changes in EMPTY or FOLDER state
else {
dispose(this.onDidChangeWorkspaceFoldersUnbind);
this.onDidChangeWorkspaceFoldersUnbind = undefined;
}
}
private onDidChangeWorkspaceFolders(): void {
const workspace = this.contextService.getWorkspace();
// Restart extension host if first root folder changed (impact on deprecated workspace.rootPath API)
const newFirstFolderResource = workspace.folders.length > 0 ? workspace.folders[0].uri : undefined;
if (!isEqual(this.firstFolderResource, newFirstFolderResource)) {
this.firstFolderResource = newFirstFolderResource;
this.extensionHostRestarter.schedule(); // buffer calls to extension host restart
}
}
}
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
workbenchRegistry.registerWorkbenchContribution(SettingsChangeRelauncher, LifecyclePhase.Restored);
workbenchRegistry.registerWorkbenchContribution(WorkspaceChangeExtHostRelauncher, LifecyclePhase.Restored);
|