aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron-util.ts
blob: 3c395ab10345ee40c9ef734d0c4b4ef1a6d65047 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Enhanced from: https://github.com/dertieran/electron-util/blob/replace-remote/source/api.js

import * as electron from 'electron';
import { initialize } from '@electron/remote/main';

export const initializeRemote = () => {
  if (process.type !== 'browser') {
    throw new Error(
      'The remote api must be initialized from the main process.',
    );
  }

  initialize();
};

export const remote = new Proxy(
  {},
  {
    get: (_target, property) => {
      // eslint-disable-next-line global-require
      const remote = require('@electron/remote');
      return remote[property];
    },
  },
);

export const api = new Proxy(electron, {
  get: (target, property) => {
    if (target[property]) {
      return target[property];
    }

    return remote[property];
  },
});