桌面菜单、.desktop 文件和 xdg-desktop-menu

发布于 2024-10-07 06:09:46 字数 846 浏览 0 评论 0原文

/usr/share/applications 中的 .desktop 文件、xdg-desktop-menu 命令和 update-desktop-database 命令之间有什么关系?

我正在尝试制作一个为我的应用程序创建桌面图标的 RPM。在 RPM 中,我将供应商应用程序名称.desktop 文件安装到 /usr/share/applications 中。然后我有以下安装后脚本:

if [ -x "`which xdg-desktop-menu 2>/dev/null`" ]; then
    xdg-desktop-menu install $RPM_BUILD_ROOT/usr/share/applications/vendor-myapp.desktop
fi

if [ -x "`which update-desktop-database 2>/dev/null`" ]; then
    update-desktop-database &> /dev/null || :
fi

并且未创建图标。 运行该命令,则会创建该图标

xdg-desktop-menu install $RPM_BUILD_ROOT/usr/share/applications/vendor-myapp.desktop

如果我稍后以非 root 身份手动 。如果我以 root 身份执行此操作(据说 RPM 就是这样做的),则不会创建图标。另外,我非常怀疑 if[] 位下的 update-desktop-database 未执行。当我手动运行整个 if[] 语句时,它会被执行。

Fedora Linux 与 Gnome。

What's the relationship between .desktop files in the /usr/share/applications, the xdg-desktop-menu command and update-desktop-database command?

I'm trying to make a RPM that creates a desktop icon for my app. In the RPM, I install the vendor-appname.desktop file into /usr/share/applications. Then I have the following post-install script:

if [ -x "`which xdg-desktop-menu 2>/dev/null`" ]; then
    xdg-desktop-menu install $RPM_BUILD_ROOT/usr/share/applications/vendor-myapp.desktop
fi

if [ -x "`which update-desktop-database 2>/dev/null`" ]; then
    update-desktop-database &> /dev/null || :
fi

And the icon is not created. The icon IS created if I run the

xdg-desktop-menu install $RPM_BUILD_ROOT/usr/share/applications/vendor-myapp.desktop

command manually later on, as a non-root. If I do so as a root (which is, supposedly, how the RPM does it), the icon is not created. Also, I have a very strong suspicion that the update-desktop-database under if[] bit is not executed. It is executed when I manually run the whole if[] statement.

Fedora Linux with Gnome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

输什么也不输骨气 2024-10-14 06:09:46

在 Fedora 上,请确保:

BuildRequires: desktop-file-utils
Requires(post): desktop-file-utils
Requires(postun): desktop-file-utils

然后(%{SOURCE1} 是您的桌面文件):

%install
[...]
desktop-file-install                                    \
--dir=${RPM_BUILD_ROOT}%{_datadir}/applications         \
%{SOURCE1}
[...]

%post
update-desktop-database &> /dev/null || :

%postun
update-desktop-database &> /dev/null || :

如果您安装自己的图标,您还需要更新图标缓存,在相关规范文件部分中添加:

%post
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :

%postun
if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :

参考:

On Fedora, be sure of:

BuildRequires: desktop-file-utils
Requires(post): desktop-file-utils
Requires(postun): desktop-file-utils

Then (%{SOURCE1} is your desktop file):

%install
[...]
desktop-file-install                                    \
--dir=${RPM_BUILD_ROOT}%{_datadir}/applications         \
%{SOURCE1}
[...]

%post
update-desktop-database &> /dev/null || :

%postun
update-desktop-database &> /dev/null || :

If you install your own icon, you also need to update the icon cache, adding in the relative specfile sections:

%post
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :

%postun
if [ $1 -eq 0 ] ; then
    touch --no-create %{_datadir}/icons/hicolor &>/dev/null
    gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi

%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :

Refs:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文