mirror of
https://gitee.com/energye/energy.git
synced 2024-12-02 11:47:37 +08:00
upgrade-dev v2.3.19
This commit is contained in:
parent
7944a4fdec
commit
ccd1d744ce
@ -731,7 +731,9 @@ func (m *TCEFChromium) SendProcessMessage(targetProcess CefProcessId, message *I
|
||||
func (m *TCEFChromium) SendProcessMessageForJSONBytes(name string, targetProcess CefProcessId, message json.JSONObject) {
|
||||
if !m.initialized {
|
||||
m.initialized = m.Initialized()
|
||||
return
|
||||
if !m.initialized {
|
||||
return
|
||||
}
|
||||
}
|
||||
var data = message.Bytes()
|
||||
imports.Proc(internale_CEFChromium_SendProcessMessageForJSONBytes).Call(m.Instance(), api.PascalStr(name), targetProcess.ToPtr(), uintptr(unsafe.Pointer(&data[0])), uintptr(uint32(len(data))))
|
||||
|
@ -87,7 +87,7 @@ func main() {
|
||||
//触发JS监听的事件,并传入参数
|
||||
//ipc.Emit("onTestName1", r0, testGoEmit, r2, r3, r4, r5, r6, r7, r8, r9, r10)
|
||||
ipc.EmitAndCallback("onTestName2", []interface{}{r0, testGoEmit, r2, r3, r4, r5, r6, r7, r8, r9, r10}, func(r1 string, r2 int, r3 float64, r4 bool) {
|
||||
//fmt.Println("onTestName1 callback", r1, r2, r3, r4)
|
||||
fmt.Println("onTestName1 callback", r1, r2, r3, r4)
|
||||
})
|
||||
})
|
||||
ipc.On("testGoEmitAndCallback", func() {
|
||||
|
@ -59,9 +59,9 @@ func (m *contextCallback) Invoke(context IContext) {
|
||||
// result
|
||||
context.Result(resultArgument.Bytes())
|
||||
resultArgument.Free()
|
||||
return
|
||||
} else {
|
||||
context.Result(nil)
|
||||
}
|
||||
context.Result(nil)
|
||||
}
|
||||
|
||||
// ArgumentCallback 参数回调
|
||||
@ -90,104 +90,80 @@ func (m *argumentCallback) Invoke(context IContext) {
|
||||
inType := rt.In(i)
|
||||
if i < argsSize {
|
||||
argsValue := argsList.GetByIndex(i)
|
||||
if argsValue == nil {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
continue
|
||||
}
|
||||
switch inType.Kind() {
|
||||
case reflect.String:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.String())
|
||||
case reflect.Int:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Int())
|
||||
case reflect.Int8:
|
||||
inArgsValues[i] = reflect.ValueOf(int8(argsValue.Int()))
|
||||
case reflect.Int16:
|
||||
inArgsValues[i] = reflect.ValueOf(int16(argsValue.Int()))
|
||||
case reflect.Int32:
|
||||
inArgsValues[i] = reflect.ValueOf(int32(argsValue.Int()))
|
||||
case reflect.Int64:
|
||||
inArgsValues[i] = reflect.ValueOf(int64(argsValue.Int()))
|
||||
case reflect.Uint:
|
||||
inArgsValues[i] = reflect.ValueOf(uint(argsValue.Int()))
|
||||
case reflect.Uint8:
|
||||
inArgsValues[i] = reflect.ValueOf(uint8(argsValue.Int()))
|
||||
case reflect.Uint16:
|
||||
inArgsValues[i] = reflect.ValueOf(uint16(argsValue.Int()))
|
||||
case reflect.Uint32:
|
||||
inArgsValues[i] = reflect.ValueOf(uint32(argsValue.Int()))
|
||||
case reflect.Uint64:
|
||||
inArgsValues[i] = reflect.ValueOf(uint64(argsValue.Int()))
|
||||
case reflect.Uintptr:
|
||||
inArgsValues[i] = reflect.ValueOf(uintptr(argsValue.Int()))
|
||||
case reflect.Float32:
|
||||
inArgsValues[i] = reflect.ValueOf(float32(argsValue.Float()))
|
||||
case reflect.Float64:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Float())
|
||||
case reflect.Bool:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Bool())
|
||||
case reflect.Struct:
|
||||
if argsValue.IsObject() {
|
||||
// struct
|
||||
if jsonBytes := argsValue.Bytes(); jsonBytes != nil {
|
||||
v := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, v.Interface()); err == nil {
|
||||
inArgsValues[i] = v.Elem()
|
||||
continue
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
case reflect.Map:
|
||||
if argsValue.IsObject() {
|
||||
// map key=string : value != interface
|
||||
if inType.Elem().Kind() != reflect.Interface {
|
||||
if argsValue != nil {
|
||||
switch inType.Kind() {
|
||||
case reflect.String:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.String())
|
||||
case reflect.Int:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Int())
|
||||
case reflect.Int8:
|
||||
inArgsValues[i] = reflect.ValueOf(int8(argsValue.Int()))
|
||||
case reflect.Int16:
|
||||
inArgsValues[i] = reflect.ValueOf(int16(argsValue.Int()))
|
||||
case reflect.Int32:
|
||||
inArgsValues[i] = reflect.ValueOf(int32(argsValue.Int()))
|
||||
case reflect.Int64:
|
||||
inArgsValues[i] = reflect.ValueOf(int64(argsValue.Int()))
|
||||
case reflect.Uint:
|
||||
inArgsValues[i] = reflect.ValueOf(uint(argsValue.Int()))
|
||||
case reflect.Uint8:
|
||||
inArgsValues[i] = reflect.ValueOf(uint8(argsValue.Int()))
|
||||
case reflect.Uint16:
|
||||
inArgsValues[i] = reflect.ValueOf(uint16(argsValue.Int()))
|
||||
case reflect.Uint32:
|
||||
inArgsValues[i] = reflect.ValueOf(uint32(argsValue.Int()))
|
||||
case reflect.Uint64:
|
||||
inArgsValues[i] = reflect.ValueOf(uint64(argsValue.Int()))
|
||||
case reflect.Uintptr:
|
||||
inArgsValues[i] = reflect.ValueOf(uintptr(argsValue.Int()))
|
||||
case reflect.Float32:
|
||||
inArgsValues[i] = reflect.ValueOf(float32(argsValue.Float()))
|
||||
case reflect.Float64:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Float())
|
||||
case reflect.Bool:
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Bool())
|
||||
case reflect.Struct:
|
||||
if argsValue.IsObject() {
|
||||
// struct
|
||||
if jsonBytes := argsValue.Bytes(); jsonBytes != nil {
|
||||
vv := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, vv.Interface()); err == nil {
|
||||
inArgsValues[i] = vv.Elem()
|
||||
continue
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
v := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, v.Interface()); err == nil {
|
||||
inArgsValues[i] = v.Elem()
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
if argsValue.IsObject() {
|
||||
// map key=string : value != interface
|
||||
if inType.Elem().Kind() != reflect.Interface {
|
||||
if jsonBytes := argsValue.Bytes(); jsonBytes != nil {
|
||||
vv := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, vv.Interface()); err == nil {
|
||||
inArgsValues[i] = vv.Elem()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Data())
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Data())
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
case reflect.Slice:
|
||||
if argsValue.IsArray() {
|
||||
// slick value != interface
|
||||
if inType.Elem().Kind() != reflect.Interface {
|
||||
if jsonBytes := argsValue.Bytes(); jsonBytes != nil {
|
||||
vv := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, vv.Interface()); err == nil {
|
||||
inArgsValues[i] = vv.Elem()
|
||||
continue
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
case reflect.Slice:
|
||||
if argsValue.IsArray() {
|
||||
// slice value != interface
|
||||
if inType.Elem().Kind() != reflect.Interface {
|
||||
if jsonBytes := argsValue.Bytes(); jsonBytes != nil {
|
||||
vv := reflect.New(inType)
|
||||
if err := jsoniter.Unmarshal(jsonBytes, vv.Interface()); err == nil {
|
||||
inArgsValues[i] = vv.Elem()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Data())
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.ValueOf(argsValue.Data())
|
||||
}
|
||||
} else {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
default:
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if !inArgsValues[i].IsValid() {
|
||||
inArgsValues[i] = reflect.New(inType).Elem()
|
||||
}
|
||||
}
|
||||
@ -208,8 +184,8 @@ func (m *argumentCallback) Invoke(context IContext) {
|
||||
// result
|
||||
context.Result(resultArgument.Bytes())
|
||||
resultArgument.Free()
|
||||
return
|
||||
} else {
|
||||
// result nil
|
||||
context.Result(nil)
|
||||
}
|
||||
// result nil
|
||||
context.Result(nil)
|
||||
}
|
||||
|
23
ipc/ipc.go
23
ipc/ipc.go
@ -67,7 +67,9 @@ func SetProcessMessage(pm IProcessMessage) {
|
||||
|
||||
//On
|
||||
//
|
||||
// 参数 回调函数fn: EmitContextCallback 或 func(...) {}
|
||||
// 参数
|
||||
// name: 事件名称
|
||||
// fn : 事件回调函数 EmitContextCallback 或 func(...) [result...] {}
|
||||
//
|
||||
// IPC GO 监听事件, 自定义参数,仅支持对应 JavaScript 对应 Go 的常用类型
|
||||
//
|
||||
@ -76,7 +78,7 @@ func SetProcessMessage(pm IProcessMessage) {
|
||||
//
|
||||
// 复杂类型: slice, map, struct
|
||||
//
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}, struct: array or object
|
||||
//
|
||||
// slice: 只能是 any 或 interface{}
|
||||
// map: key 只能 string 类型, value 基本类型+复杂类型
|
||||
@ -93,8 +95,7 @@ func SetProcessMessage(pm IProcessMessage) {
|
||||
// }
|
||||
//
|
||||
// 出参
|
||||
//
|
||||
// 与入参相同
|
||||
// fn回调函数的出参与入参使用方式相同
|
||||
func On(name string, fn any) {
|
||||
if callbackFN := createCallback(fn); callbackFN != nil {
|
||||
browser.addOnEvent(name, callbackFN)
|
||||
@ -119,7 +120,7 @@ func RemoveOn(name string) {
|
||||
// name: JS 监听的事件名
|
||||
// []argument: 入参 基本类型: int(int8 ~ uint64), bool, float(float32、float64), string
|
||||
// 复杂类型: slice, map, struct
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}, struct: array or object
|
||||
func Emit(name string, argument ...any) {
|
||||
if browser == nil || name == "" || browser.processMessage == nil {
|
||||
return
|
||||
@ -134,8 +135,8 @@ func Emit(name string, argument ...any) {
|
||||
// name: JS 监听的事件名
|
||||
// []argument: 入参 基本类型: int(int8 ~ uint64), bool, float(float32、float64), string
|
||||
// 复杂类型: slice, map, struct
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}
|
||||
// callback: 无返回值的回调函数, 接收返回值. 函数类型 EmitContextCallback 或 func(...) {}
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}, struct: array or object
|
||||
// callback: 无返回值的回调函数, 接收返回值. 函数类型 EmitContextCallback 或 func(...) [result...] {}
|
||||
func EmitAndCallback(name string, argument []any, fn any) {
|
||||
if browser == nil || name == "" || browser.processMessage == nil {
|
||||
return
|
||||
@ -148,11 +149,11 @@ func EmitAndCallback(name string, argument []any, fn any) {
|
||||
// IPC GO 中触发指定目标 JS 监听的事件
|
||||
//
|
||||
// 参数
|
||||
// name: JS 监听的事件名
|
||||
// name: JS监听的事件名
|
||||
// target: 接收事件的目标
|
||||
// []argument: 入参 基本类型: int(int8 ~ uint64), bool, float(float32、float64), string
|
||||
// 复杂类型: slice, map, struct
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}, struct: array or object
|
||||
func EmitTarget(name string, target ITarget, argument ...any) {
|
||||
if browser == nil || name == "" || browser.processMessage == nil {
|
||||
return
|
||||
@ -168,8 +169,8 @@ func EmitTarget(name string, target ITarget, argument ...any) {
|
||||
// target: 接收事件的目标
|
||||
// []argument: 入参 基本类型: int(int8 ~ uint64), bool, float(float32、float64), string
|
||||
// 复杂类型: slice, map, struct
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}
|
||||
// callback: 无返回值的回调函数, 接收返回值. 函数类型 EmitContextCallback 或 func(...) {}
|
||||
// 复杂类型限制示例: slice: []interface{}, map: map[string]interface{}, struct: array or object
|
||||
// callback: 无返回值的回调函数, 接收返回值. 函数类型 EmitContextCallback 或 func(...) [result...] {}
|
||||
func EmitTargetAndCallback(name string, target ITarget, argument []any, fn any) {
|
||||
if browser == nil || name == "" || browser.processMessage == nil {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user