Skip to content

Commit

Permalink
Fix: Windows开发者工具关闭时的警告,和每次打开开发者工具时创建新窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
sxmxta committed Nov 29, 2023
1 parent a0775e1 commit 7e54108
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cef/aux_devtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ func (m *ICefBrowser) createBrowserDevTools(browserWindow IBrowserWindow) {
if common.IsWindows() {
// 如果开启开发者工具, 需要在IU线程中创建window
browserWindow.AsLCLBrowserWindow().BrowserWindow().createAuxTools()
browserWindow.AsLCLBrowserWindow().BrowserWindow().GetAuxTools().SetDevTools(createDevtoolsWindow(browserWindow.AsLCLBrowserWindow().BrowserWindow()))
browserWindow.AsLCLBrowserWindow().BrowserWindow().GetAuxTools().DevTools().SetCaption(fmt.Sprintf("%s - %s", devToolsName, m.MainFrame().Url()))
devTools := browserWindow.AsLCLBrowserWindow().BrowserWindow().GetAuxTools()
if devTools.DevTools() == nil {
devTools.SetDevTools(createDevtoolsWindow(browserWindow.AsLCLBrowserWindow().BrowserWindow()))
devTools.DevTools().SetCaption(fmt.Sprintf("%s - %s", devToolsName, m.MainFrame().Url()))
}
browserWindow.RunOnMainThread(func() { // show window, run is main ui thread
browserWindow.AsLCLBrowserWindow().BrowserWindow().GetAuxTools().DevTools().Show()
devTools.DevTools().Show()
})
} else {
browserWindow.Chromium().ShowDevTools(nil)
Expand Down
8 changes: 5 additions & 3 deletions cef/aux_devtools_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// 在显示开发者工具时,需要在显示的窗口中初始化 CEFWindow
// 步骤
// 1. 创建窗口, 设置窗口宽高为0, 展示位置在屏幕之外
// 2. 创建 CEFWindow
// 2. 创建 CEFWindow
// 3. show & hide, 先显示窗口让CEF初始化CEFWindow, 紧跟着隐藏掉
// 4. 设置默认的窗口宽高、居中显示在桌面并显示在任务栏
func createDevtoolsWindow(owner *LCLBrowserWindow) *devToolsWindow {
Expand All @@ -40,12 +40,14 @@ func createDevtoolsWindow(owner *LCLBrowserWindow) *devToolsWindow {
window.SetShowInTaskBar(types.StAlways)
window.SetVisible(false)
window.TForm.SetOnClose(func(sender lcl.IObject, action *types.TCloseAction) {
*action = types.CaFree
*action = types.CaFree // 释放掉窗口
owner.Chromium().CloseDevTools(window.WindowParent()) // close devtools
window.Free()
// 关闭窗口后
// 将父窗口开发者工具(当前自己)设置为空, 以便在下次正确创建
owner.GetAuxTools().SetDevTools(nil)
})
window.TForm.SetOnShow(func(sender lcl.IObject) {
// 显示开发者工具
owner.Chromium().ShowDevTools(window.WindowParent())
})
return window
Expand Down

0 comments on commit 7e54108

Please sign in to comment.