提交 bdd4b769 编写于 作者: yanghye's avatar yanghye

dev示例 内置加载资源

上级 43271bfd
package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/logger"
"github.com/energye/golcl/lcl"
//_ "net/http/pprof"
)
//go:embed resources
var resources embed.FS
func main() {
logger.SetEnable(true)
logger.SetLevel(logger.CefLog_Debug)
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
var app = cef.NewApplication()
//app.SetDisableWebSecurity(true)
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "fs://energy/index.html"
cef.BrowserWindow.Config.Title = "Energy - Local load"
cef.BrowserWindow.Config.LocalResource(cef.LocalLoadConfig{
Enable: true,
FS: &resources,
FileRoot: "resources",
Home: "index.html",
Proxy: &cef.XHRProxy{
Scheme: consts.LpsHttps,
IP: "energy.yanghy.cn",
},
})
if common.IsLinux() && app.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
window.Chromium().SetOnResourceLoadComplete(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, request *cef.ICefRequest, response *cef.ICefResponse, status consts.TCefUrlRequestStatus, receivedContentLength int64) {
//fmt.Println("SetOnResourceLoadComplete", request.URL(), status, receivedContentLength)
})
})
//运行应用
cef.Run(app)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册