Documentation and refinement

This commit is contained in:
2026-03-18 08:57:06 +01:00
parent 9bdc4ba894
commit ba2af5010b
7 changed files with 47 additions and 136 deletions

View File

@@ -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))

View File

@@ -110,8 +110,9 @@
wv-context-base-url
wv-win-window-nr
wv-context?
test
;test
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@@ -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)

View File

@@ -31,6 +31,9 @@
(define/public (clone context)
(new wv-settings% [ini ini] [wv-context context]))
(define/public (context)
wv-context)
(super-new)
)
)

View File

@@ -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)
)

View File

@@ -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();

View File

@@ -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
}