Meteor-desktop setAsDefaultProtocolClient for external links

Hello, I was wondering if anyone has done it before, found several examples on regular electron apps, but having trouble on figuring out how it has to be done using meteor-desktop, already tried following https://www.electronjs.org/docs/api/protocol but couldn’t make it work as all custom code should go inside .desktop/desktop.js which abstracts all of electron internal workings if I’m correct.

Added also this to the builderOptions

"protocols": [
            {
                "name": "my protocol",
                "role": "Viewer",
                "schemes": [
                    "myprotocol"
                ]
            }
        ]

then on desktop.js I tried the following, but its not working when trying to open a link with myprotocol://test

eventsBus.on('beforeLoadFinish', () => {
            app.setAsDefaultProtocolClient('myprotocol')
        });

        app.on('open-url', function (event, url) {
            event.preventDefault()
            console.log(`url triggered on procotol: ${url}`);
        });

Tried building as well as I read somewhere that it only works on built apps and not on development FYI.

Thank you

Hey,

please provide target platform(s), meteor-desktop, electron, electron-builder versions.

On Mac it will definitely not work when just running npm run desktop. Like you said you need to build the app.

constructor in desktop.js

        app.setAsDefaultProtocolClient('myprotocol')

        app.on('open-url', function (event, url) {
            event.preventDefault()
            log.info(`url triggered on procotol: ${url}`);
        });

npm run desktop -- build-installer
cd ".desktop-installer/mac/My Meteor App.app/Contents/MacOS"
./My\ Meteor\ App

in other terminal open myprotocol://test

I can see:
info: [desktop] url triggered on procotol: myprotocol://test

Haven’t tested on Windows. The docs are saying it should work there without building the app.

1 Like

Thanks for the response Bartosz!

Platforms: Windows/Mac/Linux
meteor-desktop: 2.2.5
electron: 6.1.7
electron-builder: 21.2.0

I’m currently testing on Linux, so that might be also the problem, will test the code on the constructor for windows on a vm and report.

Thank you!