- detect_browser
- escape_attr
- escape_html
- escape_js
- fire_call
- generate_id
- generate_routes
- get_free_port
- handle_message
- is_valid_email
- new_packed_app
- parse_attrs
- run
- run_embedded
- run_packed
- sanitize_path
- start_browser
- start_browser_with_token
- truncate_string
- Verb
- BrowserConfig
- Client
- Config
- Context
- EmbeddedFile
- PackedApp
- Route
- WindowConfig
fn detect_browser() !BrowserConfigdetect_browser detects available browser on the system
fn escape_attr(input string) stringescape_attr escapes HTML attribute values
fn escape_html(input string) stringescape_html escapes special HTML characters to prevent XSS attacks Use this when outputting user-generated content in HTML
fn escape_js(input string) stringescape_js escapes JavaScript special characters Use this when outputting data in JavaScript contexts
fn fire_call[T](mut app T, method_name string, message map[string]json2.Any) !stringfire_call calls the method
fn generate_id() stringgenerate_id generates a unique ID string
fn generate_routes[T](app &T) !map[string]Routegenerate_routes generates route structs for an app
fn get_free_port() !u16get_free_port try to get a free port to websocket listen to
fn handle_message[T](mut app T, message map[string]json2.Any) !stringhandle_message checks routes and calls the handler
fn is_valid_email(email string) boolis_valid_email validates email format (basic check)
fn new_packed_app() PackedAppnew_packed_app creates a new PackedApp instance
fn parse_attrs(name string, attrs []string) !([]Verb, string)parse_attrs parses function attributes for verbs and path
fn run[T](mut app T, html_filename string) !run opens the html_filename in browser and starts the event loop
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')!
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
fn sanitize_path(path string) !stringsanitize_path validates and sanitizes the file path
fn start_browser(filename string, vxui_ws_port u16) !start_browser starts the browser and open the filename
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
fn truncate_string(s string, max_len int) stringtruncate_string truncates a string to max length with ellipsis
enum Verb {
any_verb
get
post
put
delete
patch
}Verb represents HTTP methods
struct BrowserConfig {
path string
args []string
}BrowserConfig holds browser path and arguments
struct Client {
pub:
id string
token string
connected time.Time
pub mut:
connection &websocket.Client = unsafe { nil }
}Client represents a connected browser client
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
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
fn (mut ctx Context) run_js(js_code string, timeout_ms int) !stringrun_js executes JavaScript in the frontend and returns the result timeout is in milliseconds, 0 means no wait
fn (mut ctx Context) run_js_client(client_id string, js_code string, timeout_ms int) !stringrun_js_client executes JavaScript on a specific client
fn (mut ctx Context) get_clients() []stringget_clients returns list of connected client IDs
fn (mut ctx Context) get_client_count() intget_client_count returns the number of connected clients
fn (mut ctx Context) close_client(client_id string) !close_client disconnects a specific client
fn (mut ctx Context) broadcast(message string) !broadcast sends a message to all connected clients
fn (mut ctx Context) set_window_size(width int, height int)set_window_size sets the window dimensions
fn (mut ctx Context) set_window_position(x int, y int)set_window_position sets the window position (-1 for center)
fn (mut ctx Context) set_window_title(title string)set_window_title sets the window title
fn (mut ctx Context) set_resizable(resizable bool)set_resizable sets whether the window can be resized
fn (ctx Context) get_port() u16get_port returns the WebSocket port
fn (ctx Context) get_token() stringget_token returns the security token
struct EmbeddedFile {
pub:
data []u8
size int
}EmbeddedFile represents an embedded file
struct PackedApp {
pub mut:
files map[string]EmbeddedFile
}PackedApp holds embedded frontend resources
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)
fn (mut p PackedApp) add_file_string(path string, content string)add_file_string adds an embedded file from string
fn (p PackedApp) extract_to(dir string) !extract_to extracts all files to a directory
fn (p PackedApp) extract_to_temp() !stringextract_to_temp extracts all files to a temp directory and returns the path
fn (p PackedApp) get_file(path string) !EmbeddedFileget_file retrieves a file by path
fn (p PackedApp) get_file_content(path string) !stringget_file_content retrieves file content as string
fn (p PackedApp) has_file(path string) boolhas_file checks if a file exists
fn (p PackedApp) list_files() []stringlist_files returns all file paths
fn (p PackedApp) total_size() inttotal_size returns total size of all embedded files
fn (p PackedApp) cleanup(dir string)cleanup removes extracted files
struct Route {
verb []Verb
path string
}Route represents a registered route
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