Skip to content

Commit

Permalink
refactor: move WebContentsView to index.ts because it is exported fro…
Browse files Browse the repository at this point in the history
…m CrossProcessExports
  • Loading branch information
ductridev committed Oct 14, 2024
1 parent 4927fe1 commit 160a0bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Electron from 'electron';
import { WebContentsView } from './src/main/index';
import { WebContentsView } from './index';

export {
ClientRequest,
Expand Down
17 changes: 17 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Electron from 'electron';
import { isVersionGreaterOrEqual } from './src/common/utils';

const electronVersion = process.versions.electron;

// Check if WebContentsView exists and if the version is >= 29.0.0
let WebContentsView_: any; // Use 'any' for dynamic checking

if (isVersionGreaterOrEqual('29.0.0', electronVersion) && 'WebContentsView' in Electron) {
WebContentsView_ = Electron.WebContentsView; // Assign if it exists
} else {
console.warn("WebContentsView is not available in this version of Electron.");
WebContentsView_ = undefined; // Explicitly set to undefined if not available
}

// Export the WebContentsView for use in other parts of your application
export const WebContentsView = WebContentsView_;
12 changes: 0 additions & 12 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
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 };

0 comments on commit 160a0bb

Please sign in to comment.