energy/example/view-source/view-source.go

36 lines
1.0 KiB
Go
Raw Normal View History

2023-02-03 11:39:02 +08:00
package main
import (
"embed"
"fmt"
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/pkgs/assetserve"
2023-02-03 11:39:02 +08:00
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
2023-02-28 18:41:12 +08:00
cefApp := cef.NewApplication()
2023-02-03 11:39:02 +08:00
//指定一个URL地址或本地html文件目录
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
cef.BrowserWindow.Config.Title = "Energy 查看网页源码"
config := cef.BrowserWindow.Config.ChromiumConfig()
config.SetEnableViewSource(true)
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
fmt.Println("主进程启动 创建一个内置http服务")
//通过内置http服务加载资源
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.AssetsFSName = "resources" //必须设置目录名
server.Assets = &resources
go server.StartHttpServer()
})
//运行应用
cef.Run(cefApp)
}