diff --git a/example/browser-frameless/frameless.go b/example/browser-frameless/frameless.go index a7603956..706e395d 100644 --- a/example/browser-frameless/frameless.go +++ b/example/browser-frameless/frameless.go @@ -1,3 +1,11 @@ +//---------------------------------------- +// +// Copyright © yanghy. All Rights Reserved. +// +// Licensed under GNU General Public License v3.0 +// +//---------------------------------------- + package main import ( @@ -5,6 +13,7 @@ import ( "fmt" "github.com/energye/energy/cef" "github.com/energye/energy/common/assetserve" + "github.com/energye/energy/ipc" ) //go:embed resources @@ -14,20 +23,49 @@ func main() { //全局初始化 每个应用都必须调用的 cef.GlobalInit(nil, &resources) //创建应用 - cefApp := cef.NewApplication(nil) + config := cef.NewApplicationConfig() + config.SetMultiThreadedMessageLoop(false) + config.SetExternalMessagePump(false) + cefApp := cef.NewApplication(config) //指定一个URL地址,或本地html文件目录 cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html" - cef.BrowserWindow.Config.IconFS = "resources/icon.ico" - cef.BrowserWindow.Config.Title = "Energy 无边框可拖拽窗口" + cef.BrowserWindow.Config.IconFS = "resources/icon.png" cef.BrowserWindow.Config.EnableHideCaption = true - config := cef.BrowserWindow.Config.ChromiumConfig() - config.SetEnableViewSource(true) + cef.BrowserWindow.Config.Title = "Energy Vue + ElementUI 示例" + chromiumConfig := cef.BrowserWindow.Config.ChromiumConfig() + chromiumConfig.SetEnableMenu(false) //禁用右键菜单 + + ipc.IPC.Browser().SetOnEvent(func(event ipc.IEventOn) { + //监听窗口状态事件 + event.On("window-state", func(context ipc.IIPCContext) { + bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId()) + state := context.Arguments().GetInt32(0) + if state == 0 { + fmt.Println("窗口最小化") + bw.Minimize() + } else if state == 1 { + fmt.Println("窗口最大化/还原") + bw.Maximize() + } + }) + //监听窗口关闭事件 + event.On("window-close", func(context ipc.IIPCContext) { + bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId()) + bw.CloseBrowserWindow() + }) + }) + cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) { + // + }) + //在主进程启动成功之后执行 + //在这里启动内置http服务 + //内置http服务需要使用 go:embed resources 内置资源到执行程序中 cef.SetBrowserProcessStartAfterCallback(func(b bool) { fmt.Println("主进程启动 创建一个内置http服务") //通过内置http服务加载资源 server := assetserve.NewAssetsHttpServer() - server.PORT = 22022 - server.AssetsFSName = "resources" //必须设置目录名 + server.PORT = 22022 //服务端口号 + server.AssetsFSName = "resources" //必须设置目录名和资源文件夹同名 server.Assets = &resources go server.StartHttpServer() }) diff --git a/example/browser-frameless/resources/icon.png b/example/browser-frameless/resources/icon.png new file mode 100644 index 00000000..420c6187 Binary files /dev/null and b/example/browser-frameless/resources/icon.png differ diff --git a/example/browser-frameless/resources/index.html b/example/browser-frameless/resources/index.html index b9c7c7a3..ecd040f2 100644 --- a/example/browser-frameless/resources/index.html +++ b/example/browser-frameless/resources/index.html @@ -1,47 +1,148 @@ - +
-