Skip to content

Latest commit

 

History

History
579 lines (422 loc) · 11.2 KB

File metadata and controls

579 lines (422 loc) · 11.2 KB

module vxui

Contents

detect_browser

fn detect_browser() !BrowserConfig

detect_browser detects available browser on the system

[Return to contents]

escape_attr

fn escape_attr(input string) string

escape_attr escapes HTML attribute values

[Return to contents]

escape_html

fn escape_html(input string) string

escape_html escapes special HTML characters to prevent XSS attacks Use this when outputting user-generated content in HTML

[Return to contents]

escape_js

fn escape_js(input string) string

escape_js escapes JavaScript special characters Use this when outputting data in JavaScript contexts

[Return to contents]

fire_call

fn fire_call[T](mut app T, method_name string, message map[string]json2.Any) !string

fire_call calls the method

[Return to contents]

generate_id

fn generate_id() string

generate_id generates a unique ID string

[Return to contents]

generate_routes

fn generate_routes[T](app &T) !map[string]Route

generate_routes generates route structs for an app

[Return to contents]

get_free_port

fn get_free_port() !u16

get_free_port try to get a free port to websocket listen to

[Return to contents]

handle_message

fn handle_message[T](mut app T, message map[string]json2.Any) !string

handle_message checks routes and calls the handler

[Return to contents]

is_valid_email

fn is_valid_email(email string) bool

is_valid_email validates email format (basic check)

[Return to contents]

new_packed_app

fn new_packed_app() PackedApp

new_packed_app creates a new PackedApp instance

[Return to contents]

parse_attrs

fn parse_attrs(name string, attrs []string) !([]Verb, string)

parse_attrs parses function attributes for verbs and path

[Return to contents]

run

fn run[T](mut app T, html_filename string) !

run opens the html_filename in browser and starts the event loop

[Return to contents]

run_embedded

fn run_embedded[T](mut app T, html_data []u8, filename string) !

run_embedded is a convenience function for running with embedded HTML Usage: vxui.run_embedded(mut app, $embed_file('ui/index.html'), 'index.html')!

[Return to contents]

run_packed

fn run_packed[T](mut app T, mut packed PackedApp, entry_file string) !

run_packed runs the app with packed (embedded) resources This allows distributing a single executable with all frontend files embedded

[Return to contents]

sanitize_path

fn sanitize_path(path string) !string

sanitize_path validates and sanitizes the file path

[Return to contents]

start_browser

fn start_browser(filename string, vxui_ws_port u16) !

start_browser starts the browser and open the filename

[Return to contents]

start_browser_with_token

fn start_browser_with_token(filename string, vxui_ws_port u16, token string, window WindowConfig) !

start_browser_with_token starts the browser with security token and window config

[Return to contents]

truncate_string

fn truncate_string(s string, max_len int) string

truncate_string truncates a string to max length with ellipsis

[Return to contents]

Verb

enum Verb {
	any_verb
	get
	post
	put
	delete
	patch
}

Verb represents HTTP methods

[Return to contents]

BrowserConfig

struct BrowserConfig {
	path string
	args []string
}

BrowserConfig holds browser path and arguments

[Return to contents]

Client

struct Client {
pub:
	id        string
	token     string
	connected time.Time
pub mut:
	connection &websocket.Client = unsafe { nil }
}

Client represents a connected browser client

[Return to contents]

Config

struct Config {
pub mut:
	// Connection settings
	close_timer      int = 50 // Close app after N cycles with no browser (each cycle is ~1ms)
	ws_ping_interval int = 10 // WebSocket ping interval in seconds

	// Security settings
	token        string // Security token (auto-generated if empty)
	require_auth bool = true // Require token authentication

	// Client settings
	multi_client bool // Allow multiple browser clients
	max_clients  int = 10 // Maximum number of concurrent clients (0 = unlimited)

	// JavaScript execution settings
	js_timeout_default int = 5000 // Default timeout for run_js() in milliseconds
	js_poll_interval   int = 10   // Polling interval for JS result in milliseconds

	// Window settings
	window WindowConfig
}

Config holds vxui runtime configuration

[Return to contents]

Context

struct Context {
mut:
	ws_port      u16
	ws           websocket.Server
	routes       map[string]Route
	clients      map[string]Client // client_id -> Client
	mu           sync.RwMutex
	js_callbacks map[string]chan string // JS execution callbacks
pub mut:
	close_timer  int      = 50 // close app after `close_timer` cycles with no browser
	logger       &log.Log = &log.Log{}
	token        string // Security token for client authentication
	multi_client bool   // Allow multiple clients
	window       WindowConfig
}

Context is the main struct of vxui

[Return to contents]

run_js

fn (mut ctx Context) run_js(js_code string, timeout_ms int) !string

run_js executes JavaScript in the frontend and returns the result timeout is in milliseconds, 0 means no wait

[Return to contents]

run_js_client

fn (mut ctx Context) run_js_client(client_id string, js_code string, timeout_ms int) !string

run_js_client executes JavaScript on a specific client

[Return to contents]

get_clients

fn (mut ctx Context) get_clients() []string

get_clients returns list of connected client IDs

[Return to contents]

get_client_count

fn (mut ctx Context) get_client_count() int

get_client_count returns the number of connected clients

[Return to contents]

close_client

fn (mut ctx Context) close_client(client_id string) !

close_client disconnects a specific client

[Return to contents]

broadcast

fn (mut ctx Context) broadcast(message string) !

broadcast sends a message to all connected clients

[Return to contents]

set_window_size

fn (mut ctx Context) set_window_size(width int, height int)

set_window_size sets the window dimensions

[Return to contents]

set_window_position

fn (mut ctx Context) set_window_position(x int, y int)

set_window_position sets the window position (-1 for center)

[Return to contents]

set_window_title

fn (mut ctx Context) set_window_title(title string)

set_window_title sets the window title

[Return to contents]

set_resizable

fn (mut ctx Context) set_resizable(resizable bool)

set_resizable sets whether the window can be resized

[Return to contents]

get_port

fn (ctx Context) get_port() u16

get_port returns the WebSocket port

[Return to contents]

get_token

fn (ctx Context) get_token() string

get_token returns the security token

[Return to contents]

EmbeddedFile

struct EmbeddedFile {
pub:
	data []u8
	size int
}

EmbeddedFile represents an embedded file

[Return to contents]

PackedApp

struct PackedApp {
pub mut:
	files map[string]EmbeddedFile
}

PackedApp holds embedded frontend resources

[Return to contents]

add_file

fn (mut p PackedApp) add_file(path string, data []u8)

add_file adds an embedded file to the packed app Accepts both []u8 and EmbedFileData (from $embed_file)

[Return to contents]

add_file_string

fn (mut p PackedApp) add_file_string(path string, content string)

add_file_string adds an embedded file from string

[Return to contents]

extract_to

fn (p PackedApp) extract_to(dir string) !

extract_to extracts all files to a directory

[Return to contents]

extract_to_temp

fn (p PackedApp) extract_to_temp() !string

extract_to_temp extracts all files to a temp directory and returns the path

[Return to contents]

get_file

fn (p PackedApp) get_file(path string) !EmbeddedFile

get_file retrieves a file by path

[Return to contents]

get_file_content

fn (p PackedApp) get_file_content(path string) !string

get_file_content retrieves file content as string

[Return to contents]

has_file

fn (p PackedApp) has_file(path string) bool

has_file checks if a file exists

[Return to contents]

list_files

fn (p PackedApp) list_files() []string

list_files returns all file paths

[Return to contents]

total_size

fn (p PackedApp) total_size() int

total_size returns total size of all embedded files

[Return to contents]

cleanup

fn (p PackedApp) cleanup(dir string)

cleanup removes extracted files

[Return to contents]

Route

struct Route {
	verb []Verb
	path string
}

Route represents a registered route

[Return to contents]

WindowConfig

struct WindowConfig {
pub mut:
	width       int  = 800
	height      int  = 600
	x           int  = -1 // -1 means center
	y           int  = -1
	min_width   int  = 100
	min_height  int  = 100
	resizable   bool = true
	frameless   bool
	transparent bool
	title       string
}

WindowConfig holds window configuration

[Return to contents]

Powered by vdoc. Generated on: 24 Feb 2026 10:49:48