Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
3659531f
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3659531f
编写于
10月 08, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A: Go IPC 添加在子进程发送到指定主进程消息
上级
ca2ee38f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
16 deletion
+51
-16
cef/application.go
cef/application.go
+23
-3
cef/internal/ipc/ipc.go
cef/internal/ipc/ipc.go
+6
-6
cef/internal/ipc/send.go
cef/internal/ipc/send.go
+8
-3
cef/ipc/target/target.go
cef/ipc/target/target.go
+14
-4
未找到文件。
cef/application.go
浏览文件 @
3659531f
...
...
@@ -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
}
...
...
cef/internal/ipc/ipc.go
浏览文件 @
3659531f
...
...
@@ -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
}
}
...
...
cef/internal/ipc/send.go
浏览文件 @
3659531f
...
...
@@ -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
()
}
cef/ipc/target/target.go
浏览文件 @
3659531f
...
...
@@ -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, TgGo
Sub: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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录