Reputation: 1670
When a user double clicks on a file with an extension of cmf
, I would like to automatically launch the Electron application that I've built. I've been searching around and I've seen several mentions of the electron-builder
but no examples of how this can be used to create this association.
Upvotes: 1
Views: 173
Reputation: 18487
You want to look at the protocol functionality. I don't have enough experience with it to understand the finer points: like which app takes precedence if multiple app register the same protocol. Some of that might be user-defined.
const { app, protocol } = require('electron')
const path = require('path')
app.on('ready', () => {
protocol.registerFileProtocol('atom', (request, callback) => {
const url = request.url.substr(7)
callback({ path: path.normalize(`${__dirname}/${url}`) })
}, (error) => {
if (error) console.error('Failed to register protocol')
})
})
Upvotes: 1