2023-01-25 09:31:07 +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
|
2023-01-25 09:31:07 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// energy application run
|
2023-01-19 09:13:45 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/energye/energy/common"
|
|
|
|
|
"github.com/energye/energy/consts"
|
2023-02-06 15:25:28 +08:00
|
|
|
|
"github.com/energye/energy/logger"
|
2023-01-19 09:13:45 +08:00
|
|
|
|
"github.com/energye/golcl/lcl"
|
|
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2023-02-20 00:20:01 +08:00
|
|
|
|
//BrowserWindow 是基于LCL和VF窗口组件的浏览器主窗口
|
2023-01-19 09:13:45 +08:00
|
|
|
|
//
|
2023-02-20 00:20:01 +08:00
|
|
|
|
//可以对窗口的属性设置和事件监听,Chromium的配置和事件监听.
|
2023-01-19 09:13:45 +08:00
|
|
|
|
//
|
2023-02-20 00:20:01 +08:00
|
|
|
|
//该窗口是主窗体,因此初始化时必须第一个初始化完成,如果创建子窗口最好在 SetBrowserInitAfter 回调函数中创建
|
|
|
|
|
//
|
|
|
|
|
//VF窗口组件默认在Linux平台自动开启
|
|
|
|
|
//LCL窗口组件默认在Windows、MacOSX平台自动开启
|
2023-03-04 11:19:45 +08:00
|
|
|
|
BrowserWindow = &browserWindow{
|
2023-01-19 09:13:45 +08:00
|
|
|
|
browserEvent: &BrowserEvent{},
|
|
|
|
|
Config: &browserConfig{
|
|
|
|
|
WindowProperty: NewWindowProperty(),
|
|
|
|
|
},
|
|
|
|
|
windowInfo: make(map[int32]IBrowserWindow),
|
|
|
|
|
windowSerial: 1, //默认1开始
|
|
|
|
|
}
|
|
|
|
|
browserProcessStartAfterCallback browserProcessStartAfterCallbackFunc
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type browserProcessStartAfterCallbackFunc func(success bool)
|
|
|
|
|
|
|
|
|
|
// SetBrowserProcessStartAfterCallback 主进程启动之后回调函数
|
|
|
|
|
func SetBrowserProcessStartAfterCallback(callback browserProcessStartAfterCallbackFunc) {
|
|
|
|
|
if common.Args.IsMain() {
|
|
|
|
|
if browserProcessStartAfterCallback == nil {
|
|
|
|
|
browserProcessStartAfterCallback = callback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Run
|
2023-01-19 09:13:45 +08:00
|
|
|
|
// 运行应用
|
|
|
|
|
//
|
|
|
|
|
// 在这里启动浏览器的主进程和子进程
|
2023-02-28 21:10:16 +08:00
|
|
|
|
func Run(app *TCEFApplication) {
|
2023-02-06 15:25:28 +08:00
|
|
|
|
defer func() {
|
|
|
|
|
logger.Debug("application process [", common.Args.ProcessType(), "] run end")
|
|
|
|
|
api.EnergyLibRelease()
|
|
|
|
|
}()
|
2023-02-28 21:10:16 +08:00
|
|
|
|
//MacOSX 多进程时,需要调用StartSubProcess来启动子进程
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if common.IsDarwin() && !consts.SingleProcess && !common.Args.IsMain() {
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 启动子进程
|
2023-02-28 21:10:16 +08:00
|
|
|
|
app.StartSubProcess()
|
|
|
|
|
app.Free()
|
2023-01-19 09:13:45 +08:00
|
|
|
|
} else {
|
2023-02-28 21:10:16 +08:00
|
|
|
|
//externalMessagePump 和 multiThreadedMessageLoop 为 false 时, 启用 VF (ViewsFrameworkBrowserWindow) 窗口组件
|
|
|
|
|
emp := app.ExternalMessagePump()
|
|
|
|
|
mtml := app.MultiThreadedMessageLoop()
|
2023-02-28 18:41:12 +08:00
|
|
|
|
consts.IsMessageLoop = !emp && !mtml
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if consts.IsMessageLoop {
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 启用VF窗口组件
|
2023-02-28 21:10:16 +08:00
|
|
|
|
BrowserWindow.appContextInitialized(app)
|
2023-01-19 09:13:45 +08:00
|
|
|
|
}
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 启动主进程
|
2023-02-28 21:10:16 +08:00
|
|
|
|
success := app.StartMainProcess()
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 主进程启动成功之后回调
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if browserProcessStartAfterCallback != nil {
|
|
|
|
|
browserProcessStartAfterCallback(success)
|
|
|
|
|
}
|
|
|
|
|
if success {
|
2023-03-02 11:15:49 +08:00
|
|
|
|
appMainRunCallback()
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if consts.IsMessageLoop {
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// VF窗口消息轮询
|
2023-02-28 21:10:16 +08:00
|
|
|
|
app.RunMessageLoop()
|
2023-01-19 09:13:45 +08:00
|
|
|
|
} else {
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 创建LCL窗口组件
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if BrowserWindow.mainBrowserWindow == nil {
|
2023-03-04 11:19:45 +08:00
|
|
|
|
BrowserWindow.mainBrowserWindow = &lclBrowserWindow{}
|
2023-01-19 09:13:45 +08:00
|
|
|
|
}
|
2023-03-13 17:43:22 +08:00
|
|
|
|
// 运行主窗口
|
2023-01-19 09:13:45 +08:00
|
|
|
|
lcl.RunApp(&BrowserWindow.mainBrowserWindow)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|