有一种方法可以用 Gconf 注册 URL 协议处理程序,现在已经过时了,而且似乎无法用 DConf(或 Gsettings,它推荐的包装器)来做同样的事情。
自 DConf 以来,如何正确注册 URL 协议处理程序?
此外,在我的 Ubuntu 12.04 上,有些东西对我来说看起来很奇怪(因为我不明白)
该协议apt://
应由apturl
命令处理。我的 Opera 浏览器也是如此,但这只是因为我使用浏览器的配置工具添加了这个特定的关联。否则,在其余环境中:
xdg-open apt://foo.bar
打开elinks
(我的www-browser
选择)。gnome-open apt://foo.bar
打开软件?中心。gconf-editor
,我看到一个键,/desktop/gnome/url-handlers/apt
其值为apturl "%s"
并且已启用。这种配置似乎被忽略了,这是合理预期的,因为 GConf 被认为已过时。dconf-editor
,我看不到任何与 URL 处理程序或协议相关的内容/desktop/gnome
我的眼睛看起来有点乱(只是用这个措辞开玩笑,没什么不好的)
下面是什么?
旁注:我正在寻找即使在未加载完整桌面环境的情况下也能最好工作的东西,例如在运行 i3wm 会话时只gsettings-daemon
加载(以及与此案例无关的其他内容)。
“注册”协议处理程序的另一种方法是使用*.desktop
文件及其 MIME 类型;例如MimeType=application/<the-protocol>;
。
我找到了一个/usr/share/applications/ubuntu-software-center.desktop
有这个内容的:
[Desktop Entry]
Name=Ubuntu Software Center
GenericName=Software Center
Comment=Lets you choose from thousands of applications available for Ubuntu
Exec=/usr/bin/software-center %u
Icon=softwarecenter
Terminal=false
Type=Application
Categories=PackageManager;GTK;System;Settings;
MimeType=application/x-deb;application/x-debian-package;x-scheme-handler/apt;
StartupNotify=true
X-Ubuntu-Gettext-Domain=software-center
Keywords=Sources;PPA;Install;Uninstall;Remove;Purchase;Catalogue;Store;
Run Code Online (Sandbox Code Playgroud)
这解释了为什么gnome-open apt://foo.bar
打开 Software?Center 而不是apturl
。
所以我安装了这个apturl.desktop
在~/.local/share/applications
:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/usr/bin/apturl %u
Name=APT?URL
Comment=APT?URL handler
Icon=
Categories=Application;Network;
MimeType=x-scheme-handler/apt;
Run Code Online (Sandbox Code Playgroud)
之后update-desktop-database
,甚至重新启动后,无论是xdg-open
和gnome-open
仍然做同样忽略此用户的桌面文件,它像往常一样与用户桌面?文件,应该重写那个在/usr/share/applications/
。
也许指定x-scheme-handler
MIME 类型的桌面文件有一些特殊之处,并且它们没有以通常的方式处理。
桌面?文件方式不回答问题。
小智 13
打开~/.local/share/applications/mimeapps.list
并添加如下一行:
x-scheme-handler/apt=apturl.desktop
Run Code Online (Sandbox Code Playgroud)
Pab*_*chi 11
xdg-mime
也许更优雅(在本例中,我使用"apt",将其更改为任何其他方案):
/usr/share/applications/defaults.list
。apt.desktop
文件(这里有一些示例)添加到~/.local/share/applications/
(用户范围)或/usr/share/applications/
(系统范围)。sudo
):update-desktop-database
xdg-mime default apt.desktop x-scheme-handler/apt
Run Code Online (Sandbox Code Playgroud)
这会将方案的新 MIME 类型附加到~/.config/mimeapps.list
或~/.local/share/applications/mimeapps.list
。您可以为系统上的所有用户注册新的 MIME 类型sudo xdg-mime install --mode system <xml file>
。
另请参阅添加 MIME 类型。