Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Opening files with electron from double click

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 loadsenter image description here

if anyone could find out a work around that'll fix this it would be very appreciated, thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!