2022-12-30 18:22:21 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2022-12-31 13:16:30 +08:00
|
|
|
|
"embed"
|
2022-12-31 15:46:17 +08:00
|
|
|
|
"fmt"
|
2022-12-30 18:22:21 +08:00
|
|
|
|
"github.com/energye/energy/cef"
|
2022-12-31 15:46:17 +08:00
|
|
|
|
"github.com/energye/energy/common/assetserve"
|
2022-12-30 18:22:21 +08:00
|
|
|
|
)
|
|
|
|
|
|
2022-12-31 13:16:30 +08:00
|
|
|
|
//go:embed resources
|
|
|
|
|
var resources embed.FS
|
|
|
|
|
|
2022-12-30 18:22:21 +08:00
|
|
|
|
func main() {
|
|
|
|
|
//全局初始化 每个应用都必须调用的
|
2022-12-31 15:46:17 +08:00
|
|
|
|
cef.GlobalCEFInit(nil, &resources)
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//创建应用
|
2022-12-31 13:16:30 +08:00
|
|
|
|
config := cef.NewApplicationConfig()
|
|
|
|
|
config.SetMultiThreadedMessageLoop(false)
|
|
|
|
|
config.SetExternalMessagePump(false)
|
|
|
|
|
cefApp := cef.NewApplication(config)
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//指定一个URL地址,或本地html文件目录
|
2022-12-31 15:46:17 +08:00
|
|
|
|
cef.BrowserWindow.Config.DefaultUrl = "http://localhost:22022/index.html"
|
|
|
|
|
cef.BrowserWindow.Config.Icon = "resources/icon.png"
|
2023-01-01 22:19:26 +08:00
|
|
|
|
cef.BrowserWindow.SetViewFrameBrowserInit(func(event *cef.BrowserEvent, window *cef.ViewsFrameworkBrowserWindow) {
|
|
|
|
|
fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
|
|
|
|
|
fmt.Printf("%+v\n", window)
|
2022-12-31 15:46:17 +08:00
|
|
|
|
|
2023-01-01 22:19:26 +08:00
|
|
|
|
})
|
|
|
|
|
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window *cef.TCefWindowInfo) {
|
|
|
|
|
fmt.Println("cef.BrowserWindow.SetBrowserInit", window)
|
|
|
|
|
fmt.Printf("%+v\n", window)
|
|
|
|
|
|
|
|
|
|
})
|
2022-12-31 15:46:17 +08:00
|
|
|
|
//在主进程启动成功之后执行
|
|
|
|
|
//在这里启动内置http服务
|
|
|
|
|
//内置http服务需要使用 go:embed resources 内置资源到执行程序中
|
|
|
|
|
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
|
|
|
|
|
fmt.Println("主进程启动 创建一个内置http服务")
|
|
|
|
|
//通过内置http服务加载资源
|
|
|
|
|
server := assetserve.NewAssetsHttpServer()
|
|
|
|
|
server.PORT = 22022 //服务端口号
|
|
|
|
|
server.AssetsFSName = "resources" //必须设置目录名和资源文件夹同名
|
|
|
|
|
server.Assets = &resources
|
|
|
|
|
go server.StartHttpServer()
|
|
|
|
|
})
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//运行应用
|
|
|
|
|
cef.Run(cefApp)
|
|
|
|
|
}
|