
我正在為我的應用程式建立一個基於 java 的 snap 包,並從互聯網下載壁紙。到目前為止一切順利,但現在我添加了一個新功能來設定所選的壁紙,但它不起作用。此功能是為 Unity 和 Gnome 3 桌面實現的,它們提供了一種透過 gsettings 命令列工具設定桌面桌布的簡單方法。
這樣,執行gsettings 設定 org.gnome.desktop.background 圖片-uri file://blablabla.jpg你可以直接改變桌面壁紙,我的基於java的應用程式正在使用這個工具和這個命令來實現這個目標。
首先,當我在快照包中測試wallpaperdownloader時,它抱怨因為它在快照中沒有找到gsettings二進位。現在它已經修復了,因為我已經包含了libglib2.0-bin作為舞台包。然而,它不起作用。我猜 snap 套件內的 gsettings 無法操作 snap 外部的文件,我需要直接修改使用者主目錄中的這些文件。我可以實現這個目標還是受到限制?
這些是檔案 snapcraft.yaml 和桌布下載啟動時執行的腳本
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
桌布下載器.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:我嘗試過 gsettings 和 unity7 插件,但它們不起作用,儘管我只將它們包含在 snapcraft.yaml 檔案中,並且沒有應用任何調整/配置。
非常感謝,
埃洛伊
答案1
最後,我解決了這個問題。訣竅是使用設定介面和 snapcraft-desktop-helpers 部分來自 Wiki (桌面/gtk3)。這些是主要文件。我發布它們只是為了防止它們對其他人解決類似問題有所幫助。
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
桌布下載器.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