From 15333a70d89f3dc3a7685dc60c0e8319ea7939fc Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 7 Nov 2024 09:44:37 -0800 Subject: [PATCH] Implement a `handle` property that is a string (#233267) * Implement a `handle` property that is a string For Microsoft auth * fix integration tests --- extensions/vscode-api-tests/package.json | 1 + .../extensions/common/extensionsApiProposals.ts | 3 +++ src/vs/platform/window/common/window.ts | 1 + .../windows/electron-main/windowImpl.ts | 5 +++++ src/vs/workbench/api/common/extHost.api.impl.ts | 4 ++++ .../electron-sandbox/environmentService.ts | 2 ++ .../extensions/common/extensionHostProtocol.ts | 1 + .../localProcessExtensionHost.ts | 3 ++- .../vscode.proposed.nativeWindowHandle.d.ts | 17 +++++++++++++++++ 9 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/vscode-dts/vscode.proposed.nativeWindowHandle.d.ts diff --git a/extensions/vscode-api-tests/package.json b/extensions/vscode-api-tests/package.json index f62982eca50..5f7681bf9d6 100644 --- a/extensions/vscode-api-tests/package.json +++ b/extensions/vscode-api-tests/package.json @@ -30,6 +30,7 @@ "interactive", "languageStatusText", "mappedEditsProvider", + "nativeWindowHandle", "notebookCellExecutionState", "notebookDeprecated", "notebookLiveShare", diff --git a/src/vs/platform/extensions/common/extensionsApiProposals.ts b/src/vs/platform/extensions/common/extensionsApiProposals.ts index ef880b81e6d..98e678996e5 100644 --- a/src/vs/platform/extensions/common/extensionsApiProposals.ts +++ b/src/vs/platform/extensions/common/extensionsApiProposals.ts @@ -245,6 +245,9 @@ const _allApiProposals = { multiDocumentHighlightProvider: { proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.multiDocumentHighlightProvider.d.ts', }, + nativeWindowHandle: { + proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.nativeWindowHandle.d.ts', + }, newSymbolNamesProvider: { proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.newSymbolNamesProvider.d.ts', }, diff --git a/src/vs/platform/window/common/window.ts b/src/vs/platform/window/common/window.ts index a3c02dba449..cd0240d8bdc 100644 --- a/src/vs/platform/window/common/window.ts +++ b/src/vs/platform/window/common/window.ts @@ -354,6 +354,7 @@ export interface IOSConfiguration { export interface INativeWindowConfiguration extends IWindowConfiguration, NativeParsedArgs, ISandboxConfiguration { mainPid: number; + handle?: string; machineId: string; sqmId: string; diff --git a/src/vs/platform/windows/electron-main/windowImpl.ts b/src/vs/platform/windows/electron-main/windowImpl.ts index f0540656eed..6a3ecb6a7e1 100644 --- a/src/vs/platform/windows/electron-main/windowImpl.ts +++ b/src/vs/platform/windows/electron-main/windowImpl.ts @@ -1092,6 +1092,11 @@ export class CodeWindow extends BaseWindow implements ICodeWindow { } // Update window related properties + try { + configuration.handle = this._win.getNativeWindowHandle().toString('base64'); + } catch (error) { + this.logService.error(`Error getting native window handle: ${error}`); + } configuration.fullscreen = this.isFullScreen; configuration.maximized = this._win.isMaximized(); configuration.partsSplash = this.themeMainService.getWindowSplash(); diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index d45dd274008..9c2c8edabd0 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -437,6 +437,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'resolvers'); return initData.commit; }, + get handle(): string | undefined { + checkProposedApiEnabled(extension, 'nativeWindowHandle'); + return initData.handle; + } }; if (!initData.environment.extensionTestsLocationURI) { // allow to patch env-function when running tests diff --git a/src/vs/workbench/services/environment/electron-sandbox/environmentService.ts b/src/vs/workbench/services/environment/electron-sandbox/environmentService.ts index 749c5e0a167..aebabc00203 100644 --- a/src/vs/workbench/services/environment/electron-sandbox/environmentService.ts +++ b/src/vs/workbench/services/environment/electron-sandbox/environmentService.ts @@ -26,6 +26,7 @@ export interface INativeWorkbenchEnvironmentService extends IBrowserWorkbenchEnv // --- Window readonly window: { id: number; + handle?: string; colorScheme: IColorScheme; maximized?: boolean; accessibilitySupport?: boolean; @@ -83,6 +84,7 @@ export class NativeWorkbenchEnvironmentService extends AbstractNativeEnvironment get window() { return { id: this.configuration.windowId, + handle: this.configuration.handle, colorScheme: this.configuration.colorScheme, maximized: this.configuration.maximized, accessibilitySupport: this.configuration.accessibilitySupport, diff --git a/src/vs/workbench/services/extensions/common/extensionHostProtocol.ts b/src/vs/workbench/services/extensions/common/extensionHostProtocol.ts index da967f8262f..98e78cff2f0 100644 --- a/src/vs/workbench/services/extensions/common/extensionHostProtocol.ts +++ b/src/vs/workbench/services/extensions/common/extensionHostProtocol.ts @@ -53,6 +53,7 @@ export interface IExtensionHostInitData { consoleForward: { includeStack: boolean; logNative: boolean }; uiKind: UIKind; messagePorts?: ReadonlyMap; + handle?: string; } export interface IEnvironment { diff --git a/src/vs/workbench/services/extensions/electron-sandbox/localProcessExtensionHost.ts b/src/vs/workbench/services/extensions/electron-sandbox/localProcessExtensionHost.ts index e62e021ae8d..c815dbddf6b 100644 --- a/src/vs/workbench/services/extensions/electron-sandbox/localProcessExtensionHost.ts +++ b/src/vs/workbench/services/extensions/electron-sandbox/localProcessExtensionHost.ts @@ -511,7 +511,8 @@ export class NativeLocalProcessExtensionHost implements IExtensionHost { loggers: [...this._loggerService.getRegisteredLoggers()], logsLocation: this._environmentService.extHostLogsPath, autoStart: (this.startup === ExtensionHostStartup.EagerAutoStart), - uiKind: UIKind.Desktop + uiKind: UIKind.Desktop, + handle: this._environmentService.window.handle }; } diff --git a/src/vscode-dts/vscode.proposed.nativeWindowHandle.d.ts b/src/vscode-dts/vscode.proposed.nativeWindowHandle.d.ts new file mode 100644 index 00000000000..b5699ade4da --- /dev/null +++ b/src/vscode-dts/vscode.proposed.nativeWindowHandle.d.ts @@ -0,0 +1,17 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// https://github.com/microsoft/vscode/issues/229431 + +declare module 'vscode' { + + export namespace env { + /** + * Retrieves a base64 representation of a native window + * handle of the current window. + */ + export const handle: string | undefined; + } +}