microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.9k stars 29.52k forks source link

Proposed API for window handle #233106

Open TylerLeonhardt opened 3 weeks ago

TylerLeonhardt commented 3 weeks ago

For Broker support in Microsoft Authentication (https://github.com/microsoft/vscode/issues/229431) we need the window handle for this API: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/brokering.md#window-parenting

So, I need to be able to access the window handle from Main alllll the way in an extension.

Here's the proposal:

    export namespace env {
        /**
         * Retrieves the native window handle of the current window.
         *
         * @returns A promise that resolves to a Buffer containing the native window handle.
         */
        export function getNativeWindowHandle(): Thenable<Buffer | undefined>;
    }
jrieken commented 3 weeks ago
TylerLeonhardt commented 3 weeks ago

UInt8Array was cumbersome to pass across processes... so I landed on a base64 string. From there, an extension (Microsoft auth) can simply turn that into a Buffer Buffer.from(env.handle, 'base64') and pass it through.

New proposal:

    export namespace env {
        /**
         * Retrieves a base64 representation of a native window
         * handle of the current window.
         */
        export const handle: string | undefined;
    }
jrieken commented 3 weeks ago

Let's keep this open to track lifecyle of this proposal

TylerLeonhardt commented 3 weeks ago

handle on env feels weird. Couple ideas:

jrieken commented 3 weeks ago

I believe window.handle is the most correct but maybe a more telling name, like nativeHandle or so?

jrieken commented 2 weeks ago

what about AUX windows?

TylerLeonhardt commented 1 week ago

New proposal:

declare module 'vscode' {

    export namespace window {
        /**
         * Retrieves the native window handle of the current active window.
         * This will be updated when the active window changes.
         */
        export const nativeHandle: Uint8Array | undefined;
    }
}