a web browser in golang

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-01-26 08:55:42 -06:00
parent e22fe52844
commit 9b55d767af
10 changed files with 933 additions and 0 deletions

9
go-web-browser/Makefile Normal file
View File

@ -0,0 +1,9 @@
run:
LD_LIBRARY_PATH=./libs/ ./go-web-browser
prep:
GO111MODULE="off" go get -v .
build:
GO111MODULE="off" go build -v -x
# go build

109
go-web-browser/README.md Normal file
View File

@ -0,0 +1,109 @@
<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?style=flat-square">
<br/>
<a 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 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`:
```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?*
- See our [getting started guide](https://github.com/ImVexed/muon/blob/master/getting-started.md)
## Q: *Is there perfect Chrome or Firefox feature parity?*
- No, see [Missing Ultralight Features](https://github.com/ultralight-ux/Ultralight/issues/178)
## 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](https://github.com/ultralight-ux/Ultralight#getting-the-latest-sdk) 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](https://github.com/ultralight-ux/Ultralight#getting-the-latest-sdk) 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](https://ultralig.ht/) 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](https://github.com/ultralight-ux/Ultralight/tree/master/license).

80
go-web-browser/b0x.yml Normal file
View File

@ -0,0 +1,80 @@
# all folders and files are relative to the path
# where fileb0x was run at!
# default: main
pkg: webfiles
# destination
dest: "./webfiles/"
# gofmt
# type: bool
# default: false
fmt: true
# compress files
# at the moment, only supports gzip
#
# type: object
compression:
# activates the compression
#
# type: bool
# default: false
compress: true
# valid values are:
# -> "NoCompression"
# -> "BestSpeed"
# -> "BestCompression"
# -> "DefaultCompression" or ""
#
# type: string
# default: "DefaultCompression" # when: Compress == true && Method == ""
method: "BestCompression"
# true = do it yourself (the file is written as gzip compressed file into the memory file system)
# false = decompress files at run time (while writing file into memory file system)
#
# type: bool
# default: false
keep: false
# ---------------
# -- DANGEROUS --
# ---------------
#
# cleans the destination folder (only b0xfiles)
# you should use this when using the spread function
# type: bool
# default: false
clean: false
# default: ab0x.go
output: "ab0x.go"
# [unexporTed] builds non-exporTed functions, variables and types...
# type: bool
# default: false
unexporTed: false
# [spread] means it will make a file to hold all fileb0x data
# and each file into a separaTed .go file
#
# example:
# theres 2 files in the folder assets, they're: hello.json and world.txt
# when spread is activaTed, fileb0x will make a file:
# b0x.go or [output]'s data, assets_hello.json.go and assets_world.txt.go
#
#
# type: bool
# default: false
spread: false
# [lcf] log changed files when spread is active
lcf: true
custom:
- files:
- "./public/build/"
base: "public/build/"

View File

@ -0,0 +1,16 @@
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
reactjs.org FALSE / FALSE 1737816711 _ga GA1.2.1575035271.1674744711
reactjs.org FALSE / FALSE 1674831111 _gid GA1.2.315261024.1674744711
.app.link TRUE / TRUE 1706280819 _s nVh5UZnyPSX%2BjZMzGeOJOhkzkvrOWX7vNsavkj53OTMJoRbjvR3u0%2FUTAjckXZNb
.twitter.com TRUE / TRUE 1737816754 guest_id_marketing v1%3A167474475435406140
.twitter.com TRUE / TRUE 1737816754 guest_id_ads v1%3A167474475435406140
.twitter.com TRUE / TRUE 1737816754 personalization_id "v1_/8QsdsjoES02yQmbJSLIpw=="
.twitter.com TRUE / TRUE 1737816754 guest_id v1%3A167474475435406140
.twitter.com TRUE / TRUE 1674766355 ct0 634f153fe6d5bfb258d0cbe06128f3ff
.twitter.com TRUE / TRUE 1674755555 gt 1618622938780934144
.twitter.com TRUE / TRUE 1675349556 external_referer padhuUp37zhzlZj1DFmOK0aqVXVYMDbrNryw37HkfEIN7E1jASwNOnVkkohzgOWO1NJlYRw%2Fod4%3D|0|8e8t2xd8A2w%3D
twitter.com FALSE / FALSE 1737816818 _ga GA1.2.1427383957.1674744757
twitter.com FALSE / FALSE 1674831218 _gid GA1.2.1904932596.1674744757

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

33
go-web-browser/main.go Normal file
View File

@ -0,0 +1,33 @@
//go:generate fileb0x b0x.yml
package main
import (
"github.com/ImVexed/muon"
"git.wit.org/jcarr/golang-examples/go-web-browser/webfiles"
"net/http"
)
func main() {
fileHandler := http.FileServer(webfiles.HTTP)
cfg := &muon.Config{
Title: "Hello, World!",
Height: 500,
Width: 500,
Titled: true,
Resizeable: true,
}
m := muon.New(cfg, fileHandler)
m.Bind("add", add)
if err := m.Start(); err != nil {
panic(err)
}
}
func add(a float64, b float64) float64 {
return a + b
}

File diff suppressed because one or more lines are too long