如何在 snap 包限制内执行 gsettings

如何在 snap 包限制内执行 gsettings

我正在为我的应用程序构建一个 snap 包,该应用程序基于 Java,可从互联网下载壁纸。到目前为止一切顺利,但现在我添加了一个新功能来设置所选壁纸,但它不起作用。此功能是为 Unity 和 Gnome 3 桌面实现的,它们提供了一种通过 gsettings 命令行工具设置桌面壁纸的简便方法。

这样,执行gsettings 设置 org.gnome.desktop.background 图片 uri 文件://blablabla.jpg你可以直接更改桌面壁纸,我的基于java的应用程序正在使用这个工具和这个命令来实现这个目标。

首先,当我在 snap 包中测试 wallpaperdownloader 时,它抱怨说没有在 snap 中找到 gsettings 二进制文件。现在这个问题已经解决了,因为我已经包含了libglib2.0-bin作为阶段包。然而,它不起作用。我猜 snap 包中的 gsettings 无法操作 snap 之外的文件,我需要直接修改用户主目录中的那些文件。我能做到这一点吗,还是受到限制?

这些是 snapcraft.yaml 文件和 wallpaperdownloaded 启动时执行的脚本

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

墙纸下载器

#!/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

墙纸下载器

#!/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

相关内容