be789ae0c7e95dd2cfa668db9ae5c2adfc34f0c3 — Nicolas Graves 22 days ago 8f7baa4
rde: librewolf: Generalize feature to firefox-based browsers

Signed-off-by: Andrew Tropin <andrew@trop.in>
1 files changed, 34 insertions(+), 21 deletions(-)

M src/rde/features/web-browsers.scm
M src/rde/features/web-browsers.scm => src/rde/features/web-browsers.scm +34 -21
@@ 1,6 1,7 @@
;;; rde --- Reproducible development environment.
;;; Copyright © 2023 Miguel Ángel Moreno <me@mianmoreno.com>
;;; Copyright © 2023, 2024 Nicolas Graves <ngraves@ngraves.fr>
;;; This file is part of rde.

@@ 172,64 173,76 @@ exec ~a ~a $@"
;; TODO: [Andrew Tropin, 2024-04-24] Use DNS over HTTPS by default
(define* (feature-librewolf
          (librewolf librewolf)
          (browser librewolf)
          (browser-name (match (package-name browser)
                          ("librewolf" "LibreWolf")
                          ("icecat" "IceCat")
                          ("icecat-minimal" "IceCat")
                          (name (string-capitalize name))))
          (bin-name (match (package-name browser)
                      ("icecat-minimal" "icecat")
                      (name name)))
          (default-browser? #t)
          (desktop-startup-flags '("")))
  "Configure the LibreWolf browser."
  (ensure-pred file-like? librewolf)
  "Configure a recent Firefox-based browser.  The option browser-name allows
to prettify the name for xdg-mime.  Defaults to LibreWolf.  Tested with IceCat
and Firefox."
  (ensure-pred file-like? browser)
  (ensure-pred string? browser-name)
  (ensure-pred string? bin-name)
  (ensure-pred boolean? default-browser?)
  (ensure-pred list-of-strings? desktop-startup-flags)

  (define f-name 'librewolf)
  (define f-name (string->symbol (package-name browser)))
  (define binary (file-append browser "/bin/" bin-name))

  (define librewolf-binary (file-append librewolf "/bin/librewolf"))
  (define (get-home-services config)
    "Return home services related to LibreWolf."
    (format #f "Return home services related to ~a." browser-name)
     (if default-browser?
           (symbol-append 'set- f-name '-as-default-browser)
           `(("BROWSER" . ,librewolf-binary)))
           `(("BROWSER" . ,binary)))
           (symbol-append f-name '-xdg-defaults)
              '((x-scheme-handler/http . librewolf.desktop)
                (x-scheme-handler/https . librewolf.desktop)
                (x-scheme-handler/about . librewolf.desktop)
                (text/html . librewolf.desktop))))))
              `((x-scheme-handler/http . ,(symbol-append f-name '.desktop))
                (x-scheme-handler/https . ,(symbol-append f-name '.desktop))
                (x-scheme-handler/about . ,(symbol-append f-name '.desktop))
                (text/html . ,(symbol-append f-name '.desktop)))))))
       (symbol-append 'add- f-name)
       (list librewolf))
       (list browser))
       (symbol-append 'add- f-name '-xdg-desktop-entry)
           (file "librewolf")
           (name "LibreWolf")
           (file (package-name browser))
           (name browser-name)
           (type 'application)
            `((exec . ,#~(string-join
                           #$@desktop-startup-flags "%U")))
              (terminal . #f)
              (comment . "Access the Internet")))))))))))

   (name f-name)
   (values `((,f-name . ,librewolf)
   (values `((,f-name . ,browser)
             ,@(if default-browser?
                   `((default-browser . ,librewolf-binary))
                   `((default-browser . ,binary))
   (home-services-getter get-home-services)))