Skip to content

Commit

Permalink
Use the async version of Electron's dialog API (#40211)
Browse files Browse the repository at this point in the history
* dialogs - move dialog handling to main side

* dialogs - adopt windows dialogs methods in main

* dialogs - use async dialog API and queue up dialogs on the main side
  • Loading branch information
bpasero authored Dec 14, 2017
1 parent a0ac2af commit 78cc1e9
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 197 deletions.
7 changes: 4 additions & 3 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

import { app, ipcMain as ipc, BrowserWindow, dialog } from 'electron';
import { app, ipcMain as ipc, BrowserWindow } from 'electron';
import * as platform from 'vs/base/common/platform';
import { WindowsManager } from 'vs/code/electron-main/windows';
import { IWindowsService, OpenContext } from 'vs/platform/windows/common/windows';
Expand Down Expand Up @@ -376,6 +376,7 @@ export class CodeApplication {

private afterWindowOpen(accessor: ServicesAccessor): void {
const appInstantiationService = accessor.get(IInstantiationService);
const windowsMainService = accessor.get(IWindowsMainService);

let windowsMutex: Mutex = null;
if (platform.isWindows) {
Expand All @@ -387,7 +388,7 @@ export class CodeApplication {
this.toDispose.push({ dispose: () => windowsMutex.release() });
} catch (e) {
if (!this.environmentService.isBuilt) {
dialog.showMessageBox({
windowsMainService.showMessageBox({
title: product.nameLong,
type: 'warning',
message: 'Failed to load windows-mutex!',
Expand All @@ -403,7 +404,7 @@ export class CodeApplication {
<any>require.__$__nodeRequire('windows-foreground-love');
} catch (e) {
if (!this.environmentService.isBuilt) {
dialog.showMessageBox({
windowsMainService.showMessageBox({
title: product.nameLong,
type: 'warning',
message: 'Failed to load windows-foreground-love!',
Expand Down
14 changes: 6 additions & 8 deletions src/vs/code/electron-main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as nls from 'vs/nls';
import { isMacintosh, isLinux, isWindows, language } from 'vs/base/common/platform';
import * as arrays from 'vs/base/common/arrays';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem, BrowserWindow, clipboard } from 'electron';
import { ipcMain as ipc, app, shell, Menu, MenuItem, BrowserWindow, clipboard } from 'electron';
import { OpenContext, IRunActionInWindowRequest } from 'vs/platform/windows/common/windows';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { AutoSaveConfiguration } from 'vs/platform/files/common/files';
Expand Down Expand Up @@ -1217,20 +1217,18 @@ export class CodeMenu {
buttons.push(mnemonicButtonLabel(nls.localize({ key: 'copy', comment: ['&& denotes a mnemonic'] }, "&&Copy"))); // https://github.com/Microsoft/vscode/issues/37608
}

const result = dialog.showMessageBox(lastActiveWindow && lastActiveWindow.win, {
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);
}
});

if (isWindows && result === 1) {
clipboard.writeText(detail);
}

this.reportMenuActionTelemetry('showAboutDialog');
}

private openUrl(url: string, id: string): void {
Expand Down
Loading

0 comments on commit 78cc1e9

Please sign in to comment.