~abcdw/rde-devel

rde: circadian: Pass in url for geolocation endpoint v3 APPLIED

jgart: 1
 rde: circadian: Pass in url for geolocation endpoint

 1 files changed, 12 insertions(+), 8 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/54600/mbox | git am -3
Learn more about email & git

[PATCH v3] rde: circadian: Pass in url for geolocation endpoint Export this patch

Co-authored-by: Andrew Tropin <andrew@trop.in>
---

Here's a v3 with the code formatted.

all best,

jgart

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

diff --git a/src/rde/features/emacs-xyz.scm b/src/rde/features/emacs-xyz.scm
index 12d68fba..3f41800b 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,21 +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
                                            (buffer-string)
                                            :object-type 'plist))))
                (let* ((json-data
                        (json-parse-string
                         (buffer-string)
                         :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)))
            (setq calendar-longitude (if coordinates (car coordinates) 0))
-- 
2.45.2