2023-06-15 18:29:23 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// 辅助工具-开发者工具
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/energye/energy/v2/common"
|
|
|
|
"github.com/energye/golcl/lcl"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-06-29 12:07:34 +08:00
|
|
|
devToolsName = "DevTools"
|
2023-06-15 18:29:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type devToolsWindow struct {
|
|
|
|
*lcl.TForm
|
|
|
|
parent ICEFWindowParent
|
|
|
|
}
|
|
|
|
|
2023-08-29 09:55:10 +08:00
|
|
|
func updateBrowserDevTools(window IBrowserWindow, browser *ICefBrowser, title string) {
|
|
|
|
if window.IsLCL() {
|
|
|
|
window := window.AsLCLBrowserWindow().BrowserWindow()
|
|
|
|
if window.GetAuxTools() != nil && window.GetAuxTools().DevTools() != nil {
|
|
|
|
window.GetAuxTools().DevTools().SetCaption(fmt.Sprintf("%s - %s", devToolsName, browser.MainFrame().Url()))
|
2023-06-15 18:29:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefBrowser) createBrowserDevTools(browserWindow IBrowserWindow) {
|
|
|
|
if browserWindow.IsLCL() {
|
|
|
|
if common.IsWindows() {
|
2023-06-22 12:50:33 +08:00
|
|
|
// 如果开启开发者工具, 需要在IU线程中创建window
|
2023-06-29 12:07:34 +08:00
|
|
|
browserWindow.AsLCLBrowserWindow().BrowserWindow().createAuxTools()
|
2023-11-29 23:01:54 +08:00
|
|
|
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()))
|
|
|
|
}
|
2024-01-04 12:50:25 +08:00
|
|
|
RunOnMainThread(func() { // show window, run is main ui thread
|
2023-11-29 23:01:54 +08:00
|
|
|
devTools.DevTools().Show()
|
2023-06-15 18:29:23 +08:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
browserWindow.Chromium().ShowDevTools(nil)
|
|
|
|
}
|
|
|
|
} else if browserWindow.IsViewsFramework() {
|
|
|
|
browserWindow.Chromium().ShowDevTools(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *devToolsWindow) WindowParent() ICEFWindowParent {
|
|
|
|
return m.parent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *devToolsWindow) SetWindowParent(parent ICEFWindowParent) {
|
|
|
|
m.parent = parent
|
|
|
|
}
|