mirror of
https://gitee.com/energye/energy.git
synced 2024-12-02 19:57:48 +08:00
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
//----------------------------------------
|
|
//
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
//
|
|
// Licensed under GNU General Public License v3.0
|
|
//
|
|
//----------------------------------------
|
|
|
|
package cef
|
|
|
|
import (
|
|
"fmt"
|
|
. "github.com/energye/energy/consts"
|
|
"github.com/energye/energy/logger"
|
|
)
|
|
|
|
const (
|
|
view_source_name = "ViewSource"
|
|
)
|
|
|
|
func updateBrowserViewSource(browser *ICefBrowser, title string) {
|
|
if browserWinInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); browserWinInfo != nil && browserWinInfo.WindowType() == WT_VIEW_SOURCE {
|
|
QueueAsyncCall(func(id int) {
|
|
if mainFrame := browser.MainFrame(); mainFrame != nil {
|
|
browserWinInfo.SetCaption(fmt.Sprintf("%s - %s", view_source_name, mainFrame.Url))
|
|
} else {
|
|
logger.Error("failed to get main frame")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func viewSourceAfterCreate(browser *ICefBrowser) bool {
|
|
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
|
|
if winInfo.WindowType() == WT_VIEW_SOURCE && winInfo.auxTools.viewSourceWindow != nil {
|
|
winInfo.auxTools.viewSourceWindow.chromium.LoadUrl(winInfo.auxTools.viewSourceUrl)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func createBrowserViewSource(browser *ICefBrowser, frame *ICefFrame) {
|
|
var viewSourceUrl = fmt.Sprintf("view-source:%s", frame.Url)
|
|
QueueAsyncCall(func(id int) {
|
|
var m = BrowserWindow.popupWindow
|
|
if m != nil {
|
|
m.SetShowInTaskBar()
|
|
m.SetWindowType(WT_VIEW_SOURCE)
|
|
m.ChromiumCreate(nil, viewSourceUrl)
|
|
m.putChromiumWindowInfo()
|
|
m.defaultChromiumEvent()
|
|
m.SetWidth(1024)
|
|
m.SetHeight(768)
|
|
if winInfo := BrowserWindow.GetWindowInfo(m.windowId); winInfo != nil {
|
|
if winInfo.auxTools == nil {
|
|
winInfo.auxTools = &auxTools{}
|
|
}
|
|
winInfo.auxTools.viewSourceUrl = viewSourceUrl
|
|
winInfo.auxTools.viewSourceWindow = m
|
|
}
|
|
m.Show()
|
|
} else {
|
|
logger.Fatal("Window not initialized successfully")
|
|
}
|
|
})
|
|
}
|