diff --git a/example/browser-frameless/frameless.go b/example/browser-frameless/frameless.go index a76039568265ac20a2d687f2d6cc4eecffa01856..706e395d98ca0f167ee853a76db9a599388c87e9 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 0000000000000000000000000000000000000000..420c618771688b74da662ab95e5e95d87aa7bbe6 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 b9c7c7a3e1c78904a78f1532a8bb8344b2e40264..ecd040f2888f872111c379f94ea1607c9c1282a0 100644 --- a/example/browser-frameless/resources/index.html +++ b/example/browser-frameless/resources/index.html @@ -1,47 +1,148 @@ - + - browser-frameless - - + + + - -
- 这是一个宽700px, 高50px的可拖拽窗口区域 - 这块区域内容可点击  -
-

- 无边框可拖拽窗口
- cef.BrowserWindow.Config.EnableHideCaption = true
- -webkit-app-region: drag/no-drag -

-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 -
-
- 文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容文本内容 + +
+ + + + + + + + 选项1 + 选项2 + + + 选项3 + + + + 选项4-1 + + + + + + + 选项1 + 选项2 + + + 选项3 + + + + 选项4-1 + + + + + + + 选项1 + 选项2 + + + 选项3 + + + + 选项4-1 + + + + + + + +
+ 窗口标题栏 VUE + ElementUI +
+
+ + + + 查看 + 新增 + 删除 + + Energy + + + 最小化 + 最大化 + 关闭 + +
+
+ + + + + + + + + + + +
+
+ + \ No newline at end of file