Documentation ¶
Overview ¶
Package webview implements Go bindings to https://github.com/zserge/webview C library.
Bindings closely repeat the C APIs and include both, a simplified single-function API to just open a full-screen webview window, and a more advanced and featureful set of APIs, including Go-to-JavaScript bindings.
The library uses gtk-webkit, Cocoa/Webkit and MSHTML (IE8..11) as a browser engine and supports Linux, MacOS and Windows 7..10 respectively.
Index ¶
Constants ¶
const ( // DialogFlagFile is a normal file picker dialog DialogFlagFile = C.WEBVIEW_DIALOG_FLAG_FILE // DialogFlagDirectory is an open directory dialog DialogFlagDirectory = C.WEBVIEW_DIALOG_FLAG_DIRECTORY // DialogFlagInfo is an info alert dialog DialogFlagInfo = C.WEBVIEW_DIALOG_FLAG_INFO // DialogFlagWarning is a warning alert dialog DialogFlagWarning = C.WEBVIEW_DIALOG_FLAG_WARNING // DialogFlagError is an error dialog DialogFlagError = C.WEBVIEW_DIALOG_FLAG_ERROR )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DialogType ¶
type DialogType int
DialogType is an enumeration of all supported system dialog types
const ( // DialogTypeOpen is a system file open dialog DialogTypeOpen DialogType = iota // DialogTypeSave is a system file save dialog DialogTypeSave // DialogTypeAlert is a system alert dialog (message box) DialogTypeAlert )
type ExternalInvokeCallbackFunc ¶
ExternalInvokeCallbackFunc is a function type that is called every time "window.external.invoke()" is called from JavaScript. Data is the only obligatory string parameter passed into the "invoke(data)" function from JavaScript. To pass more complex data serialized JSON or base64 encoded string can be used.
type Settings ¶
type Settings struct { // WebView main window title Title string // WebView application icon path Icon string // URL to open in a webview URL string // Window width in pixels Width int // Window height in pixels Height int // Window minimal width in pixels MinWidth int // Window minimal height in pixels MinHeight int // Window maximum width in pixels MaxWidth int // Window maximum height in pixels MaxHeight int // Allows/disallows window resizing Resizable bool // Enable debugging tools (Linux/BSD/MacOS, on Windows use Firebug) Debug bool // A callback that is executed when JavaScript calls "window.external.invoke()" ExternalInvokeCallback ExternalInvokeCallbackFunc }
Settings is a set of parameters to customize the initial WebView appearance and behavior. It is passed into the webview.New() constructor.
type WebView ¶
type WebView interface { // Run() starts the main UI loop until the user closes the webview window or // Terminate() is called. Run() // Loop() runs a single iteration of the main UI. Loop(blocking bool) bool // SetTitle() changes window title. This method must be called from the main // thread only. See Dispatch() for more details. SetTitle(title string) // SetIcon() changes application and window icon. This method must be called from // the main thread only. See Dispatch() for more details. SetIcon(iconPath string) // SetSize() changes window size. This method must be called from // the main thread only. See Dispatch() for more details. SetSize(width, height int, limits ...int) // SetFullscreen() controls window full-screen mode. This method must be // called from the main thread only. See Dispatch() for more details. SetFullscreen(fullscreen bool) // SetColor() changes window background color. This method must be called from // the main thread only. See Dispatch() for more details. SetColor(r, g, b, a uint8) // Eval() evaluates an arbitrary JS code inside the webview. This method must // be called from the main thread only. See Dispatch() for more details. Eval(js string) error // InjectJS() injects an arbitrary block of CSS code using the JS API. This // method must be called from the main thread only. See Dispatch() for more // details. InjectCSS(css string) // Dialog() opens a system dialog of the given type and title. String // argument can be provided for certain dialogs, such as alert boxes. For // alert boxes argument is a message inside the dialog box. Dialog(dlgType DialogType, flags int, title string, arg string) string // Terminate() breaks the main UI loop. This method must be called from the main thread // only. See Dispatch() for more details. Terminate() // Dispatch() schedules some arbitrary function to be executed on the main UI // thread. This may be helpful if you want to run some JavaScript from // background threads/goroutines, or to terminate the app. Dispatch(func()) // Exit() closes the window and cleans up the resources. Use Terminate() to // forcefully break out of the main UI loop. Exit() // Bind() registers a binding between a given value and a JavaScript object with the // given name. A value must be a struct or a struct pointer. All methods are // available under their camel-case names, starting with a lower-case letter, // e.g. "FooBar" becomes "fooBar" in JavaScript. // Bind() returns a function that updates JavaScript object with the current // Go value. You only need to call it if you change Go value asynchronously. Bind(name string, v interface{}) (sync func(), err error) }
WebView is an interface that wraps the basic methods for controlling the UI loop, handling multithreading and providing JavaScript bindings.