2022-12-07 15:50:59 +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-12-07 15:50:59 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// Browser Window 配置
|
2022-10-26 16:48:32 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
2022-11-02 12:47:47 +08:00
|
|
|
|
"github.com/energye/energy/common"
|
2022-10-26 16:48:32 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-01-06 18:26:40 +08:00
|
|
|
|
type browserWindowOnEventCallback func(event *BrowserEvent, window IBrowserWindow)
|
|
|
|
|
type browserWindowAfterOnEventCallback func(window IBrowserWindow)
|
2023-01-01 22:19:26 +08:00
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 创建主窗口指定的一些快捷配置属性
|
2022-10-26 16:48:32 +08:00
|
|
|
|
type browserConfig struct {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
WindowProperty
|
2023-01-06 23:08:10 +08:00
|
|
|
|
chromiumConfig *tCefChromiumConfig //主窗体浏览器配置
|
2023-01-06 18:26:40 +08:00
|
|
|
|
browserWindowOnEventCallback browserWindowOnEventCallback //主窗口初始化回调 - 基于LCL窗口
|
|
|
|
|
browserWindowAfterOnEventCallback browserWindowAfterOnEventCallback //主窗口初始化之后回调
|
2022-10-26 16:48:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 设置chromium配置
|
2022-10-26 16:48:32 +08:00
|
|
|
|
func (m *browserConfig) SetChromiumConfig(chromiumConfig *tCefChromiumConfig) {
|
2022-11-02 12:47:47 +08:00
|
|
|
|
if chromiumConfig != nil && common.Args.IsMain() {
|
2022-10-26 16:48:32 +08:00
|
|
|
|
m.chromiumConfig = chromiumConfig
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 获取/创建 CEF Chromium Config
|
2023-01-05 13:02:03 +08:00
|
|
|
|
func (m *browserConfig) ChromiumConfig() *tCefChromiumConfig {
|
|
|
|
|
if m.chromiumConfig == nil {
|
|
|
|
|
m.chromiumConfig = NewChromiumConfig()
|
|
|
|
|
}
|
|
|
|
|
return m.chromiumConfig
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 主窗口初始化回调
|
2023-01-01 22:19:26 +08:00
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 该回调函数和基于CEF窗口回调是互斥的,默认情况只有一个会被回调
|
2023-01-01 22:19:26 +08:00
|
|
|
|
func (m *browserConfig) setBrowserWindowInitOnEvent(fn browserWindowOnEventCallback) {
|
2022-11-02 12:47:47 +08:00
|
|
|
|
if fn != nil && common.Args.IsMain() {
|
2022-10-26 16:48:32 +08:00
|
|
|
|
m.browserWindowOnEventCallback = fn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// 主窗口初始化回调 - 基于LCL窗口
|
2023-01-01 22:19:26 +08:00
|
|
|
|
func (m *browserConfig) setBrowserWindowInitAfterOnEvent(fn browserWindowAfterOnEventCallback) {
|
2022-11-02 12:47:47 +08:00
|
|
|
|
if fn != nil && common.Args.IsMain() {
|
2022-10-26 16:48:32 +08:00
|
|
|
|
m.browserWindowAfterOnEventCallback = fn
|
|
|
|
|
}
|
|
|
|
|
}
|