简体   繁体   中英

app and autoUpdater not available in reactjs, but available in nodejs

I'm stuck with an electron problem. Or react, I don't know. I'm trying to create a React.Component for using the electron.autoUpdater with it.

I'm using

import {app, autoUpdater, dialog} from 'electron';

in react component, but none of those classes are available. They are available in nodejs when using with require('electron') (which is normal, ok), but not available in reactjs. But the rest of components are there!

Is there something I should include or need to know? In nodejs, available modules are:

{ clipboard: [Getter],
  crashReporter: [Getter],
  nativeImage: [Getter],
  shell: [Getter],
  app: [Getter],
  autoUpdater: [Getter],
  BrowserView: [Getter],
  BrowserWindow: [Getter],
  contentTracing: [Getter],
  dialog: [Getter],
  globalShortcut: [Getter],
  ipcMain: [Getter],
  Menu: [Getter],
  MenuItem: [Getter],
  net: [Getter],
  Notification: [Getter],
  powerMonitor: [Getter],
  powerSaveBlocker: [Getter],
  protocol: [Getter],
  screen: [Getter],
  session: [Getter],
  systemPreferences: [Getter],
  TouchBar: [Getter],
  Tray: [Getter],
  webContents: [Getter] }

In react, the available components are:

clipboard, crashReporter, desktopCapturer, 
ipcRenderer, nativeImage, remote, screen, shell, webFrame.

I tried using window.require('electron'); the command works, but those modules are still not available

Thank you in advance

I think I found the problem. This answer helped me: https://github.com/electron/electron/issues/9920#issuecomment-318986025

the idea is that app, autoUpdater and a lot of other components are available on electron.remote I don't know why, but the keyword "remote" denotes that you are using the same app,autoUpdater etc like in the master process. Any other explanation?

PS: I will let you know if this solution work.

NOTSOLATEREDIT:

this is my solution, and works smooth. Is there any better way of doing this?

import electron from 'electron';
const app = electron.remote.app;
const autoUpdater = electron.remote.autoUpdater;
const dialog = electron.remote.dialog;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM