energy/cef/init.go

76 lines
2.0 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// 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-05-31 17:41:14 +08:00
// Energy Global initialization
2022-10-04 13:21:05 +08:00
package cef
import (
"embed"
2023-05-31 18:00:34 +08:00
. "github.com/energye/energy/v2/cef/process"
. "github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/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-05-31 17:41:14 +08:00
// GlobalInit 全局初始化
// 需要手动调用的函数,在main函数中调用
// 参数:
// libs 内置到应用程序的类库
// resources 内置到应用程序的资源文件
// MacOSX环境, goland、ide等开发环境需配置命令行参数[energy_env=dev]以保证应用正常运行
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))
}
2023-06-02 08:32:10 +08:00
// golcl
2022-10-04 13:21:05 +08:00
inits.Init(libs, resources)
2023-06-02 08:32:10 +08:00
// def
defInit()
// macos command line
2022-12-13 23:05:49 +08:00
setMacOSXCommandLine(api.PascalStr(Args.CommandLine()))
2023-06-02 08:32:10 +08:00
// main thread run call
applicationQueueAsyncCallInit()
2022-10-04 13:21:05 +08:00
//应用低层出错异常捕获
lcl.Application.SetOnException(func(sender lcl.IObject, e *lcl.Exception) {
if exceptionCallback != nil {
exceptionCallback(sender, e)
} else {
2023-03-14 11:06:08 +08:00
logger.Error("ResultString:", e.Message())
2022-10-04 13:21:05 +08:00
}
})
}
2023-03-25 11:38:56 +08:00
// v8init v8初始化
func v8init() {
2023-05-31 17:41:14 +08:00
if Args.IsMain() || Args.IsRender() {
//ipc初始化
ipcInit()
//bind初始化
//bindInit()
2023-05-31 17:41:14 +08:00
}
2023-03-25 11:38:56 +08:00
}