runtime

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CachedDir

func CachedDir() (string, error)

CachedDir returns the versioned cache directory.

func EncodeStr

func EncodeStr(s string) []byte

EncodeStr returns a length-prefixed UTF-8 string: [uint32_le len]bytes.

func EncodeU32U32

func EncodeU32U32(a, b uint32) []byte

EncodeU32U32 returns two consecutive little-endian uint32 values.

func EncodeWindowCreate

func EncodeWindowCreate(width, height int, debug bool, title string) []byte

EncodeWindowCreate builds the WindowCreate payload.

width:u32 height:u32 debug:u8 title:str

func EnsureRenderer

func EnsureRenderer(localPath string, prebuilt bool) (string, error)

EnsureRenderer guarantees the renderer binary and its dependencies are present in the cache directory, returning the path to the executable.

func EnsureWebView2

func EnsureWebView2() (string, error)

EnsureWebView2 is a no-op on non-Windows platforms; WebView2 is Windows-only. Returns ("", nil) so call-sites need no platform guards.

func WriteFrame

func WriteFrame(w io.Writer, typ CmdByte, payload []byte) error

WriteFrame writes a length-prefixed frame to w:

[4] uint32_le payload_length
[N] payload

Not goroutine-safe on its own — callers must hold the write mutex.

Types

type CmdByte

type CmdByte = uint8
const (
	CmdWindowCreate CmdByte = 0x01
	CmdLoadFile     CmdByte = 0x02
	CmdLoadHTML     CmdByte = 0x03
	CmdLoadURL      CmdByte = 0x04
	CmdEval         CmdByte = 0x05
	CmdSetTitle     CmdByte = 0x06
	CmdSetSize      CmdByte = 0x07
	CmdPostText     CmdByte = 0x08
	CmdPostBinary   CmdByte = 0x09
	CmdQuit         CmdByte = 0x0A
)

type Config

type Config struct {
	Title        string
	Width        int
	Height       int
	Debug        bool
	Logging      bool
	RendererPath string
	Prebuilt     bool
	OnReady      func()
	OnClose      func() bool
}

Config holds the parameters used when starting a renderer process.

type Event

type Event struct {
	Type    evtByte
	Channel string
	Text    string
	Data    []byte
}

Event is a decoded inbound frame from the renderer.

func ReadEvent

func ReadEvent(r io.Reader) (*Event, error)

ReadEvent reads and decodes one inbound frame from r. Blocks until a full frame is available or an error occurs.

type MessageHandler

type MessageHandler func(text string, data []byte, binary bool)

MessageHandler is the internal callback type used by the ipc package.

type Runtime

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

Runtime manages a single renderer subprocess and its IPC connection. Each BrowserWindow owns exactly one Runtime.

func New

func New(cfg Config) (*Runtime, error)

New creates a Runtime for the given config. Does not spawn the renderer — call Run to do that. Cheap to call: no processes, no sockets, no I/O.

func (*Runtime) OffMessage

func (rt *Runtime) OffMessage(channel string)

OffMessage removes the handler for the named channel.

func (*Runtime) OnMessage

func (rt *Runtime) OnMessage(channel string, h MessageHandler)

OnMessage registers an inbound message handler for the named channel.

func (*Runtime) Quit

func (rt *Runtime) Quit()

Quit sends CmdQuit to the renderer and unblocks the event loop. Safe to call from any goroutine; idempotent.

func (*Runtime) Run

func (rt *Runtime) Run() error

Run resolves the renderer binary, spawns the renderer process, and blocks on the event loop until the window is closed or Quit is called.

func (*Runtime) Send

func (rt *Runtime) Send(typ CmdByte, payload []byte)

Send writes a framed command to the renderer. Safe to call from any goroutine.

type Transport

type Transport struct {
	ID   string // the opaque random ID passed to the renderer via --channel
	Path string // the full platform-specific socket/pipe path
	// contains filtered or unexported fields
}

Transport is a connected net.Conn to the renderer process. On Linux/macOS it is a Unix socket; on Windows a named pipe.

func ListenTransport

func ListenTransport(id string) (*Transport, error)

ListenTransport creates the server-side socket/pipe and returns a Transport whose Accept method blocks until the renderer connects.

func (*Transport) Accept

func (t *Transport) Accept() error

Accept blocks until the renderer connects. The listener is intentionally left open until Close is called — on Windows, go-winio shares its IOCP completion port between the listener and any accepted connections, so closing the listener early silently breaks reads on the accepted connection.

func (*Transport) Close

func (t *Transport) Close() error

Close tears down the transport.

func (*Transport) Conn

func (t *Transport) Conn() net.Conn

Conn returns the active connection. Nil until Accept returns.

Jump to

Keyboard shortcuts

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