From 7bbf45c14e8058fd8bedcd14ff6bb727e44db8a7 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 25 Nov 2020 11:38:15 +0100 Subject: [PATCH] env - only show one notifications not two (fix #111246) --- src/vs/code/electron-main/app.ts | 7 +++++-- src/vs/code/electron-main/auth2.ts | 3 ++- src/vs/code/electron-main/window.ts | 17 +++++++++++------ .../launch/electron-main/launchMainService.ts | 3 ++- .../platform/menubar/electron-main/menubar.ts | 5 +++-- .../platform/windows/electron-main/windows.ts | 3 ++- .../windows/electron-main/windowsMainService.ts | 9 +++++---- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 7175b7a17ea..2a74fe4ed76 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -87,6 +87,7 @@ import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; import { DisplayMainService, IDisplayMainService } from 'vs/platform/display/electron-main/displayMainService'; import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper'; import { isEqualOrParent } from 'vs/base/common/extpath'; +import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation'; export class CodeApplication extends Disposable { private windowsMainService: IWindowsMainService | undefined; @@ -290,9 +291,11 @@ export class CodeApplication extends Disposable { // Handle slow shell environment resolve calls: // - a warning after 3s but continue to resolve // - an error after 10s and stop trying to resolve - const shellEnvSlowWarningHandle = setTimeout(() => window?.sendWhenReady('vscode:showShellEnvSlowWarning'), 3000); + const cts = new CancellationTokenSource(); + const shellEnvSlowWarningHandle = setTimeout(() => window?.sendWhenReady('vscode:showShellEnvSlowWarning', cts.token), 3000); const shellEnvTimeoutErrorHandle = setTimeout(function () { - window?.sendWhenReady('vscode:showShellEnvTimeoutError'); + cts.dispose(true); + window?.sendWhenReady('vscode:showShellEnvTimeoutError', CancellationToken.None); acceptShellEnv({}); }, 10000); diff --git a/src/vs/code/electron-main/auth2.ts b/src/vs/code/electron-main/auth2.ts index 1bce044577e..1b84d4bc4d9 100644 --- a/src/vs/code/electron-main/auth2.ts +++ b/src/vs/code/electron-main/auth2.ts @@ -13,6 +13,7 @@ import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeH import { IEncryptionMainService } from 'vs/platform/encryption/electron-main/encryptionMainService'; import { generateUuid } from 'vs/base/common/uuid'; import product from 'vs/platform/product/common/product'; +import { CancellationToken } from 'vs/base/common/cancellation'; interface ElectronAuthenticationResponseDetails extends AuthenticationResponseDetails { firstAuthAttempt?: boolean; // https://github.com/electron/electron/blob/84a42a050e7d45225e69df5bd2d2bf9f1037ea41/shell/browser/login_handler.cc#L70 @@ -192,7 +193,7 @@ export class ProxyAuthHandler2 extends Disposable { password: this.sessionCredentials?.password ?? storedPassword, // prefer to show already used password (if any) over stored replyChannel: `vscode:proxyAuthResponse:${generateUuid()}` }; - window.sendWhenReady('vscode:openProxyAuthenticationDialog', payload); + window.sendWhenReady('vscode:openProxyAuthenticationDialog', CancellationToken.None, payload); this.state = ProxyAuthState.LoginDialogShown; // Handle reply diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 5b0fe508826..1968e72b9c7 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -36,6 +36,7 @@ import { IStorageMainService } from 'vs/platform/storage/node/storageMainService import { ByteSize, IFileService } from 'vs/platform/files/common/files'; import { FileAccess, Schemas } from 'vs/base/common/network'; import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper'; +import { CancellationToken } from 'vs/base/common/cancellation'; export interface IWindowCreationOptions { state: IWindowState; @@ -518,11 +519,11 @@ export class CodeWindow extends Disposable implements ICodeWindow { // Window Fullscreen this._win.on('enter-full-screen', () => { - this.sendWhenReady('vscode:enterFullScreen'); + this.sendWhenReady('vscode:enterFullScreen', CancellationToken.None); }); this._win.on('leave-full-screen', () => { - this.sendWhenReady('vscode:leaveFullScreen'); + this.sendWhenReady('vscode:leaveFullScreen', CancellationToken.None); }); // Window Failed to load @@ -1100,7 +1101,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { } // Events - this.sendWhenReady(fullscreen ? 'vscode:enterFullScreen' : 'vscode:leaveFullScreen'); + this.sendWhenReady(fullscreen ? 'vscode:enterFullScreen' : 'vscode:leaveFullScreen', CancellationToken.None); // Respect configured menu bar visibility or default to toggle if not set if (this.currentMenuBarVisibility) { @@ -1241,11 +1242,15 @@ export class CodeWindow extends Disposable implements ICodeWindow { } } - sendWhenReady(channel: string, ...args: any[]): void { + sendWhenReady(channel: string, token: CancellationToken, ...args: any[]): void { if (this.isReady) { this.send(channel, ...args); } else { - this.ready().then(() => this.send(channel, ...args)); + this.ready().then(() => { + if (!token.isCancellationRequested) { + this.send(channel, ...args); + } + }); } } @@ -1295,7 +1300,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { mode: 'buttons', segmentStyle: 'automatic', change: (selectedIndex) => { - this.sendWhenReady('vscode:runAction', { id: (control.segments[selectedIndex] as ITouchBarSegment).id, from: 'touchbar' }); + this.sendWhenReady('vscode:runAction', CancellationToken.None, { id: (control.segments[selectedIndex] as ITouchBarSegment).id, from: 'touchbar' }); } }); diff --git a/src/vs/platform/launch/electron-main/launchMainService.ts b/src/vs/platform/launch/electron-main/launchMainService.ts index 069bb585c19..2e48223e568 100644 --- a/src/vs/platform/launch/electron-main/launchMainService.ts +++ b/src/vs/platform/launch/electron-main/launchMainService.ts @@ -20,6 +20,7 @@ import { coalesce } from 'vs/base/common/arrays'; import { IDiagnosticInfoOptions, IDiagnosticInfo, IRemoteDiagnosticInfo, IRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics'; import { IMainProcessInfo, IWindowInfo } from 'vs/platform/launch/node/launch'; import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper'; +import { CancellationToken } from 'vs/base/common/cancellation'; export const ID = 'launchMainService'; export const ILaunchMainService = createDecorator(ID); @@ -248,7 +249,7 @@ export class LaunchMainService implements ILaunchMainService { folders: options.includeWorkspaceMetadata ? this.getFolderURIs(window) : undefined }; - window.sendWhenReady('vscode:getDiagnosticInfo', { replyChannel, args }); + window.sendWhenReady('vscode:getDiagnosticInfo', CancellationToken.None, { replyChannel, args }); ipcMain.once(replyChannel, (_: IpcEvent, data: IRemoteDiagnosticInfo) => { // No data is returned if getting the connection fails. diff --git a/src/vs/platform/menubar/electron-main/menubar.ts b/src/vs/platform/menubar/electron-main/menubar.ts index e2a0efb0bd5..90fba9c3fb1 100644 --- a/src/vs/platform/menubar/electron-main/menubar.ts +++ b/src/vs/platform/menubar/electron-main/menubar.ts @@ -24,6 +24,7 @@ import { IStateService } from 'vs/platform/state/node/state'; import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; import { WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification } from 'vs/base/common/actions'; import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService'; +import { CancellationToken } from 'vs/base/common/cancellation'; const telemetryFrom = 'menu'; @@ -754,10 +755,10 @@ export class Menubar { if (invocation.type === 'commandId') { const runActionPayload: INativeRunActionInWindowRequest = { id: invocation.commandId, from: 'menu' }; - activeWindow.sendWhenReady('vscode:runAction', runActionPayload); + activeWindow.sendWhenReady('vscode:runAction', CancellationToken.None, runActionPayload); } else { const runKeybindingPayload: INativeRunKeybindingInWindowRequest = { userSettingsLabel: invocation.userSettingsLabel }; - activeWindow.sendWhenReady('vscode:runKeybinding', runKeybindingPayload); + activeWindow.sendWhenReady('vscode:runKeybinding', CancellationToken.None, runKeybindingPayload); } } else { this.logService.trace('menubar#runActionInRenderer: no active window found', invocation); diff --git a/src/vs/platform/windows/electron-main/windows.ts b/src/vs/platform/windows/electron-main/windows.ts index 6359b340711..83eccca73c4 100644 --- a/src/vs/platform/windows/electron-main/windows.ts +++ b/src/vs/platform/windows/electron-main/windows.ts @@ -14,6 +14,7 @@ import { ISerializableCommandAction } from 'vs/platform/actions/common/actions'; import { URI } from 'vs/base/common/uri'; import { Rectangle, BrowserWindow, WebContents } from 'electron'; import { IDisposable } from 'vs/base/common/lifecycle'; +import { CancellationToken } from 'vs/base/common/cancellation'; export interface IWindowState { width?: number; @@ -72,7 +73,7 @@ export interface ICodeWindow extends IDisposable { getBounds(): Rectangle; send(channel: string, ...args: any[]): void; - sendWhenReady(channel: string, ...args: any[]): void; + sendWhenReady(channel: string, token: CancellationToken, ...args: any[]): void; readonly isFullScreen: boolean; toggleFullScreen(): void; diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 30f5d85c93e..74beab39da6 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -39,6 +39,7 @@ import { withNullAsUndefined } from 'vs/base/common/types'; import { isWindowsDriveLetter, toSlashes, parseLineAndColumnAware } from 'vs/base/common/extpath'; import { CharCode } from 'vs/base/common/charCode'; import { getPathLabel } from 'vs/base/common/labels'; +import { CancellationToken } from 'vs/base/common/cancellation'; export interface IWindowState { workspace?: IWorkspaceIdentifier; @@ -758,7 +759,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic params.termProgram = configuration.userEnv['TERM_PROGRAM']; } - window.sendWhenReady('vscode:openFiles', params); + window.sendWhenReady('vscode:openFiles', CancellationToken.None, params); return window; } @@ -767,7 +768,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic window.focus(); // make sure window has focus const request: IAddFoldersRequest = { foldersToAdd }; - window.sendWhenReady('vscode:addFolders', request); + window.sendWhenReady('vscode:addFolders', CancellationToken.None, request); return window; } @@ -1679,7 +1680,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic const focusedWindow = this.getFocusedWindow() || this.getLastActiveWindow(); if (focusedWindow) { - focusedWindow.sendWhenReady(channel, ...args); + focusedWindow.sendWhenReady(channel, CancellationToken.None, ...args); } } @@ -1689,7 +1690,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic continue; // do not send if we are instructed to ignore it } - window.sendWhenReady(channel, payload); + window.sendWhenReady(channel, CancellationToken.None, payload); } }