Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda