~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
1

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

Details
Message ID
<20240821183938.16051-1-jgart@dismail.de>
DKIM signature
pass
Download raw message
Patch: +12 -8
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
Details
Message ID
<87ikvs7ftp.fsf@trop.in>
In-Reply-To
<20240821183938.16051-1-jgart@dismail.de> (view parent)
DKIM signature
pass
Download raw message
On 2024-08-21 13:39, jgart wrote:

> 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."

Added a docstring about geolocate-url.

>    (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."

Updated docstring.

>            (let ((response
>                   (ignore-errors
> -                   (url-retrieve-synchronously
> -                    "https://location.services.mozilla.com/v1/geolocate?key=geoclue"
> -                    t))))
> +                  (url-retrieve-synchronously
> +                   ,geolocate-url
> +                   t))))

Merged into one line.

>              (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))

Thank you for the patch, applied, updated, pushed.

-- 
Best regards,
Andrew Tropin
Reply to thread Export thread (mbox)