webkitgtk

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 18 Imported by: 0

README

webkitgtk Go Reference Release Go Report Card License

Pure Go WebKitGTK binding for Linux and FreeBSD.

This is pre release software so expect bugs and potentially API breaking changes but each release will be tagged to avoid breaking people's code.

Installation

# go 1.21.5+
go get github.com/malivvan/webkitgtk

Example

The following example shows how to create a simple GTK window with a button that closes the application when clicked.

package main

import ui "github.com/malivvan/webkitgtk"

type API struct {
	app *ui.App
}

func (a *API) Quit() error {
	a.app.Quit()
	return nil
}

func main() {
	app := ui.New(ui.AppOptions{
		Name: "example",
	})
	app.Open(ui.WindowOptions{
		Title: "example",
		HTML:  `<button onclick="app.quit()">quit</button>`,
		Define: map[string]interface{}{
			"app": &API{app: app},
		},
	})
	if err := app.Run(); err != nil {
		panic(err)
	}
}

Running and building

Running / building the application is the same as for any other Go program, aka. just go run and go build.

Dependencies

Either webkit2gtk-4.1 (stable) or webkitgtk-6.0 (unstable) is required at runtime. If both are installed the stable version will be used.

Debian / Ubuntu apt install libwebkit2gtk-4.1 apt install libwebkitgtk-6.0
RHEL / Fedora dnf install webkitgtk4 dnf install webkitgtk3
Arch pacman -S webkit2gtk-4.1 pacman -S webkitgtk-6.0
Alpine apk add webkit2gtk apk add webkit2gtk-6.0
Gentoo emerge -av net-libs/webkit-gtk
FreeBSD pkg install webkit2-gtk3 pkg install webkit2-gtk4

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var URLScheme = "app"
View Source
var UserAgent = "webkit2gtk"

Functions

This section is empty.

Types

type App

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

func New

func New(options AppOptions) *App

func (*App) CurrentWindow

func (a *App) CurrentWindow() *Window

func (*App) Open

func (a *App) Open(options WindowOptions) *Window

Open opens a new window with the given options.

func (*App) Quit

func (a *App) Quit()

func (*App) Run

func (a *App) Run() error

type AppOptions

type AppOptions struct {
	Name                   string
	Debug                  bool
	LogWriter              io.Writer
	HideOnLastWindowClosed bool
	PanicHandler           func(any)
}

type WebkitSettings

type WebkitSettings struct {
	EnableJavascript                          bool
	AutoLoadImages                            bool
	LoadIconsIgnoringImageLoadSetting         bool
	EnableOfflineWebApplicationCache          bool
	EnableHtml5LocalStorage                   bool
	EnableHtml5Database                       bool
	EnableXssAuditor                          bool
	EnableFrameFlattening                     bool
	EnablePlugins                             bool
	EnableJava                                bool
	JavascriptCanOpenWindowsAutomatically     bool
	EnableHyperlinkAuditing                   bool
	DefaultFontFamily                         string
	MonospaceFontFamily                       string
	SerifFontFamily                           string
	SansSerifFontFamily                       string
	CursiveFontFamily                         string
	FantasyFontFamily                         string
	PictographFontFamily                      string
	DefaultFontSize                           uint32
	DefaultMonospaceFontSize                  uint32
	MinimumFontSize                           uint32
	DefaultCharset                            string
	EnableDeveloperExtras                     bool
	EnableResizableTextAreas                  bool
	EnableTabsToLinks                         bool
	EnableDnsPrefetching                      bool
	EnableCaretBrowsing                       bool
	EnableFullscreen                          bool
	PrintBackgrounds                          bool
	EnableWebAudio                            bool
	EnableWebgl                               bool
	AllowModalDialogs                         bool
	ZoomTextOnly                              bool
	JavascriptCanAccessClipboard              bool
	MediaPlaybackRequiresUserGesture          bool
	MediaPlaybackAllowsInline                 bool
	DrawCompositingIndicators                 bool
	EnableSiteSpecificQuirks                  bool
	EnablePageCache                           bool
	UserAgent                                 string
	EnableSmoothScrolling                     bool
	EnableAccelerated2DCanvas                 bool
	EnableWriteConsoleMessagesToStdout        bool
	EnableMediaStream                         bool
	EnableMockCaptureDevices                  bool
	EnableSpatialNavigation                   bool
	EnableMediaSource                         bool
	EnableEncryptedMedia                      bool
	EnableMediaCapabilities                   bool
	AllowFileAccessFromFileUrls               bool
	AllowUniversalAccessFromFileUrls          bool
	AllowTopNavigationToDataUrls              bool
	HardwareAccelerationPolicy                int
	EnableBackForwardNavigationGestures       bool
	EnableJavascriptMarkup                    bool
	EnableMedia                               bool
	MediaContentTypesRequiringHardwareSupport string
	EnableWebRTC                              bool
	DisableWebSecurity                        bool
}

type Window

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

func (*Window) AddCSS

func (w *Window) AddCSS(css string)

func (*Window) Center

func (w *Window) Center()

func (*Window) Close

func (w *Window) Close()

func (*Window) DisableSizeConstraints

func (w *Window) DisableSizeConstraints()

func (*Window) ExecJS

func (w *Window) ExecJS(js string)

func (*Window) Focus

func (w *Window) Focus()

func (*Window) Fullscreen

func (w *Window) Fullscreen()

func (*Window) GetSize

func (w *Window) GetSize() (int, int)

func (*Window) GetZoom

func (w *Window) GetZoom() float64

func (*Window) Hide

func (w *Window) Hide()

func (*Window) ID

func (w *Window) ID() uint

func (*Window) IsFocused

func (w *Window) IsFocused() bool

func (*Window) IsFullscreen

func (w *Window) IsFullscreen() bool

func (*Window) IsMaximised

func (w *Window) IsMaximised() bool

func (*Window) IsMinimised

func (w *Window) IsMinimised() bool

func (*Window) Maximise

func (w *Window) Maximise()

func (*Window) Minimise

func (w *Window) Minimise()

func (*Window) Restore

func (w *Window) Restore()

func (*Window) SetFrameless

func (w *Window) SetFrameless(frameless bool)

func (*Window) SetMaxSize

func (w *Window) SetMaxSize(width, height int)

func (*Window) SetMinMaxSize

func (w *Window) SetMinMaxSize(minWidth, minHeight, maxWidth, maxHeight int)

func (*Window) SetMinSize

func (w *Window) SetMinSize(width, height int)

func (*Window) SetOverlay

func (w *Window) SetOverlay(alwaysOnTop bool)

func (*Window) SetSize

func (w *Window) SetSize(width, height int)

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

func (*Window) SetURL

func (w *Window) SetURL(uri string)

func (*Window) SetZoom

func (w *Window) SetZoom(zoom float64)

func (*Window) Show

func (w *Window) Show()

func (*Window) ToggleDevTools

func (w *Window) ToggleDevTools()

func (*Window) Unfullscreen

func (w *Window) Unfullscreen()

func (*Window) Unmaximise

func (w *Window) Unmaximise()

func (*Window) Unminimise

func (w *Window) Unminimise()

func (*Window) ZoomIn

func (w *Window) ZoomIn()

func (*Window) ZoomOut

func (w *Window) ZoomOut()

func (*Window) ZoomReset

func (w *Window) ZoomReset()

type WindowOptions

type WindowOptions struct {
	// Name is a unique identifier of the window.
	Name string

	// Title is the title of the page.
	Title string

	// URL is the URL of the page to load.
	URL string

	// HTML Content to load (if URL is not set).
	HTML string

	// CSS to load after the page has loaded.
	CSS []string

	// JS to load after the page has loaded.
	JS []string

	// Define global Variables and APIs.
	Define map[string]interface{}

	// Width is the starting width of the window.
	Width int

	// Height is the starting height of the window.
	Height int

	// Overlay will make the window float above other windows.
	Overlay bool

	// Frameless will remove the window frame.
	Frameless bool

	// MinWidth is the minimum width of the window.
	MinWidth int

	// MinHeight is the minimum height of the window.
	MinHeight int

	// MaxWidth is the maximum width of the window.
	MaxWidth int

	// MaxHeight is the maximum height of the window.
	MaxHeight int

	// State indicates the state of the window when it is first shown.
	// Default: WindowStateNormal
	State WindowState

	// Centered will Center the window on the screen.
	Centered bool

	// Color specified the window color as a hex string (#RGB, #RGBA, #RRGGBB, #RRGGBBAA)
	Color string

	// X is the starting X position of the window.
	X int

	// Y is the starting Y position  of the window.
	Y int

	// Hidden will Hide the window when it is first created.
	Hidden bool

	// Zoom is the initial Zoom level of the window.
	Zoom float64

	// ZoomControlEnabled will enable the Zoom control.
	ZoomControlEnabled bool

	// OpenInspectorOnStartup will open the inspector when the window is first shown.
	OpenInspectorOnStartup bool

	// Focused indicates the window should be focused when initially shown
	Focused bool

	// HideOnClose will hide the window when it is closed instead of destroying it.
	HideOnClose bool

	// WebkitSettings exposes the underlying WebkitSettings object.
	WebkitSettings WebkitSettings
}

type WindowState

type WindowState int
const (
	WindowStateNormal WindowState = iota
	WindowStateMinimised
	WindowStateMaximised
	WindowStateFullscreen
)

Directories

Path Synopsis
examples
echo command

Jump to

Keyboard shortcuts

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