2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2022-10-04 13:21:05 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// energy 全局初始化
|
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-13 23:05:49 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
2022-12-09 21:08:30 +08:00
|
|
|
"github.com/energye/golcl/pkgs/macapp"
|
2022-10-04 13:21:05 +08:00
|
|
|
)
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ExceptionCallback 异常回调函数
|
2022-10-04 13:21:05 +08:00
|
|
|
type ExceptionCallback func(sender lcl.IObject, e *lcl.Exception)
|
|
|
|
|
|
|
|
var exceptionCallback ExceptionCallback
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnException 设置 lib-lcl -> CEF 低层异常捕获回调函数
|
2022-10-04 13:21:05 +08:00
|
|
|
func SetOnException(exception ExceptionCallback) {
|
|
|
|
exceptionCallback = exception
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// GlobalInit
|
2023-02-19 23:21:47 +08:00
|
|
|
// 全局初始化
|
2022-10-05 16:38:43 +08:00
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// 需要手动调用的函数,在main函数中调用
|
2022-10-05 16:38:43 +08:00
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// libs 内置到应用程序的类库
|
2022-10-05 16:38:43 +08:00
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// resources 内置到应用程序的资源文件
|
2023-01-26 21:47:55 +08:00
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// MacOSX环境, ide开发环境需命令行参数[energy_env=dev]以保证应用正常运行
|
2023-01-11 22:11:13 +08:00
|
|
|
func GlobalInit(libs *embed.FS, resources *embed.FS) {
|
2022-12-09 21:08:30 +08:00
|
|
|
macapp.MacApp.IsCEF(IsDarwin())
|
2023-01-26 21:47:55 +08:00
|
|
|
//MacOSX环境, ide开发环境需命令行参数[energy_env=dev]以保证应用正常运行
|
|
|
|
energyEnv := Args.Args("energy_env")
|
|
|
|
if energyEnv != "" {
|
|
|
|
macapp.MacApp.SetEnergyEnv(macapp.ENERGY_ENV(energyEnv))
|
|
|
|
}
|
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-12-13 23:05:49 +08:00
|
|
|
setMacOSXCommandLine(api.PascalStr(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
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|