emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/bluetooth fa3761da3c 21/32: add timer to periodically u


From: Stefan Kangas
Subject: [elpa] externals/bluetooth fa3761da3c 21/32: add timer to periodically update the device table in discovery mode
Date: Mon, 3 Jan 2022 15:11:08 -0500 (EST)

branch: externals/bluetooth
commit fa3761da3cda33c59634faa90a16f74945efe10e
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>

    add timer to periodically update the device table in discovery mode
    
    * bluetooth.el (bluetooth-update-interval): new customization option
---
 bluetooth.el | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/bluetooth.el b/bluetooth.el
index aafd77b98d..51b6e33840 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -58,6 +58,10 @@ This is usually `:system' if bluetoothd runs as a system 
service, or
 `:session' if it runs as a user service."
   :type '(symbol))
 
+(defcustom bluetooth-update-interval 2
+  "Update interval of the device list view."
+  :type '(natnum))
+
 (defgroup bluetooth-faces nil
   "Faces used by Bluetooth mode."
   :group 'faces)
@@ -221,17 +225,27 @@ profiles."
        (command-execute #'bluetooth-disconnect)))
 
 
-(defmacro bluetooth-defun-method (method api docstring)
+(defmacro bluetooth-defun-method (method api docstring &rest body)
   (declare (doc-string 3) (indent 2))
   (let ((name (bluetooth--function-name method)))
        `(defun ,(intern name) () ,docstring
                        (interactive)
-                       (bluetooth--dbus-method ,method ,api))))
+                       (bluetooth--dbus-method ,method ,api)
+                       ,@body)))
+
+(defvar bluetooth--update-timer nil
+  "The bluetooth device table update timer.")
 
 (bluetooth-defun-method "StartDiscovery" :adapter
-  "Start discovery mode.")
+  "Start discovery mode."
+  (setq bluetooth--update-timer
+               (run-at-time nil bluetooth-update-interval
+                                        #'bluetooth--update-list)))
+
 (bluetooth-defun-method "StopDiscovery" :adapter
-  "Stop discovery mode.")
+  "Stop discovery mode."
+  (cancel-timer bluetooth--update-timer))
+
 (bluetooth-defun-method "Pair" :device
   "Pair with device at point.")
 
@@ -539,11 +553,13 @@ This function only uses the first adapter reported by 
Bluez."
                                          "UnregisterAgent"
                                          :object-path bluetooth--own-path)
        (mapc #'dbus-unregister-object bluetooth--method-objects)
-       (dbus-unregister-object bluetooth--adapter-signal)))
+       (dbus-unregister-object bluetooth--adapter-signal)
+       (cancel-timer bluetooth--update-timer)))
 
 (defun bluetooth-unload-function ()
   "Clean up when the bluetooth feature is unloaded."
   (when (buffer-live-p (get-buffer bluetooth-buffer-name))
+       (cancel-timer bluetooth--update-timer)
        (kill-buffer bluetooth-buffer-name))
   nil)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]