2022-11-29 20:18:28 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"embed"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/energye/energy/cef"
|
|
|
|
|
"github.com/energye/energy/common/assetserve"
|
|
|
|
|
"github.com/energye/golcl/lcl"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed resources
|
|
|
|
|
var resources embed.FS
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
//全局初始化 每个应用都必须调用的
|
|
|
|
|
cef.GlobalCEFInit(nil, &resources)
|
|
|
|
|
//创建应用
|
|
|
|
|
cefApp := cef.NewApplication(nil)
|
|
|
|
|
//指定一个URL地址,或本地html文件目录
|
2023-01-03 17:53:01 +08:00
|
|
|
|
cef.BrowserWindow.Config.Url = "http://localhost:22022/key-event.html"
|
2022-11-29 22:03:17 +08:00
|
|
|
|
cef.BrowserWindow.Config.Title = "Energy - Key Event"
|
2023-01-09 11:47:30 +08:00
|
|
|
|
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
|
2022-11-29 20:18:28 +08:00
|
|
|
|
//在主窗口初始化回调函数里设置浏览器事件
|
2023-01-06 19:32:46 +08:00
|
|
|
|
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, browserWindow cef.IBrowserWindow) {
|
2022-11-29 20:18:28 +08:00
|
|
|
|
event.SetOnKeyEvent(func(sender lcl.IObject, browser *cef.ICefBrowser, event *cef.TCefKeyEvent, result *bool) {
|
|
|
|
|
fmt.Printf("%s %+v\n", string(rune(event.Character)), event)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
//内置http服务链接安全配置
|
|
|
|
|
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)
|
|
|
|
|
}
|