webui

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 8 Imported by: 0

README

WebUI Go


Screenshot

WebUI is not a web-server solution or a framework, but it allows you to use any web browser as a GUI, with your preferred language in the backend and HTML5 in the frontend. All in a lightweight portable lib.

Features

  • Fully Independent (No need for any third-party runtimes)
  • Lightweight ~200 Kb & Small memory footprint
  • Fast binary communication protocol between WebUI and the browser (Instead of JSON)
  • Multi-platform & Multi-Browser
  • Using private profile for safety
  • Original library written in Pure C

Usage

Installation
go get github.com/webui-dev/go-webui@latest
Minimal Example
package main

import "github.com/webui-dev/go-webui"

func main() {
	w := webui.NewWindow()
	w.Show("<html>Hello World</html>")
	webui.Wait()
}

Find more examples in the examples/ directory.

Documentation

Note We are currently writing documentation.

UI & The Web Technologies

Borislav Stanimirov discusses using HTML5 in the web browser as GUI at the C++ Conference 2019 (YouTube).

CPPCon

Web application UI design is not just about how a product looks but how it works. Using web technologies in your UI makes your product modern and professional, And a well-designed web application will help you make a solid first impression on potential customers. Great web application design also assists you in nurturing leads and increasing conversions. In addition, it makes navigating and using your web app easier for your users.

Why Use Web Browsers?

Today's web browsers have everything a modern UI needs. Web browsers are very sophisticated and optimized. Therefore, using it as a GUI will be an excellent choice. While old legacy GUI lib is complex and outdated, a WebView-based app is still an option. However, a WebView needs a huge SDK to build and many dependencies to run, and it can only provide some features like a real web browser. That is why WebUI uses real web browsers to give you full features of comprehensive web technologies while keeping your software lightweight and portable.

How Does it Work?

Diagram

Think of WebUI like a WebView controller, but instead of embedding the WebView controller in your program, which makes the final program big in size, and non-portable as it needs the WebView runtimes. Instead, by using WebUI, you use a tiny static/dynamic library to run any installed web browser and use it as GUI, which makes your program small, fast, and portable. All it needs is a web browser.

Runtime Dependencies Comparison
WebView Qt WebUI
Runtime Dependencies on Windows WebView2 QtCore, QtGui, QtWidgets A Web Browser
Runtime Dependencies on Linux GTK3, WebKitGTK QtCore, QtGui, QtWidgets A Web Browser
Runtime Dependencies on macOS Cocoa, WebKit QtCore, QtGui, QtWidgets A Web Browser

Wrappers

Language Status Link
Go ✔️ Go-WebUI
Nim ✔️ Nim-WebUI
Pascal ✔️ Pascal-WebUI
Python ✔️ Python-WebUI
Rust not complete Rust-WebUI
TypeScript / JavaScript ✔️ Deno-WebUI
V ✔️ V-WebUI
Zig not complete Zig-WebUI

Supported Web Browsers

Browser Windows macOS Linux
Mozilla Firefox ✔️ ✔️ ✔️
Google Chrome ✔️ ✔️ ✔️
Microsoft Edge ✔️ ✔️ ✔️
Chromium ✔️ ✔️ ✔️
Yandex ✔️ ✔️ ✔️
Brave ✔️ ✔️ ✔️
Vivaldi ✔️ ✔️ ✔️
Epic ✔️ ✔️ not available
Apple Safari not available coming soon not available
Opera coming soon coming soon coming soon
License

Licensed under the MIT License.

Stargazers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](w Window, element string, callback func(Event) T)

Bind binds a specific html element click event with a function. Empty element means all events.

func Decode

func Decode(str string) string

Decode decodes Base64 encoded text received from the the UI.

func Encode

func Encode(str string) string

Encode sends text based data to the UI using base64 encoding.

func Exit

func Exit()

Exit closes all open windows. `Wait()` will return (Break).

func GetArg

func GetArg[T any](e Event) (arg T, err error)

GetArg parses the JavaScript argument into a Go data type.

func SetRootFolder

func SetRootFolder(path string)

SetRootFolder sets the web-server root folder path for all windows.

func SetTimeout

func SetTimeout(seconds uint)

SetTimeout sets the maximum time in seconds to wait for the browser to start.

func Wait

func Wait()

Wait waits until all opened windows get closed.

Types

type Browser

type Browser uint8
const (
	AnyBrowser Browser = iota
	Chrome
	Firefox
	Edge
	Safari
	Chromium
	Opera
	Brave
	Vivaldi
	Epic
	Yandex
	ChromiumBased
)

type Data

type Data string

type Event

type Event struct {
	Window    Window
	EventType EventType
	Element   string
	Data      Data
	Size      uint
}

func (Event) Bool

func (e Event) Bool() (arg bool, err error)

Bool parses the JavaScript argument as integer.

func (Event) Int

func (e Event) Int() (arg int, err error)

Int parses the JavaScript argument as integer.

func (Event) String

func (e Event) String() (arg string, err error)

String parses the JavaScript argument as integer.

type EventType

type EventType uint8
const (
	Disconnected EventType = iota
	Connected
	MultiConnection
	UnwantedConnection
	MouseClick
	Navigation
	Callback
)

type Runtime

type Runtime uint8
const (
	None Runtime = iota
	Deno
	Nodejs
)

type ScriptOptions

type ScriptOptions struct {
	Timeout    uint
	BufferSize uint
}

type Void

type Void *struct{}

type Window

type Window uint

func NewWindow

func NewWindow() Window

NewWindow creates a new WebUI window object and returns the window number.

func NewWindowId

func NewWindowId() Window

NewWindowId returns a free window number that can be used with `NewWindow`.

func (Window) Bind

func (w Window) Bind(element string, callback func(Event) any)

Bind binds a specific html element click event with a function. Empty element means all events.

func (Window) Close

func (w Window) Close()

Close closes the window. The window object will still exist.

func (Window) Destroy

func (w Window) Destroy()

Destroy closes the window and free all memory resources.

func (Window) GetUrl

func (w Window) GetUrl() string

GetUrl returns the full current URL

func (Window) IsShown

func (w Window) IsShown() bool

IsShown checks if the window it's still running.

func (Window) Navigate

func (w Window) Navigate(url string)

Navigate navigates to a specific URL

func (Window) NewWindow

func (w Window) NewWindow()

NewWindow creates a new webui window object using a specified window number.

func (Window) Run

func (w Window) Run(script string)

Run executres JavaScript without waiting for the response.

func (Window) Script

func (w Window) Script(script string, options ScriptOptions) (resp string, err error)

Script executes JavaScript and returns the response (Make sure the response buffer can hold the response). The default BufferSize is 8KiB.

func (Window) SetHide

func (w Window) SetHide(status bool)

SetHide determines whether the window is run in hidden mode.

func (Window) SetIcon

func (w Window) SetIcon(icon string, icon_type string)

SetIcon sets the default embedded HTML favicon.

func (Window) SetKiosk

func (w Window) SetKiosk(enable bool)

SetKiosk determines whether Kiosk mode (full screen) is enabled for the window.

func (Window) SetMultiAccess

func (w Window) SetMultiAccess(access bool)

SetMultiAccess determines whether the window URL can be reused in normal web browsers.

func (Window) SetPosition

func (w Window) SetPosition(x uint, y uint)

SetPosition sets the window position.

func (Window) SetProfile

func (w Window) SetProfile(name string, path string)

SetProfile sets the web browser profile to use. An empty `name` and `path` means the default user profile. Needs to be called before `webui_show()`.

func (Window) SetRootFolder

func (w Window) SetRootFolder(path string)

SetRootFolder sets the web-server root folder path for the window.

func (Window) SetRuntime

func (w Window) SetRuntime(runtime Runtime)

SetRuntime sets the runtime for .js and .ts files to Deno and Nodejs.

func (Window) SetSize

func (w Window) SetSize(width uint, height uint)

SetSize sets the window size.

func (Window) Show

func (w Window) Show(content string) (err error)

Show opens a window using embedded HTML, or a file. If the window is already open, it will be refreshed.

func (Window) ShowBrowser

func (w Window) ShowBrowser(content string, browser Browser) (err error)

ShowBrowser opens a window using embedded HTML, or a file in a specific web browser. If the window is already open, it will be refreshed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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