
Ich erstelle ein Snap-Paket für meine Anwendung, das Java-basiert ist und Hintergrundbilder aus dem Internet herunterlädt. So weit, so gut, aber jetzt füge ich eine neue Funktion hinzu, um das ausgewählte Hintergrundbild festzulegen, und es funktioniert nicht. Diese Funktion ist für Unity- und Gnome 3-Desktops implementiert, die eine einfache Möglichkeit bieten, das Desktop-Hintergrundbild über das Befehlszeilentool gsettings festzulegen.
Auf diese Weise wird die Ausführunggsettings set org.gnome.desktop.background Bild-URI Datei://blablabla.jpgSie können das Desktop-Hintergrundbild direkt ändern und meine Java-basierte Anwendung verwendet dieses Tool und diesen Befehl, um dieses Ziel zu erreichen.
Als ich Wallpaperdownloader in einem Snap-Paket testete, beschwerte es sich, weil es die Gsettings-Binärdatei im Snap nicht finden konnte. Jetzt ist es behoben, weil ich Folgendes eingefügt habe:libglib2.0-binals Stage-Paket. Trotzdem funktioniert es nicht. Ich vermute, dass gsettings im Snap-Paket keine Dateien außerhalb des Snaps bearbeiten kann und ich diese Dateien direkt im Home-Verzeichnis des Benutzers ändern muss. Kann ich das erreichen oder ist es eingeschränkt?
Dies sind die Dateien snapcraft.yaml und das Skript, das ausgeführt wird, wenn wallpaperdownloaded gestartet wird
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
PS: Ich habe die Plugins „gsettings“ und „unity7“ ausprobiert, aber sie haben nicht funktioniert, obwohl ich sie nur in die Datei „snapcraft.yaml“ aufgenommen und keine Optimierungen/Konfigurationen vorgenommen habe.
Vielen Dank,
Eloy
Antwort1
Endlich habe ich dieses Problem gelöst. Der Trick besteht darin,geinstellungenSchnittstelle und Snapcraft-Desktop-Helpers-Teil aus dem Wiki (Desktop/Gtk3). Dies sind die Hauptdateien. Ich habe sie veröffentlicht, nur für den Fall, dass sie anderen bei der Lösung eines ähnlichen Problems helfen.
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