[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 585beb6: Add basic D-Bus integration to Gnus
From: |
Eric Abrahamsen |
Subject: |
master 585beb6: Add basic D-Bus integration to Gnus |
Date: |
Tue, 25 Aug 2020 13:34:55 -0400 (EDT) |
branch: master
commit 585beb6c12c82bb2a7f87905e1511c8346942d4a
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>
Add basic D-Bus integration to Gnus
* lisp/gnus/gnus-dbus.el: New library, registering a signal that
closes all Gnus servers when the system is going to sleep.
* lisp/gnus/gnus-start.el: Check new option
`gnus-dbus-close-on-sleep', and register the appropriate D-Bus signal
if it is non-nil.
* lisp/gnus/gnus.el: New gnus-dbus customization group.
* doc/misc/gnus.texi: Document.
---
doc/misc/gnus.texi | 22 ++++++++++++++++
etc/NEWS | 5 ++++
lisp/gnus/gnus-dbus.el | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
lisp/gnus/gnus-start.el | 3 +++
lisp/gnus/gnus.el | 4 +++
5 files changed, 102 insertions(+)
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 332926a..0bdc2fa 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -828,6 +828,7 @@ Various
* Spam Package:: A package for filtering and processing spam.
* The Gnus Registry:: A package for tracking messages by Message-ID.
* The Gnus Cloud:: A package for synchronizing Gnus marks.
+* D-Bus Integration:: Closing Gnus servers on system sleep.
* Other modes:: Interaction with other modes.
* Various Various:: Things that are really various.
@@ -22333,6 +22334,7 @@ to you, using @kbd{G b u} and updating the group will
usually fix this.
* Spam Package:: A package for filtering and processing spam.
* The Gnus Registry:: A package for tracking messages by Message-ID.
* The Gnus Cloud:: A package for synchronizing Gnus marks.
+* D-Bus Integration:: Closing Gnus servers on system sleep.
* Other modes:: Interaction with other modes.
* Various Various:: Things that are really various.
@end menu
@@ -26404,6 +26406,26 @@ CloudSynchronizationDataPack(TM)s. It's easiest to set
this from the
Server buffer (@pxref{Gnus Cloud Setup}).
@end defvar
+@node D-Bus Integration
+@section D-Bus Integration
+@cindex dbus
+@cindex D-Bus
+@cindex gnus-dbus
+@cindex system sleep
+@cindex closing servers automatically
+@cindex hung connections
+
+When using laptops or other systems that have a sleep or hibernate
+functionality, it's possible for long-running server connections to
+become ``hung'', requiring the user to manually close and re-open the
+connections after the system resumes. On systems compiled with D-Bus
+support (check the value of @code{(featurep 'dbusbind)}), Gnus can
+register a D-Bus signal to automatically close all server connections
+before the system goes to sleep. To enable this, set
+@code{gnus-dbus-close-on-sleep} to a non-nil value.
+
+For more information about D-Bus and Emacs, @pxref{Top,,, dbus, D-Bus
integration in Emacs}.
+
@node Other modes
@section Interaction with other modes
diff --git a/etc/NEWS b/etc/NEWS
index d03153c..2f8e5eb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -296,6 +296,11 @@ tags to be considered as well.
** Gnus
+++
+*** New option 'gnus-dbus-close-on-sleep'
+On systems with D-Bus support, it is now possible to register a signal
+to close all Gnus servers before the system sleeps.
+
++++
*** The key binding of 'gnus-summary-search-article-forward' has changed.
This command was previously on 'M-s' and shadowed the global 'M-s'
search prefix. The command has now been moved to 'M-s M-s'. (For
diff --git a/lisp/gnus/gnus-dbus.el b/lisp/gnus/gnus-dbus.el
new file mode 100644
index 0000000..b6e8bb9
--- /dev/null
+++ b/lisp/gnus/gnus-dbus.el
@@ -0,0 +1,68 @@
+;;; gnus-dbus.el --- DBUS integration for Gnus -*- lexical-binding: t;
-*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Eric Abrahamsen <eric@ericabrahamsen.net>
+
+;; This program 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.
+
+;; This program 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 this program. 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 :session
+ "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
diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el
index ba8b91b..fe600f1 100644
--- a/lisp/gnus/gnus-start.el
+++ b/lisp/gnus/gnus-start.el
@@ -31,6 +31,7 @@
(require 'gnus-range)
(require 'gnus-util)
(require 'gnus-cloud)
+(require 'gnus-dbus)
(autoload 'message-make-date "message")
(autoload 'gnus-agent-read-servers-validate "gnus-agent")
(autoload 'gnus-agent-save-local "gnus-agent")
@@ -798,6 +799,8 @@ prompt the user for the name of an NNTP server to use."
(gnus-run-hooks 'gnus-setup-news-hook)
(when gnus-agent
(gnus-request-create-group "queue" '(nndraft "")))
+ (when gnus-dbus-close-on-sleep
+ (gnus-dbus-register-sleep-signal))
(gnus-start-draft-setup)
;; Generate the group buffer.
(gnus-group-list-groups level)
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index cecf4d4..f615d49 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -292,6 +292,10 @@ is restarted, and sometimes reloaded."
:link '(custom-manual "(gnus)Exiting Gnus")
:group 'gnus)
+(defgroup gnus-dbus nil
+ "D-Bus integration for Gnus."
+ :group 'gnus)
+
(defconst gnus-version-number "5.13"
"Version number for this version of Gnus.")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 585beb6: Add basic D-Bus integration to Gnus,
Eric Abrahamsen <=