yes kind of a duplicate but that code no longer works with my case.
So I'm building a photo viewer, and I want to be able to view files when an image file has been set to open as default with my program to open it, but I also have made custom window controls, it has images of course, addition to that the script listed at Opening files with electron messes up those images by reading them as the data sent from main.js and it messes things up
An image of how it looks when the app loads
if anyone could find out a work around that'll fix this it would be very appreciated, thanks.
I figured it out, and it took me forever to understand the documentation and what I was doing wrong!
the main problem was placement
main.js
this script actually would go in the function that creates the window instead of outside, so like:
let mainWindow;
function createWindow() {
// creating the window and specifying fields here
// mainWindow = new BrowserWindow({/*fields here*/});
// then adding the ipc listener here
ipcMain.on('get-file-data', function(event) {
var data = null
if (process.platform == 'win32' && process.argv.length >= 2) {
var openFilePath = process.argv[1];
data = openFilePath;
}
event.returnValue = data;
});
}
// then app.on listeners down here
renderer.js
const img = document.getElementById("image id");
var data = ipcRenderer.sendSync('get-file-data')
if (data === null) {
console.log("There is no file")
} else {
console.log(data);
img.src = data;
}