85 lines
4.3 KiB
Text
85 lines
4.3 KiB
Text
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;; bjomarks-gui/tests/screenshots.bjo — the pictures of the Readme.
|
|
;;
|
|
;; bjo run tests/screenshots.bjo docs/window.png
|
|
;; bjo run tests/screenshots.bjo docs/edit.png edit
|
|
;; bjo run tests/screenshots.bjo /tmp/fetching.png fetching
|
|
;; bjo run tests/screenshots.bjo docs/unlock.png lock
|
|
;; bjo run tests/screenshots.bjo /tmp/help.png help # /tmp/help-help.png: docs/help.png
|
|
;;
|
|
;; Makes a vault of examples in the temp directory, and shows the window
|
|
;; already open on it, with the second bookmark chosen, or with the dialog
|
|
;; that edits it. The window saves a PNG of itself and closes, as
|
|
;; BJOGUI_SCREENSHOT makes it do; the dialog is saved beside it. Needs a
|
|
;; display.
|
|
|
|
(import (std prelude))
|
|
(import (std os))
|
|
(import (std datetime))
|
|
(import (bjogui app))
|
|
(import (bjomarks bookmark))
|
|
(import (bjomarks keys))
|
|
(import (bjomarks store))
|
|
(import (bjomarks-gui app))
|
|
|
|
(import/class
|
|
(UnionTheme (: AvaUnion.UnionTheme (-> UnionTheme))))
|
|
|
|
;; The last has no title, as a bookmark has before its title is fetched.
|
|
(: examples (Vec (Tuple string string (Option string) (Vec string) (Option string))))
|
|
(def examples
|
|
[(Tuple "2026-11-11T09:12:00Z" "https://doc.rust-lang.org/book/" (Some "The Rust Programming Language")
|
|
["rust" "docs"] (Some "https://web.archive.org/web/20261111/https://doc.rust-lang.org/book/"))
|
|
(Tuple "2026-11-10T18:40:00Z" "https://www.gnu.org/software/emacs/manual/" (Some "GNU Emacs Manuals Online")
|
|
["emacs" "docs"] None)
|
|
(Tuple "2026-11-09T07:05:00Z" "https://avaloniaui.net/" (Some "Avalonia UI") ["gui" "dotnet"] None)
|
|
(Tuple "2026-11-02T21:30:00Z" "https://libsodium.org/" (Some "libsodium") ["crypto"]
|
|
(Some "https://web.archive.org/web/20261102/https://libsodium.org/"))
|
|
(Tuple "2026-10-28T12:00:00Z" "https://syncthing.net/" None ["sync"] None)])
|
|
|
|
(: (-> Vault (Tuple string string (Option string) (Vec string) (Option string)) Vault))
|
|
(defun (add-example v example)
|
|
(def (Tuple added url title tags archive) example)
|
|
(def at (match (iso8601->instant added) ((Some i) i) (None (now))))
|
|
(match (vault-add v url #:title title #:tags tags #:archive archive #:added at)
|
|
((Ok (Tuple v2 _)) v2)
|
|
((Err why) (panic! why))))
|
|
|
|
(: (-> (Vec string) int))
|
|
(defun (main args)
|
|
(def shot (if (> (vec-length args) 0) (vec-ref args 0) "window.png"))
|
|
;; "edit": the dialog. "fetching": the dialog, as its title is fetched.
|
|
(def mode (if (> (vec-length args) 1) (vec-ref args 1) ""))
|
|
(def root (make-temp-directory #:prefix "bjomarks-shots-"))
|
|
(def storage (folder-storage (path-combine root "shared")))
|
|
(def local (path-combine root "local"))
|
|
(def made (match (create-vault storage local "pw" #:cost (KeyCost (iterations 1) (memory-kib 8)))
|
|
((Ok v) v)
|
|
((Err _) (panic! "the vault was not made"))))
|
|
(def v (vault-save (vec-fold (fun (e v) (add-example v e)) made examples)))
|
|
(def fresh (initial-model storage local))
|
|
(def start (record-set fresh (phase Open) (vault (Some v)) (selected 1) (status "Saved.")))
|
|
(def editing (fst (gui-update (Edit (.id (vec-ref (visible-bookmarks start) 1))) start)))
|
|
;; No fetch runs: the dialog is only told that one does.
|
|
(def model (match (Tuple mode (.draft editing))
|
|
((Tuple "edit" _) editing)
|
|
((Tuple "fetching" (Some d)) (record-set editing (draft (Some (record-set d (fetching (Some 1)))))))
|
|
;; The first screen of a device with no vault, and an empty
|
|
;; shared folder: a new vault. With settings, so that the
|
|
;; folder can be changed.
|
|
((Tuple "lock" _) (initial-model (folder-storage (path-combine root "new")) (path-combine root "device")
|
|
#:settings (path-combine root "config")))
|
|
;; The help window, beside the main one.
|
|
((Tuple "help" _) (record-set start (help #t)))
|
|
(_ start)))
|
|
(run-app model gui-update view
|
|
#:windows windows #:keys keys
|
|
#:themes (fun () (list (cast IStyle (UnionTheme.))))
|
|
#:title "Bjomarks" #:width 640.0 #:height 420.0
|
|
#:screenshot shot)
|
|
(vault-close v)
|
|
(directory-delete-tree root)
|
|
0)
|