提交 3659531f 编写于 作者: yanghye's avatar yanghye

A: Go IPC 添加在子进程发送到指定主进程消息

上级 ca2ee38f
......@@ -51,6 +51,9 @@ func NewApplication(disableRegisDefaultEvent ...bool) *TCEFApplication {
return application
}
// CreateApplication
// 创建CEF Application
// 初始化CEF时必须创建,多进程模式每个application配置都应该相同
func CreateApplication() *TCEFApplication {
var result uintptr
imports.Proc(def.CEFApplication_Create).Call(uintptr(unsafe.Pointer(&result)))
......@@ -134,10 +137,14 @@ func (m *TCEFApplication) Free() {
}
}
// AddCustomCommandLine
// 添加自定义进程启动时添加的命令行参数
func (m *TCEFApplication) AddCustomCommandLine(commandLine, value string) {
imports.Proc(def.AddCustomCommandLine).Call(api.PascalStr(commandLine), api.PascalStr(value))
}
// SetOnRegCustomSchemes
// 自定义协议注册回调函数
func (m *TCEFApplication) SetOnRegCustomSchemes(fn GlobalCEFAppEventOnRegCustomSchemes) {
m.onRegCustomSchemes = fn
}
......@@ -155,32 +162,44 @@ func (m *TCEFApplication) defaultSetOnRegCustomSchemes() {
})
}
// TODO TCefPreferenceRegistrarRef
// SetOnRegisterCustomPreferences
// TODO 该函数还未完全实现
func (m *TCEFApplication) SetOnRegisterCustomPreferences(fn GlobalCEFAppEventOnRegisterCustomPreferences) {
imports.Proc(def.CEFGlobalApp_SetOnRegisterCustomPreferences).Call(api.MakeEventDataPtr(fn))
}
// SetOnContextInitialized
// 上下文初始化
func (m *TCEFApplication) SetOnContextInitialized(fn GlobalCEFAppEventOnContextInitialized) {
imports.Proc(def.CEFGlobalApp_SetOnContextInitialized).Call(api.MakeEventDataPtr(fn))
}
// 启动子进程之前自定义命令行参数设置
// SetOnBeforeChildProcessLaunch
// 启动子进程之前自定义命令行参数设置
func (m *TCEFApplication) SetOnBeforeChildProcessLaunch(fn GlobalCEFAppEventOnBeforeChildProcessLaunch) {
imports.Proc(def.CEFGlobalApp_SetOnBeforeChildProcessLaunch).Call(api.MakeEventDataPtr(fn))
}
// SetOnGetDefaultClient
// 获取并返回CefClient, 我们自己创建并返回到 *ICefClient = myCefClient
func (m *TCEFApplication) SetOnGetDefaultClient(fn GlobalCEFAppEventOnGetDefaultClient) {
imports.Proc(def.CEFGlobalApp_SetOnGetDefaultClient).Call(api.MakeEventDataPtr(fn))
}
// SetOnGetLocalizedString
// 获取并返回本地化
func (m *TCEFApplication) SetOnGetLocalizedString(fn GlobalCEFAppEventOnGetLocalizedString) {
imports.Proc(def.CEFGlobalApp_SetOnGetLocalizedString).Call(api.MakeEventDataPtr(fn))
}
// SetOnGetDataResource
// 获取并返回本地资源
func (m *TCEFApplication) SetOnGetDataResource(fn GlobalCEFAppEventOnGetDataResource) {
imports.Proc(def.CEFGlobalApp_SetOnGetDataResource).Call(api.MakeEventDataPtr(fn))
}
// SetOnGetDataResourceForScale
// 获取并返回本地资源大小
func (m *TCEFApplication) SetOnGetDataResourceForScale(fn GlobalCEFAppEventOnGetDataResourceForScale) {
imports.Proc(def.CEFGlobalApp_SetOnGetDataResourceForScale).Call(api.MakeEventDataPtr(fn))
}
......@@ -243,7 +262,8 @@ func (m *TCEFApplication) SetOnFocusedNodeChanged(fn GlobalCEFAppEventOnFocusedN
imports.Proc(def.CEFGlobalApp_SetOnFocusedNodeChanged).Call(api.MakeEventDataPtr(fn))
}
// 进程间通信处理消息接收
// SetOnProcessMessageReceived
// 进程间通信处理消息接收回调函数
func (m *TCEFApplication) SetOnProcessMessageReceived(fn RenderProcessMessageReceived) {
m.onProcessMessageReceived = fn
}
......
......@@ -158,9 +158,9 @@ func EmitTarget(name string, tag target.ITarget, argument ...any) {
if name == "" {
return
}
if tag != nil && tag.TargetType() == target.TgGo {
if tag.ChannelId() > 0 {
emitSendToGoChannel(0, tag.ChannelId(), name, argument)
if tag != nil {
if (tag.ChannelId() > 0 && tag.TargetType() == target.TgGoSub) || (tag.TargetType() == target.TgGoMain) {
emitSendToGoChannel(0, tag, name, argument)
return
}
}
......@@ -177,10 +177,10 @@ func EmitTargetAndCallback(name string, tag target.ITarget, argument []any, fn a
return
}
var messageId int32 = 0
if tag != nil && tag.TargetType() == target.TgGo {
if tag.ChannelId() > 0 {
if tag != nil {
if (tag.ChannelId() > 0 && tag.TargetType() == target.TgGoSub) || (tag.TargetType() == target.TgGoMain) {
messageId = browser.addEmitCallback(fn)
emitSendToGoChannel(messageId, tag.ChannelId(), name, argument)
emitSendToGoChannel(messageId, tag, name, argument)
return
}
}
......
......@@ -12,11 +12,12 @@ package ipc
import (
"github.com/energye/energy/v2/cef/ipc/argument"
"github.com/energye/energy/v2/cef/ipc/target"
)
// emitSendToChannel
// trigger the specified target Go channel event
func emitSendToGoChannel(messageId int32, channelId int64, eventName string, arguments []any) {
func emitSendToGoChannel(messageId int32, tag target.ITarget, eventName string, arguments []any) {
message := &argument.List{
Id: messageId,
Name: InternalIPCGoExecuteGoEvent,
......@@ -24,10 +25,14 @@ func emitSendToGoChannel(messageId int32, channelId int64, eventName string, arg
Data: arguments,
}
if isMainProcess {
BrowserChan().IPC().Send(channelId, message.Bytes())
BrowserChan().IPC().Send(tag.ChannelId(), message.Bytes())
} else {
message.BId = RenderChan().BrowserId()
RenderChan().IPC().SendToChannel(channelId, message.Bytes())
if tag.TargetType() == target.TgGoSub {
RenderChan().IPC().SendToChannel(tag.ChannelId(), message.Bytes())
} else if tag.TargetType() == target.TgGoMain {
RenderChan().IPC().Send(message.Bytes())
}
}
message.Reset()
}
......@@ -14,12 +14,14 @@ package target
// Type
// 0: Trigger the JS event of the specified target process
// 1: Trigger GO events for the specified target process
// 1: Trigger TgGoSub events for the specified target sub process
// 2: Trigger TgGoMain events for the specified target main process
type Type int8
const (
TgJs Type = iota //JS Event
TgGo //GO Event
TgJs Type = iota //JS Event
TgGoSub //GO Event sub
TgGoMain //GO Event main
)
// ITarget
......@@ -43,7 +45,7 @@ type Target struct {
// browserId: browser window ID
// channelId: IPC channelID, frameId or GO IPC channelID
// targetType: Optional parameter, target type default 0
// Type: TgJs:JS Event, TgGo:GO Event
// Type: TgJs:JS Event, TgGoSub:GO Sub Event, TgGoMain:GO Main Event
func NewTarget(browserId int32, channelId int64, targetType ...Type) ITarget {
m := &Target{
browseId: browserId,
......@@ -55,6 +57,14 @@ func NewTarget(browserId int32, channelId int64, targetType ...Type) ITarget {
return m
}
// NewTargetMain Create a new Emit target Main Process
// targetType: TgGoMain
func NewTargetMain() ITarget {
return &Target{
targetType: TgGoMain,
}
}
// TargetType
// target type
// 0: Trigger JS event
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册