advancedwebview

package module
v0.0.0-...-54faef0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2022 License: MIT Imports: 12 Imported by: 0

README

Advanced Webview

The goal of Advanced Webview is to improve the webview go module to allow for easier creation of go UI applications.

Development

This repo is still very under development though it is at the moment perfectly functional and should be stable unless major changes in Webview or Go permit otherwise in the future.

Concepts

Threading

The Webview has to be run in the main go thread which creates limitations coming into it without prior knowledge. In order to minimize these problems I have made the function passed to Run operate in a second go thread which will allow for proper operation of gofuncs and keep the UI from ever locking up under normal operation.

Events

Often there are common events that an application would be interested in understanding for optimization, backgrounding, and normal operations. While browsers allow the ability to identify and trigger functions on these events, Webview does not have any event handling shorthand for translating these into Go, so here they are.

Html

Webview based applications often do not load websites but have internal html, css, and JS to construct their own in-app experience. This makes it a bit easier and allows for more pre-structured html-based coding of internal app pages.

Webview

https://github.com/webview/webview/

Documentation

Index

Constants

View Source
const (
	HintNone  = webview.HintNone
	HintMax   = webview.HintMax
	HintMin   = webview.HintMin
	HintFixed = webview.HintFixed
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventHandler

type EventHandler interface {
	// Type returns the type of event this handler belongs to.
	Type() EventType

	// Handle is called whenever an event of Type() happens.
	// It is the receivers' responsibility to type assert that the interface
	// is the expected struct.
	Handle(webview *Webview)
}

type EventType

type EventType int
const (
	EventTypeWindowFocus EventType = iota
	EventTypeWindowBlur
	EventTypeWindowEnter
	EventTypeWindowLeave
	EventTypeWindowResize
)

type Hint

type Hint webview.Hint

type Page

type Page struct {
	Template *template.Template
}

func ParsePage

func ParsePage(pageDirectory string, funcMap template.FuncMap) (page *Page, err error)

func (Page) Execute

func (page Page) Execute(data any) (string, error)

type Webview

type Webview struct {
	Webview webview.WebView
	// contains filtered or unexported fields
}

func New

func New(debug bool) *Webview

New Creates a gofunc/threading safe thread-alone webview and window

debug: If debug is non-zero - developer tools will be enabled (if the platform supports them)

func (Webview) Bind deprecated

func (webview Webview) Bind(name string, f interface{}) error

Bind binds a callback function so that it will appear under the given name as a global JavaScript function. Internally it uses webview_init(). Callback receives a request string and a user-provided argument pointer. Request string is a JSON array of all the arguments passed to the JavaScript function.

f must be a function f must return either value and error or just error

Deprecated: Drop-in support

func (Webview) Destroy deprecated

func (webview Webview) Destroy()

Destroy Does nothing as destroying is handled internally

Deprecated: Doesn't do anything, just for drop-in support

func (Webview) Dispatch deprecated

func (webview Webview) Dispatch(f func())

Dispatch 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.

Deprecated: Doesn't do anything, just for drop-in support

func (Webview) Eval

func (webview Webview) Eval(js string)

Eval evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also the result of the expression is ignored. Use RPC bindings if you want to receive notifications about the results of the evaluation.

func (Webview) Init

func (webview Webview) Init(js string)

Init injects JavaScript code at the initialization of the new page. Every time the webview will open a new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload. Appends to the init code.

func (Webview) Navigate

func (webview Webview) Navigate(uri string)

Navigate navigates webview to the given URI. URI may be a data URI, i.e. "data:text/html,<html>...</html>". It is often ok not to url-encode it properly, webview will re-encode it for you.

func (Webview) OnEvent

func (webview Webview) OnEvent(handler interface{})

OnEvent adds an event handler on a specific type of event and runs the handler in a go func

func (*Webview) Run

func (webview *Webview) Run(f func(webview *Webview))

Run Sets the webview to run in a standalone thread and handles destruction of the webview. f: An arbitrary function to run in a new thread, use WaitForClose in the thread.

Blocking but you can call WaitForClose in other functions, thread safe

func (Webview) SetSize

func (webview Webview) SetSize(w int, h int, hint webview.Hint)

SetSize updates native window size. See Hint constants.

func (Webview) SetTitle

func (webview Webview) SetTitle(title string)

SetTitle updates the title of the native window. Must be called from the UI thread.

func (Webview) Terminate

func (webview Webview) Terminate()

Terminate stops the main loop. It is safe to call this function from a background thread.

Nothing after this is called is guaranteed to run, use WaitForClose to confirm completion of tasks.

func (Webview) Visualize

func (webview Webview) Visualize(rawHtml string)

Visualize expects raw html "<html>...</html>".

func (*Webview) WaitForClose

func (webview *Webview) WaitForClose() (safeToClose chan<- interface{})

WaitForClose Waits for the webview window to be closed before returning, can be called as much as wanted.

Returns safeToClose which is a channel waiting for the first message sent to determine if it is safe to close the window

safeToClose needs to be sent something in order for the main thread to continue after Run

func (Webview) Window deprecated

func (webview Webview) Window() unsafe.Pointer

Window returns a native window handle pointer. 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.

Deprecated: Drop-in support

type WindowBlur

type WindowBlur struct {
}

type WindowBlurEventHandler

type WindowBlurEventHandler func(webview *Webview, blur *WindowBlur)

func (WindowBlurEventHandler) Handle

func (i WindowBlurEventHandler) Handle(webview *Webview)

func (WindowBlurEventHandler) Type

type WindowEnterEventHandler

type WindowEnterEventHandler func(webview *Webview, enter *WindowMouseEnter)

func (WindowEnterEventHandler) Handle

func (i WindowEnterEventHandler) Handle(webview *Webview)

func (WindowEnterEventHandler) Type

type WindowFocus

type WindowFocus struct {
}

type WindowFocusEventHandler

type WindowFocusEventHandler func(webview *Webview, focus *WindowFocus)

func (WindowFocusEventHandler) Handle

func (i WindowFocusEventHandler) Handle(webview *Webview)

func (WindowFocusEventHandler) Type

type WindowLeaveEventHandler

type WindowLeaveEventHandler func(webview *Webview, leave *WindowMouseLeave)

func (WindowLeaveEventHandler) Handle

func (i WindowLeaveEventHandler) Handle(webview *Webview)

func (WindowLeaveEventHandler) Type

type WindowMouseEnter

type WindowMouseEnter struct {
}

type WindowMouseLeave

type WindowMouseLeave struct {
}

type WindowResize

type WindowResize struct {
}

type WindowResizeEventHandler

type WindowResizeEventHandler func(webview *Webview, resize *WindowResize)

func (WindowResizeEventHandler) Handle

func (i WindowResizeEventHandler) Handle(webview *Webview)

func (WindowResizeEventHandler) Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL