Comments (9)
@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.
@dtolios did you follow all the instructions here? https://ember-electron.js.org/docs/guides/upgrading
from ember-electron.
I did run that, but to verify I also spun up a new ember app doing the following:
- Opened terminal in my projects/ dir
- ran
ember new ember-electron-test
- ran
ember install ember-electron
- added the webPreferences with nodeIntegration to my main.js file
- added a component which called requireNode("electron")
- ran
ember electron
- 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.
What file are you using requireNode
in?
from ember-electron.
It was a component file located in:
app/
components/
my-button.js
from ember-electron.
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.
@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.
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.
@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)
- Custom electronProjectPath HOT 9
- Blank app and errors when running the packaged app in a fresh project HOT 5
- Consider returning `window` from `openTestWindow`
- Idiomatic way to open a route in a new window? HOT 7
- `electron` command doesn't work under `ember-cli` v4.9
- Installing ember-electron in new project it fails
- protocol.interceptFileProtocol is not a function HOT 5
- Q: Compatibility with typescript HOT 10
- make fails: Expected buildPath to be an absolute path HOT 9
- Missing docs
- Installing electron deps with PNPM doesn't work HOT 4
- Electron does not start with electron-is-dev 3.0.0+ HOT 2
- Brand new app can't launch due to improper use of `electron-is-dev` HOT 4
- ember electron:publish HOT 4
- Can't use requireNode from render process HOT 4
- Migrate Windows tests to GH actions
- Should use full path to `node` for launcher HOT 3
- VS Code Debugging HOT 5
- Issue with shim loading on windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-electron.