forked from 21st-dev/1code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron-shim.js
More file actions
23 lines (22 loc) · 840 Bytes
/
electron-shim.js
File metadata and controls
23 lines (22 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Shim to ensure electron is properly loaded in Electron context
const Module = require('module');
const originalRequire = Module.prototype.require;
Module.prototype.require = function(id) {
if (id === 'electron') {
// Check if we're in Electron by looking for process.versions.electron
if (process.versions && process.versions.electron) {
// Use the built-in electron module
const { builtinModules } = require('module');
if (builtinModules.includes('electron')) {
return require.cache['electron'] || originalRequire.call(this, 'electron');
}
// Access via process
try {
return process.electronBinding ? process.electronBinding('electron') : originalRequire.call(this, id);
} catch (e) {
// Fallback
}
}
}
return originalRequire.call(this, id);
};