diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 1468494b475..214b4fdc2e1 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1602,3 +1602,9 @@ export class ModifierKeyEmitter extends Emitter { this._subscriptions.dispose(); } } + +export function getCookieValue(name: string): string | undefined { + const match = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)'); // See https://stackoverflow.com/a/25490531 + + return match ? match.pop() : undefined; +} diff --git a/src/vs/editor/browser/services/openerService.ts b/src/vs/editor/browser/services/openerService.ts index 1360871f738..b979ca3cad3 100644 --- a/src/vs/editor/browser/services/openerService.ts +++ b/src/vs/editor/browser/services/openerService.ts @@ -16,7 +16,6 @@ import { IOpener, IOpenerService, IValidator, IExternalUriResolver, OpenOptions, import { EditorOpenContext } from 'vs/platform/editor/common/editor'; import { ResourceMap } from 'vs/base/common/map'; - class CommandOpener implements IOpener { constructor(@ICommandService private readonly _commandService: ICommandService) { } @@ -108,7 +107,7 @@ export class OpenerService implements IOpenerService { ) { // Default external opener is going through window.open() this._externalOpener = { - openExternal: href => { + openExternal: async href => { // ensure to open HTTP/HTTPS links into new windows // to not trigger a navigation. Any other link is // safe to be set as HREF to prevent a blank window @@ -118,11 +117,11 @@ export class OpenerService implements IOpenerService { } else { window.location.href = href; } - return Promise.resolve(true); + return true; } }; - // Default opener: maito, http(s), command, and catch-all-editors + // Default opener: any external, maito, http(s), command, and catch-all-editors this._openers.push({ open: async (target: URI | string, options?: OpenOptions) => { if (options?.openExternal || matchesScheme(target, Schemas.mailto) || matchesScheme(target, Schemas.http) || matchesScheme(target, Schemas.https)) { diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts index 20df4472969..08c6a397ade 100644 --- a/src/vs/workbench/browser/web.main.ts +++ b/src/vs/workbench/browser/web.main.ts @@ -5,7 +5,7 @@ import { mark } from 'vs/base/common/performance'; import { hash } from 'vs/base/common/hash'; -import { domContentLoaded, addDisposableListener, EventType, EventHelper, detectFullscreen, addDisposableThrottledListener } from 'vs/base/browser/dom'; +import { domContentLoaded, addDisposableListener, EventType, EventHelper, detectFullscreen, addDisposableThrottledListener, getCookieValue } from 'vs/base/browser/dom'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ILogService, ConsoleLogService, MultiplexLogService, getLogLevel } from 'vs/platform/log/common/log'; import { ConsoleLogInAutomationService } from 'vs/platform/log/browser/log'; @@ -142,9 +142,7 @@ class BrowserMain extends Disposable { event.veto(true); // prevent data loss from pending storage update } })); - this._register(workbench.onWillShutdown(() => { - storageService.close(); - })); + this._register(workbench.onWillShutdown(() => storageService.close())); this._register(workbench.onShutdown(() => this.dispose())); // Fullscreen (Browser) @@ -181,9 +179,8 @@ class BrowserMain extends Disposable { const logService = new BufferLogService(getLogLevel(environmentService)); serviceCollection.set(ILogService, logService); - const connectionToken = environmentService.options.connectionToken || this.getCookieValue('vscode-tkn'); - // Remote + const connectionToken = environmentService.options.connectionToken || getCookieValue('vscode-tkn'); const remoteAuthorityResolverService = new RemoteAuthorityResolverService(connectionToken, this.configuration.resourceUriProvider); serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService); @@ -240,12 +237,14 @@ class BrowserMain extends Disposable { if (await userDataInitializationService.requiresInitialization()) { mark('willInitRequiredUserData'); + // Initialize required resources - settings & global state await userDataInitializationService.initializeRequiredResources(); // Important: Reload only local user configuration after initializing // Reloading complete configuraiton blocks workbench until remote configuration is loaded. await configurationService.reloadLocalUserConfiguration(); + mark('didInitRequiredUserData'); } @@ -370,12 +369,6 @@ class BrowserMain extends Disposable { return { id: 'empty-window' }; } - - private getCookieValue(name: string): string | undefined { - const match = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)'); // See https://stackoverflow.com/a/25490531 - - return match ? match.pop() : undefined; - } } export function main(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise { diff --git a/src/vs/workbench/electron-browser/desktop.main.ts b/src/vs/workbench/electron-browser/desktop.main.ts index fdcd679f8b8..dd3d59cb4ea 100644 --- a/src/vs/workbench/electron-browser/desktop.main.ts +++ b/src/vs/workbench/electron-browser/desktop.main.ts @@ -344,8 +344,11 @@ class DesktopMain extends Disposable { const folder = folderUri.scheme === Schemas.file ? URI.file(sanitizeFilePath(folderUri.fsPath, process.env['VSCODE_CWD'] || process.cwd())) // For local: ensure path is absolute : folderUri; - const id = await this.createHash(folderUri); - return { id, folder }; + + return { + id: await this.createHash(folderUri), + folder + }; } catch (error) { onUnexpectedError(error); } diff --git a/src/vs/workbench/electron-sandbox/window.ts b/src/vs/workbench/electron-sandbox/window.ts index 37afcaaf5a9..8c4309244ee 100644 --- a/src/vs/workbench/electron-sandbox/window.ts +++ b/src/vs/workbench/electron-sandbox/window.ts @@ -3,11 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as nls from 'vs/nls'; +import { localize } from 'vs/nls'; import { URI } from 'vs/base/common/uri'; -import * as errors from 'vs/base/common/errors'; +import { onUnexpectedError } from 'vs/base/common/errors'; import { equals } from 'vs/base/common/objects'; -import * as DOM from 'vs/base/browser/dom'; +import { EventType, EventHelper, addDisposableListener } from 'vs/base/browser/dom'; import { IAction, Separator } from 'vs/base/common/actions'; import { IFileService } from 'vs/platform/files/common/files'; import { EditorResourceAccessor, IUntitledTextResourceEditorInput, SideBySideEditor, pathsToEditors } from 'vs/workbench/common/editor'; @@ -126,9 +126,9 @@ export class NativeWindow extends Disposable { this._register(this.editorService.onDidActiveEditorChange(() => this.updateTouchbarMenu())); // prevent opening a real URL inside the shell - [DOM.EventType.DRAG_OVER, DOM.EventType.DROP].forEach(event => { + [EventType.DRAG_OVER, EventType.DROP].forEach(event => { window.document.body.addEventListener(event, (e: DragEvent) => { - DOM.EventHelper.stop(e); + EventHelper.stop(e); }); }); @@ -173,7 +173,7 @@ export class NativeWindow extends Disposable { // Error reporting from main ipcRenderer.on('vscode:reportError', (event: unknown, error: string) => { if (error) { - errors.onUnexpectedError(JSON.parse(error)); + onUnexpectedError(JSON.parse(error)); } }); @@ -188,13 +188,13 @@ export class NativeWindow extends Disposable { // Shell Environment Issue Notifications const choices: IPromptChoice[] = [{ - label: nls.localize('learnMode', "Learn More"), + label: localize('learnMode', "Learn More"), run: () => this.openerService.open('https://go.microsoft.com/fwlink/?linkid=2149667') }]; ipcRenderer.on('vscode:showShellEnvSlowWarning', () => this.notificationService.prompt( Severity.Warning, - nls.localize('shellEnvSlowWarning', "Resolving your shell environment is taking very long. Please review your shell configuration."), + localize('shellEnvSlowWarning', "Resolving your shell environment is taking very long. Please review your shell configuration."), choices, { sticky: true, @@ -204,7 +204,7 @@ export class NativeWindow extends Disposable { ipcRenderer.on('vscode:showShellEnvTimeoutError', () => this.notificationService.prompt( Severity.Error, - nls.localize('shellEnvTimeoutError', "Unable to resolve your shell environment in a reasonable time. Please review your shell configuration."), + localize('shellEnvTimeoutError', "Unable to resolve your shell environment in a reasonable time. Please review your shell configuration."), choices )); @@ -222,20 +222,20 @@ export class NativeWindow extends Disposable { // Proxy Login Dialog ipcRenderer.on('vscode:openProxyAuthenticationDialog', async (event: unknown, payload: { authInfo: AuthInfo, username?: string, password?: string, replyChannel: string }) => { const rememberCredentials = this.storageService.getBoolean(NativeWindow.REMEMBER_PROXY_CREDENTIALS_KEY, StorageScope.GLOBAL); - const result = await this.dialogService.input(Severity.Warning, nls.localize('proxyAuthRequired', "Proxy Authentication Required"), + const result = await this.dialogService.input(Severity.Warning, localize('proxyAuthRequired', "Proxy Authentication Required"), [ - nls.localize({ key: 'loginButton', comment: ['&& denotes a mnemonic'] }, "&&Log In"), - nls.localize({ key: 'cancelButton', comment: ['&& denotes a mnemonic'] }, "&&Cancel") + localize({ key: 'loginButton', comment: ['&& denotes a mnemonic'] }, "&&Log In"), + localize({ key: 'cancelButton', comment: ['&& denotes a mnemonic'] }, "&&Cancel") ], [ - { placeholder: nls.localize('username', "Username"), value: payload.username }, - { placeholder: nls.localize('password', "Password"), type: 'password', value: payload.password } + { placeholder: localize('username', "Username"), value: payload.username }, + { placeholder: localize('password', "Password"), type: 'password', value: payload.password } ], { cancelId: 1, - detail: nls.localize('proxyDetail', "The proxy {0} requires a username and password.", `${payload.authInfo.host}:${payload.authInfo.port}`), + detail: localize('proxyDetail', "The proxy {0} requires a username and password.", `${payload.authInfo.host}:${payload.authInfo.port}`), checkbox: { - label: nls.localize('rememberCredentials', "Remember my credentials"), + label: localize('rememberCredentials', "Remember my credentials"), checked: rememberCredentials } }); @@ -303,8 +303,8 @@ export class NativeWindow extends Disposable { if (isMacintosh && getTitleBarStyle(this.configurationService) === 'custom') { const titlePart = assertIsDefined(this.layoutService.getContainer(Parts.TITLEBAR_PART)); - this._register(DOM.addDisposableListener(titlePart, DOM.EventType.DBLCLICK, e => { - DOM.EventHelper.stop(e); + this._register(addDisposableListener(titlePart, EventType.DBLCLICK, e => { + EventHelper.stop(e); this.nativeHostService.handleTitleDoubleClick(); })); @@ -331,9 +331,7 @@ export class NativeWindow extends Disposable { this.onDidChangeMaximized(this.environmentService.configuration.maximized ?? false); // Detect panel position to determine minimum width - this._register(this.layoutService.onPanelPositionChange(pos => { - this.onDidPanelPositionChange(positionFromString(pos)); - })); + this._register(this.layoutService.onPanelPositionChange(pos => this.onDidPanelPositionChange(positionFromString(pos)))); this.onDidPanelPositionChange(this.layoutService.getPanelPosition()); } @@ -350,18 +348,19 @@ export class NativeWindow extends Disposable { } private getWindowMinimumWidth(panelPosition: Position = this.layoutService.getPanelPosition()): number { + // if panel is on the side, then return the larger minwidth const panelOnSide = panelPosition === Position.LEFT || panelPosition === Position.RIGHT; if (panelOnSide) { return WindowMinimumSize.WIDTH_WITH_VERTICAL_PANEL; } - else { - return WindowMinimumSize.WIDTH; - } + + return WindowMinimumSize.WIDTH; } private onDidPanelPositionChange(pos: Position): void { const minWidth = this.getWindowMinimumWidth(pos); + this.nativeHostService.setMinimumSize(minWidth, undefined); } @@ -470,7 +469,7 @@ export class NativeWindow extends Disposable { // Show warning message (unix only) if (isAdmin && !isWindows) { - this.notificationService.warn(nls.localize('runningAsRoot', "It is not recommended to run {0} as root user.", this.productService.nameShort)); + this.notificationService.warn(localize('runningAsRoot', "It is not recommended to run {0} as root user.", this.productService.nameShort)); } }); @@ -704,7 +703,7 @@ class NativeMenubarControl extends MenubarControl { if (isMacintosh) { this.menus['Preferences'] = this._register(this.menuService.createMenu(MenuId.MenubarPreferencesMenu, this.contextKeyService)); - this.topLevelTitles['Preferences'] = nls.localize('mPreferences', "Preferences"); + this.topLevelTitles['Preferences'] = localize('mPreferences', "Preferences"); } for (const topLevelMenuName of Object.keys(this.topLevelTitles)) {