Code Monkey home page Code Monkey logo

Comments (9)

dtolios avatar dtolios commented on June 15, 2024 1

@bendemboski ahhh, yes i did, i should be more careful next time to only upgrade one dependency at a time. I'll try the experiment you mentioned and let you know later today.

from ember-electron.

RobbieTheWagner avatar RobbieTheWagner commented on June 15, 2024

@dtolios did you follow all the instructions here? https://ember-electron.js.org/docs/guides/upgrading

from ember-electron.

dtolios avatar dtolios commented on June 15, 2024

I did run that, but to verify I also spun up a new ember app doing the following:

  1. Opened terminal in my projects/ dir
  2. ran ember new ember-electron-test
  3. ran ember install ember-electron
  4. added the webPreferences with nodeIntegration to my main.js file
  5. added a component which called requireNode("electron")
  6. ran ember electron
  7. saw error in my console

With that said, I've also been reading that I can wrap what I need using a preload script, but I'm also having a bit of trouble there, because the script doesn't seem to be run.

from ember-electron.

RobbieTheWagner avatar RobbieTheWagner commented on June 15, 2024

What file are you using requireNode in?

from ember-electron.

dtolios avatar dtolios commented on June 15, 2024

It was a component file located in:

app/
  components/
    my-button.js

from ember-electron.

dtolios avatar dtolios commented on June 15, 2024

Just a quick update, I was able to get around this in what I think is a nicer way this morning by using a preload script to wrap APIs. Here's what I did:

// in index.js of my electron app

// code...
mainWindow = new BrowserWindow({
    width: 1280,
    height: 720,
    frame: false,
    resizable: false,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
    },
  });

// code...

  ipcMain.on("minimize", () => {
    mainWindow.minimize();
  });

  ipcMain.on("quit", () => {
    app.quit();
  });
// in preload.js
const { contextBridge, ipcRenderer, shell } = require("electron");

contextBridge.exposeInMainWorld("electron", {
  myOpenExternal: (url) => shell.openExternal(url),
  myMinimize: () => ipcRenderer.send("minimize"),
  myClose: () => ipcRenderer.send("quit"),
});

Then in my components i can just call things like:

window.electron.myMinimize();

I think this is a better solution overall to needing to requireNode to get access to the electron APIs.

from ember-electron.

bendemboski avatar bendemboski commented on June 15, 2024

@dtolios did you also upgrade to Electron 12 at the same time as upgrading ember-electron? Because in Electron 12 context isolation is enabled by default. That would mean that you could require "normal" node modules, but not electron itself.

You are correct that the method you are using is Electron's recommendation, and probably the best way to go for your application.

Now that context isolation is enabled by default in the latest Electron, we should probably add some information about it the relevant ember-electron documentation section.

@dtolios would you mind trying a quick experiment, and roll back to the state where things weren't working, and then see if disabling context isolation fixes your issue? I'm 90% sure it will, but since this is a first-run experience for users of ember-electron, I'd love to triple check that it's the (only) issue you're seeing.

And thanks for bringing this to our attention!

from ember-electron.

dtolios avatar dtolios commented on June 15, 2024

Apologies for the delay. You were right about disabling context isolation @bendemboski

With electron 12, ember-electron 3.0.0, and the following browserWindow options, everything worked as before:

mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
    },
  });

We can close this issue since both solutions would work here, and hopefully if anyone else runs across this, the recommended "preload" script method helps point them in a direction where they don't need to requireNode in their apps!

from ember-electron.

bendemboski avatar bendemboski commented on June 15, 2024

@dtolios great, thanks a lot for confirming that! I've opened #769 updating the documentation to cover context isolation. If you see anything missing or any improvements that would have better helped you figure out what was going on, feel free to comment on that PR.

from ember-electron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.