Library
Index
Webviews
Webviews.Consts.WindowSizeHint
Webviews.Webview
Base.bind
Base.close
Base.resize!
Base.run
Webviews.API.bind_raw
Webviews.API.clear_timeout
Webviews.API.destroy
Webviews.API.dispatch
Webviews.API.eval!
Webviews.API.html!
Webviews.API.init!
Webviews.API.navigate!
Webviews.API.return_raw
Webviews.API.set_timeout
Webviews.API.terminate
Webviews.API.title!
Webviews.API.unbind
Webviews.API.window_handle
Public Interface
Webviews
— ModuleWebviews
Julia wrappers for webview, a tiny cross-platform webview library.
Webviews.Webview
— TypeWebview(
size=(1024, 768);
title="",
debug=false,
size_fixed=false,
unsafe_window_handle=C_NULL,
enable_webio=true,
auto_terminate=true
)
Webview(width, height; kwargs...)
Create a new webview instance with size
and title
.
- If
debug
is true, developer tools will be enabled (if the platform supports them). - UNSAFE
unsafe_window_handle
can be an unsafe pointer to the platforms specific native window handle.
If it's non-null - then child WebView is embedded into the given parent window. Otherwise a new window is created. Depending on the platform, a GtkWindow
, NSWindow
or HWND
pointer can be passed here.
- If
enable_webio
is true, then WebIO will be enabled. - The process will be terminated when all webviews with
auto_terminate=true
are destroyed.
Webviews.Consts.WindowSizeHint
— TypeWindowSizeHint
Enum to specify the window size hint. Values:
WEBVIEW_HINT_NONE
: Width and height are default size.WEBVIEW_HINT_MIN
: Width and height are minimum bounds.WEBVIEW_HINT_MAX
: Width and height are maximum bounds.WEBVIEW_HINT_FIXED
: Window size can not be changed by a user.
Base.run
— Methodrun(w::Webview)
Runs the webview event loop. Runs the main event loop until it's terminated. After this function exits, the webview is automatically destroyed.
Note: This function will show all webview windows that were created.
Webviews.API.terminate
— Functionterminate()
Stops the main loop. It is safe to call this function from another other background thread.
Base.close
— Methodclose(w::Webview)
Closes the webview window.
Webviews.API.destroy
— Functiondestroy(w::Webview)
Destroys the webview and closes the window along with freeing all internal resources.
Webviews.API.dispatch
— Functiondispatch(f::Function, w::Webview)
Posts a function to be executed on the main thread. You normally do not need to call this function, unless you want to tweak the native window.
The function f
should be callable without arguments.
Webviews.API.window_handle
— Functionwindow_handle(w::Webview)
UNSAFE An unsafe pointer to the webviews platform specific native window handle. When using GTK backend the pointer is GtkWindow
pointer, when using Cocoa backend the pointer is NSWindow
pointer, when using Win32 backend the pointer is HWND
pointer.
Webviews.API.title!
— Functiontitle!(w::Webview, title::AbstractString)
Sets the native window title.
Base.resize!
— Methodresize!(w::Webview, [size::Tuple{Integer, Integer}]; [hint::WindowSizeHint])
Sets the native window size.
Webviews.API.navigate!
— Functionnavigate!(w::Webview, url::AbstractString)
Navigates webview to the given URL. URL may be a data URI, i.e. "data:text/html,<html>...</html>"
.
Webviews.API.html!
— Functionhtml!(w::Webview, html::AbstractString)
html!(w::Webview, body)
Set webview HTML directly. If body
is not a string, such as a WebIO.Node
, it will be converted to HTML first.
Webviews.API.init!
— Functioninit(w::Webview, js::AbstractString)
Injects JavaScript code at the initialization of the new page. Every time the webview will open a the new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload
.
Webviews.API.eval!
— Functioneval!(w::Webview, js::AbstractString)
Evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also the result of the expression is ignored. Use bind
if you want to receive notifications about the results of the evaluation.
Webviews.API.bind_raw
— Functionbind_raw(f::Function, w::Webview, name::AbstractString)
Binds a callback so that it will appear in the webview with the given name as a global async JavaScript function. Callback receives a seq and req value. The seq parameter is an identifier for using Webviews.return_raw
to return a value while the req parameter is a string of an JSON array representing the arguments passed from the JavaScript function call.
The callback function must has the method f(seq::String, req::String)
.
Base.bind
— Methodbind(f::Function, w::Webview, name::AbstractString)
Binds a callback so that it will appear in the webview with the given name as a global async JavaScript function. Callback arguments are automatically converted from json to as closely as possible match the arguments in the webview context and the callback automatically converts and returns the return value to the webview.
The callback function must handle a Tuple
as its argument.
Webviews.API.unbind
— Functionunbind(w::Webview, name::AbstractString)
Unbinds a previously bound function freeing its resource and removing it from the webview JavaScript context.
Webviews.API.return_raw
— Functionreturn_raw(w::Webview, seq::String, success::Bool, result_or_err)
Allows to return a value from the native binding. Original request pointer must be provided to help internal RPC engine match requests with responses.
Webviews.API.set_timeout
— Functionset_timeout(f::Function, w::Webview, interval::Real; [repeat::Bool=false])
Sets a function to be called after the given interval in webview's event loop. If repeat
is true
, f
will be called repeatedly. The function f
should be callable without arguments.
This function returns a timer_id::Ptr{Cvoid}
which can be used in clear_timeout(webview, timer_id)
.
Webviews.API.clear_timeout
— Functionclear_timeout(w::Webview, timer_id::Ptr{Cvoid})
Clears a previously set timeout.