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-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"
|
2023-07-19 16:56:14 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports/tempdll"
|
2023-05-31 18:00:34 +08:00
|
|
|
"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"
|
2023-07-19 16:56:14 +08:00
|
|
|
"github.com/energye/golcl/pkgs/libname"
|
2022-12-09 21:08:30 +08:00
|
|
|
"github.com/energye/golcl/pkgs/macapp"
|
2023-07-19 18:22:54 +08:00
|
|
|
"runtime"
|
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]以保证应用正常运行
|
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))
|
|
|
|
}
|
2023-07-19 16:56:14 +08:00
|
|
|
// 如果使用 liblclbinres 编译则通过该方式加载动态库
|
|
|
|
if dllPath, dllOk := tempdll.CheckAndReleaseDLL(); dllOk {
|
|
|
|
api.SetLoadUILibCallback(func() (path string, ok bool) {
|
2023-07-19 18:22:54 +08:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
//MacOSX从Frameworks加载
|
|
|
|
libname.LibName = "@executable_path/../Frameworks/" + libname.GetDLLName()
|
|
|
|
} else {
|
|
|
|
libname.LibName = dllPath
|
|
|
|
}
|
2023-07-19 16:56:14 +08:00
|
|
|
path = dllPath
|
|
|
|
ok = dllOk
|
|
|
|
return
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// go lcl
|
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
|
2022-12-07 21:29:38 +08:00
|
|
|
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初始化
|
2023-06-01 10:15:20 +08:00
|
|
|
//bindInit()
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
2023-03-25 11:38:56 +08:00
|
|
|
}
|