~abcdw/rde-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH v2] rde: circadian: Pass in url for geolocation endpoint

Details
Message ID
<20240821063753.400804-1-jgart@dismail.de>
DKIM signature
pass
Download raw message
Patch: +17 -12
Co-authored-by: Andrew Tropin <andrew@trop.in>
---

Here's a v2 just putting the json parse in a separate variable within
the let* block.

all best,

jgart

 src/rde/features/emacs-xyz.scm | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/rde/features/emacs-xyz.scm b/src/rde/features/emacs-xyz.scm
index 12d68fba..0afece83 100644
--- a/src/rde/features/emacs-xyz.scm
+++ b/src/rde/features/emacs-xyz.scm
@@ -485,10 +485,12 @@ with references to researches.")))

(define* (feature-emacs-circadian
          #:key
          (emacs-circadian emacs-circadian))
          (emacs-circadian emacs-circadian)
          (geolocate-url #f))
  "Configure the circadian.el Emacs package for theme-switching
based on the time of the day."
  (ensure-pred file-like? emacs-circadian)
  (ensure-pred string? geolocate-url)

  (define emacs-f-name 'circadian)
  (define f-name (symbol-append 'emacs- emacs-f-name))
@@ -503,20 +505,23 @@ based on the time of the day."
          "Get current location coordinates through Mozilla's Geolocation API."
          (let ((response
                 (ignore-errors
                   (url-retrieve-synchronously
                    "https://location.services.mozilla.com/v1/geolocate?key=geoclue"
                    t))))
                  (url-retrieve-synchronously
                   ,geolocate-url
                   t))))
            (when response
              (with-current-buffer response
                (goto-char (point-min))
                (re-search-forward (rx bol "\n") nil t)
                (delete-region (point) (point-min))
                (let* ((location (car (cdr (json-parse-string
                                   (goto-char (point-min))
                                   (re-search-forward (rx bol "\n") nil t)
                                   (delete-region (point) (point-min))
                                   (let* ((json-data
                                           (json-parse-string
                                            (buffer-string)
                                            :object-type 'plist))))
                       (latitude (plist-get location :lat))
                       (longitude (plist-get location :lng)))
                  (cons longitude latitude))))))
                                            :object-type 'plist))
                                          (location
                                           (plist-get json-data :location))
                                          (latitude (plist-get location :lat))
                                          (longitude (plist-get location :lng)))
                                     (cons longitude latitude))))))

        (with-eval-after-load 'solar
          (let ((coordinates (rde-circadian--get-geolocation)))
-- 
2.45.2
Reply to thread Export thread (mbox)