packaging + alpha

This commit is contained in:
ImVexed 2019-10-01 21:38:14 -05:00
parent a74a62b04d
commit 63dc58ac61
No known key found for this signature in database
GPG Key ID: F16360BA6A2715B8
31 changed files with 235 additions and 202 deletions

View File

@ -0,0 +1,3 @@
module cra
go 1.13

View File

@ -0,0 +1,30 @@
//go:generate fileb0x b0x.yml
package main
import (
"cra/webfiles"
"http"
)
func main() {
fileHandler := http.FileServer(webfiles.HTTP)
cfg := &muon.Config{
Title: "Hello, World!",
Height: 500,
Width: 500,
Hint: 2 | 4,
}
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
}

View File

@ -1,6 +1,6 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import logo from './logo.svg';
function App() {
/*eslint-disable no-undef*/
@ -9,8 +9,7 @@ function App() {
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
ts
{/* {getOS()} */}
{window.add(1, 2)}
</p>
<a
className="App-link"

View File

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@ -7897,15 +7897,15 @@ react-dev-utils@^9.0.4:
strip-ansi "5.2.0"
text-table "0.2.0"
react-dom@16.9.0:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.9.0.tgz#5e65527a5e26f22ae3701131bcccaee9fb0d3962"
integrity sha512-YFT2rxO9hM70ewk9jq0y6sQk8cL02xm4+IzYBz75CQGlClQQ1Bxq0nhHF6OtSbit+AIahujJgb/CPRibFkMNJQ==
react-dom@^16.9.0:
version "16.10.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.0.tgz#319356767b5c044f3c016eef28518ef7726dce84"
integrity sha512-0QJQUFrKG04hB/1lWyUs/FOd1qNseKGRQI+JBRsADIqVAFxYObhZ2zsVQKjt+nVSCmi8KA0sL52RLwwWuXQtOw==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.15.0"
scheduler "^0.16.0"
react-error-overlay@^6.0.2:
version "6.0.2"
@ -7978,10 +7978,10 @@ react-scripts@3.1.2:
optionalDependencies:
fsevents "2.0.7"
react@16.9.0:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"
integrity sha512-+7LQnFBwkiw+BobzOF6N//BdoNw0ouwmSJTEm9cglOOmsg/TMiFHZLe2sEoN5M7LgJTj9oHH0gxklfnQe66S1w==
react@^16.9.0:
version "16.10.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.10.0.tgz#95c41e8fc1c706e174deef54b663b5ab94c8ee32"
integrity sha512-lc37bD3j6ZWJRso/a1rrFu6CO1qOf30ZadUDBi1c5RHA1lBSWA8x2MGABB6Oikk+RfmgC+kAT+XegL0eD1ecKg==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
@ -8436,10 +8436,10 @@ saxes@^3.1.9:
dependencies:
xmlchars "^2.1.1"
scheduler@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e"
integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg==
scheduler@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.0.tgz#cc8914b79c5c1cfa16714cb1ddc4cbd2c7513efa"
integrity sha512-Jq59uCXQzi71B562VEjuDgvsgfTfkLDvdjNhA7hamN/fKBxecXIEFF24Zu4OVrnAz9NJJ8twa9X16Zp4b0P/xQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

View File

@ -1,21 +0,0 @@
package fileserver
import (
"log"
"net"
"net/http"
"test/webfiles"
)
func Serve() (string, error) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return "", err
}
go func() {
log.Fatal(http.Serve(ln, http.FileServer(webfiles.HTTP)))
}()
return "http://" + ln.Addr().String(), nil
}

9
go.mod
View File

@ -1,5 +1,8 @@
module test
module muon
go 1.12
go 1.13
require golang.org/x/net v0.0.0-20190926025831-c00fd9afed17
require (
github.com/capnm/sysinfo v0.0.0-20130621111458-5909a53897f3
golang.org/x/net v0.0.0-20190926025831-c00fd9afed17
)

76
main.go
View File

@ -1,76 +0,0 @@
//go:generate fileb0x b0x.yml
package main
import (
"fmt"
"runtime"
. "test/ultralight"
"unsafe"
"test/fileserver"
)
func jsHandle(
ctx JSContextRef,
function JSObjectRef,
thisObject JSObjectRef,
argumentCount uint,
arguments []JSValueRef,
exception []JSValueRef) JSValueRef {
fmt.Println("Hello, World!")
return JSValueMakeString(ctx, JSStringCreateWithUTF8CString(runtime.GOOS))
}
func main() {
cfg := UlCreateConfig()
app := UlCreateApp(cfg)
mm := UlAppGetMainMonitor(app)
wnd := UlCreateWindow(mm, 500, 500, false, 2|4)
UlWindowSetTitle(wnd, "Hello, World!")
UlAppSetWindow(app, wnd)
ov := UlCreateOverlay(wnd, 500, 500, 0, 0)
UlWindowSetResizeCallback(wnd, resizeCallback, unsafe.Pointer(&ov))
view := UlOverlayGetView(ov)
addr, err := fileserver.Serve()
if err != nil {
panic(err)
}
fmt.Println(addr)
url := UlCreateString(addr)
defer UlDestroyString(url)
addFunctionToView(view, "getOS", jsHandle)
UlViewLoadURL(view, url)
UlAppRun(app)
}
func addFunctionToView(view ULView, name string, callback JSObjectCallAsFunctionCallback) {
ctx := UlViewGetJSContext(view)
gobj := JSContextGetGlobalObject(ctx)
fn := JSStringCreateWithUTF8CString(name)
defer JSStringRelease(fn)
fob := JSObjectMakeFunctionWithCallback(ctx, fn, callback)
val := *(*JSValueRef)(unsafe.Pointer(&fob))
JSObjectSetProperty(ctx, gobj, fn, val, KJSPropertyAttributeNone, []JSValueRef{})
}
func resizeCallback(user_data unsafe.Pointer, width uint32, height uint32) {
overlay := *(*ULOverlay)(user_data)
UlOverlayResize(overlay, width, height)
}

174
muon.go Normal file
View File

@ -0,0 +1,174 @@
package main
import (
"net"
"net/http"
"reflect"
"unsafe"
. "muon/ultralight"
)
type Window struct {
wnd ULWindow
view ULView
app ULApp
handler http.Handler
cfg *Config
}
type ipf struct {
Function reflect.Value
ParamTypes []reflect.Type
ReturnTypes []reflect.Type
}
type Config struct {
Title string
Height uint32
Width uint32
Hint uint32
X int32
Y int32
}
func New(cfg *Config, handler http.Handler) *Window {
w := &Window{
cfg: cfg,
handler: handler,
}
ufg := UlCreateConfig()
w.app = UlCreateApp(ufg)
mm := UlAppGetMainMonitor(w.app)
w.wnd = UlCreateWindow(mm, w.cfg.Height, w.cfg.Width, false, w.cfg.Hint)
UlWindowSetTitle(w.wnd, w.cfg.Title)
UlAppSetWindow(w.app, w.wnd)
ov := UlCreateOverlay(w.wnd, w.cfg.Height, w.cfg.Width, w.cfg.X, w.cfg.Y)
UlWindowSetResizeCallback(w.wnd, resizeCallback, unsafe.Pointer(&ov))
w.view = UlOverlayGetView(ov)
return w
}
func (w *Window) Start() error {
addr, err := serveHandler(w.handler)
if err != nil {
return err
}
url := UlCreateString(addr)
defer UlDestroyString(url)
UlViewLoadURL(w.view, url)
UlAppRun(w.app)
return nil
}
// Bind registers the given function to the given name in the Window's JS global object
func (w *Window) Bind(name string, function interface{}) {
f := &ipf{
Function: reflect.ValueOf(function),
}
t := f.Function.Type()
f.ParamTypes = make([]reflect.Type, t.NumIn())
for i := 0; i < t.NumIn(); i++ {
f.ParamTypes[i] = t.In(i)
}
f.ReturnTypes = make([]reflect.Type, t.NumOut())
for i := 0; i < t.NumOut(); i++ {
f.ParamTypes[i] = t.Out(i)
}
addFunctionToView(w.view, name, w.makeIPCCallback(f))
}
func (w *Window) makeIPCCallback(f *ipf) func(JSContextRef, JSObjectRef, JSObjectRef, uint, []JSValueRef, []JSValueRef) JSValueRef {
return func(
ctx JSContextRef,
function JSObjectRef,
thisObject JSObjectRef,
argumentCount uint,
arguments []JSValueRef,
exception []JSValueRef) JSValueRef {
params := make([]reflect.Value, argumentCount)
for i := uint(0); i < argumentCount; i++ {
switch JSValueGetType(ctx, arguments[i]) {
case KJSTypeBoolean:
params[i] = reflect.ValueOf(JSValueToBoolean(ctx, arguments[i]))
case KJSTypeNumber:
params[i] = reflect.ValueOf(JSValueToNumber(ctx, arguments[i], exception))
case KJSTypeString:
ref := JSValueToStringCopy(ctx, arguments[i], exception)
params[i] = reflect.ValueOf(*(*string)(unsafe.Pointer(&ref)))
JSStringRelease(ref)
default:
panic("Not implemented!") // TODO: Object JSON
}
}
val := f.Function.Call(params)
if len(val) > 1 {
panic("Not implemented!") // TODO: more than 1 return type
}
switch val[0].Kind() {
case reflect.Float64:
return JSValueMakeNumber(ctx, val[0].Float())
case reflect.Bool:
return JSValueMakeBoolean(ctx, val[0].Bool())
case reflect.String:
return JSValueMakeString(ctx, JSStringCreateWithUTF8CString(val[0].String()))
default:
panic("Not implemented!") // TODO: Object JSON
}
}
}
func addFunctionToView(view ULView, name string, callback JSObjectCallAsFunctionCallback) {
ctx := UlViewGetJSContext(view)
gobj := JSContextGetGlobalObject(ctx)
fn := JSStringCreateWithUTF8CString(name)
defer JSStringRelease(fn)
fob := JSObjectMakeFunctionWithCallback(ctx, fn, callback)
val := *(*JSValueRef)(unsafe.Pointer(&fob))
JSObjectSetProperty(ctx, gobj, fn, val, KJSPropertyAttributeNone, []JSValueRef{})
}
func resizeCallback(user_data unsafe.Pointer, width uint32, height uint32) {
overlay := *(*ULOverlay)(user_data)
UlOverlayResize(overlay, width, height)
}
func serveHandler(handler http.Handler) (string, error) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return "", err
}
go func() {
panic(http.Serve(ln, handler))
}()
return "http://" + ln.Addr().String(), nil
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@ -1,43 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@ -1,25 +0,0 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -1,2 +0,0 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
#include "_cgo_export.h"

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
package ultralight
@ -886,7 +886,7 @@ func jSObjectCallAsFunctionCallback89F9469B(cctx C.JSContextRef, cfunction C.JSO
hxff73280 := (*sliceHeader)(unsafe.Pointer(&arguments89f9469b))
hxff73280.Data = unsafe.Pointer(carguments)
hxff73280.Cap = 0x7fffffff
// hxff73280.Len = ?
hxff73280.Len = int(argumentCount89f9469b) // <-- Was commented out
var exception89f9469b []JSValueRef
hxfa9955c := (*sliceHeader)(unsafe.Pointer(&exception89f9469b))

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
#include "AppCore/CAPI.h"

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
package ultralight

View File

@ -1,9 +0,0 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
/*
Ultralight bindings for golang
*/
package ultralight

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
package ultralight

View File

@ -1,6 +1,6 @@
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
// WARNING: This file has automatically been generated on Thu, 26 Sep 2019 10:38:04 CDT.
// WARNING: This file has automatically been generated on Fri, 27 Sep 2019 21:28:43 CDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
package ultralight