From ba2af5010bdd4eafab38153daa043873bcf728cc Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 18 Mar 2026 08:57:06 +0100 Subject: [PATCH] Documentation and refinement --- example1/example.rkt | 5 +- private/racket-webview.rkt | 3 +- private/wv-context.rkt | 2 +- private/wv-settings.rkt | 3 ++ private/wv-window.rkt | 22 +++++---- rktwebview_qt/rktwebview.cpp | 56 ++-------------------- scrbl/wv-settings.scrbl | 92 ++++++++---------------------------- 7 files changed, 47 insertions(+), 136 deletions(-) diff --git a/example1/example.rkt b/example1/example.rkt index 01d6c57..a946d30 100644 --- a/example1/example.rkt +++ b/example1/example.rkt @@ -317,6 +317,9 @@ (let* ((ini (new ini% [file 'web-racket-example1])) (context (new wv-context% [base-path cur-dir] [ini ini])) (window (new example-1-window% - [wv-context context])) + [wv-context context] + [title "This is an example1 window"] + ) + ) ) window)) diff --git a/private/racket-webview.rkt b/private/racket-webview.rkt index 3a4e6d4..292d8a1 100644 --- a/private/racket-webview.rkt +++ b/private/racket-webview.rkt @@ -110,8 +110,9 @@ wv-context-base-url wv-win-window-nr + wv-context? - test + ;test ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/private/wv-context.rkt b/private/wv-context.rkt index 9cee471..47c4f29 100644 --- a/private/wv-context.rkt +++ b/private/wv-context.rkt @@ -14,7 +14,7 @@ [file-getter (webview-standard-file-getter base-path)] [context-js (λ () "")] [boilerplate-js (webview-default-boilerplate-js context-js)] - [ini (error "You need to provide a 'ini' file settings interface for settings, e.g. simple-ini")] + [ini (error "You need to provide a 'ini' file settings interface for settings, e.g. simple-ini/class")] ) (define wv-context #f) diff --git a/private/wv-settings.rkt b/private/wv-settings.rkt index 5b4baa9..9b6cbc1 100644 --- a/private/wv-settings.rkt +++ b/private/wv-settings.rkt @@ -31,6 +31,9 @@ (define/public (clone context) (new wv-settings% [ini ini] [wv-context context])) + (define/public (context) + wv-context) + (super-new) ) ) diff --git a/private/wv-window.rkt b/private/wv-window.rkt index f3c3bb3..77cf0e9 100644 --- a/private/wv-window.rkt +++ b/private/wv-window.rkt @@ -57,9 +57,10 @@ [height #f] [x #f] [y #f] - [wv #f] ) + (define wv #f) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Administration ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -304,6 +305,9 @@ ) ) + (define/public (set-title! title) + (webview-set-title! wv title)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Files / Directories ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -418,14 +422,16 @@ ;; Create window (write (list wv-context html-path event-handler parent)) (newline) - (set! wv (webview-create - (send wv-context context) - html-path - event-handler - #:parent (if (eq? parent #f) - #f - (get-field wv parent)))) + (let ((wv-parent (if (eq? parent #f) #f (hash-ref (send parent info) 'wv)))) + (set! wv (webview-create + (send wv-context context) + html-path + event-handler + #:parent wv-parent))) + ;; Set title + (send this set-title! title) + ;; Move and resize window to settings (send this init-size) ) diff --git a/rktwebview_qt/rktwebview.cpp b/rktwebview_qt/rktwebview.cpp index 1dd867e..9dfa0ae 100644 --- a/rktwebview_qt/rktwebview.cpp +++ b/rktwebview_qt/rktwebview.cpp @@ -17,78 +17,28 @@ uint64_t current_ms() { // Main C Interface ///////////////////////////////////////////////////////////////////// -//static int pipefd[2]; -//static bool started = false; -//static pid_t webview_process; -//static bool cannot_fork_or_pipe = false; - Rktwebview_qt *handler = nullptr; -void destroyApp() -{ - if (handler != nullptr) { - QCoreApplication *app = QApplication::instance(); - if (app != nullptr) { - app->exit(0); - delete app; - } - } -} - void rkt_webview_cleanup() { if (handler != nullptr) { - - rkt_webview_process_events(100); - - //QTimer app_quit; - //QObject::connect(&app_quit, &QTimer::timeout, handler->app(), &QApplication::quit, Qt::ConnectionType::QueuedConnection); - - //app_quit.setSingleShot(true); - //app_quit.start(250); - - //handler->app()->exec(); - - //fprintf(stderr, "cleanup: handler = %p\n", handler); - - // TODO - // Do not delete the QApplication, although it will result in QThreadStorage warnings. - // If the app is deleted, QtWebEngineProfileBuilder->createProfile will memory corrupt. - //handler->deleteApp(); - - //delete handler; - //handler = nullptr; - - //fprintf(stderr, "cleanup: handler = %p\n", handler); + // Does nothing. + // See QTBUG-145033 + // QtWebEngine cannot be started as part of QApplication more than once in an application run. } } void rkt_webview_init() { if (handler == nullptr) { - //fprintf(stderr, "init: handler = %p\n", handler); handler = new Rktwebview_qt(); - //fprintf(stderr, "init: handler = %p\n", handler); - atexit(destroyApp); } if (handler->app() == nullptr) { handler->initApp(); - - //QTimer app_exit; - //QObject::connect(&app_exit, &QTimer::timeout, handler->app(), []() { - // handler->app()->exit(0); - //}, Qt::ConnectionType::QueuedConnection); - - //app_exit.setSingleShot(true); - //app_exit.start(250); - - //QApplication *a = handler->app(); - //a->exec(); } } - rkt_wv_context_t rkt_webview_new_context(const char *boilerplate_js, const char *optional_server_cert_pem) { rkt_webview_init(); diff --git a/scrbl/wv-settings.scrbl b/scrbl/wv-settings.scrbl index fa270e6..a047baf 100644 --- a/scrbl/wv-settings.scrbl +++ b/scrbl/wv-settings.scrbl @@ -9,113 +9,61 @@ racket/file) ) -@defmodule[wv-settings] +@defmodule[racket-webview] @title{Object-Oriented Interface: @racket[wv-settings%]} @author[@author+email["Hans Dijkema" "hans@dijkewijk.nl"]] @defclass[wv-settings% object% ()]{ -An OO wrapper around a settings backend implementing the -@racket[simple-ini/class] interface. - +An OO wrapper around a settings backend implementing, e.g. @racket[simple-ini/class]. A @racket[wv-settings%] object represents a view on one settings section. The supplied @racket[wv-context] value is used as the section identifier for -context-local settings. - -The class delegates all actual storage operations to the supplied +context-local settings. The class delegates all actual storage operations to the supplied @racket[ini] object. @defconstructor[([ini object?] - [wv-context any/c])]{ -Creates a new settings object. - -The @racket[ini] argument is the backing settings object. - + [wv-context symbol?])]{ +Creates a new settings object. The @racket[ini] argument is the backing settings object. The @racket[wv-context] argument is used as the section identifier for -context-local settings. - -The class assumes that @racket[ini] supports methods compatible with: +context-local settings. The class assumes that @racket[ini] supports methods compatible with: @itemlist[#:style 'compact @item{@racket[(send ini get section key)]} @item{@racket[(send ini get section key default)]} @item{@racket[(send ini set! section key value)]} ] - -In typical use, @racket[ini] is an instance of a class from -@racket[simple-ini/class]. } -@defmethod*[([(get [key any/c]) any/c] - [(get [key any/c] [default-value any/c]) any/c])]{ -Returns the value associated with @racket[key] in the current section. - -Without a default value, this method delegates to: - -@racketblock[ -(send ini get wv-context key) -] - -With a default value, it delegates to: - -@racketblock[ -(send ini get wv-context key default-value) -] +@defmethod*[([(get [key symbol?]) any/c] + [(get [key symbol?] [default-value any/c]) any/c])]{ +Returns the value associated with @racket[key] in the current section. +Returns @tt{default-value} (when supplied) if the key is not found. } -@defmethod*[([(set! [key any/c] [value any/c]) this])]{ +@defmethod*[([(set! [key symbol?] [value any/c]) this])]{ Stores @racket[value] under @racket[key] in the current section. - -This method delegates to: - -@racketblock[ -(send ini set! wv-context key value) -] } -@defmethod*[([(get/global [key any/c]) any/c] - [(get/global [key any/c] [default-value any/c]) any/c])]{ +@defmethod*[([(get/global [key symbol?]) any/c] + [(get/global [key symbol?] [default-value any/c]) any/c])]{ Returns the value associated with @racket[key] in the global section. - -Without a default value, this method delegates to: - -@racketblock[ -(send ini get 'global key) -] - -With a default value, it delegates to: - -@racketblock[ -(send ini get 'global key default-value) -] +This method delegates to @tt{(send ini get 'global key default-value)}. } -@defmethod*[([(set/global! [key any/c] [value any/c]) this])]{ -Stores @racket[value] under @racket[key] in the global section. - -This method delegates to: - -@racketblock[ -(send ini set! 'global key value) -] +@defmethod*[([(set/global! [key symbol?] [value any/c]) this])]{ +Stores @racket[value] under @racket[key] in the global section. +Delegates to @tt{(send ini set! 'global key value)}. } @defmethod*[([(clone [context any/c]) (is-a?/c wv-settings%)])]{ Creates a new @racket[wv-settings%] object using the same -@racket[ini] backend but another section identifier. - -This method is equivalent to: - -@racketblock[ -(new wv-settings% [ini ini] [wv-context context]) -] - +@racket[ini] backend but with another section identifier. It is intended to support cheap creation of per-section settings views. } -@defmethod*[([(context) any/c])]{ +@defmethod*[([(context) symbol?])]{ Returns the section identifier associated with this settings object. } -} ; end class \ No newline at end of file +} \ No newline at end of file