This commit is contained in:
ImVexed 2019-10-04 18:54:37 -05:00
parent 301bb5f499
commit 6e39406e80
5 changed files with 121 additions and 4 deletions

80
README.md Normal file
View File

@ -0,0 +1,80 @@
<p align="center">
<img width="200" height="200" src="./logo.svg" alt="gnet">
<br /> <br />
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/ImVexed/muon"><img src="https://goreportcard.com/badge/github.com/ImVexed/muon?style=flat-square"></a>
<img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/ImVexed/muon">
<br/>
<a title="Doc for gnet" target="_blank" href="https://gowalker.org/github.com/ImVexed/muon"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square"></a>
</p>
----
`Muon` is a lightweight alternative to Electron written in Golang in about ~300 LoC, using Ultralight instead of Chromium. [Ultralight](https://ultralig.ht/) is a corss-platform WebKit rewrite using the GPU to target embeded 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
| | Muon | Electron |
|:----:|---------|----------|
| CPU | 0.0% | 1.2% |
| MEM | 26.0 MB | 201.7 MB |
| SIZE | 42 MB | 136 MB |
# Example
From `examples/create-react-app/main.go`:
```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,
Hint: 2 | 4,
}
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: *I get `exit status 3221225781` when I try to run my program*
- Your program likely can't find the [Ultralight](https://ultralig.ht/) libraries. Ensure they're either installed on the system, or, in the same folder as your program.

View File

@ -3,6 +3,3 @@
- Run `yarn && yarn build` inside of `public/`
- Run `go generate && go build` inside this directory.
- Ensure Ultralight libraries are installed
## Help! I get `exit status 3221225781` when I try to run the executable!
Due to Ultralight's licensing it can only be dynamically linked to. Meaning you'll need to either add the respective `.dll`'s or `.so`'s to either a system path, or the same directory as the the executable. You can find these libraries on https://ultralig.ht/ (The version that Muon uses can be found in `ultralight/libs/`)

Binary file not shown.

36
logo.svg Normal file
View File

@ -0,0 +1,36 @@
<svg width="500" height="499" xmlns="http://www.w3.org/2000/svg">
<!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ -->
<g>
<title>background</title>
<rect fill="none" id="canvas_background" height="501" width="502" y="-1" x="-1"/>
<g display="none" overflow="visible" y="0" x="0" height="100%" width="100%" id="canvasGrid">
<rect fill="url(#gridpattern)" stroke-width="0" y="1" x="1" height="400" width="504"/>
</g>
</g>
<g>
<title>Layer 1</title>
<g stroke="null" id="svg_24">
<g stroke="null" transform="matrix(1.63521002689062,0,0,1.6809230736495255,-26426.23454689122,-18662.590335853565) " class="signage-logo" id="svg_11">
<defs stroke="null" transform="translate(0.888778805732727,0.912152111530304) translate(16159.896484375,0) translate(0,11101.5986328125) ">
<linearGradient stroke="null" y2="0.000532" x2="1.000533" y1="0.999468" x1="-0.000533" id="svg_15">
<stop stroke="null" offset="0.05" stop-color="#7197c6" id="svg_17"/>
<stop stroke="null" offset="0.95" stop-color="#355883" id="svg_16"/>
</linearGradient>
</defs>
<g stroke="null" transform="translate(0,11101.5986328125) scale(2.4385147094726562) " id="svg_12">
<g stroke="null" fill="url(#svg_15)" transform="translate(30.489402770996094,-0.6671631336212158) scale(1.334328293800354) " class="ugSTNpRxV" id="svg_14">
<path stroke="null" id="svg_19" d="m4990.973641,25.980336l-0.5,0c-0.9,0 -1.6,-0.7 -1.6,-1.6c0,-0.9 0.7,-1.6 1.6,-1.6l0.5,0c0.9,0 1.6,0.7 1.6,1.6c0.1,0.8 -0.6,1.6 -1.6,1.6zm15.5,-11.9c0.3,1.4 0.6,2.8 0.8,4.3c2.3,1.7 3.7,3.7 3.7,5.8s-1.4,4.2 -3.7,5.8c-0.2,1.5 -0.5,3 -0.8,4.3c4.8,-2.5 7.8,-6.1 7.8,-10.2c0,-3.9 -3,-7.5 -7.8,-10z"/>
<path stroke="null" id="svg_20" d="m4994.673641,37.680336c0.6,-1 1.1,-2.2 1.5,-3.5c-1.8,0.3 -3.6,0.4 -5.5,0.4c-10.8,0 -20.1,-4.7 -20.1,-10.3s9.3,-10.3 20.2,-10.3c1.9,0 3.7,0.1 5.5,0.4c-0.5,-1.4 -1,-2.5 -1.5,-3.5c-1.3,-0.1 -2.6,-0.2 -3.9,-0.2c-13.2,0 -23.5,6 -23.5,13.6s10.2,13.6 23.4,13.6c1.3,0 2.7,-0.1 3.9,-0.2z"/>
<path stroke="null" id="svg_21" d="m4977.373641,20.380336c-0.1,1.3 -0.2,2.6 -0.2,3.9s0.1,2.7 0.2,3.9c1,0.6 2.2,1.1 3.5,1.5c-0.3,-1.8 -0.4,-3.6 -0.4,-5.5s0.1,-3.7 0.4,-5.5c-1.3,0.6 -2.5,1.1 -3.5,1.7z"/>
<path stroke="null" id="svg_22" d="m4990.773641,0.780336c-4.1,0 -7.7,3 -10.2,7.8c1.4,-0.3 2.8,-0.6 4.3,-0.8c1.7,-2.3 3.7,-3.7 5.8,-3.7c5.6,0 10.3,9.3 10.3,20.2c0,10.9 -4.7,20.2 -10.3,20.2c-2.1,0 -4.2,-1.4 -5.8,-3.7c-1.5,-0.2 -3,-0.5 -4.3,-0.8c2.5,4.8 6.1,7.8 10.2,7.8c7.6,0 13.6,-10.3 13.6,-23.5s-6,-23.5 -13.6,-23.5z"/>
</g>
<g stroke="null" fill="#355883" transform="translate(62.58000183105469,121.71343231201172) scale(1) " class="text" id="svg_13">
<path stroke="null" id="svg_23" d="m6587.346858,0.374061l4.98,0l0,-42l-8.28,0l-5.4,21.48l-5.46,-21.48l-8.46,0l0,42l4.8,0l0,-37.68l6.42,23.58l4.98,0l6.42,-23.58l0,37.68zm34.59,-2.55c1.86,-1.7 2.79,-4.25 2.79,-7.65l0,-31.8l-5.22,0l0,32.94c0,1.24 -0.46,2.3 -1.38,3.18c-0.92,0.88 -2.12,1.32 -3.6,1.32l-2.1,0c-1.48,0 -2.68,-0.44 -3.6,-1.32c-0.92,-0.88 -1.38,-1.94 -1.38,-3.18l0,-32.94l-5.22,0l0,31.8c0,3.4 0.93,5.95 2.79,7.65c1.86,1.7 4.53,2.55 8.01,2.55l0.9,0c3.48,0 6.15,-0.85 8.01,-2.55zm32.94,0c1.86,-1.7 2.79,-4.25 2.79,-7.65l0,-21.6c0,-3.4 -0.93,-5.95 -2.79,-7.65c-1.86,-1.7 -4.53,-2.55 -8.01,-2.55l-2.04,0c-3.48,0 -6.15,0.85 -8.01,2.55c-1.86,1.7 -2.79,4.25 -2.79,7.65l0,21.6c0,3.4 0.93,5.95 2.79,7.65c1.86,1.7 4.53,2.55 8.01,2.55l2.04,0c3.48,0 6.15,-0.85 8.01,-2.55zm-3.81,-33.57c0.92,0.88 1.38,1.94 1.38,3.18l0,23.88c0,1.24 -0.46,2.3 -1.38,3.18c-0.92,0.88 -2.12,1.32 -3.6,1.32l-3.24,0c-1.48,0 -2.68,-0.44 -3.6,-1.32c-0.92,-0.88 -1.38,-1.94 -1.38,-3.18l0,-23.88c0,-1.24 0.46,-2.3 1.38,-3.18c0.92,-0.88 2.12,-1.32 3.6,-1.32l3.24,0c1.48,0 2.68,0.44 3.6,1.32zm30.24,36.12l8.58,0l0,-42l-4.86,0l0,37.56l-9.24,-37.56l-8.52,0l0,42l4.86,0l0,-37.56l9.18,37.56z"/>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -11,6 +11,7 @@ import (
. "github.com/ImVexed/muon/ultralight"
)
// Window represents a single Ultralight instance
type Window struct {
wnd ULWindow
view ULView
@ -25,6 +26,7 @@ type ipf struct {
ReturnTypes []reflect.Type
}
// Config contains configurable controls for the Ultralight engine
type Config struct {
Title string
Height uint32
@ -34,6 +36,7 @@ type Config struct {
Y int32
}
// New creates a Ultralight Window
func New(cfg *Config, handler http.Handler) *Window {
w := &Window{
cfg: cfg,
@ -57,6 +60,7 @@ func New(cfg *Config, handler http.Handler) *Window {
return w
}
// Start sets up the Ultralight runtime and begins showing the Window
func (w *Window) Start() error {
addr, err := serveHandler(w.handler)