documentation

This commit is contained in:
2026-04-01 16:23:56 +02:00
parent 5ee62d0064
commit ab666368b1
27 changed files with 1080 additions and 164 deletions

View File

@@ -5,6 +5,7 @@
"utils.rkt"
"mimetypes.rkt"
"rgba.rkt"
"menu.rkt"
finalizer
racket/async-channel
web-server/http
@@ -73,6 +74,8 @@
webview-set-html!
webview-base-url
webview-set-menu!
webview-set-innerHTML!
webview-set-value!
@@ -105,6 +108,7 @@
webview-standard-file-getter
webview-default-boilerplate-js
webview-default-boilerplate-css
webview-version
webview-info
@@ -123,16 +127,38 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-runtime-path js-path "../js")
(define-runtime-path css-path "../js")
(define (webview-default-boilerplate-js . custom-js)
(let ((file (build-path js-path "boilerplate.js")))
(let ((bjs (file->string file)))
(let ((file (build-path js-path "boilerplate.js"))
(menu-js-file (build-path js-path "menu.js")))
(let ((bjs (file->string file))
(mjs (file->string menu-js-file))
)
(let ((js (string-append bjs
mjs
(if (null? custom-js)
""
((car custom-js))))))
js))))
(define (webview-default-boilerplate-css . custom-css)
(let ((file (build-path css-path "boilerplate.css"))
(menu-css-file (build-path css-path "menu.css")))
(let ((bcss (file->string file))
(mcss (file->string menu-css-file))
)
(let ((css (string-append bcss
mcss
(if (null? custom-css)
""
((car custom-css)))
)
)
)
css))))
(define-struct wv-context
([context #:mutable]
[port #:mutable]
@@ -142,6 +168,7 @@
[request-count #:mutable]
[sec-token-cache #:mutable]
[cert-ou-token #:mutable]
[boilerplate-css #:mutable]
)
#:transparent
)
@@ -153,16 +180,16 @@
)
#:transparent)
(define re_head #px"[<][/][Hh][eE][aA][dD][>]")
(define (process-html context path out)
(let ((html (file->string path)))
(display html out)))
; (boilerplate-js ((wv-context-boilerplate-js wv-win-handle))))
; (set! html (string-replace html "<head>"
; (string-append "<head>" "\n"
; "<script>" "\n"
; boilerplate-js "\n"
; "</script>" "\n")))
; (display html out)))
(let ((html* (regexp-replace re_head html
(string-append "<style>\n"
(wv-context-boilerplate-css context)
"\n</style>\n"
"</head>"))))
(display html* out))))
(define (process-file context ext path out)
(let ((content (file->bytes path)))
@@ -414,11 +441,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define/contract (webview-new-context file-getter
#:boilerplate-js [bj (webview-default-boilerplate-js)])
(->* (procedure?) (#:boilerplate-js string?) wv-context?)
#:boilerplate-js [bj (webview-default-boilerplate-js)]
#:boilerplate-css [bc (webview-default-boilerplate-css)])
(->* (procedure?) (#:boilerplate-js string? #:boilerplate-css string?) wv-context?)
(let* ((h (make-wv-context 0 0 file-getter #f #f 0
(make-lru 250 #:cmp eq?)
(symbol->string (make-security-token))
bc
))
(cert (generate-self-signed-cert 2048 365 '("127.0.0.1" "localhost")
"NL" "Dijkema"
@@ -497,6 +526,17 @@
)
)
(define/contract (webview-set-menu! wv menu)
(-> wv-win? is-wv-menu? symbol?)
(let* ((json (wv-menu->json menu))
(js (string-append "window._web_wire_menu('"
json
"');"))
)
(webview-run-js wv js)
)
)
(define (loglevel? x)
(and (symbol? x)
(or (eq? x 'error) (eq? x 'info) (eq? x 'debug) (eq? x 'warning))))