mirror of
https://gitee.com/energye/energy.git
synced 2024-11-30 10:47:57 +08:00
upgrade-dev v2.2.0
This commit is contained in:
parent
3695dbdcd8
commit
e4186ef1b5
@ -347,6 +347,12 @@ func (m *ICefV8Value) GetValueByIndex(index int) *ICefV8Value {
|
||||
|
||||
// setValueByKey internal
|
||||
func (m *ICefV8Value) setValueByKey(key string, value *ICefV8Value, attribute consts.TCefV8PropertyAttributes) bool {
|
||||
if m.valueByKeys != nil {
|
||||
if v, ok := m.valueByKeys[key]; ok {
|
||||
v.Free()
|
||||
}
|
||||
m.valueByKeys[key] = value
|
||||
}
|
||||
r1, _, _ := imports.Proc(internale_CefV8Value_SetValueByKey).Call(m.Instance(), api.PascalStr(key), value.Instance(), attribute.ToPtr())
|
||||
return api.GoBool(r1)
|
||||
}
|
||||
@ -360,6 +366,9 @@ func (m *ICefV8Value) SetValueByKey(key string, value *ICefV8Value, attribute co
|
||||
}
|
||||
|
||||
func (m *ICefV8Value) SetValueByIndex(index int32, value *ICefV8Value) bool {
|
||||
if m.valueByIndex != nil {
|
||||
m.valueByIndex = append(m.valueByIndex, value)
|
||||
}
|
||||
r1, _, _ := imports.Proc(internale_CefV8Value_SetValueByIndex).Call(m.Instance(), uintptr(index), value.Instance())
|
||||
return api.GoBool(r1)
|
||||
}
|
||||
@ -486,6 +495,22 @@ func (m *ICefV8Value) RejectPromise(errorMsg string) bool {
|
||||
|
||||
func (m *ICefV8Value) Free() {
|
||||
if m.instance != nil {
|
||||
if m.valueByIndex != nil {
|
||||
for _, v := range m.valueByIndex {
|
||||
if v != nil && v.instance != nil {
|
||||
v.Free()
|
||||
}
|
||||
}
|
||||
m.valueByIndex = nil
|
||||
}
|
||||
if m.valueByKeys != nil {
|
||||
for _, v := range m.valueByKeys {
|
||||
if v != nil && v.instance != nil {
|
||||
v.Free()
|
||||
}
|
||||
}
|
||||
m.valueByKeys = nil
|
||||
}
|
||||
//var data = m.Instance()
|
||||
//imports.Proc(internale_CefV8Value_Free).Call(uintptr(unsafe.Pointer(&data)))
|
||||
m.base.Free(m.Instance())
|
||||
@ -669,8 +694,9 @@ func (*cefV8Value) NewObject(accessor *ICefV8Accessor) *ICefV8Value {
|
||||
var result uintptr
|
||||
imports.Proc(internale_CefV8ValueRef_NewObject).Call(accessor.Instance(), uintptr(0), uintptr(unsafe.Pointer(&result)))
|
||||
return &ICefV8Value{
|
||||
instance: unsafe.Pointer(result),
|
||||
valueType: consts.V8vtObject,
|
||||
instance: unsafe.Pointer(result),
|
||||
valueType: consts.V8vtObject,
|
||||
valueByKeys: make(map[string]*ICefV8Value),
|
||||
}
|
||||
}
|
||||
|
||||
@ -678,8 +704,9 @@ func (*cefV8Value) NewArray(len int32) *ICefV8Value {
|
||||
var result uintptr
|
||||
imports.Proc(internale_CefV8ValueRef_NewArray).Call(uintptr(len), uintptr(unsafe.Pointer(&result)))
|
||||
return &ICefV8Value{
|
||||
instance: unsafe.Pointer(result),
|
||||
valueType: consts.V8vtArray,
|
||||
instance: unsafe.Pointer(result),
|
||||
valueType: consts.V8vtArray,
|
||||
valueByIndex: make([]*ICefV8Value, len),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,9 +354,11 @@ type ICefV8Context struct {
|
||||
|
||||
// ICefV8Value
|
||||
type ICefV8Value struct {
|
||||
base TCefBaseRefCounted
|
||||
instance unsafe.Pointer
|
||||
valueType V8ValueType
|
||||
base TCefBaseRefCounted
|
||||
instance unsafe.Pointer
|
||||
valueType V8ValueType
|
||||
valueByIndex []*ICefV8Value
|
||||
valueByKeys map[string]*ICefV8Value
|
||||
}
|
||||
|
||||
// ICefV8ValueKeys
|
||||
|
@ -474,8 +474,10 @@ func dictionaryValueToV8Value(dictionary *ICefDictionaryValue) (*ICefV8Value, er
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// BytesToV8ArrayValue JSONArray 字节数组转换 TCefV8ValueArray
|
||||
func (m *v8ValueProcessMessageConvert) BytesToV8ArrayValue(resultArgsBytes []byte) (*TCefV8ValueArray, error) {
|
||||
fmt.Println("result-bytes:", string(resultArgsBytes))
|
||||
//只能是 JSONArray 对象类型
|
||||
jsonArray := json.NewJSONArray(resultArgsBytes)
|
||||
if jsonArray == nil {
|
||||
return nil, errors.New("parsing parameter failure")
|
||||
@ -485,7 +487,28 @@ func (m *v8ValueProcessMessageConvert) BytesToV8ArrayValue(resultArgsBytes []byt
|
||||
for i := 0; i < size; i++ {
|
||||
value := jsonArray.GetByIndex(i)
|
||||
switch value.Type() {
|
||||
|
||||
case consts.GO_VALUE_STRING:
|
||||
resultArgs.Add(V8ValueRef.NewString(value.String()))
|
||||
case consts.GO_VALUE_INT:
|
||||
resultArgs.Add(V8ValueRef.NewInt(int32(value.Int())))
|
||||
case consts.GO_VALUE_UINT:
|
||||
resultArgs.Add(V8ValueRef.NewUInt(uint32(value.UInt())))
|
||||
case consts.GO_VALUE_FLOAT64:
|
||||
resultArgs.Add(V8ValueRef.NewDouble(value.Float()))
|
||||
case consts.GO_VALUE_BOOL:
|
||||
resultArgs.Add(V8ValueRef.NewBool(value.Bool()))
|
||||
case consts.GO_VALUE_SLICE:
|
||||
if v := m.JSONArrayToV8Value(value.JSONArray()); v != nil {
|
||||
resultArgs.Add(v)
|
||||
} else {
|
||||
resultArgs.Add(V8ValueRef.NewNull())
|
||||
}
|
||||
case consts.GO_VALUE_MAP:
|
||||
if v := m.JSONObjectToV8Value(value.JSONObject()); v != nil {
|
||||
resultArgs.Add(v)
|
||||
} else {
|
||||
resultArgs.Add(V8ValueRef.NewNull())
|
||||
}
|
||||
}
|
||||
fmt.Println("type:", value.Type())
|
||||
}
|
||||
@ -494,6 +517,94 @@ func (m *v8ValueProcessMessageConvert) BytesToV8ArrayValue(resultArgsBytes []byt
|
||||
return resultArgs, nil
|
||||
}
|
||||
|
||||
// JSONArrayToV8Value JSONArray 转 ICefV8Value
|
||||
func (m *v8ValueProcessMessageConvert) JSONArrayToV8Value(array json.JSONArray) *ICefV8Value {
|
||||
if array == nil || !array.IsArray() {
|
||||
return nil
|
||||
}
|
||||
size := array.Size()
|
||||
result := V8ValueRef.NewArray(int32(size))
|
||||
for i := 0; i < size; i++ {
|
||||
value := array.GetByIndex(i)
|
||||
if value == nil {
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewNull())
|
||||
continue
|
||||
}
|
||||
switch value.Type() {
|
||||
case consts.GO_VALUE_STRING:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewString(value.String()))
|
||||
case consts.GO_VALUE_INT:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewInt(int32(value.Int())))
|
||||
case consts.GO_VALUE_UINT:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewUInt(uint32(value.UInt())))
|
||||
case consts.GO_VALUE_FLOAT64:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewDouble(value.Float()))
|
||||
case consts.GO_VALUE_BOOL:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewBool(value.Bool()))
|
||||
case consts.GO_VALUE_SLICE:
|
||||
if v := m.JSONArrayToV8Value(value); v != nil {
|
||||
result.SetValueByIndex(int32(i), v)
|
||||
} else {
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewNull())
|
||||
}
|
||||
case consts.GO_VALUE_MAP:
|
||||
if v := m.JSONObjectToV8Value(value.JSONObject()); v != nil {
|
||||
result.SetValueByIndex(int32(i), v)
|
||||
} else {
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewNull())
|
||||
}
|
||||
default:
|
||||
result.SetValueByIndex(int32(i), V8ValueRef.NewNull())
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// JSONObjectToV8Value JSONObject 转 ICefV8Value
|
||||
func (m *v8ValueProcessMessageConvert) JSONObjectToV8Value(object json.JSONObject) *ICefV8Value {
|
||||
if object == nil || !object.IsObject() {
|
||||
return nil
|
||||
}
|
||||
size := object.Size()
|
||||
result := V8ValueRef.NewObject(nil)
|
||||
keys := object.Keys()
|
||||
for i := 0; i < size; i++ {
|
||||
key := keys[i]
|
||||
value := object.GetByKey(key)
|
||||
if value == nil {
|
||||
result.setValueByKey(key, V8ValueRef.NewNull(), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
continue
|
||||
}
|
||||
switch value.Type() {
|
||||
case consts.GO_VALUE_STRING:
|
||||
result.setValueByKey(key, V8ValueRef.NewString(value.String()), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
case consts.GO_VALUE_INT:
|
||||
result.setValueByKey(key, V8ValueRef.NewInt(int32(value.Int())), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
case consts.GO_VALUE_UINT:
|
||||
result.setValueByKey(key, V8ValueRef.NewUInt(uint32(value.UInt())), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
case consts.GO_VALUE_FLOAT64:
|
||||
result.setValueByKey(key, V8ValueRef.NewDouble(value.Float()), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
case consts.GO_VALUE_BOOL:
|
||||
result.setValueByKey(key, V8ValueRef.NewBool(value.Bool()), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
case consts.GO_VALUE_SLICE:
|
||||
if v := m.JSONArrayToV8Value(value.JSONArray()); v != nil {
|
||||
result.setValueByKey(key, v, consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
} else {
|
||||
result.setValueByKey(key, V8ValueRef.NewNull(), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
}
|
||||
case consts.GO_VALUE_MAP:
|
||||
if v := m.JSONObjectToV8Value(value); v != nil {
|
||||
result.setValueByKey(key, v, consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
} else {
|
||||
result.setValueByKey(key, V8ValueRef.NewNull(), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
}
|
||||
default:
|
||||
result.setValueByKey(key, V8ValueRef.NewNull(), consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// V8ValueToProcessMessageBytes ICefV8Value 转换 []byte 进程消息
|
||||
func (m *v8ValueProcessMessageConvert) V8ValueToProcessMessageBytes(v8value *ICefV8Value) []byte {
|
||||
if result, err := m.V8valueArrayToSlice(v8value); err == nil {
|
||||
|
@ -8,8 +8,7 @@ import (
|
||||
"github.com/energye/energy/common/assetserve"
|
||||
"github.com/energye/energy/example/dev-test/ipc-event/src"
|
||||
"github.com/energye/energy/ipc"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
//_ "net/http/pprof"
|
||||
)
|
||||
|
||||
//go:embed resources
|
||||
@ -17,10 +16,10 @@ var resources embed.FS
|
||||
var cefApp *cef.TCEFApplication
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
fmt.Println("pprof")
|
||||
http.ListenAndServe(":9999", nil)
|
||||
}()
|
||||
//go func() {
|
||||
// fmt.Println("pprof")
|
||||
// http.ListenAndServe(":9999", nil)
|
||||
//}()
|
||||
//logger.SetEnable(true)
|
||||
//logger.SetLevel(logger.CefLog_Debug)
|
||||
//全局初始化 每个应用都必须调用的
|
||||
@ -102,7 +101,7 @@ func main() {
|
||||
objMapArr[1] = r9
|
||||
objMapArr[2] = r9
|
||||
err := &MyError{error: "返回值"}
|
||||
context.Result("asdfsadf", 123123, true, err /*, r5, r6, r7, r8, r9*/)
|
||||
context.Result("asdfsadf", 123123, true, err, r5, r6, r7, r8, r9)
|
||||
})
|
||||
|
||||
cef.VariableBind.Bind("funcName", func(intVar int, stringVar string, doubleVar float64) (string, int, bool) {
|
||||
|
@ -50,8 +50,17 @@
|
||||
]
|
||||
let args1 = "中文中文中文中文中文中文中文string 中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文string 中文中文中文中文中文中文中文中文中文中文中文中文中string 文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文"
|
||||
let ok = ipc.emit("testEmitName", [args1, idx, true, 1999.66 + idx, "字符串?", 29999.66 + idx, objectValue, arrayValue, 8888888888888 + idx, null, undefined],
|
||||
function (r1, r2, r3) {
|
||||
|
||||
function (r1, r2, r3, r4, r5, r6, r7, r8, r9) {
|
||||
clearMsg()
|
||||
msg("r1", r1);
|
||||
msg("r2", r2);
|
||||
msg("r3", r3);
|
||||
msg("r4", r4);
|
||||
msg("r5", r5);
|
||||
msg("r6", r6);
|
||||
msg("r7", r7);
|
||||
msg("r8", r8);
|
||||
msg("r9", r9);
|
||||
}
|
||||
/*function (result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12, result13) {
|
||||
//msg('testEmitName 回调函数执行了', result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12);
|
||||
|
@ -507,7 +507,14 @@ func (m *jsonData) Float() float64 {
|
||||
|
||||
func (m *jsonData) Bool() bool {
|
||||
if m.IsBool() {
|
||||
return m.V.(bool)
|
||||
switch m.V.(type) {
|
||||
case bool:
|
||||
return m.V.(bool)
|
||||
case []uint8:
|
||||
if v := m.V.([]uint8); len(v) > 0 {
|
||||
return v[0] != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user