upgrade-dev v2.3.16

This commit is contained in:
杨红岩 2023-03-20 21:35:21 +08:00
parent a1332eb510
commit 3196b294a5
3 changed files with 67 additions and 57 deletions

View File

@ -47,7 +47,7 @@ func browserProcessMessageReceived(browser *ICefBrowser, frame *ICefFrame, sourc
} else if message.Name() == internalProcessMessageIPCOn {
result = ipcBrowser.ipcOnMessage(browser, frame, sourceProcess, message)
} else if message.Name() == internalProcessMessageIPCEmitReply {
result = ipcBrowser.ipcGoExecuteMethodMessageReply(browser, frame, sourceProcess, message)
//result = ipcBrowser.ipcGoExecuteMethodMessageReply(browser, frame, sourceProcess, message)
}
return
}

View File

@ -39,53 +39,22 @@ func (m *ipcBrowserProcess) ipcChannelBrowser() {
//message.Set(ipc_event, emitNameValue)
//message.Set(ipc_argumentList, json.NewJSONArray(args).Data())
fmt.Println("ipcChannelBrowser", err)
fmt.Println("data", data.Name, data.EventName, json.NewJSONArray(data.Data).GetIntByIndex(1))
if data.Name == internalIPCJSExecuteGoEvent {
//result = ipcBrowser.ipcGoExecuteMethodMessage(browser, frame, sourceProcess, message)
} else if data.Name == internalProcessMessageIPCOn {
//result = ipcBrowser.ipcOnMessage(browser, frame, sourceProcess, message)
} else if data.Name == internalProcessMessageIPCEmitReply {
//result = ipcBrowser.ipcGoExecuteMethodMessageReply(browser, frame, sourceProcess, message)
}
}
context.Free()
})
}
}
func (m *ipcBrowserProcess) ipcGoExecuteMethodMessageReply(browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) (result bool) {
fmt.Println("unlock")
//fmt.Println("ipcGoExecuteMethodMessageReply", message.Name())
//messageId := message.ArgumentList().GetInt(0)
//if callback := ipc.CheckEmitCallback(messageId); callback != nil {
// //第二个参数 true 有返回参数
// if isReturn := message.ArgumentList().GetBool(1); isReturn {
// //[]byte
// binaryValue := message.ArgumentList().GetBinary(2)
// var (
// count uint32
// resultArgsBytes []byte
// )
// if binaryValue.IsValid() {
// size := binaryValue.GetSize()
// resultArgsBytes = make([]byte, size)
// count = binaryValue.GetData(resultArgsBytes, 0)
// binaryValue.Free()
// }
// if count > 0 {
// ipcContext := ipc.NewContext(browser.Identifier(), frame.Identifier(), false, resultArgsBytes)
// if ctxCallback := callback.ContextCallback(); ctxCallback != nil {
// ctxCallback.Invoke(ipcContext)
// } else if argsCallback := callback.ArgumentCallback(); argsCallback != nil {
// argsCallback.Invoke(ipcContext)
// }
// if ipcContext.ArgumentList() != nil {
// ipcContext.ArgumentList().Free()
// }
// ipcContext.Result(nil)
// }
// resultArgsBytes = nil
// }
//}
return
}
// ipcGoExecuteMethodMessage 执行 Go 监听函数
func (m *ipcBrowserProcess) ipcGoExecuteMethodMessage(browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) (result bool) {
func (m *ipcBrowserProcess) ipcGoExecuteMethodMessage(browserId int32, frameId int64, message *ICefProcessMessage) (result bool) {
result = true
argumentListBytes := message.ArgumentList().GetBinary(0)
var messageDataBytes []byte
@ -123,7 +92,7 @@ func (m *ipcBrowserProcess) ipcGoExecuteMethodMessage(browser *ICefBrowser, fram
if eventCallback == nil {
return
}
ipcContext := ipc.NewContext(browser.Identifier(), frame.Identifier(), true, argumentList)
ipcContext := ipc.NewContext(browserId, frameId, true, argumentList)
//调用监听函数
if ctxCallback := eventCallback.ContextCallback(); ctxCallback != nil {
ctxCallback.Invoke(ipcContext)
@ -143,7 +112,7 @@ func (m *ipcBrowserProcess) ipcGoExecuteMethodMessage(browser *ICefBrowser, fram
replyMessage.Add((replay.Result()[0]).([]byte))
}
}
frame.SendProcessMessageForJSONBytes(internalIPCJSExecuteGoEventReplay, consts.PID_RENDER, replyMessage.Bytes())
//frame.SendProcessMessageForJSONBytes(internalIPCJSExecuteGoEventReplay, consts.PID_RENDER, replyMessage.Bytes())
replyMessage.Free()
replay.Clear()
}
@ -155,6 +124,42 @@ func (m *ipcBrowserProcess) ipcGoExecuteMethodMessage(browser *ICefBrowser, fram
return
}
func (m *ipcBrowserProcess) ipcGoExecuteMethodMessageReply(browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) (result bool) {
//fmt.Println("ipcGoExecuteMethodMessageReply", message.Name())
//messageId := message.ArgumentList().GetInt(0)
//if callback := ipc.CheckEmitCallback(messageId); callback != nil {
// //第二个参数 true 有返回参数
// if isReturn := message.ArgumentList().GetBool(1); isReturn {
// //[]byte
// binaryValue := message.ArgumentList().GetBinary(2)
// var (
// count uint32
// resultArgsBytes []byte
// )
// if binaryValue.IsValid() {
// size := binaryValue.GetSize()
// resultArgsBytes = make([]byte, size)
// count = binaryValue.GetData(resultArgsBytes, 0)
// binaryValue.Free()
// }
// if count > 0 {
// ipcContext := ipc.NewContext(browser.Identifier(), frame.Identifier(), false, resultArgsBytes)
// if ctxCallback := callback.ContextCallback(); ctxCallback != nil {
// ctxCallback.Invoke(ipcContext)
// } else if argsCallback := callback.ArgumentCallback(); argsCallback != nil {
// argsCallback.Invoke(ipcContext)
// }
// if ipcContext.ArgumentList() != nil {
// ipcContext.ArgumentList().Free()
// }
// ipcContext.Result(nil)
// }
// resultArgsBytes = nil
// }
//}
return
}
// ipcOnMessage 监听事件
func (m *ipcBrowserProcess) ipcOnMessage(browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) bool {
fmt.Println("ipcOnMessage", message.Name(), message.ArgumentList().Size())

View File

@ -118,6 +118,8 @@ func NewJSON(data []byte) JSON {
return &jsonData{T: GO_VALUE_MAP, V: v, S: len(v)}
}
}
} else {
println("NewJSON error:", err.Error())
}
return nil
}
@ -133,6 +135,12 @@ func NewJSONArray(value any) JSONArray {
} else {
return nil
}
case string:
if v := NewJSON([]byte(value.(string))); v != nil {
return v.JSONArray()
} else {
return nil
}
}
rv := reflect.ValueOf(value)
kind := rv.Kind()
@ -142,17 +150,12 @@ func NewJSONArray(value any) JSONArray {
if kind != reflect.Slice && kind != reflect.Array {
return nil
}
switch value.(type) {
case []byte:
//目的是为了转为any类型
if byt, err := jsoniter.Marshal(value); err == nil {
var v []any
if err = jsoniter.Unmarshal(byt, &v); err == nil {
return &jsonData{T: GO_VALUE_SLICE, V: v, S: len(v)}
}
//转为[]any类型
if byt, err := jsoniter.Marshal(value); err == nil {
var v []any
if err = jsoniter.Unmarshal(byt, &v); err == nil {
return &jsonData{T: GO_VALUE_SLICE, V: v, S: len(v)}
}
default:
return &jsonData{T: GO_VALUE_SLICE, V: rv.Interface().([]any), S: len(rv.Interface().([]any))}
}
}
return &jsonData{T: GO_VALUE_SLICE, V: make([]any, 0), S: 0}
@ -169,6 +172,12 @@ func NewJSONObject(value any) JSONObject {
} else {
return nil
}
case string:
if v := NewJSON([]byte(value.(string))); v != nil {
return v.JSONObject()
} else {
return nil
}
}
rv := reflect.ValueOf(value)
kind := rv.Kind()
@ -178,7 +187,7 @@ func NewJSONObject(value any) JSONObject {
if kind != reflect.Map && kind != reflect.Struct {
return nil
}
//目的是为了转为any类型
//转为map[string]any类型
if byt, err := jsoniter.Marshal(value); err == nil {
var v map[string]any
if err = jsoniter.Unmarshal(byt, &v); err == nil {
@ -227,10 +236,6 @@ func (m *jsonData) Add(value ...any) {
}
}
func (m *jsonData) SetSize(index int, value any) {
}
func (m *jsonData) SetByIndex(index int, value any) {
if m.IsArray() && index < m.S {
switch value.(type) {