muon

package module
v0.0.0-...-f107cdf Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: MIT Imports: 8 Imported by: 0

README

gnet

GitHub code size in bytes


Muon is a lightweight alternative to Electron written in Golang in about ~300 LoC, using Ultralight instead of Chromium. Ultralight is a cross-platform WebKit rewrite using the GPU to target embedded desktop applications that resulted in a fast, lightweight, and low-memory HTML UI solution that blends the power of Chromium with the small footprint of Native UI.

Features

  • Full JS to Go interop
  • GPU based rendering
  • Cross-platform
  • Hot-reloading
  • Superior disk size + memory & cpu usage

Comparison with a "Hello, World!" React App

Muon Electron
CPU 0.0% 1.2%
MEM 26.0 MB 201.7 MB
DISK 42 MB 136 MB

Example

From examples/create-react-app/main.go:

package main

import (
  "github.com/ImVexed/muon"

  "cra-go/webfiles"
  "net/http"
)

func main() {
  // Any static asset packer of your liking (ex. fileb0x)
  fileHandler := http.FileServer(webfiles.HTTP)

  cfg := &muon.Config{
    Title:      "Hello, World!",
    Height:     500,
    Width:      500,
    Titled:     true,
    Resizeable: true,
  }

  m := muon.New(cfg, fileHandler)

  // Expose our `add` function to the JS runtime
  m.Bind("add", add)

  // Show the Window and start the Runtime
  if err := m.Start(); err != nil {
    panic(err)
  }
}

// Muon automatically handles interop to and from the JS runtime
func add(a float64, b float64) float64 {
  return a + b
}

FAQ

Q: How are JS types translated to Go types?

  • JS: Boolean Go: bool
  • JS: Number Go: float64
  • JS: String Go: string
  • JS: Object Go: struct via JSON

Q: How do I setup Ultralight?

Q: Is there perfect Chrome or Firefox feature parity?

Q: How do I get rid of the Console on Windows?

  • Add -ldflags -H=windowsgui to either your go build or go run to get rid of the window.

Q: I get exit status 3221225781

  • Your program likely can't find the Ultralight libraries. Ensure they're either installed on the system, or, in the same folder as your program. Currently, Muon uses the 1.1 Ultralight pre-release that hasn't yet propagated to their main site and can only be downloaded from the Ultralight github repo.

Q: I get libWebCore.so: cannot open shared object file

  • If you're attempting to load the libraries out of the same directory as your program add -ldflags "-r ." to your go build to set rpath to the local directory for library resolution.

Q: I get symbol not found: ulCreateSettings

  • This likely means you're not using the 1.1 Ultralight pre-release which can be downloaded only from their GitHub Repo for now

Q: How do I compile for x86?

  • Currently, Ultralight only supports Windows for x86. Ensure you have a 32-bit gcc in your path, and ensure you have CGO_ENABLED=1 and GOARCH=386 environment variables set.

Licensing

While muon itself is MIT licensed, Ultralight is not.

Ultralight is free for non-commercial use, educational use, 
and also free for commercial use by small indie developers making
less than US$100,000 a year. You can find full terms in the SDK. 
Pricing plans for larger commercial projects will be announced later.

Their specific license terms can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Title  string
	Height uint32
	Width  uint32
	X      int32
	Y      int32

	Resizeable  bool
	Borderless  bool
	Titled      bool
	Maximizable bool
}

Config contains configurable controls for the Ultralight engine

type Window

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

Window represents a single Ultralight instance

func New

func New(cfg *Config, handler http.Handler) *Window

New creates a Ultralight Window

func (*Window) Bind

func (w *Window) Bind(name string, function interface{})

Bind registers the given function to the given name in the Window's JS global object

func (*Window) Eval

func (w *Window) Eval(js string, ret reflect.Type) (interface{}, error)

Eval evaluates a given JavaScript string in the given Window view. `ret` is necessary for JSON serialization if an object is returned.

func (*Window) Move

func (w *Window) Move(x int, y int)

Move sets the Window's position to the given coordinates

func (*Window) Resize

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

Resize changes the given Window's size

func (*Window) Start

func (w *Window) Start() error

Start sets up the Ultralight runtime and begins showing the Window

Directories

Path Synopsis
Ultralight bindings for golang
Ultralight bindings for golang

Jump to

Keyboard shortcuts

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