Not able to costomize the Exec field in desktop file

the desktop file is copied by snapcraft and customized e.g. Icon field is changed though the Exec field is not present, this leads to
destkop file didn't specify Exec field
when launched.

Opening the desktop file with a text editor shows all the fields are present, only Exec missing…
now actually what I want is Exec=xdg-open http://localhost:8000 which works well if I add this line to the desktop file after snap installation.

Is adding this simple line not possible with snapcraft? was reading everywhere that snapcraft is changing Exec= to the apps command name though in my case is even missing…
Are there workarounds?

In my case my app is a daemon (with a system tray icon):

...
icon: snap/gui/icon.png
apps:
  torch:
    command: opt/torch/bin/torch
    daemon: simple
    restart-condition: always
    plugs:
      - network
      - network-bind
      - home
      - desktop
      - desktop-legacy
...

desktop file:

[Desktop Entry]
Type=Application
Name=torch
GenericName=torch
Comment=iot
Exec=xdg-open http://localhost:8000
Icon=${SNAP}/meta/gui/icon.png
Categories=Utility;
Keywords=iot;
StartupNotify=false
Terminal=false

I’d like to launch the browser with the torch.desktop to reach the daemons GUI

Do you have anything else defined in apps besides daemon? My guess would be it’s removing Exec because it doesn’t have anything to actually launch. Add another entry in apps and use that entry in torch.desktop to launch daemons GUI.

...
apps:
  torch:
    command: xdg-open http://localhost:8000
  torch-daemon:
    command: opt/torch/bin/torch
    daemon: simple
    ...
1 Like

The Exec line needs to reference an app provided by your snap. That app could easily be a single line shell script that runs exec xdg-open http://localhost:8000.

The reason for the rewriting is to ensure that any code executed by a desktop file provided by your snap is appropriately sandboxed.

Following from @jamesh’s comment this is what your desktop file should look like:

[Desktop Entry]
Type=Application
Name=torch
GenericName=torch
Comment=iot
Exec=torch # I changed this line
Icon=${SNAP}/meta/gui/icon.png
Categories=Utility;
Keywords=iot;
StartupNotify=false
Terminal=false

Failed to generate snap metadata: The specified command ‘xdg-open http://localhost:8000’ defined in the app ‘torch’ is not executable.

:frowning:

if I use a shell script and add it to the snapcraft part install:

chmod +x ./open_browser.sh
cp ./open_browser.sh $SNAPCRAFT_PART_INSTALL/.
chmod +x $SNAPCRAFT_PART_INSTALL/open_browser.sh
mv $SNAPCRAFT_PART_INSTALL/open_browser.sh $SNAPCRAFT_PART_INSTALL/open_browser
chmod +x $SNAPCRAFT_PART_INSTALL/open_browser
ls -al $SNAPCRAFT_PART_INSTALL/
drwxr-xr-x 5 root root 4096 Sep 17 18:41 .
drwxr-xr-x 6 root root 4096 Sep 17 18:41 ..
drwxr-xr-x 2 root root 4096 Sep 17 18:41 bin
-rwxr-xr-x 1 root root  160 Sep 17 18:41 open_browser
drwxr-xr-x 3 root root 4096 Sep 17 18:41 opt
drwxr-xr-x 3 root root 4096 Sep 17 18:41 usr
Building part-info 
Staging torch 
Staging part-info 
Priming torch 
Priming part-info 
Failed to generate snap metadata: The specified command 'open_browser' defined in the app 'torch' is not executable.

ok, it seems like my part and my app have to have the same name…

not only missing a way to add xdg-open to my snap

if I do:
snap run --shell torch -c "xdg-open http://localhost:8000"

I get:
Error org.freedesktop.DBus.Error.ServiceUnknown: The name com.canonical.SafeLauncher was not provided by any .service files

If I do the same command above with another app that I created that have the same plugs but also extensions: [gnome-3-28] then it works.

there there a way to use xdg-open with cli apps that do not have any desktop extensions?