electron.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const electron = typeof require !== 'undefined'
  2. // All exports module see https://www.electronjs.org -> API -> Renderer process Modules
  3. ? (function requireElectron() {
  4. const avoid_parse_require = require;
  5. return avoid_parse_require("electron");
  6. }())
  7. : (function nodeIntegrationWarn() {
  8. console.error(`If you need to use "electron" in the Renderer process, make sure that "nodeIntegration" is enabled in the Main process.`);
  9. return {
  10. // TODO: polyfill
  11. };
  12. }());
  13. // Proxy in Worker
  14. let _ipcRenderer;
  15. if (typeof document === 'undefined') {
  16. _ipcRenderer = {};
  17. const keys = [
  18. 'invoke',
  19. 'postMessage',
  20. 'send',
  21. 'sendSync',
  22. 'sendTo',
  23. 'sendToHost',
  24. // propertype
  25. 'addListener',
  26. 'emit',
  27. 'eventNames',
  28. 'getMaxListeners',
  29. 'listenerCount',
  30. 'listeners',
  31. 'off',
  32. 'on',
  33. 'once',
  34. 'prependListener',
  35. 'prependOnceListener',
  36. 'rawListeners',
  37. 'removeAllListeners',
  38. 'removeListener',
  39. 'setMaxListeners',
  40. ];
  41. for (const key of keys) {
  42. _ipcRenderer[key] = () => {
  43. throw new Error(
  44. 'ipcRenderer doesn\'t work in a Web Worker.\n' +
  45. 'You can see https://github.com/electron-vite/vite-plugin-electron/issues/69'
  46. );
  47. };
  48. }
  49. } else {
  50. _ipcRenderer = electron.ipcRenderer;
  51. }
  52. export { electron as default };
  53. export const clipboard = electron.clipboard;
  54. export const contextBridge = electron.contextBridge;
  55. export const crashReporter = electron.crashReporter;
  56. export const ipcRenderer = _ipcRenderer;
  57. export const nativeImage = electron.nativeImage;
  58. export const shell = electron.shell;
  59. export const webFrame = electron.webFrame;
  60. export const deprecate = electron.deprecate;