2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2022-10-04 16:38:43 +08:00
|
|
|
// Licensed under GNU General Public License v3.0
|
2022-10-04 13:21:05 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2022-11-02 12:47:47 +08:00
|
|
|
. "github.com/energye/energy/common"
|
2022-10-04 22:34:57 +08:00
|
|
|
. "github.com/energye/energy/consts"
|
|
|
|
"github.com/energye/energy/ipc"
|
|
|
|
"github.com/energye/energy/logger"
|
2022-12-05 10:44:24 +08:00
|
|
|
"github.com/energye/golcl/energy/inits"
|
2022-10-04 13:21:05 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
2022-12-09 21:08:30 +08:00
|
|
|
"github.com/energye/golcl/pkgs/macapp"
|
2022-10-04 13:21:05 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExceptionCallback func(sender lcl.IObject, e *lcl.Exception)
|
|
|
|
|
|
|
|
var exceptionCallback ExceptionCallback
|
|
|
|
|
2022-10-05 16:38:43 +08:00
|
|
|
//设置cef低层异常捕获回调函数
|
2022-10-04 13:21:05 +08:00
|
|
|
func SetOnException(exception ExceptionCallback) {
|
|
|
|
exceptionCallback = exception
|
|
|
|
}
|
|
|
|
|
2022-10-05 16:38:43 +08:00
|
|
|
//全局初始化
|
|
|
|
//
|
|
|
|
//需要手动调用的函数,在main函数中调用
|
|
|
|
//
|
|
|
|
//libs 内置到应用程序的类库
|
|
|
|
//
|
|
|
|
//resources 内置到应用程序的资源文件
|
2022-10-04 13:21:05 +08:00
|
|
|
func GlobalCEFInit(libs *embed.FS, resources *embed.FS) {
|
2022-12-09 21:08:30 +08:00
|
|
|
macapp.MacApp.IsCEF(IsDarwin())
|
2022-10-04 13:21:05 +08:00
|
|
|
inits.Init(libs, resources)
|
|
|
|
if Args.IsRender() {
|
|
|
|
netIpcPort := Args.Args(MAINARGS_NETIPCPORT)
|
2022-10-04 22:34:57 +08:00
|
|
|
if netIpcPort != Empty {
|
|
|
|
ipc.IPC.SetPort(int(StrToInt32(netIpcPort)))
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-05 16:38:43 +08:00
|
|
|
//IPC通道选择初始化, 在不支持unix的系统中将选择net socket
|
2022-10-04 22:34:57 +08:00
|
|
|
ipc.IPCChannelChooseInit()
|
2022-10-05 16:38:43 +08:00
|
|
|
//macos的命令行设置
|
2022-10-04 22:34:57 +08:00
|
|
|
setMacOSXCommandLine(GoStrToDStr(Args.CommandLine()))
|
2022-12-07 21:29:38 +08:00
|
|
|
applicationQueueAsyncCallInit()
|
2022-10-05 16:38:43 +08:00
|
|
|
//对于go绑定到v8引擎js的事件处理函数
|
2022-10-04 13:21:05 +08:00
|
|
|
cefV8WindowBindFuncEventsInit()
|
2022-12-07 22:55:29 +08:00
|
|
|
//ipc事件初始化
|
2022-10-04 13:21:05 +08:00
|
|
|
cefIPCInit()
|
|
|
|
//应用低层出错异常捕获
|
|
|
|
lcl.Application.SetOnException(func(sender lcl.IObject, e *lcl.Exception) {
|
|
|
|
if exceptionCallback != nil {
|
|
|
|
exceptionCallback(sender, e)
|
|
|
|
} else {
|
2022-10-05 20:43:25 +08:00
|
|
|
logger.Error("Exception:", e.Message())
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|