URI Scheme Registration on Ubuntu/Linux


A similar issue to what I encountered on macOS is plaguing me on Ubuntu…

My issue is that when the SAFE Browser sends the ‘auth-response’ back to my application, it opens another instance of the application… Meaning the original version that tried to initializeApp never hears a response.

My code to do with the URI scheme is almost identical to what’s in this app…

I have tested it on Ubuntu and sure enough safe-app-base works perfectly. My app however…

… Doesn’t work. The only real difference I can see is that I am using electron-forge to orchestrate the running of the application. I fail to see though how this would break things. It is worth noting that my app exhibits this behaviour when ran through the command line. When packaged, it does hear the response back but I get a “Could not connect to the SAFE Network” error message. I am guessing these issues are interrelated. Things work perfectly on macOS so I am guessing this is an Ubuntu only issue. If anyone has any advice on how to fix this that would be amazing.


FYI - I’ve had some trouble running the email example before where the only way I could get it to work was to formally build the executable, then run the executable explicitly from the command line.


@DaBrown95, as @jlpell explains it, it has to do with how to launch the app in each case (unpackaged/packaged), and we’ve also been working on this to have our example apps to register the URI correctly in both cases. @hunterlester was able to fix it in the email app, but he is still working on getting it right for the WHM, perhaps he can share more details of it. You can also take a look at the master branch of the email app and see if that approach also works for your app.


@jlpell @bochaco Thank you so much for the quick replies.

Thanks for pointing me in that direction, I will take a look shortly… Hopefully the fix I am looking for is in there. The Email example app uses electron-forge too so that should be the most similar to mine.

@hunterlester is there anything specifically you can remember that had to be included to correct this functionality?


Try this:

On line 26 I added:

const cwd = process.cwd();
const electronExt = process.platform === 'win32' ? '.cmd' : '';

For customExecPath, I changed to:

customExecPath: isDevMode ? [`${cwd}/node_modules/.bin/electron${electronExt}`, `${cwd}`] : [app.getPath('exe')]

In ~/.local/share/applications/david-brown-safe-wiki.desktop, you should see:

  1 [Desktop Entry]
  2 Type=Application
  3 Name=SAFE-Wiki
  4 Exec="/home/<user>/path/to/safe-wiki/node_modules/.bin/electron" "/home/path/to/safe-wiki" %u
  5 Terminal=false
  6 MimeType=x-scheme-handler/safe-y29tlmvszwn0cm9ulnnhzmutd2lraq
  7 NoDisplay=true

I just fired up Ubuntu in a VM and that did the trick.


Amazing, Thank you so much @hunterlester! It now functions as expected which is awesome. :grinning: That fix even fixes the issue with running the app packaged which is awesome.

One strange thing though… When running the app through yarn start, On hearing the ‘auth-response’ I am presented with this error message…

I can actually ignore this error and the app appears to function normally. I did a little digging and came across this thread,

A user by the name of kivS suggested that the fix is as simple as using…

const shouldQuit = app.makeSingleInstance(() =>{
  if(mainWindow) mainWindow.show();
if(shouldQuit) app.exit();

app.exit() instead of app.quit(). I tried this and sure enough, it fixed the issue. Very strange. Just thought I would add this fix here for future reference. Looking at the Electron Documentation…

It looks like unless you properly handle the before-quit and will-quit event then using app.quit() then that might be what is causing the error message that I get.