Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/window.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export type CodeWindow = Window & typeof globalThis & {
7
readonly vscodeWindowId: number;
8
};
9
10
export function ensureCodeWindow(targetWindow: Window, fallbackWindowId: number): asserts targetWindow is CodeWindow {
11
const codeWindow = targetWindow as Partial<CodeWindow>;
12
13
if (typeof codeWindow.vscodeWindowId !== 'number') {
14
Object.defineProperty(codeWindow, 'vscodeWindowId', {
15
get: () => fallbackWindowId
16
});
17
}
18
}
19
20
// eslint-disable-next-line no-restricted-globals
21
export const mainWindow = window as CodeWindow;
22
23
export function isAuxiliaryWindow(obj: Window): obj is CodeWindow {
24
if (obj === mainWindow) {
25
return false;
26
}
27
28
const candidate = obj as CodeWindow | undefined;
29
30
return typeof candidate?.vscodeWindowId === 'number';
31
}
32
33