[windows-x] Generate runtime wrapper in project, initial model binding, better error handling in calls, assetdir fix,

This commit is contained in:
Lea Anthony
2021-08-27 21:11:03 +10:00
parent f20ce7411d
commit a7c5064a33
51 changed files with 849 additions and 55 deletions
+10 -8
View File
@@ -112,14 +112,8 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
return fmt.Errorf("No asset directory provided. Please use -assetdir to indicate which directory contains your built assets.")
}
assetDir, err = filepath.Abs(assetDir)
if err != nil {
return err
}
if assetDir != "" && assetDir != projectConfig.AssetDirectory {
projectConfig.AssetDirectory = assetDir
err := projectConfig.Save()
if assetDir != "" {
assetDir, err = filepath.Abs(assetDir)
if err != nil {
return err
}
@@ -129,6 +123,14 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
assetDir = projectConfig.AssetDirectory
}
if assetDir != projectConfig.AssetDirectory {
projectConfig.AssetDirectory = assetDir
err := projectConfig.Save()
if err != nil {
return err
}
}
wailsjsdir, err = filepath.Abs(wailsjsdir)
if err != nil {
return err
+1
View File
@@ -69,6 +69,7 @@ require (
github.com/tidwall/gjson v1.8.0 // indirect
github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.1.0 // indirect
github.com/tkrajina/typescriptify-golang-structs v0.1.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
+3
View File
@@ -179,6 +179,9 @@ github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.7 h1:sgVPwu/yygHJ2m1pJDLgGM/h+1F5odx5Q9ljG3imRm8=
github.com/tidwall/sjson v1.1.7/go.mod h1:w/yG+ezBeTdUxiKs5NcPicO9diP38nk96QBAbIIGeFs=
github.com/tkrajina/go-reflector v0.5.4/go.mod h1:9PyLgEOzc78ey/JmQQHbW8cQJ1oucLlNQsg8yFvkVk8=
github.com/tkrajina/typescriptify-golang-structs v0.1.6 h1:AlUeArKYvOdsl0wL7VKtRDgBqT7Hvk87w7hYGrITcqg=
github.com/tkrajina/typescriptify-golang-structs v0.1.6/go.mod h1:mfb2iqie4FjTKHfbjjCp08SRphjYaM7f2LdfUcNP7wY=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
+6
View File
@@ -97,6 +97,12 @@ func CreateApp(appoptions *options.App) (*App, error) {
// Create binding exemptions - Ugly hack. There must be a better way
bindingExemptions := []interface{}{appoptions.OnStartup, appoptions.OnShutdown, appoptions.OnDomReady}
appBindings := binding.NewBindings(myLogger, appoptions.Bind, bindingExemptions)
bindingsDir := "."
err = appBindings.WriteTS(bindingsDir)
if err != nil {
return nil, err
}
eventHandler := runtime.NewEvents(myLogger)
ctx = context.WithValue(ctx, "events", eventHandler)
messageDispatcher := dispatcher.NewDispatcher(myLogger, appBindings, eventHandler)
+12 -2
View File
@@ -2,6 +2,8 @@ package binding
import (
"fmt"
"github.com/tkrajina/typescriptify-golang-structs/typescriptify"
"path/filepath"
"reflect"
"runtime"
"strings"
@@ -15,13 +17,17 @@ type Bindings struct {
db *DB
logger logger.CustomLogger
exemptions slicer.StringSlicer
// Typescript writer
converter *typescriptify.TypeScriptify
}
// NewBindings returns a new Bindings object
func NewBindings(logger *logger.Logger, structPointersToBind []interface{}, exemptions []interface{}) *Bindings {
result := &Bindings{
db: newDB(),
logger: logger.CustomLogger("Bindings"),
db: newDB(),
logger: logger.CustomLogger("Bindings"),
converter: typescriptify.New(),
}
for _, exemption := range exemptions {
@@ -65,6 +71,10 @@ func (b *Bindings) Add(structPtr interface{}) error {
return nil
}
func (b *Bindings) WriteTS(dir string) error {
return b.converter.ConvertToFile(filepath.Join(dir, "models.ts"))
}
func (b *Bindings) DB() *DB {
return b.db
}
+18
View File
@@ -77,6 +77,24 @@ func (b *Bindings) getMethods(value interface{}) ([]*BoundMethod, error) {
for inputIndex := 0; inputIndex < inputParamCount; inputIndex++ {
input := methodType.In(inputIndex)
thisParam := newParameter("", input)
// Process struct pointer params
if input.Kind() == reflect.Ptr {
if input.Elem().Kind() == reflect.Struct {
typ := input.Elem()
a := reflect.New(typ)
s := reflect.Indirect(a).Interface()
b.converter.Add(s)
}
}
// Process struct params
if input.Kind() == reflect.Struct {
a := reflect.New(input)
s := reflect.Indirect(a).Interface()
b.converter.Add(s)
}
inputs = append(inputs, thisParam)
}
@@ -264,6 +264,8 @@ func (f *Frontend) processMessage(message string) {
result, err := f.dispatcher.ProcessMessage(message, f)
if err != nil {
f.logger.Error(err.Error())
f.Callback(result)
return
}
if result == "" {
return
+13 -1
View File
@@ -28,7 +28,9 @@ func (d *Dispatcher) processCallMessage(message string) (string, error) {
args, err := registeredMethod.ParseArgs(payload.Args)
if err != nil {
return "", fmt.Errorf("error parsing arguments: %s", err.Error())
errmsg := fmt.Errorf("error parsing arguments: %s", err.Error())
result, _ := d.NewErrorCallback(errmsg.Error(), payload.CallbackID)
return result, errmsg
}
result, err := registeredMethod.Call(args)
@@ -56,3 +58,13 @@ type CallbackMessage struct {
Err string `json:"error"`
CallbackID string `json:"callbackid"`
}
func (d *Dispatcher) NewErrorCallback(message string, callbackID string) (string, error) {
result := &CallbackMessage{
CallbackID: callbackID,
Err: message,
}
messageData, err := json.Marshal(result)
d.log.Trace("json call result data: %+v\n", string(messageData))
return string(messageData), err
}
@@ -4,12 +4,12 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
import { Call } from './calls';
import {Call} from './calls';
window.backend = {};
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
+1 -1
View File
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
+1 -1
View File
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
+1 -1
View File
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 9 */
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
+1 -1
View File
@@ -4,7 +4,7 @@
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The lightweight framework for web-like apps
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
@@ -9,6 +9,7 @@
"build:ipc-dev": "cd dev && npm run build",
"build:runtime-desktop-prod": "esbuild desktop/main.js --bundle --minify --outfile=runtime_prod_desktop.js",
"build:runtime-desktop-dev": "esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_dev_desktop.js",
"build:runtime-wrapper": "cd wrapper && esbuild main.js --bundle --minify --outfile=runtime.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Lea Anthony <lea.anthony@gmail.com>",
File diff suppressed because one or more lines are too long
@@ -0,0 +1,4 @@
# Wails Runtime
This module is the Javascript runtime library for the [Wails](https://wails.app) framework. It is intended to be
installed as part of a [Wails](https://wails.app) project, not a standalone module.
@@ -0,0 +1,58 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 9 */
/**
* Registers an event listener that will be invoked `maxCallbacks` times before being destroyed
*
* @export
* @param {string} eventName
* @param {function} callback
* @param {number} maxCallbacks
*/
export function EventsOnMultiple(eventName, callback, maxCallbacks) {
window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
}
/**
* Registers an event listener that will be invoked every time the event is emitted
*
* @export
* @param {string} eventName
* @param {function} callback
*/
export function EventsOn(eventName, callback) {
OnMultiple(eventName, callback, -1);
}
/**
* Registers an event listener that will be invoked once then destroyed
*
* @export
* @param {string} eventName
* @param {function} callback
*/
export function EventsOnce(eventName, callback) {
OnMultiple(eventName, callback, 1);
}
/**
* Emit an event with the given name and data
*
* @export
* @param {string} eventName
*/
export function EventsEmit(eventName) {
let args = [eventName].slice.call(arguments);
return window.runtime.EventsEmit.apply(null, args);
}

Some files were not shown because too many files have changed in this diff Show More