Launch browser with a .desktop entry

Hi,

I’m not sure which plug to connect, but I’m maintaining a snap that is accessible through the browser only. I don’t want to ship a browser with the snap, since it’s mostly used on servers-systems.

But someone might try it out on their computer and I though it would be much more user-friendly to have a desktop entry, that would open the browser at the localhost:IP that it’s running on.

Is this possible? Tried to use x-www-browser http://localhost:IP in the Exec=-field, but it’s removed by snapd.

Is this possible? Do I need a particular interface for it?

If not possible, feel free to come with suggestions :slight_smile:

Happy weekend, Joachim

try to use xdg-open instead (it is shipped in the base snap) …

Hi @ogra, thanks for the suggestion. But could you elaborate a little? Should I make a new app in my snapcraft.yaml, call xdg-open as the command, and then reference this app in the Exec= of desktop-entry? E.g

app:
   open:
      command: xdg-open http://localhost:IP/

then in snap/gui/snap-name.desktop:

[Desktop Entry]
Name=Snap name
...
Exec=snap-name.open

Or should I be able to call xdg-open ... in the Exec=-field in the desktop entry directly? E.g:

[Desktop Entry]
Name=Snap name
...
Exec=xdg-open http://localhost:IP/

I’ve tried both without any success.

The first fails during build with Failed to generate snap metadata: The specified command 'xdg-open ...' defined in the app 'open' does not exist.

The second results in a desktop-file but the Exec=-field is removed.

iirc you’ll need to make an actual wrapper that ships with your snap and then calls xdg-open, something like

#!/bin/bash
xdg-open http://localhost:1234

Make sure this wrapper exists as an app definition in your snapcraft.yaml and then set exec= to the app that calls this wrapper.

I don’t think you can call xdg-open directly because it’s in the core/base snap, not your own and this trips things up.

This will also need the desktop interface plugged.

2 Likes