webview

package
v1.16.15 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package webview implements Go bindings to https://github.com/zserge/webview C library. It is a modified version of webview.go from that repository 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

View Source
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
)
View Source
const (
	IMAGE_ICON = 1

	LR_DEFAULTSIZE  = 0x00000040
	LR_LOADFROMFILE = 0x00000010

	SW_SHOW = 5

	CW_USEDEFAULT = ^0x7fffffff

	WS_CAPTION          = 0x00c00000
	WS_MAXIMIZEBOX      = 0x00010000
	WS_MINIMIZEBOX      = 0x00020000
	WS_OVERLAPPED       = 0x00000000
	WS_SYSMENU          = 0x00080000
	WS_THICKFRAME       = 0x00040000
	WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX

	WM_DESTROY       = 0x0002
	WM_SETICON       = 0x0080
	WM_MOUSEMOVE     = 0x0200
	WM_LBUTTONDOWN   = 0x0201
	WM_LBUTTONUP     = 0x0202
	WM_LBUTTONDBLCLK = 0x0203
	WM_RBUTTONDOWN   = 0x0204
	WM_RBUTTONUP     = 0x0205
	WM_RBUTTONDBLCLK = 0x0206
	WM_APP           = 0x8000
)
View Source
const (
	NIM_ADD        = 0x00000000
	NIM_MODIFY     = 0x00000001
	NIM_DELETE     = 0x00000002
	NIM_SETFOCUS   = 0x00000003
	NIM_SETVERSION = 0x00000004

	NIF_MESSAGE  = 0x00000001
	NIF_ICON     = 0x00000002
	NIF_TIP      = 0x00000004
	NIF_STATE    = 0x00000008
	NIF_INFO     = 0x00000010
	NIF_GUID     = 0x00000020
	NIF_REALTIME = 0x00000040
	NIF_SHOWTIP  = 0x00000080

	NIS_HIDDEN     = 0x00000001
	NIS_SHAREDICON = 0x00000002

	NIIF_NONE               = 0x00000000
	NIIF_INFO               = 0x00000001
	NIIF_WARNING            = 0x00000002
	NIIF_ERROR              = 0x00000003
	NIIF_USER               = 0x00000004
	NIIF_NOSOUND            = 0x00000010
	NIIF_LARGE_ICON         = 0x00000020
	NIIF_RESPECT_QUIET_TIME = 0x00000080
	NIIF_ICON_MASK          = 0x0000000F

	NIN_BALLOONSHOW      = 0x0402
	NIN_BALLOONTIMEOUT   = 0x0404
	NIN_BALLOONUSERCLICK = 0x0405
)
View Source
const TrayIconMsg = WM_APP + 1

Variables

This section is empty.

Functions

func CreateWindowEx

func CreateWindowEx(
	dwExStyle uint32,
	lpClassName, lpWindowName *uint16,
	dwStyle uint32,
	X, Y, nWidth, nHeight int32,
	hWndParent, hMenu, hInstance uintptr,
	lpParam unsafe.Pointer) (uintptr, error)

func DefWindowProc

func DefWindowProc(
	hWnd uintptr,
	Msg uint32,
	wParam, lParam uintptr) (uintptr, error)

func DispatchMessage

func DispatchMessage(lpMsg *MSG) (uintptr, error)

func GetMessage

func GetMessage(
	lpMsg *MSG,
	hWnd uintptr,
	uMsgFilterMin,
	uMsgFilterMax uint32) (int32, error)

func GetModuleHandle

func GetModuleHandle(lpModuleName *uint16) (uintptr, error)

func LOWORD

func LOWORD(dwValue uint32) uint16

func LoadImage

func LoadImage(
	hInst uintptr,
	name *uint16,
	type_ uint32,
	cx, cy int32,
	fuLoad uint32) (uintptr, error)

func Open

func Open(title, url string, w, h int, resizable bool) error

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

func PostQuitMessage

func PostQuitMessage(nExitCode int32)

func RegisterClassEx

func RegisterClassEx(Arg1 *WNDCLASSEX) (uint16, error)

func Shell_NotifyIcon

func Shell_NotifyIcon(
	dwMessage uint32,
	lpData *NOTIFYICONDATA) (int32, error)

func ShowWindow

func ShowWindow(hWnd uintptr, nCmdShow int32) (int32, error)

func TranslateMessage

func TranslateMessage(lpMsg *MSG) (int32, error)

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

type ExternalInvokeCallbackFunc func(w WebView, 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 GUID

type GUID struct {
	Data1 uint32
	Data2 uint16
	Data3 uint16
	Data4 [8]byte
}

type MSG

type MSG struct {
	Hwnd     uintptr
	Message  uint32
	WParam   uintptr
	LParam   uintptr
	Time     uint32
	Pt       POINT
	LPrivate uint32
}

type NOTIFYICONDATA

type NOTIFYICONDATA struct {
	CbSize           uint32
	HWnd             uintptr
	UID              uint32
	UFlags           uint32
	UCallbackMessage uint32
	HIcon            uintptr
	SzTip            [128]uint16
	DwState          uint32
	DwStateMask      uint32
	SzInfo           [256]uint16
	UVersion         uint32
	SzInfoTitle      [64]uint16
	DwInfoFlags      uint32
	GUIDItem         GUID
	HBalloonIcon     uintptr
}

type POINT

type POINT struct {
	X int32
	Y int32
}

type Settings

type Settings struct {
	// WebView main window title
	Title 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 TrayIcon

type TrayIcon struct {
	// contains filtered or unexported fields
}

func NewTrayIcon

func NewTrayIcon(hwnd uintptr) (*TrayIcon, error)

func (*TrayIcon) Dispose

func (ti *TrayIcon) Dispose() error

func (*TrayIcon) SetIcon

func (ti *TrayIcon) SetIcon(icon uintptr) error

func (*TrayIcon) SetTooltip

func (ti *TrayIcon) SetTooltip(tooltip string) error

func (*TrayIcon) ShowBalloonNotification

func (ti *TrayIcon) ShowBalloonNotification(title, text string) error

type WNDCLASSEX

type WNDCLASSEX struct {
	CbSize        uint32
	Style         uint32
	LpfnWndProc   uintptr
	CbClsExtra    int32
	CbWndExtra    int32
	HInstance     uintptr
	HIcon         uintptr
	HCursor       uintptr
	HbrBackground uintptr
	LpszMenuName  *uint16
	LpszClassName *uint16
	HIconSm       uintptr
}

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)

	ShowWindow()
	// Focus() puts the main window into focus
	Focus()

	// SetMinSize() sets the minimum size of the window
	SetMinSize(width, height int)

	// SetMaxSize() sets the maximum size of the window
	SetMaxSize(width, height 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, filter 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()
}

WebView is an interface that wraps the basic methods for controlling the UI loop, handling multithreading and providing JavaScript bindings.

func NewWebview

func NewWebview(settings Settings) WebView

NewWebview creates and opens a new webview window using the given settings. The returned object implements the WebView interface. This function returns nil if a window can not be created.

Jump to

Keyboard shortcuts

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