energy/cef/cef-aux-view-source-window.go

70 lines
2.0 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
2022-10-04 16:38:43 +08:00
// Licensed under GNU General Public License v3.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
package cef
import (
"fmt"
2022-10-04 22:34:57 +08:00
. "github.com/energye/energy/consts"
2022-10-20 14:16:38 +08:00
"github.com/energye/energy/logger"
2022-10-04 13:21:05 +08:00
)
const (
view_source_name = "ViewSource"
)
func updateBrowserViewSource(browser *ICefBrowser, title string) {
2022-11-01 17:18:46 +08:00
if browserWinInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); browserWinInfo != nil && browserWinInfo.Window != nil && browserWinInfo.Window.WindowType() == WT_VIEW_SOURCE {
2022-10-04 13:21:05 +08:00
if browserWinInfo.Window != nil {
QueueAsyncCall(func(id int) {
2022-10-20 14:16:38 +08:00
if mainFrame := browser.MainFrame(); mainFrame != nil {
browserWinInfo.Window.SetCaption(fmt.Sprintf("%s - %s", view_source_name, mainFrame.Url))
} else {
logger.Error("failed to get main frame")
}
2022-10-04 13:21:05 +08:00
})
}
}
}
func viewSourceAfterCreate(browser *ICefBrowser) bool {
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
2022-11-01 17:18:46 +08:00
if winInfo.Window.WindowType() == WT_VIEW_SOURCE && winInfo.auxTools.viewSourceWindow != nil {
2022-10-04 13:21:05 +08:00
winInfo.auxTools.viewSourceWindow.chromium.LoadUrl(winInfo.auxTools.viewSourceUrl)
return true
}
}
return false
}
func createBrowserViewSource(browser *ICefBrowser, frame *ICefFrame) {
BrowserWindow.uiLock.Lock()
defer BrowserWindow.uiLock.Unlock()
var viewSourceUrl = fmt.Sprintf("view-source:%s", frame.Url)
QueueAsyncCall(func(id int) {
var m = BrowserWindow.popupWindow
2022-10-20 14:16:38 +08:00
if m != nil {
m.SetShowInTaskBar()
2022-10-20 14:16:38 +08:00
m.SetWindowType(WT_VIEW_SOURCE)
m.ChromiumCreate(nil, viewSourceUrl)
m.chromium.EnableIndependentEvent()
2022-10-20 14:16:38 +08:00
m.putChromiumWindowInfo()
m.defaultChromiumEvent()
m.SetWidth(1024)
m.SetHeight(768)
if winInfo := BrowserWindow.GetWindowInfo(m.windowId); winInfo != nil {
winInfo.auxTools.viewSourceUrl = viewSourceUrl
winInfo.auxTools.viewSourceWindow = m
}
m.Show()
} else {
logger.Fatal("Window not initialized successfully")
2022-10-04 13:21:05 +08:00
}
})
}