0

I'm building a snap package for my application which is java-based and downloads wallpapers from the Internet. So far so good, but now I'm adding a new feature to set the wallpaper selected and it doesn't work. This feature is implemented for Unity and Gnome 3 desktops, which provide an easy way of setting desktop wallpaper via gsettings command line tool.

This way, executing gsettings set org.gnome.desktop.background picture-uri file://blablabla.jpg you can change the desktop wallpaper directly, and my java-based application is using this tool and this command to achieve this goal.

First, when I tested wallpaperdownloader within a snap package, it complained because it didn't find gsettings binary within the snap. Now it is fixed, because I have included libglib2.0-bin as a stage package. Nevertheless, it doesn't work. I guess gsettings inside snap package cannot manipulate files outside the snap, and I need to directly modify those files within user's home directory. Can I achive this or it is restricted?

These are the files snapcraft.yaml and the script executed when wallpaperdownloaded is launched

snapcraft.yml

name: wallpaperdownloader
version: "2.2"
summary: Download and manage your favorite wallpapers from the Internet
description: WallpaperDownloader is a simple GUI Java based application for downloading and managing wallpapers from the Internet
confinement: strict

apps:
  wallpaperdownloader:
    command: wallpaperdownloader.sh
    plugs: [x11, network-bind, home]

parts:
  # Pulls the code from the original source (master branch)
  wallpaperdownloader:
    plugin: maven
    source: .
    stage-packages:
      - libglib2.0-bin

  # It will copy wallpaperdownloader script into /bin/
  # This script contains all the commands needed (sets env variables, launches the jar file...) to
  # execute the application
  exec:
    plugin: copy
    files:
      wallpaperdownloader.sh: bin/wallpaperdownloader.sh

wallpaperdownloader.sh

#!/bin/sh
# Only for packaging!
# Script for snap packaging wallpaperdownloader application. It is not related to the code itself
# Not good, needed for fontconfig
export XDG_DATA_HOME=$SNAP/usr/share
# Font Config
export FONTCONFIG_PATH=$SNAP/etc/fonts/config.d
export FONTCONFIG_FILE=$SNAP/etc/fonts/fonts.conf
export HOME=$SNAP_USER_DATA
java -jar -Duser.home=$SNAP_USER_DATA $SNAP/jar/wallpaperdownloader.jar

P.S.: I've tried gsettings and unity7 plugins but they didn't work althoug I only included them in snapcraft.yaml file and I didn't apply any tweak/configuration.

Thank you very much,

Eloy

1

Finally, I solved this problem. The trick is to use gsettings interface and snapcraft-desktop-helpers part fromt the Wiki (desktop/gtk3). These are the main files. I published them just in case they are helpful for others to solve a similar problem.

snapcraft.yaml

name: wallpaperdownloader
version: "2.2"
summary: Download and manage your favorite wallpapers from the Internet
description: WallpaperDownloader is a simple GUI Java based application for downloading and managing wallpapers from the Internet
grade: stable
confinement: strict

apps:
  wallpaperdownloader:
    command: wallpaperdownloader.sh
    plugs: [x11, network-bind, home, gsettings]

parts:
  # Pulls the code from the original source (master branch)
  # desktop/gtk3 is a snapcraft part (snapcraft-desktop-helpers) from the Wiki: https://wiki.ubuntu.com/snapcraft/parts
  # It enables desktop integration and gsettings manipulation from the confined application
  # It is necessary to use gsettings interface (see above) in order to have a fully functional
  # desktop/gtk3 part
  # Github repository for snapcraft-desktop-helpers: https://github.com/ubuntu/snapcraft-desktop-helpers
  wallpaperdownloader:
    plugin: maven
    source: ..
    after: [desktop/gtk3]

  # It will copy wallpaperdownloader script into /bin/
  # This script contains all the commands needed (sets env variables, launches the jar file...) to
  # execute the application
  exec:
    plugin: dump
    source: scripts

wallpaperdownloader.sh

#!/bin/sh
# Only for packaging!
# Script for snap packaging wallpaperdownloader application. It is not related to the code itself
# Not good, needed for fontconfig
export XDG_DATA_HOME=$SNAP/usr/share
# Font Config
export FONTCONFIG_PATH=$SNAP/etc/fonts/config.d
export FONTCONFIG_FILE=$SNAP/etc/fonts/fonts.conf
export HOME=$SNAP_USER_DATA
desktop-launch java -jar -Duser.home=$SNAP_USER_DATA $SNAP/jar/wallpaperdownloader.jar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.