-
Notifications
You must be signed in to change notification settings - Fork 22
/
init.go
122 lines (116 loc) · 3.7 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
// Energy Global initialization
package cef
import (
_ "github.com/energye/energy/v2/cef/internal/def"
. "github.com/energye/energy/v2/cef/process"
. "github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/common/imports"
"github.com/energye/energy/v2/common/imports/tempdll"
"github.com/energye/golcl/energy/emfs"
"github.com/energye/golcl/energy/inits"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"github.com/energye/golcl/lcl/api/dllimports"
"github.com/energye/golcl/pkgs/libname"
"github.com/energye/golcl/pkgs/macapp"
"os"
)
// GlobalInit 全局初始化
// 需要手动调用的函数,在main函数中调用
// 参数:
// libs 内置到应用程序的类库
// resources 内置到应用程序的资源文件
// MacOSX环境, goland、ide等开发环境需配置命令行参数[energy_env=dev]以保证应用正常运行
func GlobalInit(libs emfs.IEmbedFS, resources emfs.IEmbedFS) {
if IsDarwin() {
macapp.MacApp.IsCEF(true)
//MacOSX环境, ide开发环境需命令行参数[energy_env=dev]以保证应用正常运行
var env = func() string {
energyEnv, env := Args.Args("energy_env"), Args.Args("env")
if energyEnv != "" {
return energyEnv
}
if env != "" {
return env
}
return ""
}()
if env != "" {
macapp.MacApp.SetEnergyEnv(macapp.ENERGY_ENV(env))
}
}
// lcl 初始化时回调,如果设置了该回调函数需要通过该函数返回liblcl库
api.SetLoadLibCallback(func() (liblcl dllimports.DLL, err error) {
// load liblcl
// liblcl name, 不为空时表示自定义加载目录
if libname.LibName == "" {
// 如果使用内置dll编译,则通过该方式加载动态库
path, fullPath, ok := tempdll.CheckAndReleaseDLL(libname.GetDLLName())
if ok {
libname.LibName = fullPath
// 设置到tempDllDir, 使用tempdll将最优先从该目录加载
libname.SetTempDllDir(path)
}
}
if IsDarwin() { // MacOS固定加载目录
//MacOSX从Frameworks加载
libname.LibName = "@executable_path/../Frameworks/" + libname.GetDLLName()
} else if libname.LibName == "" {
libname.LibName = libname.LibPath(libname.GetDLLName())
}
if libname.LibName != "" {
liblcl, err = dllimports.NewDLL(libname.LibName)
}
if liblcl == 0 {
panic(`Hint:
Golcl dependency library liblcl was not found
Please check whether liblcl exists locally
If local liblcl exist, please put it in the specified location, If it does not exist, please download it from the Energy official website.
Configuration Location:
1. Current program execution directory
2. USER_HOME/golcl/
3. Environment variables LCL_HOME or ENERGY_HOME
environment variable LCL_HOME is configured preferentially in the non-energy framework
environment variable ENERGY_HOME takes precedence in the Energy framework
ENERGY_HOME environment variable is recommended
`)
}
// 加载完成设置到libenergy全局
imports.LibEnergy().SetOk(true)
imports.LibEnergy().SetDll(liblcl)
imports.LibLCLExt().SetOk(true)
imports.LibLCLExt().SetDll(liblcl)
return
})
emfs.SetEMFS(libs, resources)
// go lcl init
inits.InitAll()
// macos command line
if IsDarwin() {
argsList := lcl.NewStringList()
for _, v := range os.Args {
argsList.Add(v)
}
// 手动设置进程命令参数
SetCommandLine(argsList)
argsList.Free()
}
// main thread run call
applicationQueueAsyncCallInit()
}
// v8init v8初始化
func v8init() {
if Args.IsMain() || Args.IsRender() {
//ipc初始化
ipcInit()
}
}