windowsService.ts 18.5 KB
Newer Older
J
Joao Moreno 已提交
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';

J
Joao Moreno 已提交
8
import * as nls from 'vs/nls';
J
Joao Moreno 已提交
9
import { TPromise } from 'vs/base/common/winjs.base';
10 11
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { assign } from 'vs/base/common/objects';
J
jordanmkasla2009 已提交
12
import URI from 'vs/base/common/uri';
J
Joao Moreno 已提交
13
import product from 'vs/platform/node/product';
14
import { IWindowsService, OpenContext, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IDevToolsOptions } from 'vs/platform/windows/common/windows';
15
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
S
SteVen Batten 已提交
16
import { shell, crashReporter, app, Menu, clipboard, BrowserWindow } from 'electron';
17
import { Event, fromNodeEventEmitter, mapEvent, filterEvent, anyEvent } from 'vs/base/common/event';
J
Joao Moreno 已提交
18
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
19 20
import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain';
import { IWindowsMainService, ISharedProcess } from 'vs/platform/windows/electron-main/windows';
B
Benjamin Pasero 已提交
21
import { IHistoryMainService, IRecentlyOpened } from 'vs/platform/history/common/history';
22
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData } from 'vs/platform/workspaces/common/workspaces';
B
Benjamin Pasero 已提交
23
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
24
import { Schemas } from 'vs/base/common/network';
J
Joao Moreno 已提交
25
import { mnemonicButtonLabel } from 'vs/base/common/labels';
S
SteVen Batten 已提交
26
import { isWindows, isMacintosh } from 'vs/base/common/platform';
27
import { ILogService } from 'vs/platform/log/common/log';
28

J
Joao Moreno 已提交
29
export class WindowsService implements IWindowsService, IURLHandler, IDisposable {
J
Joao Moreno 已提交
30 31 32

	_serviceBrand: any;

33 34
	private disposables: IDisposable[] = [];

35 36 37 38 39 40 41
	readonly onWindowOpen: Event<number> = filterEvent(fromNodeEventEmitter(app, 'browser-window-created', (_, w: Electron.BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
	readonly onWindowFocus: Event<number> = anyEvent(
		mapEvent(filterEvent(mapEvent(this.windowsMainService.onWindowsCountChanged, () => this.windowsMainService.getLastActiveWindow()), w => !!w), w => w.id),
		filterEvent(fromNodeEventEmitter(app, 'browser-window-focus', (_, w: Electron.BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id))
	);

	readonly onWindowBlur: Event<number> = filterEvent(fromNodeEventEmitter(app, 'browser-window-blur', (_, w: Electron.BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
42 43
	readonly onWindowMaximize: Event<number> = filterEvent(fromNodeEventEmitter(app, 'browser-window-maximize', (_, w: Electron.BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
	readonly onWindowUnmaximize: Event<number> = filterEvent(fromNodeEventEmitter(app, 'browser-window-unmaximize', (_, w: Electron.BrowserWindow) => w.id), id => !!this.windowsMainService.getWindowById(id));
J
Joao Moreno 已提交
44

S
SteVen Batten 已提交
45 46
	readonly onRecentlyOpenedChange: Event<void> = this.historyService.onRecentlyOpenedChange;

J
Joao Moreno 已提交
47
	constructor(
48
		private sharedProcess: ISharedProcess,
49
		@IWindowsMainService private windowsMainService: IWindowsMainService,
50
		@IEnvironmentService private environmentService: IEnvironmentService,
51
		@IURLService urlService: IURLService,
52
		@ILifecycleService private lifecycleService: ILifecycleService,
J
Joao Moreno 已提交
53 54
		@IHistoryMainService private historyService: IHistoryMainService,
		@ILogService private logService: ILogService
55
	) {
J
Joao Moreno 已提交
56
		urlService.registerHandler(this);
57
	}
J
Joao Moreno 已提交
58

B
Benjamin Pasero 已提交
59
	pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
J
Joao Moreno 已提交
60
		this.logService.trace('windowsService#pickFileFolderAndOpen');
B
Benjamin Pasero 已提交
61 62
		this.windowsMainService.pickFileFolderAndOpen(options);

J
Joao Moreno 已提交
63 64 65
		return TPromise.as(null);
	}

B
Benjamin Pasero 已提交
66
	pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
J
Joao Moreno 已提交
67
		this.logService.trace('windowsService#pickFileAndOpen');
B
Benjamin Pasero 已提交
68 69
		this.windowsMainService.pickFileAndOpen(options);

J
Joao Moreno 已提交
70 71 72
		return TPromise.as(null);
	}

B
Benjamin Pasero 已提交
73
	pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
J
Joao Moreno 已提交
74
		this.logService.trace('windowsService#pickFolderAndOpen');
B
Benjamin Pasero 已提交
75
		this.windowsMainService.pickFolderAndOpen(options);
76

J
Joao Moreno 已提交
77 78
		return TPromise.as(null);
	}
79

80
	pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
J
Joao Moreno 已提交
81
		this.logService.trace('windowsService#pickWorkspaceAndOpen');
82 83 84 85 86
		this.windowsMainService.pickWorkspaceAndOpen(options);

		return TPromise.as(null);
	}

87
	showMessageBox(windowId: number, options: Electron.MessageBoxOptions): TPromise<IMessageBoxResult> {
J
Joao Moreno 已提交
88
		this.logService.trace('windowsService#showMessageBox', windowId);
89 90 91 92 93 94
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		return this.windowsMainService.showMessageBox(options, codeWindow);
	}

	showSaveDialog(windowId: number, options: Electron.SaveDialogOptions): TPromise<string> {
J
Joao Moreno 已提交
95
		this.logService.trace('windowsService#showSaveDialog', windowId);
96 97 98 99 100 101
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		return this.windowsMainService.showSaveDialog(options, codeWindow);
	}

	showOpenDialog(windowId: number, options: Electron.OpenDialogOptions): TPromise<string[]> {
J
Joao Moreno 已提交
102
		this.logService.trace('windowsService#showOpenDialog', windowId);
103 104 105 106 107
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		return this.windowsMainService.showOpenDialog(options, codeWindow);
	}

108
	reloadWindow(windowId: number, args: ParsedArgs): TPromise<void> {
J
Joao Moreno 已提交
109
		this.logService.trace('windowsService#reloadWindow', windowId);
B
Benjamin Pasero 已提交
110
		const codeWindow = this.windowsMainService.getWindowById(windowId);
111

B
Benjamin Pasero 已提交
112
		if (codeWindow) {
113
			this.windowsMainService.reload(codeWindow, args);
114 115 116 117
		}

		return TPromise.as(null);
	}
J
Joao Moreno 已提交
118

119
	openDevTools(windowId: number, options?: IDevToolsOptions): TPromise<void> {
J
Joao Moreno 已提交
120
		this.logService.trace('windowsService#openDevTools', windowId);
B
Benjamin Pasero 已提交
121
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
122

B
Benjamin Pasero 已提交
123
		if (codeWindow) {
124
			codeWindow.win.webContents.openDevTools(options);
J
Joao Moreno 已提交
125 126 127 128 129
		}

		return TPromise.as(null);
	}

J
Joao Moreno 已提交
130
	toggleDevTools(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
131
		this.logService.trace('windowsService#toggleDevTools', windowId);
B
Benjamin Pasero 已提交
132
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
133

B
Benjamin Pasero 已提交
134 135
		if (codeWindow) {
			const contents = codeWindow.win.webContents;
S
SteVen Batten 已提交
136
			if (isMacintosh && codeWindow.hasHiddenTitleBarStyle() && !codeWindow.win.isFullScreen() && !contents.isDevToolsOpened()) {
137 138 139 140
				contents.openDevTools({ mode: 'undocked' }); // due to https://github.com/electron/electron/issues/3647
			} else {
				contents.toggleDevTools();
			}
J
Joao Moreno 已提交
141 142 143 144
		}

		return TPromise.as(null);
	}
145

B
Benjamin Pasero 已提交
146
	updateTouchBar(windowId: number, items: ISerializableCommandAction[][]): TPromise<void> {
J
Joao Moreno 已提交
147
		this.logService.trace('windowsService#updateTouchBar', windowId);
148 149 150 151 152 153 154 155 156
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		if (codeWindow) {
			codeWindow.updateTouchBar(items);
		}

		return TPromise.as(null);
	}

157
	closeWorkspace(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
158
		this.logService.trace('windowsService#closeWorkspace', windowId);
B
Benjamin Pasero 已提交
159
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
160

B
Benjamin Pasero 已提交
161
		if (codeWindow) {
162
			this.windowsMainService.closeWorkspace(codeWindow);
163 164 165 166
		}

		return TPromise.as(null);
	}
J
Joao Moreno 已提交
167

168
	createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
J
Joao Moreno 已提交
169
		this.logService.trace('windowsService#createAndEnterWorkspace', windowId);
170 171 172
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		if (codeWindow) {
173
			return this.windowsMainService.createAndEnterWorkspace(codeWindow, folders, path);
174 175
		}

176 177 178
		return TPromise.as(null);
	}

179
	saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
J
Joao Moreno 已提交
180
		this.logService.trace('windowsService#saveAndEnterWorkspace', windowId);
181 182 183
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		if (codeWindow) {
184
			return this.windowsMainService.saveAndEnterWorkspace(codeWindow, path);
185 186
		}

187 188 189
		return TPromise.as(null);
	}

J
Joao Moreno 已提交
190
	toggleFullScreen(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
191
		this.logService.trace('windowsService#toggleFullScreen', windowId);
B
Benjamin Pasero 已提交
192
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
193

B
Benjamin Pasero 已提交
194 195
		if (codeWindow) {
			codeWindow.toggleFullScreen();
J
Joao Moreno 已提交
196 197 198 199 200
		}

		return TPromise.as(null);
	}

201
	setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
J
Joao Moreno 已提交
202
		this.logService.trace('windowsService#setRepresentedFilename', windowId);
B
Benjamin Pasero 已提交
203
		const codeWindow = this.windowsMainService.getWindowById(windowId);
204

B
Benjamin Pasero 已提交
205 206
		if (codeWindow) {
			codeWindow.setRepresentedFilename(fileName);
207 208 209 210 211
		}

		return TPromise.as(null);
	}

212
	addRecentlyOpened(files: string[]): TPromise<void> {
J
Joao Moreno 已提交
213
		this.logService.trace('windowsService#addRecentlyOpened');
214
		this.historyService.addRecentlyOpened(void 0, files);
215 216 217 218

		return TPromise.as(null);
	}

219
	removeFromRecentlyOpened(paths: string[]): TPromise<void> {
J
Joao Moreno 已提交
220
		this.logService.trace('windowsService#removeFromRecentlyOpened');
221
		this.historyService.removeFromRecentlyOpened(paths);
B
Benjamin Pasero 已提交
222 223 224 225

		return TPromise.as(null);
	}

B
Benjamin Pasero 已提交
226
	clearRecentlyOpened(): TPromise<void> {
J
Joao Moreno 已提交
227
		this.logService.trace('windowsService#clearRecentlyOpened');
B
Benjamin Pasero 已提交
228
		this.historyService.clearRecentlyOpened();
229

C
22768  
Cristian 已提交
230 231 232
		return TPromise.as(null);
	}

233
	getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened> {
J
Joao Moreno 已提交
234
		this.logService.trace('windowsService#getRecentlyOpened', windowId);
B
Benjamin Pasero 已提交
235
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
236

B
Benjamin Pasero 已提交
237
		if (codeWindow) {
B
Benjamin Pasero 已提交
238
			return TPromise.as(this.historyService.getRecentlyOpened(codeWindow.config.workspace || codeWindow.config.folderPath, codeWindow.config.filesToOpen));
J
Joao Moreno 已提交
239 240
		}

B
Benjamin Pasero 已提交
241
		return TPromise.as(this.historyService.getRecentlyOpened());
J
Joao Moreno 已提交
242 243
	}

244
	showPreviousWindowTab(): TPromise<void> {
J
Joao Moreno 已提交
245
		this.logService.trace('windowsService#showPreviousWindowTab');
246 247 248 249 250 251
		Menu.sendActionToFirstResponder('selectPreviousTab:');

		return TPromise.as(void 0);
	}

	showNextWindowTab(): TPromise<void> {
J
Joao Moreno 已提交
252
		this.logService.trace('windowsService#showNextWindowTab');
253 254 255 256 257 258
		Menu.sendActionToFirstResponder('selectNextTab:');

		return TPromise.as(void 0);
	}

	moveWindowTabToNewWindow(): TPromise<void> {
J
Joao Moreno 已提交
259
		this.logService.trace('windowsService#moveWindowTabToNewWindow');
260 261 262 263 264 265
		Menu.sendActionToFirstResponder('moveTabToNewWindow:');

		return TPromise.as(void 0);
	}

	mergeAllWindowTabs(): TPromise<void> {
J
Joao Moreno 已提交
266
		this.logService.trace('windowsService#mergeAllWindowTabs');
267 268 269 270 271 272
		Menu.sendActionToFirstResponder('mergeAllWindows:');

		return TPromise.as(void 0);
	}

	toggleWindowTabsBar(): TPromise<void> {
J
Joao Moreno 已提交
273
		this.logService.trace('windowsService#toggleWindowTabsBar');
274 275 276 277 278
		Menu.sendActionToFirstResponder('toggleTabBar:');

		return TPromise.as(void 0);
	}

J
Joao Moreno 已提交
279
	focusWindow(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
280
		this.logService.trace('windowsService#focusWindow', windowId);
B
Benjamin Pasero 已提交
281
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
282

B
Benjamin Pasero 已提交
283 284
		if (codeWindow) {
			codeWindow.win.focus();
J
Joao Moreno 已提交
285 286 287 288 289
		}

		return TPromise.as(null);
	}

290
	closeWindow(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
291
		this.logService.trace('windowsService#closeWindow', windowId);
292 293 294 295 296 297 298 299 300
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		if (codeWindow) {
			codeWindow.win.close();
		}

		return TPromise.as(null);
	}

301
	isFocused(windowId: number): TPromise<boolean> {
J
Joao Moreno 已提交
302
		this.logService.trace('windowsService#isFocused', windowId);
B
Benjamin Pasero 已提交
303
		const codeWindow = this.windowsMainService.getWindowById(windowId);
304

B
Benjamin Pasero 已提交
305 306
		if (codeWindow) {
			return TPromise.as(codeWindow.win.isFocused());
307 308 309 310 311
		}

		return TPromise.as(null);
	}

312
	isMaximized(windowId: number): TPromise<boolean> {
J
Joao Moreno 已提交
313
		this.logService.trace('windowsService#isMaximized', windowId);
B
Benjamin Pasero 已提交
314
		const codeWindow = this.windowsMainService.getWindowById(windowId);
315

B
Benjamin Pasero 已提交
316 317
		if (codeWindow) {
			return TPromise.as(codeWindow.win.isMaximized());
318 319 320 321 322 323
		}

		return TPromise.as(null);
	}

	maximizeWindow(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
324
		this.logService.trace('windowsService#maximizeWindow', windowId);
B
Benjamin Pasero 已提交
325
		const codeWindow = this.windowsMainService.getWindowById(windowId);
326

B
Benjamin Pasero 已提交
327 328
		if (codeWindow) {
			codeWindow.win.maximize();
329 330 331 332 333 334
		}

		return TPromise.as(null);
	}

	unmaximizeWindow(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
335
		this.logService.trace('windowsService#unmaximizeWindow', windowId);
B
Benjamin Pasero 已提交
336
		const codeWindow = this.windowsMainService.getWindowById(windowId);
337

B
Benjamin Pasero 已提交
338 339
		if (codeWindow) {
			codeWindow.win.unmaximize();
340 341 342 343 344
		}

		return TPromise.as(null);
	}

345
	minimizeWindow(windowId: number): TPromise<void> {
B
Benjamin Pasero 已提交
346
		this.logService.trace('windowsService#minimizeWindow', windowId);
347 348 349 350 351 352 353 354 355
		const codeWindow = this.windowsMainService.getWindowById(windowId);

		if (codeWindow) {
			codeWindow.win.minimize();
		}

		return TPromise.as(null);
	}

356
	onWindowTitleDoubleClick(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
357
		this.logService.trace('windowsService#onWindowTitleDoubleClick', windowId);
B
Benjamin Pasero 已提交
358
		const codeWindow = this.windowsMainService.getWindowById(windowId);
359

B
Benjamin Pasero 已提交
360 361
		if (codeWindow) {
			codeWindow.onWindowTitleDoubleClick();
362 363 364 365 366
		}

		return TPromise.as(null);
	}

J
Joao Moreno 已提交
367
	setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
J
Joao Moreno 已提交
368
		this.logService.trace('windowsService#setDocumentEdited', windowId);
B
Benjamin Pasero 已提交
369
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
370

B
Benjamin Pasero 已提交
371 372
		if (codeWindow && codeWindow.win.isDocumentEdited() !== flag) {
			codeWindow.win.setDocumentEdited(flag);
J
Joao Moreno 已提交
373 374 375 376 377
		}

		return TPromise.as(null);
	}

B
Benjamin Pasero 已提交
378
	openWindow(windowId: number, paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean }): TPromise<void> {
J
Joao Moreno 已提交
379
		this.logService.trace('windowsService#openWindow');
J
Joao Moreno 已提交
380 381
		if (!paths || !paths.length) {
			return TPromise.as(null);
J
Joao Moreno 已提交
382 383
		}

384 385
		this.windowsMainService.open({
			context: OpenContext.API,
B
Benjamin Pasero 已提交
386
			contextWindowId: windowId,
387 388 389 390 391 392 393
			cli: this.environmentService.args,
			pathsToOpen: paths,
			forceNewWindow: options && options.forceNewWindow,
			forceReuseWindow: options && options.forceReuseWindow,
			forceOpenWorkspaceAsFile: options && options.forceOpenWorkspaceAsFile
		});

J
Joao Moreno 已提交
394 395
		return TPromise.as(null);
	}
J
Joao Moreno 已提交
396 397

	openNewWindow(): TPromise<void> {
J
Joao Moreno 已提交
398
		this.logService.trace('windowsService#openNewWindow');
C
chrmarti 已提交
399
		this.windowsMainService.openNewWindow(OpenContext.API);
J
Joao Moreno 已提交
400 401
		return TPromise.as(null);
	}
J
Joao Moreno 已提交
402 403

	showWindow(windowId: number): TPromise<void> {
J
Joao Moreno 已提交
404
		this.logService.trace('windowsService#showWindow', windowId);
B
Benjamin Pasero 已提交
405
		const codeWindow = this.windowsMainService.getWindowById(windowId);
J
Joao Moreno 已提交
406

B
Benjamin Pasero 已提交
407 408
		if (codeWindow) {
			codeWindow.win.show();
J
Joao Moreno 已提交
409 410 411 412
		}

		return TPromise.as(null);
	}
J
Joao Moreno 已提交
413

414
	getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderPath?: string; title: string; filename?: string; }[]> {
J
Joao Moreno 已提交
415
		this.logService.trace('windowsService#getWindows');
J
Joao Moreno 已提交
416
		const windows = this.windowsMainService.getWindows();
417
		const result = windows.map(w => ({ id: w.id, workspace: w.openedWorkspace, openedFolderPath: w.openedFolderPath, title: w.win.getTitle(), filename: w.getRepresentedFilename() }));
418

J
Joao Moreno 已提交
419 420
		return TPromise.as(result);
	}
J
Joao Moreno 已提交
421

422
	getWindowCount(): TPromise<number> {
J
Joao Moreno 已提交
423
		this.logService.trace('windowsService#getWindowCount');
424 425 426
		return TPromise.as(this.windowsMainService.getWindows().length);
	}

J
Joao Moreno 已提交
427 428 429 430
	log(severity: string, ...messages: string[]): TPromise<void> {
		console[severity].apply(console, ...messages);
		return TPromise.as(null);
	}
431

J
Joao Moreno 已提交
432
	showItemInFolder(path: string): TPromise<void> {
J
Joao Moreno 已提交
433
		this.logService.trace('windowsService#showItemInFolder');
J
Joao Moreno 已提交
434 435 436
		shell.showItemInFolder(path);
		return TPromise.as(null);
	}
J
Joao Moreno 已提交
437

438
	openExternal(url: string): TPromise<boolean> {
J
Joao Moreno 已提交
439
		this.logService.trace('windowsService#openExternal');
440
		return TPromise.as(shell.openExternal(url));
J
Joao Moreno 已提交
441
	}
442 443

	startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise<void> {
J
Joao Moreno 已提交
444
		this.logService.trace('windowsService#startCrashReporter');
445 446 447
		crashReporter.start(config);
		return TPromise.as(null);
	}
448

449
	quit(): TPromise<void> {
J
Joao Moreno 已提交
450
		this.logService.trace('windowsService#quit');
451 452 453 454
		this.windowsMainService.quit();
		return TPromise.as(null);
	}

J
Johannes Rieken 已提交
455
	relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
J
Joao Moreno 已提交
456
		this.logService.trace('windowsService#relaunch');
457 458
		this.lifecycleService.relaunch(options);

J
Johannes Rieken 已提交
459 460 461
		return TPromise.as(null);
	}

462
	whenSharedProcessReady(): TPromise<void> {
J
Joao Moreno 已提交
463
		this.logService.trace('windowsService#whenSharedProcessReady');
464 465 466
		return this.sharedProcess.whenReady();
	}

467
	toggleSharedProcess(): TPromise<void> {
J
Joao Moreno 已提交
468
		this.logService.trace('windowsService#toggleSharedProcess');
469 470 471 472
		this.sharedProcess.toggle();
		return TPromise.as(null);
	}

S
SteVen Batten 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
	openAccessibilityOptions(): TPromise<void> {
		this.logService.trace('windowsService#openAccessibilityOptions');

		const win = new BrowserWindow({
			alwaysOnTop: true,
			skipTaskbar: true,
			resizable: false,
			width: 450,
			height: 300,
			show: true,
			title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options"),
			webPreferences: {
				disableBlinkFeatures: 'Auxclick'
			}
		});

		win.setMenuBarVisibility(false);

		win.loadURL('chrome://accessibility');

		return TPromise.as(null);
	}

J
Joao Moreno 已提交
496
	openAboutDialog(): TPromise<void> {
J
Joao Moreno 已提交
497
		this.logService.trace('windowsService#openAboutDialog');
J
Joao Moreno 已提交
498 499 500
		const lastActiveWindow = this.windowsMainService.getFocusedWindow() || this.windowsMainService.getLastActiveWindow();

		const detail = nls.localize('aboutDetail',
B
Benjamin Pasero 已提交
501
			"Version: {0}\nCommit: {1}\nDate: {2}\nElectron: {3}\nChrome: {4}\nNode.js: {5}\nV8: {6}\nArchitecture: {7}",
J
Joao Moreno 已提交
502 503 504 505 506 507
			app.getVersion(),
			product.commit || 'Unknown',
			product.date || 'Unknown',
			process.versions['electron'],
			process.versions['chrome'],
			process.versions['node'],
508
			process.versions['v8'],
J
Joao Moreno 已提交
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
			process.arch
		);

		const buttons = [nls.localize('okButton', "OK")];
		if (isWindows) {
			buttons.push(mnemonicButtonLabel(nls.localize({ key: 'copy', comment: ['&& denotes a mnemonic'] }, "&&Copy"))); // https://github.com/Microsoft/vscode/issues/37608
		}

		this.windowsMainService.showMessageBox({
			title: product.nameLong,
			type: 'info',
			message: product.nameLong,
			detail: `\n${detail}`,
			buttons,
			noLink: true
		}, lastActiveWindow).then(result => {
			if (isWindows && result.button === 1) {
				clipboard.writeText(detail);
			}
		});

		return TPromise.as(null);
	}

J
Joao Moreno 已提交
533
	handleURL(uri: URI): TPromise<boolean> {
J
Joao Moreno 已提交
534 535
		// Catch file URLs
		if (uri.authority === Schemas.file && !!uri.path) {
J
Joao Moreno 已提交
536 537
			this.openFileForURI(URI.file(uri.fsPath));
			return TPromise.as(true);
J
Joao Moreno 已提交
538 539
		}

540
		return TPromise.wrap(false);
J
Joao Moreno 已提交
541 542
	}

543
	private openFileForURI(uri: URI): TPromise<boolean> {
544
		const cli = assign(Object.create(null), this.environmentService.args, { goto: true });
545
		const pathsToOpen = [uri.fsPath];
546

C
chrmarti 已提交
547
		this.windowsMainService.open({ context: OpenContext.API, cli, pathsToOpen });
548
		return TPromise.wrap(true);
549 550
	}

551 552 553
	dispose(): void {
		this.disposables = dispose(this.disposables);
	}
554
}