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
- func CheckType(typ TYPE) bool
- func Debug(a ...interface{})
- func Debugf(format string, a ...interface{})
- func Handler(msg string, ln Listen, cb Callback)
- func Open(title, url string, w, h int, resizable bool) error
- type Binding
- type Callback
- type Component
- func (m *Component) GetName() string
- func (m *Component) GetWV() WV
- func (m *Component) GetWidget(widgetId string) WidgetInterface
- func (m *Component) GetWidgets() map[string]WidgetInterface
- func (m *Component) NewWidget(widgetId string) WidgetInterface
- func (m *Component) SetWidget(widgetId string, w WidgetInterface) WidgetInterface
- type ComponentInterface
- type Data
- type DialogType
- type EventFn
- type ExternalInvokeCallbackFunc
- type Listen
- type RPCData
- type Settings
- type SockJSSyncHandler
- type TYPE
- type WV
- type WebView
- type Widget
- func (m *Widget) CBEvent(fn EventFn) WidgetInterface
- func (m *Widget) Eval(js string) error
- func (m *Widget) GetComponent() ComponentInterface
- func (m *Widget) GetEvent() EventFn
- func (m *Widget) GetId() string
- func (m *Widget) GetValue() w.WMap
- func (m *Widget) GoSyncJS()
- func (m *Widget) SetValue(value interface{})
- type WidgetInterface
- type WinExtInvokeSyncHandler
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 ¶
func Debug ¶
func Debug(a ...interface{})
Debug prints a debug string using stderr on Linux/BSD, NSLog on MacOS and OutputDebugString on Windows.
func Debugf ¶
func Debugf(format string, a ...interface{})
Debugf prints a formatted debug string using stderr on Linux/BSD, NSLog on MacOS and OutputDebugString on Windows.
func Open ¶
Open is a simplified API to open a single native window with a full-size webview in it. It can be helpful if you want to communicate with the core app using XHR or WebSockets (as opposed to using JavaScript bindings).
Window appearance can be customized using title, width, height and resizable parameters. URL must be provided and can user either a http or https protocol, or be a local file:// URL. On some platforms "data:" URLs are also supported (Linux/MacOS).
Types ¶
type Binding ¶
type Binding interface { BindingJS(widgets map[string]WidgetInterface) EvalJS(wv WV) }
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
func (*Component) GetWidget ¶
func (m *Component) GetWidget(widgetId string) WidgetInterface
获取一个小控件
func (*Component) GetWidgets ¶
func (m *Component) GetWidgets() map[string]WidgetInterface
func (*Component) NewWidget ¶
func (m *Component) NewWidget(widgetId string) WidgetInterface
创建一个小控件
func (*Component) SetWidget ¶
func (m *Component) SetWidget(widgetId string, w WidgetInterface) WidgetInterface
设置一个小控件,返回老的控件信息
type ComponentInterface ¶
type ComponentInterface interface { GetName() string NewWidget(widgetId string) WidgetInterface GetWidget(widgetId string) WidgetInterface GetWidgets() map[string]WidgetInterface SetWidget(widgetId string, w WidgetInterface) WidgetInterface GetWV() WV }
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 EventFn ¶
type EventFn func(w WidgetInterface) *RPCData
type ExternalInvokeCallbackFunc ¶
type ExternalInvokeCallbackFunc func(data string)
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 ExternalInvokeCallbackFunc func(w WebView, data string)
type RPCData ¶
type RPCData struct { Type TYPE `json:"type"` ComponentName string `json:"componentName"` WidgetId string `json:"widgetId"` Value Data `json:"value"` }
func NewRPCData ¶
func NewRPCData(typ TYPE, w WidgetInterface, value Data) *RPCData
type Settings ¶
type Settings struct { // WebView main window title Title string //设置图标 Icon string // URL to open in a webview URL string // Window width in pixels Width int // Window height in pixels Height 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 SockJSSyncHandler ¶
type SockJSSyncHandler struct { }
func (SockJSSyncHandler) BindWidgetChangeEventListen ¶
func (SockJSSyncHandler) BindWidgetChangeEventListen(wd RPCData, fn Callback)
小控件事件绑定 change 事件
func (SockJSSyncHandler) BindWidgetClickEventListen ¶
func (SockJSSyncHandler) BindWidgetClickEventListen(wd RPCData, fn Callback)
小控件事件绑定 click 事件
func (SockJSSyncHandler) BindWidgetUpdateListen ¶
func (SockJSSyncHandler) BindWidgetUpdateListen(wd RPCData)
小控件数据更新监听
func (SockJSSyncHandler) Listen ¶
func (m SockJSSyncHandler) Listen(wd RPCData)
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) // 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() //绑定控件 //BindWidget(widget WidgetInterface) //创建组件 NewComponent(componentName string) ComponentInterface }
WebView is an interface that wraps the basic methods for controlling the UI loop, handling multithreading and providing JavaScript bindings.
type WidgetInterface ¶
type WidgetInterface interface { GoSyncJS() Eval(js string) error GetComponent() ComponentInterface CBEvent(EventFn) WidgetInterface GetEvent() EventFn GetValue() w.WMap GetId() string SetValue(value interface{}) }
type WinExtInvokeSyncHandler ¶
type WinExtInvokeSyncHandler struct { }
func (WinExtInvokeSyncHandler) BindWidgetChangeEventListen ¶
func (m WinExtInvokeSyncHandler) BindWidgetChangeEventListen(wd RPCData, fn Callback)
func (WinExtInvokeSyncHandler) BindWidgetClickEventListen ¶
func (m WinExtInvokeSyncHandler) BindWidgetClickEventListen(wd RPCData, fn Callback)
func (WinExtInvokeSyncHandler) BindWidgetUpdateListen ¶
func (m WinExtInvokeSyncHandler) BindWidgetUpdateListen(wd RPCData)
组件数据更新监听
func (WinExtInvokeSyncHandler) Listen ¶
func (m WinExtInvokeSyncHandler) Listen(wd RPCData)
window.external.invoke 监听