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-05-31 17:41:14 +08:00
|
|
|
|
|
2023-01-19 09:13:45 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
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/consts"
|
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-05-31 17:41:14 +08:00
|
|
|
|
// 可以对窗口的属性设置和事件监听,Chromium的配置和事件监听.
|
|
|
|
|
// 该窗口是主窗体,因此初始化时必须第一个初始化完成,如果创建子窗口最好在 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(),
|
|
|
|
|
},
|
2023-05-31 17:41:14 +08:00
|
|
|
|
windowInfo: make(map[int32]IBrowserWindow),
|
2023-01-19 09:13:45 +08:00
|
|
|
|
}
|
|
|
|
|
browserProcessStartAfterCallback browserProcessStartAfterCallbackFunc
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type browserProcessStartAfterCallbackFunc func(success bool)
|
|
|
|
|
|
|
|
|
|
// SetBrowserProcessStartAfterCallback 主进程启动之后回调函数
|
|
|
|
|
func SetBrowserProcessStartAfterCallback(callback browserProcessStartAfterCallbackFunc) {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if process.Args.IsMain() {
|
2023-01-19 09:13:45 +08:00
|
|
|
|
if browserProcessStartAfterCallback == nil {
|
|
|
|
|
browserProcessStartAfterCallback = callback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// Run 运行应用
|
|
|
|
|
// 在这里启动浏览器的主进程和子进程
|
2023-02-28 21:10:16 +08:00
|
|
|
|
func Run(app *TCEFApplication) {
|
2023-02-06 15:25:28 +08:00
|
|
|
|
defer func() {
|
|
|
|
|
api.EnergyLibRelease()
|
|
|
|
|
}()
|
2023-02-28 21:10:16 +08:00
|
|
|
|
//MacOSX 多进程时,需要调用StartSubProcess来启动子进程
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if common.IsDarwin() && !app.SingleProcess() && !process.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-05-31 17:41:14 +08:00
|
|
|
|
BrowserWindow.mainBrowserWindow = new(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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|