diff --git a/index.d.ts b/index.d.ts index 26836fb..032f042 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,5 @@ import * as Electron from 'electron'; +import { WebContentsView } from './src/main/index'; export { ClientRequest, @@ -57,6 +58,9 @@ export var Tray: typeof Electron.Tray; export var webContents: typeof Electron.webContents; export var webFrameMain: typeof Electron.webFrameMain; +// Taken from `RemoteMainInterface` but WebContentsView is only available in Electron >= 29.0.0 +export { WebContentsView }; + // Taken from `Remote` export function getCurrentWebContents(): Electron.WebContents; export function getCurrentWindow(): Electron.BrowserWindow; diff --git a/src/common/utils.ts b/src/common/utils.ts new file mode 100644 index 0000000..e57621a --- /dev/null +++ b/src/common/utils.ts @@ -0,0 +1,11 @@ +export function isVersionGreaterOrEqual(requiredVersion: string, currentVersion: string): boolean { + const required = requiredVersion.split('.').map(Number); + const current = currentVersion.split('.').map(Number); + + for (let i = 0; i < required.length; i++) { + if (current[i] > required[i]) return true; + if (current[i] < required[i]) return false; + } + + return true; +} \ No newline at end of file diff --git a/src/main/index.ts b/src/main/index.ts index c4bc390..3b71ca1 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1 +1,13 @@ export { initialize, isInitialized, enable } from "./server"; + +import { isVersionGreaterOrEqual } from '../common/utils'; + +const electronVersion = process.versions.electron; + +let WebContentsView: typeof Electron.WebContentsView | undefined; + +if (isVersionGreaterOrEqual('29.0.0', electronVersion)) { + WebContentsView = Electron.WebContentsView; +} + +export { WebContentsView }; \ No newline at end of file