Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening File with Extension in Electron

I'm trying to make it so when a .ito file is clicked on my electron application opens and does something. I'm using electron-builder as my build system and see that it specifies a fileAssociations field in the configuration documentation. The issue I'm having is that it doesn't seem to be documented what function this calls in the application.

I've gone through all the documentation and tried implementing icpMain event listeners but couldn't find the name of the listener I was looking for.

like image 318
Jake Sylvestre Avatar asked Dec 08 '25 20:12

Jake Sylvestre


1 Answers

I cannot exactly answer your question, since I don't need to set file associations in my Electron apps, but, on macOS, I've been able to have some code called when force-dropping a file from the Finder (with both Option and Command keys pressed) on my app icon in the Dock.

On macOS, you have to listen to the app event open-file from the main process.

From a renderer process, making use of remote, this code works for me:

require('electron').remote.app.on('open-file', (event, path) =>
{
    event.preventDefault();
    console.log(path);
});

On Windows, it seems that you have to parse process.argv to get the file path.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!