I used Electron Packager to build my application which has some initial data in a NeDB. But then the packager generates the db file alright without the data after I ran the .exe file that was created.
Related
I have an electron application that I'm packaging up with electron-builder.
Within that application there is a distribution of an exe that I want to be able to call from electron.
The build section of my package.json includes an asarUnpack property, like so:
"asarUnpack": [
"**/node_modules/dist-myexe.exe/**/*",
],
This means that when my application is installed, the exe is extracted under
C:\Program Files\MyElectronApp\resources\app.asar.unpacked\node_modules\myexe.exe\vendor\myexe.exe.
However, when I attempt to child-process.spawn on that exe, windows attempts to run a version from:
%APPDATA%\Local\Temp\par-blahblahblah\cache-blahblahblah\myexe.exe
I'm wondering if this is related to: https://github.com/electron/electron/issues/12092
Is this expected behaviour for electron apps? How can I target the exe that is in Program Files instead?
The exe I was trying to execute on was exiftool.exe, which is actually the culprit extracting to Temp, not electron.
I am using webpack-dev-server to build and serve an electron app. I am using the multi-target support so it builds and serves both the Renderer and Main files. These are available at http://localhost:8080/, in my case the Main entry point is http://localhost:8080/background.js, and the Renderer index.html is http://localhost:8080/ which loads http://localhost:8080/js/main.js.
webpack-dev-server only builds the files in memory - they are never written to disk. However Electron only seems to run its Main process from files on disk. I.e. if I run electron path/to/background.js it works fine, but that file doesn't exist when using webpack-dev-server. If I run electron http://localhost:8080/ it just loads the Renderer index.html and never runs background.js.
Basically I want to do
electron http://localhost:8080/background.js
and have it download and run that file as the Main process. That command doesn't work (it just opens the background.js file as text. Is there any way to achieve this short of doing it manually with curl or whatever?
I settled on a workaround - you can make webpack-dev-server serve its output from memory and write the files to disk. I added this to the webpack config for my Main process:
devServer: {
writeToDisk: true
}
Note that due to a bug you need to add it to your Renderer config too, even though you don't need those files, otherwise nothing gets written.
I’m having problems using pdfkit in Electron due to “fs.readFileSync is not a function” … how can i use fs library in Electron? I’ve read that is disabled for security reasons, but i would need it to be executed offline.
In Electron Framework as we know we have two type of process .
1.) Main Process
2.)Render Process
so main.js file which you passed to command electron main.js (Note:- while you are calling it with command line arguments ) so at this time electron will create 2 process . one is main process in which your main.js run and from that process it will launch your index.html file and scripts which you include in it in another render process.
so in that main.js file use the fs module like we do in the node.js using
const fs = require('fs');
fs.readFileSync()
and the data you get it here pass to the render process using interprocess communication provided by the Electron Framework using its APIs IPCRender IPCMain.
I'm creating a portable Electron app that writes some files to the program folder. It works pretty well when I package it without the --asar option in Electron-packager, which leaves the resources folder with plain html + js files.
Now when I try to compile it with the --asar option, so that it packages the resources folder into one file, I can't access the program directory any more with the following code:
remote.app.getAppPath()
This now returns the path of the asar file, so I can't really write to the application folder any more. Is there any way around this?
No, you cannot modify the asar of a running Electron app. You should be saving your config outside of the asar path.
In my Electron application, I have a button in which a user can click which triggers node's child_process and runs an external .jar file in the background:
exec(`java -jar encoder.jar -i filein -o fileout`, function(err, stdout, stderr)
The actual .jar file is located within the root directory of the project. When running in development mode(unpackaged) this works great. However, when I package it and run the application, I get the following error:
There was an error: Error: Unable to access jarfile encoder.jar
Am I to assume that everything in the project folder gets packaged when using electron-packager? If not, what am I missing?
look into process.resourcesPath