windowsService.ts 17.7 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';
J
Joao Moreno 已提交
16
import { shell, crashReporter, app, Menu, clipboard } 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';
23
import { ICommandAction } from 'vs/platform/actions/common/actions';
24
import { Schemas } from 'vs/base/common/network';
J
Joao Moreno 已提交
25 26
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { isWindows } 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

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

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

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

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

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

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

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

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

		return TPromise.as(null);
	}

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

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

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

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

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

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

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

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

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

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}
143

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

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

		return TPromise.as(null);
	}

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

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

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

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

		return TPromise.as(null);
	}

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

		return TPromise.as(null);
	}

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

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

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

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

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

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

		return TPromise.as(void 0);
	}

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

		return TPromise.as(void 0);
	}

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

		return TPromise.as(void 0);
	}

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

		return TPromise.as(void 0);
	}

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

		return TPromise.as(void 0);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

		return TPromise.as(null);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

J
Joao Moreno 已提交
471
	openAboutDialog(): TPromise<void> {
J
Joao Moreno 已提交
472
		this.logService.trace('windowsService#openAboutDialog');
J
Joao Moreno 已提交
473 474 475
		const lastActiveWindow = this.windowsMainService.getFocusedWindow() || this.windowsMainService.getLastActiveWindow();

		const detail = nls.localize('aboutDetail',
B
Benjamin Pasero 已提交
476
			"Version: {0}\nCommit: {1}\nDate: {2}\nElectron: {3}\nChrome: {4}\nNode.js: {5}\nV8: {6}\nArchitecture: {7}",
J
Joao Moreno 已提交
477 478 479 480 481 482
			app.getVersion(),
			product.commit || 'Unknown',
			product.date || 'Unknown',
			process.versions['electron'],
			process.versions['chrome'],
			process.versions['node'],
483
			process.versions['v8'],
J
Joao Moreno 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
			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);
			}
		});
504 505 506 507

		return TPromise.as(null);
	}

J
Joao Moreno 已提交
508 509 510
	async handleURL(uri: URI): TPromise<boolean> {
		// Catch file URLs
		if (uri.authority === Schemas.file && !!uri.path) {
J
Joao Moreno 已提交
511
			return this.openFileForURI(URI.file(uri.fsPath));
J
Joao 已提交
512 513
		}

J
Joao Moreno 已提交
514 515 516
		return false;
	}

J
Joao Moreno 已提交
517
	private async openFileForURI(uri: URI): TPromise<boolean> {
518
		const cli = assign(Object.create(null), this.environmentService.args, { goto: true });
519
		const pathsToOpen = [uri.fsPath];
520

C
chrmarti 已提交
521
		this.windowsMainService.open({ context: OpenContext.API, cli, pathsToOpen });
J
Joao Moreno 已提交
522
		return true;
523 524
	}

525 526 527
	dispose(): void {
		this.disposables = dispose(this.disposables);
	}
528
}