1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
;;; gnus-dbus.el --- DBUS integration for Gnus -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2025 Free Software Foundation, Inc.
;; Author: Eric Abrahamsen <eric@ericabrahamsen.net>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library contains some Gnus integration for systems using DBUS.
;; At present it registers a signal to close all Gnus servers before
;; system sleep or hibernation.
;;; Code:
(require 'gnus)
(require 'dbus)
(declare-function gnus-close-all-servers "gnus-start")
(defcustom gnus-dbus-close-on-sleep nil
"When non-nil, close Gnus servers on system sleep."
:group 'gnus-dbus
:type 'boolean)
(defvar gnus-dbus-sleep-registration-object nil
"Object returned from `dbus-register-signal'.
Used to unregister the signal.")
(defun gnus-dbus-register-sleep-signal ()
"Use `dbus-register-signal' to close servers on sleep."
(when (featurep 'dbusbind)
(setq gnus-dbus-sleep-registration-object
(dbus-register-signal :system
"org.freedesktop.login1"
"/org/freedesktop/login1"
"org.freedesktop.login1.Manager"
"PrepareForSleep"
#'gnus-dbus-sleep-handler))
(gnus-add-shutdown #'gnus-dbus-unregister-sleep-signal 'gnus)))
(defun gnus-dbus-sleep-handler (sleep-start)
;; Sleep-start is t before sleeping.
(when (and sleep-start
(gnus-alive-p))
(condition-case nil
(gnus-close-all-servers)
(error nil))))
(defun gnus-dbus-unregister-sleep-signal ()
(condition-case nil
(dbus-unregister-object
gnus-dbus-sleep-registration-object)
(wrong-type-argument nil)))
(provide 'gnus-dbus)
;;; gnus-dbus.el ends here
|