mirror of
https://gitee.com/energye/energy.git
synced 2024-12-15 09:51:35 +08:00
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package main
|
||
|
||
import (
|
||
"embed"
|
||
"fmt"
|
||
"github.com/energye/energy/cef"
|
||
"github.com/energye/energy/common/assetserve"
|
||
)
|
||
|
||
//go:embed resources
|
||
var resources embed.FS
|
||
|
||
func main() {
|
||
//全局初始化 每个应用都必须调用的
|
||
cef.GlobalCEFInit(nil, &resources)
|
||
//创建应用
|
||
config := cef.NewApplicationConfig()
|
||
config.SetMultiThreadedMessageLoop(false)
|
||
config.SetExternalMessagePump(false)
|
||
cefApp := cef.NewApplication(config)
|
||
//指定一个URL地址,或本地html文件目录
|
||
cef.BrowserWindow.Config.DefaultUrl = "http://localhost:22022/index.html"
|
||
cef.BrowserWindow.Config.Icon = "resources/icon.png"
|
||
cef.BrowserWindow.SetViewFrameBrowserInit(func(event *cef.BrowserEvent, window *cef.ViewsFrameworkBrowserWindow) {
|
||
fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
|
||
fmt.Printf("%+v\n", window)
|
||
|
||
})
|
||
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window *cef.TCefWindowInfo) {
|
||
fmt.Println("cef.BrowserWindow.SetBrowserInit", window)
|
||
fmt.Printf("%+v\n", window)
|
||
|
||
})
|
||
//在主进程启动成功之后执行
|
||
//在这里启动内置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()
|
||
})
|
||
//运行应用
|
||
cef.Run(cefApp)
|
||
}
|