[Emacs] Use DBus calls instead of shell commands

This commit is contained in:
Lucien Cartier-Tilet 2021-12-27 13:43:59 +01:00
parent 91b06ee7b1
commit 1f38d7a68c
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -3620,12 +3620,17 @@ human-friendly name."
#+end_src #+end_src
#+begin_src emacs-lisp #+begin_src emacs-lisp
(require 'dbus)
(defun bluetooth-get-devices () (defun bluetooth-get-devices ()
(let ((literal-devices (string-trim (shell-command-to-string (let ((bus-list (dbus-introspect-get-node-names :system "org.bluez" "/org/bluez/hci0")))
(concat bluetooth-command " devices")))))
(mapcar (lambda (device) (mapcar (lambda (device)
(create-bluetooth-device device)) `(,(dbus-get-property :system
(split-string literal-devices "\n")))) "org.bluez"
(concat "/org/bluez/hci0/" device)
"org.bluez.Device1"
"Alias")
. ,device))
bus-list)))
#+end_src #+end_src
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -3634,10 +3639,15 @@ human-friendly name."
(progn (progn
(bluetooth-turn-on) (bluetooth-turn-on)
(let* ((devices (bluetooth-get-devices)) (let* ((devices (bluetooth-get-devices))
(target-device (completing-read "Device: " (device (alist-get (completing-read "Device: " devices)
devices)) devices nil nil #'string=)))
(target-address (cdr (assoc target-device devices)))) (dbus-call-method-asynchronously
(shell-command (mapconcat #'identity `(,bluetooth-command "connect" ,target-address) " "))))) :system "org.bluez"
(concat "/org/bluez/hci0" device)
"org.bluez.Device1"
"Connect"
(lambda (&optional msg)
(when msg (message "%s" msg)))))))
#+end_src #+end_src
** Making my life easier ** Making my life easier