给 org-pomodoro 增加桌面通知功能

org-notify不是第三方包吗?

org-mode 自带

引用哪个包?

org-notify恐怕是不行哦

(defun org-notify (notification &optional play-sound)
  "Send a NOTIFICATION and maybe PLAY-SOUND.
If PLAY-SOUND is non-nil, it overrides `org-clock-sound'."
  (org-show-notification notification)
  (if play-sound (org-clock-play-sound play-sound)))

使用了org-show-notification,而它又是这样定义的:

(defun org-show-notification (notification)
  "Show notification.
Use `org-show-notification-handler' if defined,
use libnotify if available, or fall back on a message."
  (cond ((functionp org-show-notification-handler)
	 (funcall org-show-notification-handler notification))
	((stringp org-show-notification-handler)
	 (start-process "emacs-timer-notification" nil
			org-show-notification-handler notification))
	((fboundp 'notifications-notify)
	 (notifications-notify
	  :title "Org mode message"
	  :body notification
	  ;; FIXME how to link to the Org icon?
	  ;; :app-icon "~/.emacs.d/icons/mail.png"
	  :urgency 'low))
	((executable-find "notify-send")
	 (start-process "emacs-timer-notification" nil
			"notify-send" notification))
	;; Maybe the handler will send a message, so only use message as
	;; a fall back option
	(t (message "%s" notification))))

可能最后只能用message来显示消息了

在 windows 10 上测试通过,如图:

Snipaste_2020-06-17_22-14-02

1赞

我比较好奇为什么能够成功。。

能够检查一下这些值么:

  1. 看一下org-show-notification-handler的值是什么
  2. (fboundp 'notifications-notify)的结果是什么
  3. (executable-find "notify-send")的结果是什么
Debugger entered--Lisp error: (dbus-error "Emacs not compiled with dbus support")
  signal(dbus-error ("Emacs not compiled with dbus support"))
  dbus-call-method(:session "org.freedesktop.Notifications" "/org/freedesktop/Notifications" "org.freedesktop.Notifications" "Notify" :string "Emacs" :uint32 0 :string "d:/emacs27/share/emacs/28.0.50/etc/images/icons/hi..." :string "Org mode message" :string "message!" (:array) ((:dict-entry "urgency" (:variant :byte 0))) :int32 -1)
  notifications-notify(:title "Org mode message" :body "message!" :urgency low)
  org-show-notification("message!")
  org-notify("message!")
  (progn (org-notify "message!"))
  eval((progn (org-notify "message!")) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

看来不行,windows 7 可以装dbus吗?还是要重新编译?

org-show-notification-handler 的是nil

org-show-notification-handler is a variable defined in ‘org-clock.el’.
Its value is nil

  You can customize this variable.

(fboundp 'notifications-notify) 返回 t (executable-find “notify-send”) 返回nil

和 楼上的结果一样

震惊!原来 Windows 10 有 DBUS 支持了

懒得弄了,反正可以曲线救国

;; 添加finished hooks
 (add-hook 'org-pomodoro-finished-hook
 	(lambda ()
 	  (w32-shell-execute "open" "f://bz.jpg")))
 (add-hook 'org-pomodoro-break-finished-hook
 	(lambda ()
 	  (w32-shell-execute "open" "f://bk.jpg")))
 (add-hook 'org-pomodoro-long-break-finished-hook
 	(lambda ()
 	  (w32-shell-execute "open" "f://bz.jpg")))

在windows下直接重新做一个alert包让org-pomodoro包含进去,就可以使用了,看源码org-pomodoro只在一个地方调用alert函数。

(require 'cl-lib)

(defvar *alert-id* nil)

(cl-defun alert (message &key (severity 'normal) title icon category
                      buffer mode data style persistent never-persist
                      id)
  "docstring"
  (when *alert-id*
    (w32-notification-close *alert-id*))
  (setq *alert-id* (w32-notification-notify :title title :body message)))

刚刚自己测试一下,可以收到通知。

如果使用dwm窗口管理器,notify-send 会不能弹出通知窗口,安装了notification-daemon这个包就可以弹出了

在 win10 上测试过,org-notify 确实可以使用,非常感谢