window.ts 21.1 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

8
import * as nls from 'vs/nls';
9
import URI from 'vs/base/common/uri';
10 11
import * as errors from 'vs/base/common/errors';
import * as types from 'vs/base/common/types';
J
Johannes Rieken 已提交
12
import { TPromise } from 'vs/base/common/winjs.base';
13 14 15
import * as arrays from 'vs/base/common/arrays';
import * as objects from 'vs/base/common/objects';
import * as DOM from 'vs/base/browser/dom';
16 17
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { IAction, Action } from 'vs/base/common/actions';
18
import { AutoSaveConfiguration, IFileService } from 'vs/platform/files/common/files';
19
import { toResource, IUntitledResourceInput, IEditor } from 'vs/workbench/common/editor';
20
import { IWorkbenchEditorService, IResourceInputType } from 'vs/workbench/services/editor/common/editorService';
J
Johannes Rieken 已提交
21
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
J
Johannes Rieken 已提交
22
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
23
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
24
import { IWindowsService, IWindowService, IWindowSettings, IPath, IOpenFileRequest, IWindowsConfiguration, IAddFoldersRequest, IRunActionInWindowRequest } from 'vs/platform/windows/common/windows';
25 26
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
B
Benjamin Pasero 已提交
27
import { ITitleService } from 'vs/workbench/services/title/common/titleService';
28
import { IWorkbenchThemeService, VS_HC_THEME, VS_DARK_THEME } from 'vs/workbench/services/themes/common/workbenchThemeService';
29 30 31
import * as browser from 'vs/base/browser/browser';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
32
import { Position, IResourceInput } from 'vs/platform/editor/common/editor';
33
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
A
Alex Dima 已提交
34
import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
35
import { Themable } from 'vs/workbench/common/theme';
36
import { ipcRenderer as ipc, webFrame } from 'electron';
37
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
38 39 40 41 42
import { IMenuService, MenuId, IMenu, MenuItemAction, ICommandAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
I
isidor 已提交
43
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
44
import { LifecyclePhase, ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
45
import { IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
46 47 48
import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { AccessibilitySupport, isRootUser, isWindows, isMacintosh } from 'vs/base/common/platform';
import product from 'vs/platform/node/product';
49
import { INotificationService } from 'vs/platform/notification/common/notification';
E
Erich Gamma 已提交
50

51 52 53 54 55 56 57 58 59 60 61
const TextInputActions: IAction[] = [
	new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
	new Action('redo', nls.localize('redo', "Redo"), null, true, () => document.execCommand('redo') && TPromise.as(true)),
	new Separator(),
	new Action('editor.action.clipboardCutAction', nls.localize('cut', "Cut"), null, true, () => document.execCommand('cut') && TPromise.as(true)),
	new Action('editor.action.clipboardCopyAction', nls.localize('copy', "Copy"), null, true, () => document.execCommand('copy') && TPromise.as(true)),
	new Action('editor.action.clipboardPasteAction', nls.localize('paste', "Paste"), null, true, () => document.execCommand('paste') && TPromise.as(true)),
	new Separator(),
	new Action('editor.action.selectAll', nls.localize('selectAll', "Select All"), null, true, () => document.execCommand('selectAll') && TPromise.as(true))
];

62
export class ElectronWindow extends Themable {
63

64
	private static readonly AUTO_SAVE_SETTING = 'files.autoSave';
65

66 67 68 69 70 71 72
	private touchBarUpdater: RunOnceScheduler;
	private touchBarMenu: IMenu;
	private touchBarDisposables: IDisposable[];
	private lastInstalledTouchedBar: ICommandAction[][];

	private previousConfiguredZoomLevel: number;

73 74 75
	private addFoldersScheduler: RunOnceScheduler;
	private pendingFoldersToAdd: IAddFoldersRequest[];

E
Erich Gamma 已提交
76 77 78
	constructor(
		shellContainer: HTMLElement,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
79
		@IEditorGroupService private editorGroupService: IEditorGroupService,
80
		@IWindowsService private windowsService: IWindowsService,
B
Benjamin Pasero 已提交
81
		@IWindowService private windowService: IWindowService,
82 83
		@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
		@ITitleService private titleService: ITitleService,
84
		@IWorkbenchThemeService protected themeService: IWorkbenchThemeService,
85
		@INotificationService private notificationService: INotificationService,
86 87 88 89 90
		@ICommandService private commandService: ICommandService,
		@IExtensionService private extensionService: IExtensionService,
		@IViewletService private viewletService: IViewletService,
		@IContextMenuService private contextMenuService: IContextMenuService,
		@IKeybindingService private keybindingService: IKeybindingService,
91
		@ITelemetryService private telemetryService: ITelemetryService,
92
		@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
93
		@IFileService private fileService: IFileService,
94
		@IMenuService private menuService: IMenuService,
95 96
		@ILifecycleService private lifecycleService: ILifecycleService,
		@IIntegrityService private integrityService: IIntegrityService
E
Erich Gamma 已提交
97
	) {
98 99
		super(themeService);

100 101 102 103 104
		this.touchBarDisposables = [];

		this.touchBarUpdater = new RunOnceScheduler(() => this.doSetupTouchbar(), 300);
		this.toUnbind.push(this.touchBarUpdater);

105 106 107 108
		this.pendingFoldersToAdd = [];
		this.addFoldersScheduler = new RunOnceScheduler(() => this.doAddFolders(), 100);
		this.toUnbind.push(this.addFoldersScheduler);

E
Erich Gamma 已提交
109
		this.registerListeners();
110
		this.create();
E
Erich Gamma 已提交
111 112 113 114
	}

	private registerListeners(): void {

115
		// React to editor input changes
116
		this.toUnbind.push(this.editorGroupService.onEditorsChanged(() => {
E
Erich Gamma 已提交
117

118 119
			// Represented File Name
			const file = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: 'file' });
120
			this.titleService.setRepresentedFilename(file ? file.fsPath : '');
121 122 123 124

			// Touch Bar
			this.updateTouchbarMenu();
		}));
E
Erich Gamma 已提交
125

126
		// prevent opening a real URL inside the shell
127 128 129 130
		[DOM.EventType.DRAG_OVER, DOM.EventType.DROP].forEach(event => {
			window.document.body.addEventListener(event, (e: DragEvent) => {
				DOM.EventHelper.stop(e);
			});
E
Erich Gamma 已提交
131 132
		});

133
		// Support runAction event
134
		ipc.on('vscode:runAction', (event: any, request: IRunActionInWindowRequest) => {
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
			const args: any[] = [];

			// If we run an action from the touchbar, we fill in the currently active resource
			// as payload because the touch bar items are context aware depending on the editor
			if (request.from === 'touchbar') {
				const activeEditor = this.editorService.getActiveEditor();
				if (activeEditor) {
					const resource = toResource(activeEditor.input, { supportSideBySide: true });
					if (resource) {
						args.push(resource);
					}
				}
			} else {
				args.push({ from: request.from }); // TODO@telemetry this is a bit weird to send this to every action?
			}

			this.commandService.executeCommand(request.id, ...args).done(_ => {
K
kieferrm 已提交
152
				/* __GDPR__
K
kieferrm 已提交
153 154 155 156 157
					"commandExecuted" : {
						"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
						"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
					}
				*/
158
				this.telemetryService.publicLog('commandExecuted', { id: request.id, from: request.from });
J
Johannes Rieken 已提交
159
			}, err => {
160
				this.notificationService.error(err);
J
Johannes Rieken 已提交
161
			});
162 163 164
		});

		// Support resolve keybindings event
165
		ipc.on('vscode:resolveKeybindings', (event: any, rawActionIds: string) => {
166 167 168 169 170 171 172 173
			let actionIds: string[] = [];
			try {
				actionIds = JSON.parse(rawActionIds);
			} catch (error) {
				// should not happen
			}

			// Resolve keys using the keybinding service and send back to browser process
174
			this.resolveKeybindings(actionIds).done(keybindings => {
175 176 177 178 179 180
				if (keybindings.length) {
					ipc.send('vscode:keybindingsResolved', JSON.stringify(keybindings));
				}
			}, () => errors.onUnexpectedError);
		});

181
		ipc.on('vscode:reportError', (event: any, error: string) => {
182 183 184 185 186 187 188 189
			if (error) {
				const errorParsed = JSON.parse(error);
				errorParsed.mainProcess = true;
				errors.onUnexpectedError(errorParsed);
			}
		});

		// Support openFiles event for existing and new files
190
		ipc.on('vscode:openFiles', (event: any, request: IOpenFileRequest) => this.onOpenFiles(request));
191

192
		// Support addFolders event if we have a workspace opened
193
		ipc.on('vscode:addFolders', (event: any, request: IAddFoldersRequest) => this.onAddFoldersRequest(request));
194

195
		// Message support
196
		ipc.on('vscode:showInfoMessage', (event: any, message: string) => {
197
			this.notificationService.info(message);
198 199 200
		});

		// Support toggling auto save
201
		ipc.on('vscode.toggleAutoSave', () => {
202 203 204 205
			this.toggleAutoSave();
		});

		// Fullscreen Events
206
		ipc.on('vscode:enterFullScreen', () => {
207
			this.lifecycleService.when(LifecyclePhase.Running).then(() => {
208 209 210 211
				browser.setFullscreen(true);
			});
		});

212
		ipc.on('vscode:leaveFullScreen', () => {
213
			this.lifecycleService.when(LifecyclePhase.Running).then(() => {
214 215 216 217 218
				browser.setFullscreen(false);
			});
		});

		// High Contrast Events
219
		ipc.on('vscode:enterHighContrast', () => {
220
			const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
221
			if (windowConfig && windowConfig.autoDetectHighContrast) {
222
				this.lifecycleService.when(LifecyclePhase.Running).then(() => {
M
Martin Aeschlimann 已提交
223
					this.themeService.setColorTheme(VS_HC_THEME, null);
224 225
				});
			}
226 227
		});

228
		ipc.on('vscode:leaveHighContrast', () => {
229
			const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
230
			if (windowConfig && windowConfig.autoDetectHighContrast) {
231
				this.lifecycleService.when(LifecyclePhase.Running).then(() => {
M
Martin Aeschlimann 已提交
232
					this.themeService.setColorTheme(VS_DARK_THEME, null);
233 234
				});
			}
235 236
		});

A
Alex Dima 已提交
237
		// keyboard layout changed event
238
		ipc.on('vscode:keyboardLayoutChanged', () => {
239
			KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged();
A
Alex Dima 已提交
240 241
		});

242
		// keyboard layout changed event
243
		ipc.on('vscode:accessibilitySupportChanged', (event: any, accessibilitySupportEnabled: boolean) => {
244
			browser.setAccessibilitySupport(accessibilitySupportEnabled ? AccessibilitySupport.Enabled : AccessibilitySupport.Disabled);
245 246
		});

S
Sandeep Somavarapu 已提交
247 248 249 250 251 252 253
		// Zoom level changes
		this.updateWindowZoomLevel();
		this.toUnbind.push(this.configurationService.onDidChangeConfiguration(e => {
			if (e.affectsConfiguration('window.zoomLevel')) {
				this.updateWindowZoomLevel();
			}
		}));
254

255 256 257
		// Context menu support in input/textarea
		window.document.addEventListener('contextmenu', e => this.onContextMenu(e));
	}
258

259 260 261 262 263 264
	private onContextMenu(e: PointerEvent): void {
		if (e.target instanceof HTMLElement) {
			const target = <HTMLElement>e.target;
			if (target.nodeName && (target.nodeName.toLowerCase() === 'input' || target.nodeName.toLowerCase() === 'textarea')) {
				e.preventDefault();
				e.stopPropagation();
265

266 267 268 269
				this.contextMenuService.showContextMenu({
					getAnchor: () => e,
					getActions: () => TPromise.as(TextInputActions)
				});
270
			}
271 272 273
		}
	}

S
Sandeep Somavarapu 已提交
274
	private updateWindowZoomLevel(): void {
275
		const windowConfig: IWindowsConfiguration = this.configurationService.getValue<IWindowsConfiguration>();
276 277 278 279

		let newZoomLevel = 0;
		if (windowConfig.window && typeof windowConfig.window.zoomLevel === 'number') {
			newZoomLevel = windowConfig.window.zoomLevel;
280

281 282 283
			// Leave early if the configured zoom level did not change (https://github.com/Microsoft/vscode/issues/1536)
			if (this.previousConfiguredZoomLevel === newZoomLevel) {
				return;
284
			}
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

			this.previousConfiguredZoomLevel = newZoomLevel;
		}

		if (webFrame.getZoomLevel() !== newZoomLevel) {
			webFrame.setZoomLevel(newZoomLevel);
			browser.setZoomFactor(webFrame.getZoomFactor());
			// See https://github.com/Microsoft/vscode/issues/26151
			// Cannot be trusted because the webFrame might take some time
			// until it really applies the new zoom level
			browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/false);
		}
	}

	private create(): void {

		// Handle window.open() calls
		const $this = this;
		(<any>window).open = function (url: string, target: string, features: string, replace: boolean): any {
			$this.windowsService.openExternal(url);

			return null;
		};

		// Send over all extension viewlets when extensions are ready
310
		this.extensionService.whenInstalledExtensionsRegistered().then(() => {
S
Sandeep Somavarapu 已提交
311
			ipc.send('vscode:extensionViewlets', JSON.stringify(this.viewletService.getViewlets().map(v => { return { id: v.id, label: v.name }; })));
312 313
		});

314
		// Emit event when vscode has loaded
315
		this.lifecycleService.when(LifecyclePhase.Running).then(() => {
316 317 318 319 320
			ipc.send('vscode:workbenchLoaded', this.windowService.getCurrentWindowId());
		});

		// Touchbar Support
		this.updateTouchbarMenu();
321 322 323 324 325 326 327 328 329 330

		// Integrity warning
		this.integrityService.isPure().then(res => this.titleService.updateProperties({ isPure: res.isPure }));

		// Root warning
		this.lifecycleService.when(LifecyclePhase.Running).then(() => {
			let isAdminPromise: Promise<boolean>;
			if (isWindows) {
				isAdminPromise = import('native-is-elevated').then(isElevated => isElevated());
			} else {
A
Alex Dima 已提交
331
				isAdminPromise = Promise.resolve(isRootUser());
332 333 334 335 336 337 338
			}

			return isAdminPromise.then(isAdmin => {

				// Update title
				this.titleService.updateProperties({ isAdmin });

339 340
				// Show warning message (unix only)
				if (isAdmin && !isWindows) {
341
					this.notificationService.warn(nls.localize('runningAsRoot', "It is not recommended to run {0} as root user.", product.nameShort));
342 343 344
				}
			});
		});
345 346 347
	}

	private updateTouchbarMenu(): void {
348
		if (!isMacintosh) {
349 350 351
			return; // macOS only
		}

352
		const touchbarEnabled = this.configurationService.getValue<boolean>('keyboard.touchbar.enabled');
B
Benjamin Pasero 已提交
353 354
		if (!touchbarEnabled) {
			return; // disabled via setting
355 356
		}

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
		// Dispose old
		this.touchBarDisposables = dispose(this.touchBarDisposables);

		// Create new
		this.touchBarMenu = this.editorGroupService.invokeWithinEditorContext(accessor => this.menuService.createMenu(MenuId.TouchBarContext, accessor.get(IContextKeyService)));
		this.touchBarDisposables.push(this.touchBarMenu);
		this.touchBarDisposables.push(this.touchBarMenu.onDidChange(() => {
			this.scheduleSetupTouchbar();
		}));

		this.scheduleSetupTouchbar();
	}

	private scheduleSetupTouchbar(): void {
		this.touchBarUpdater.schedule();
	}

	private doSetupTouchbar(): void {
		const actions: (MenuItemAction | Separator)[] = [];

		// Fill actions into groups respecting order
I
isidor 已提交
378
		fillInActions(this.touchBarMenu, void 0, actions, this.contextMenuService);
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394

		// Convert into command action multi array
		const items: ICommandAction[][] = [];
		let group: ICommandAction[] = [];
		for (let i = 0; i < actions.length; i++) {
			const action = actions[i];

			// Command
			if (action instanceof MenuItemAction) {
				group.push(action.item);
			}

			// Separator
			else if (action instanceof Separator) {
				if (group.length) {
					items.push(group);
395
				}
396 397

				group = [];
398
			}
399 400 401 402 403 404 405 406 407 408 409
		}

		if (group.length) {
			items.push(group);
		}

		// Only update if the actions have changed
		if (!objects.equals(this.lastInstalledTouchedBar, items)) {
			this.lastInstalledTouchedBar = items;
			this.windowService.updateTouchBar(items);
		}
410 411
	}

412
	private resolveKeybindings(actionIds: string[]): TPromise<{ id: string; label: string, isNative: boolean; }[]> {
413
		return TPromise.join([this.lifecycleService.when(LifecyclePhase.Running), this.extensionService.whenInstalledExtensionsRegistered()]).then(() => {
414
			return arrays.coalesce(actionIds.map(id => {
415
				const binding = this.keybindingService.lookupKeybinding(id);
416 417 418
				if (!binding) {
					return null;
				}
419

420 421 422 423 424
				// first try to resolve a native accelerator
				const electronAccelerator = binding.getElectronAccelerator();
				if (electronAccelerator) {
					return { id, label: electronAccelerator, isNative: true };
				}
425

426 427 428 429
				// we need this fallback to support keybindings that cannot show in electron menus (e.g. chords)
				const acceleratorLabel = binding.getLabel();
				if (acceleratorLabel) {
					return { id, label: acceleratorLabel, isNative: false };
430 431 432 433 434 435 436
				}

				return null;
			}));
		});
	}

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
	private onAddFoldersRequest(request: IAddFoldersRequest): void {

		// Buffer all pending requests
		this.pendingFoldersToAdd.push(request);

		// Delay the adding of folders a bit to buffer in case more requests are coming
		if (!this.addFoldersScheduler.isScheduled()) {
			this.addFoldersScheduler.schedule();
		}
	}

	private doAddFolders(): void {
		const foldersToAdd: IWorkspaceFolderCreationData[] = [];

		this.pendingFoldersToAdd.forEach(request => {
			foldersToAdd.push(...request.foldersToAdd.map(folderToAdd => ({ uri: URI.file(folderToAdd.filePath) })));
		});

		this.pendingFoldersToAdd = [];
456

457
		this.workspaceEditingService.addFolders(foldersToAdd).done(null, errors.onUnexpectedError);
458 459
	}

460
	private onOpenFiles(request: IOpenFileRequest): void {
461 462
		const inputs: IResourceInputType[] = [];
		const diffMode = (request.filesToDiff.length === 2);
463 464 465 466 467 468 469 470 471 472 473 474 475 476

		if (!diffMode && request.filesToOpen) {
			inputs.push(...this.toInputs(request.filesToOpen, false));
		}

		if (!diffMode && request.filesToCreate) {
			inputs.push(...this.toInputs(request.filesToCreate, true));
		}

		if (diffMode) {
			inputs.push(...this.toInputs(request.filesToDiff, false));
		}

		if (inputs.length) {
477
			this.openResources(inputs, diffMode).then(null, errors.onUnexpectedError);
478
		}
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493

		if (request.filesToWait && inputs.length) {
			// In wait mode, listen to changes to the editors and wait until the files
			// are closed that the user wants to wait for. When this happens we delete
			// the wait marker file to signal to the outside that editing is done.
			const resourcesToWaitFor = request.filesToWait.paths.map(p => URI.file(p.filePath));
			const waitMarkerFile = URI.file(request.filesToWait.waitMarkerFilePath);
			const stacks = this.editorGroupService.getStacksModel();
			const unbind = stacks.onEditorClosed(() => {
				if (resourcesToWaitFor.every(r => !stacks.isOpen(r))) {
					unbind.dispose();
					this.fileService.del(waitMarkerFile).done(null, errors.onUnexpectedError);
				}
			});
		}
494 495
	}

496 497
	private openResources(resources: (IResourceInput | IUntitledResourceInput)[], diffMode: boolean): Thenable<IEditor | IEditor[]> {
		return this.lifecycleService.when(LifecyclePhase.Running).then((): TPromise<IEditor | IEditor[]> => {
N
Nick Snyder 已提交
498

499
			// In diffMode we open 2 resources as diff
500
			if (diffMode && resources.length === 2) {
501
				return this.editorService.openEditor({ leftResource: resources[0].resource, rightResource: resources[1].resource, options: { pinned: true } });
502 503 504 505 506 507 508 509 510 511 512 513
			}

			// For one file, just put it into the current active editor
			if (resources.length === 1) {
				return this.editorService.openEditor(resources[0]);
			}

			// Otherwise open all
			const activeEditor = this.editorService.getActiveEditor();
			return this.editorService.openEditors(resources.map((r, index) => {
				return {
					input: r,
514
					position: activeEditor ? activeEditor.group : Position.ONE
515 516 517 518 519
				};
			}));
		});
	}

520
	private toInputs(paths: IPath[], isNew: boolean): IResourceInputType[] {
521
		return paths.map(p => {
522 523 524 525 526 527 528
			const resource = URI.file(p.filePath);
			let input: IResourceInput | IUntitledResourceInput;
			if (isNew) {
				input = { filePath: resource.fsPath, options: { pinned: true } } as IUntitledResourceInput;
			} else {
				input = { resource, options: { pinned: true } } as IResourceInput;
			}
529 530 531 532 533 534 535 536 537 538 539 540 541

			if (!isNew && p.lineNumber) {
				input.options.selection = {
					startLineNumber: p.lineNumber,
					startColumn: p.columnNumber
				};
			}

			return input;
		});
	}

	private toggleAutoSave(): void {
542
		const setting = this.configurationService.inspect(ElectronWindow.AUTO_SAVE_SETTING);
543 544 545 546 547 548 549 550 551 552 553 554
		let userAutoSaveConfig = setting.user;
		if (types.isUndefinedOrNull(userAutoSaveConfig)) {
			userAutoSaveConfig = setting.default; // use default if setting not defined
		}

		let newAutoSaveValue: string;
		if ([AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE].some(s => s === userAutoSaveConfig)) {
			newAutoSaveValue = AutoSaveConfiguration.OFF;
		} else {
			newAutoSaveValue = AutoSaveConfiguration.AFTER_DELAY;
		}

555
		this.configurationService.updateValue(ElectronWindow.AUTO_SAVE_SETTING, newAutoSaveValue, ConfigurationTarget.USER);
556
	}
557 558 559 560 561 562

	public dispose(): void {
		this.touchBarDisposables = dispose(this.touchBarDisposables);

		super.dispose();
	}
J
Johannes Rieken 已提交
563
}