~soapdog/fafi-browser

f1b17e0bbbd8b684dbfa1c86c189022ea959f59d — Andre Alves Garzia 4 years ago 040ed8e
adding preferences and bookmarks
6 files changed, 73 insertions(+), 10 deletions(-)

M CHANGELOG.md
M config.rkt
M main.rkt
M persist.rkt
M preferences.rkt
M window.rkt
M CHANGELOG.md => CHANGELOG.md +3 -0
@@ 1,6 1,9 @@
# Version 0.10

* Refactor to move low-level protocol implementations over to `protocols/`.
* Added preferences system.
  * "Homepage": sets which URL is used for the default homepage.
  * "Show aggregators in new tab": Adds popular aggregators to the empty new tab display.

# Version 0.9 (31/08/2020)


M config.rkt => config.rkt +0 -3
@@ 9,9 9,6 @@
(define issue-tracker "https://todo.sr.ht/~soapdog/racket-gemini")
(define kofi-link "https://ko-fi.com/andregarzia")


(define homepage (get-pref 'homepage))

(define version-information
  (format #<<version
~a ~a

M main.rkt => main.rkt +4 -1
@@ 2,10 2,13 @@

(require racket/cmdline
         "config.rkt"
         "persist.rkt"
         "window.rkt")
(define homepage (get-pref 'homepage))

(define (launch-fafi [capsules '()])
  (define capsule (if (null? capsules) homepage (car capsules))) 
  (define capsule (if (null? capsules) homepage (car capsules)))
  (load-bookmarks)
  (when (debug-mode?)
    (displayln (format "Fafi ~a Running in *debug mode*" program-version)))
  (initialize-window capsule))

M persist.rkt => persist.rkt +42 -1
@@ 1,6 1,8 @@
#lang racket/base

(require racket/file)
(require racket/file
         racket/port
         racket/serialize)

(provide (all-defined-out))



@@ 39,8 41,47 @@
;;;;;;;;;;;;;;;;;;;;;;;;;

(set-default-pref 'homepage "gemini://gemini.circumlunar.space")
(set-default-pref 'new-tab-section/aggregators #t)


;;;;;;;;;;;;;;;;;;;;;;;;
;;; BOOKMARKS SYSTEM
;;;;;;;;;;;;;;;;;;;;;;;;

(define bookmarks-file (build-path data-folder "bookmarks.rktd"))

(define bookmarks (make-parameter '()))

(serializable-struct bookmark
                     (url
                      title
                      tracking
                      favourite
                      last-checksum
                      tags
                      notes)
                     #:mutable
                     #:transparent)

(define (make-bookmark url [title ""] [tracking #f] [favourite #f] [last-checksum 0] [tags '()] [notes ""])
  (bookmark url title tracking favourite last-checksum tags notes))

(define (add-bookmark b)
  (let ([bs (bookmarks)])
    (bookmarks (append bs b))))

(define (save-bookmarks)
  (let ([s (serialize (bookmarks))])
    (with-output-to-file bookmarks-file
      (write (bookmarks))
      #:exists 'replace)))

(define (load-bookmarks)
  (let ([bs (if (file-exists? bookmarks-file)
                  (deserialize (port->string (open-input-file bookmarks-file)))
                  '())])
    (bookmarks bs)))
                      

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; MAIN (just help testing stuff)

M preferences.rkt => preferences.rkt +9 -1
@@ 12,7 12,8 @@
  (new vertical-panel%
       [parent preferences-window]
       [vert-margin 2]
       [horiz-margin 2]))
       [horiz-margin 2]
       [alignment '(left bottom)]))

(define homepage-field
  (new text-field%


@@ 20,6 21,12 @@
       [parent panel]
       [init-value (get-pref 'homepage)]))

(define new-tab-section/aggregators-checkbox
  (new check-box%
       [label "Show aggregators in new tab"]
       [parent panel]
       [value (get-pref 'new-tab-section/aggregators)]))

(define footer
  (new horizontal-panel%
       [parent preferences-window]


@@ 36,6 43,7 @@

(define (save-values b e)
  (set-pref 'homepage (send homepage-field get-value))
  (set-pref 'new-tab-section/aggregators (send new-tab-section/aggregators-checkbox get-value))
  (send preferences-window show #f))

(define save-button

M window.rkt => window.rkt +15 -4
@@ 9,6 9,7 @@
  "config.rkt"
  "utils.rkt" 
  "history.rkt"
  "persist.rkt"
  "preferences.rkt")

(provide initialize-window)


@@ 58,7 59,7 @@
           ((and meta? (eq? key-code 'right))
            (go-forward))
           ((eq? key-code 'home)
            (go-to-url homepage))
            (go-to-url (get-pref 'homepage)))
           ((and ctrl? (eq? key-code #\l))
            (send address-bar focus)
            (send (send address-bar get-editor) select-all))


@@ 145,7 146,7 @@
  (new button%
       [parent toolbar]
       [label "Home"]
       [callback (lambda (button event) (go-to-url homepage))]))
       [callback (lambda (button event) (go-to-url (get-pref 'homepage)))]))

(define new-tab-button
  (new button%


@@ 158,6 159,15 @@
  (set! url (url->string (ensure-absolute-url url current-url (url-scheme (string->url current-url)))))
  (send multi-transport fetch url current-url))

(define (new-tab-template)
  (let ([aggregators (if (get-pref 'new-tab-section/aggregators)
                         `((heading 1 "Aggregators")
                           (link "gemini://gemini.circumlunar.space/capcom/" "CAPCOM")
                           (link "gemini://rawtext.club:1965/~sloum/spacewalk.gmi" "Spacewalk"))
                         '())])
    (append aggregators)))
 

(define (new-tab [url #f])
  (send browser-tabs append "New Tab")
  (send browser-tabs set-selection (sub1 (send browser-tabs get-number)))


@@ 183,7 193,8 @@
      (send address-bar set-value ""))
  
  (cond [(not (false? (tab-content tab-n))) (send multi-renderer render (tab-mime tab-n) (tab-content tab-n))]
        [(not (false? (tab-url tab-n))) (send multi-transport fetch (tab-url tab-n))]))
        [(not (false? (tab-url tab-n))) (send multi-transport fetch (tab-url tab-n))]
        [else (send multi-renderer render "text/gemini" (new-tab-template))]))

(define (close-tab n)
  (when (> n 0)


@@ 309,7 320,7 @@
         [shortcut #\p]
         [callback (λ _ (show-preferences-window))]))

   (define file-menu-separator
  (define file-menu-separator
    (new separator-menu-item%
         [parent file-menu]))