Gnus: Use new sleep library

* etc/NEWS: Announce.
* lisp/gnus/gnus-start.el: Don't require gnus-dbus.
(gnus-sleep-handler): New function.
(gnus-close-on-sleep): New variable.
(gnus-1): Add `gnus-sleep-handler' to
`system-sleep-event-functions' when `gnus-close-on-sleep' is
non-nil.
* doc/misc/gnus.texi: Update documentation.
This commit is contained in:
Morgan Smith 2026-01-20 15:18:33 -05:00 committed by Michael Albinus
parent d7c130972e
commit 984024daf3
3 changed files with 38 additions and 17 deletions

View file

@ -849,7 +849,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.
* System Sleep Integration:: Closing Gnus servers on system sleep.
* Other modes:: Interaction with other modes.
* Various Various:: Things that are really various.
@ -22712,7 +22712,7 @@ For instance, @code{nnir-notmuch-program} is now
* 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.
* System Sleep Integration:: Closing Gnus servers on system sleep.
* Other modes:: Interaction with other modes.
* Various Various:: Things that are really various.
@end menu
@ -26680,11 +26680,11 @@ 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
@node System Sleep Integration
@section System Sleep Integration
@c Section name changed from this in Emacs 31. @c
@c This anchor allows old links to continue working. @c
@anchor{D-Bus Integration}
@cindex system sleep
@cindex closing servers automatically
@cindex hung connections
@ -26692,13 +26692,10 @@ Server buffer (@pxref{Gnus Cloud Setup}).
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-@code{nil} value.
For more information about D-Bus and Emacs, @pxref{Top,,, dbus, D-Bus integration in Emacs}.
connections after the system resumes. Using the system sleep library,
Gnus can automatically close all server connections before the system
goes to sleep. To enable this, set @code{gnus-close-on-sleep} to a
non-@code{nil} value.
@node Other modes
@section Interaction with other modes

View file

@ -1967,6 +1967,14 @@ Gnus, see "(gnus) Symbolic Prefixes" in the Gnus manual.
---
*** Sorting selected groups is now possible with 'gnus-topic-mode'.
+++
*** System sleep integration is now independent of D-Bus.
The system sleep integration previously provided by customizing the
variable 'gnus-dbus-close-on-sleep' is now deprecated. A new system
using the builtin sleep library is now available by customizing
'gnus-close-on-sleep'. This will work on all systems that the sleep
library supports.
** Sieve
+++

View file

@ -31,7 +31,6 @@
(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")
@ -733,6 +732,22 @@ the first newsgroup."
;; Remove Gnus frames.
(gnus-kill-gnus-frames))
(defcustom gnus-close-on-sleep nil
"When non-nil, close Gnus servers on system sleep."
:type 'boolean
:group 'gnus-start)
(defun gnus-sleep-handler (sleep-event)
"Close connection to servers before system sleep.
See `gnus-close-on-sleep' to enable this functionality.
SLEEP-EVENT is checked to ensure this is only run before sleep."
(when (and (eq 'pre-sleep (sleep-event-state sleep-event))
(gnus-alive-p))
(condition-case nil
(gnus-close-all-servers)
(error nil))))
(defun gnus-no-server-1 (&optional arg child)
"Read network news.
If ARG is a positive number, Gnus will use that as the startup
@ -800,8 +815,9 @@ 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))
(when gnus-close-on-sleep
(add-hook 'system-sleep-event-functions
#'gnus-sleep-handler))
(gnus-start-draft-setup)
;; Generate the group buffer.
(gnus-group-list-groups level)