ubuntu20.04 gnome 似乎与emacs 不兼容导致 notifications-notify 不工作

重装了系统ubuntu20.04, 从源码重新编译了emacs27.1, 其它工作都正常,就是发现notifications-notify 不能正常工作了. 运行下面的代码,只是在minibuffer 输出一个id类的整数,没有弹出通知框,也没有发声音.

  1. 应该不是emacs27.1的问题,因为之前我在ubuntu18.04中同样方法编译过一次工作正常.
  2. 初步判断应该是少了一些包没有安装,但是查不到缺少那些包,不知道各位有没有建议?
  3. 看Elisp 文档, notifications-notify 在linux系统中不存在不支持D-Bus的情况,感觉应该不是D-Bus的问题 . 现在没有线索了…
(require 'org-clock)
(require 'notifications)
(notifications-notify
 :title "play sound"
 :sound-file "/path/to/sound.wav"
 )
;;; minibuffer 输出 302 (#o456, #x12e)

初步确定原因是 org.freedesktop.Notifications 这个服务没有启动, 理由是通过debug 发现notifications-notify 把通知的任务通过Dbus发送给了一个名字叫org.freedesktop.Notifications 的服务提供方, 但是这个服务并没有开启. 在/usr/share/dbus-1/services 目录下也确实没有这个服务:

   ca.desrt.dconf.service
  com.feralinteractive.GameMode.service
  io.snapcraft.Launcher.service
  io.snapcraft.Settings.service
  org.a11y.Bus.service
  org.bluez.obex.service
  org.fedoraproject.Config.Printing.service
  org.freedesktop.ColorHelper.service
  org.freedesktop.FileManager1.service
  org.freedesktop.IBus.service
  org.freedesktop.impl.portal.desktop.gtk.service
  org.freedesktop.impl.portal.PermissionStore.service
  org.freedesktop.impl.portal.Secret.service
  org.freedesktop.portal.Desktop.service
  org.freedesktop.portal.Documents.service
  org.freedesktop.portal.IBus.service
  org.freedesktop.secrets.service
  org.freedesktop.systemd1.service -> ../system-services/org.freedesktop.systemd1.service
  org.freedesktop.Tracker1.Miner.Extract.service
  org.freedesktop.Tracker1.Miner.Files.service
  org.freedesktop.Tracker1.service
  org.freedesktop.Tracker1.Writeback.service
  org.gnome.baobab.service
  org.gnome.Calculator.SearchProvider.service
  org.gnome.Calendar.service
  org.gnome.Characters.BackgroundService.service
  org.gnome.Characters.service
  org.gnome.Cheese.service
  org.gnome.ChromeGnomeShell.service
  org.gnome.ControlCenter.SearchProvider.service
  org.gnome.ControlCenter.service
  org.gnome.DejaDup.service
  org.gnome.DiskUtility.service
  org.gnome.evince.Daemon.service
  org.gnome.evolution.dataserver.AddressBook.service
  org.gnome.evolution.dataserver.Calendar.service
  org.gnome.evolution.dataserver.Sources.service
  org.gnome.evolution.dataserver.UserPrompter.service
  org.gnome.Extensions.service
  org.gnome.FileRoller.ArchiveManager1.service
  org.gnome.FileRoller.service
  org.gnome.font-viewer.service
  org.gnome.gedit.service
  org.gnome.Identity.service
  org.gnome.keyring.PrivatePrompter.service
  org.gnome.keyring.service
  org.gnome.keyring.SystemPrompter.service
  org.gnome.Logs.service
  org.gnome.Nautilus.service
  org.gnome.OnlineAccounts.service
  org.gnome.Rhythmbox3.service
  org.gnome.Rygel1.service
  org.gnome.Screenshot.service
  org.gnome.seahorse.Application.service
  org.gnome.Shell.CalendarServer.service
  org.gnome.Shell.Extensions.service
  org.gnome.Shell.HotplugSniffer.service
  org.gnome.Shell.Notifications.service
  org.gnome.Shell.PortalHelper.service
  org.gnome.Terminal.service
  org.gnome.Todo.service
  org.gnome.Totem.service
  org.gtk.GLib.PACRunner.service
  org.gtk.vfs.AfcVolumeMonitor.service
  org.gtk.vfs.Daemon.service
  org.gtk.vfs.GoaVolumeMonitor.service
  org.gtk.vfs.GPhoto2VolumeMonitor.service
  org.gtk.vfs.Metadata.service
  org.gtk.vfs.MTPVolumeMonitor.service
  org.gtk.vfs.UDisks2VolumeMonitor.service

问题是怎么启动这个服务呢?

  1. libnofity 已经安装,无效
### apt list | grep libnotify
libnotify-bin/focal,now 0.7.9-1ubuntu2 amd64 [installed]
libnotify-bin/focal 0.7.9-1ubuntu2 i386
libnotify-cil-dev/focal,focal 0.4.0~r3032-7build1 all
libnotify-dev/focal,now 0.7.9-1ubuntu2 amd64 [installed]
libnotify-dev/focal 0.7.9-1ubuntu2 i386
libnotify-doc/focal,focal,now 0.7.9-1ubuntu2 all [installed]
libnotify0.4-cil/focal,focal 0.4.0~r3032-7build1 all
libnotify3.0-cil-dev/focal,focal 3.0.3-3 all
libnotify3.0-cil/focal,focal 3.0.3-3 all
libnotify4/focal,now 0.7.9-1ubuntu2 amd64 [installed,automatic]
libnotify4/focal 0.7.9-1ubuntu2 i386
  1. notification-daemon 已经安装,无效

自问自答吧, 经过各种折腾, 还是没办法解决. 最终放弃ubuntu20.04, 退会18.04一切恢复正常.看来是ubuntu 20.04 在GNOME工作机制,特别是dbus服务方面根emacs并不太兼容. 总之,这次是跑的太快,掉坑里了 :joy:

我用linux mint 20一切正常。

linux mint 好像是cinnamon 桌面环境, ubuntu20.04是Gnome 3.xxx, 估计就是Gnome不兼容,至少它的桌面通知服务有点特殊,可能需要特别设置才能用.

装一下notify-osd

这个也装过, 也不行,涉及到dbus的一些协议,搞不懂.按道理说,GNOME是遵从这个协议的,即使不安装第三方软件,GNOME 自身就有这些桌面通知功能.

notify-send 测试也是很诡异, 重启电脑的时候可以发送通知, 过一会儿又不行了,需要sudo 才能.

notifications-notify 也很诡异, 也是重启的时候可以,但是不能发声音, 之后就没有任何反映了.

感觉好像有几个对协议的实现在竞争, 后来重装了ubuntu18.04没有任何问题. 后面大家有ubuntu20.04 notifications-notify 正常工作的也欢迎跟帖, 到时再测试一下.

这里记录一下这个bug, 确定根gnome有关,

(notifications-notify
      :title "some title"
      :urgency 'critical
      :sound-file file-of-sound-file
      :app-icon file-of-icon
      :timeout 3000
      )

问题出在 :sound-file 上, 估计是gnome3.36+ 的桌面通知在播放声音上有些问题, 如果有:sound-file 参数会导致通信卡死, 重启桌面, 去掉声音一切正常.

你可以用 aplay等外部程序来播放声音, 用起来问题不大.

同样遇到这个问题,我这边主要使用来通知番茄钟的开始和停止,我的环境是pop os 20.04 ,看了下代码notifications-notify调用的是notify-send,我的系统默认没安装,安装libnotify-bin 后已经恢复通知功能. 解决方法是在wiki里找到的