Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda