From f934ef7a05f3904976ea75c40bb2724279b45d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Sun, 7 Apr 2024 21:20:58 +0800 Subject: [PATCH] U: Adjust the timing of the main window settings --- cef/browser_main_window.go | 3 +-- cef/browser_window_lcl.go | 4 ++-- cef/chromium_browser_windows.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cef/browser_main_window.go b/cef/browser_main_window.go index e0903cdb..3c63a19a 100644 --- a/cef/browser_main_window.go +++ b/cef/browser_main_window.go @@ -75,7 +75,6 @@ func (m *browserWindow) createFormAndRun() { if m.Config.EnableMainWindow { // 使用主窗口创建 lcl.Application.CreateForm(&enableMainWindow, true) - BrowserWindow.mainBrowserWindow = enableMainWindow } else { // 使用禁用窗口创建, 它默认不会显示, 在它的 OnFormCreate 中创建主窗口 lcl.Application.CreateForm(&disabledMainWindow, true) @@ -88,7 +87,6 @@ func (m *browserWindow) createFormAndRun() { func (m *disableMainWindow) OnFormCreate(sender lcl.IObject) { // 禁用主窗口后需要创建一个新的窗口来代替主窗口显示 lcl.Application.CreateForm(&enableMainWindow, true) - BrowserWindow.mainBrowserWindow = enableMainWindow // 显示窗口,此时的主窗口是默认显示的第一个窗口, 如果将该主窗口关闭,在获取主窗口函数将返回无效的窗口 BrowserWindow.MainWindow().Show() } @@ -104,6 +102,7 @@ func (m *lclBrowserWindow) OnFormCreate(sender lcl.IObject) { m.defaultChromiumEvent() m.SetProperty() m.SetShowInTaskBar() + BrowserWindow.mainBrowserWindow = m if BrowserWindow.Config.browserWindowOnEventCallback != nil { BrowserWindow.browserEvent.chromium = m.Chromium() BrowserWindow.Config.browserWindowOnEventCallback(BrowserWindow.browserEvent, m) diff --git a/cef/browser_window_lcl.go b/cef/browser_window_lcl.go index a80f6c13..858447ed 100644 --- a/cef/browser_window_lcl.go +++ b/cef/browser_window_lcl.go @@ -92,9 +92,9 @@ func NewLCLBrowserWindow(config *TCefChromiumConfig, windowProperty WindowProper // owner: 被创建组件拥有者 func NewLCLWindow(windowProperty WindowProperty, owner lcl.IComponent) *LCLBrowserWindow { var window *LCLBrowserWindow - //lcl.Application.CreateForm(&window) + //lcl.Application.CreateForm(&window) // create 1 window = new(LCLBrowserWindow) - window.TForm = lcl.NewForm(owner) + window.TForm = lcl.NewForm(owner) // create 2 // 窗口设置一个名字 window.TForm.SetName(fmt.Sprintf("Form_%d", time.Now().UnixNano()/1e6)) window.windowProperty = &windowProperty diff --git a/cef/chromium_browser_windows.go b/cef/chromium_browser_windows.go index 90fdf129..9bebe3c7 100644 --- a/cef/chromium_browser_windows.go +++ b/cef/chromium_browser_windows.go @@ -70,7 +70,7 @@ func (m *TCEFChromiumBrowser) registerWindowsCompMsgEvent() { if bwEvent.onRenderCompMsg != nil { bwEvent.onRenderCompMsg(sender, message, lResult, aHandled) } - if !*aHandled { + if !*aHandled && window.cwcap != nil { window.doOnRenderCompMsg(m, cmtCEF, message, lResult, aHandled) } })