Using xdg-open in a Snap Package to open external Url

Using xdg-open in a Snap Package to open external Url

126
0
SHARE

While packaging Ktube Media Downloader  for Ubuntu 16.04, I needed to make QDesktopServices::openUrl work in the sandboxed environment. Qt uses xdg-open, a script that tries to find the users default web browser, to open URLs on linux. This dosen’t work inside a snap since no browsers are installed.

The proper way to open URLs from a snap is by sending a DBus message. At first I thought I had to modify the application to achieve this, but I later realized that a “fake” xdg-open script is enough. There’s a github repo called snapd-xdg-open that provides a working script.

Below is a snippet that you can add to your snapcraft.yaml to install the fake script:

parts:  
  snapd-xdg-open:
    source: https://github.com/ubuntu-core/snapd-xdg-open.git
    plugin: copy
    files:
      data/xdg-open: bin/xdg-open
    stage-packages:
      - dbus
SHARE