2023-01-25 09:31:07 +08:00
|
|
|
|
//----------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
|
//
|
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2023-01-25 09:31:07 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
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"
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/cef"
|
|
|
|
|
"github.com/energye/energy/v2/common"
|
|
|
|
|
"github.com/energye/energy/v2/example/dev-test/traydemo"
|
|
|
|
|
"github.com/energye/energy/v2/logger"
|
|
|
|
|
"github.com/energye/energy/v2/pkgs/assetserve"
|
2023-01-01 23:24:00 +08:00
|
|
|
|
"github.com/energye/golcl/lcl"
|
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() {
|
2023-02-06 15:26:27 +08:00
|
|
|
|
logger.SetEnable(true)
|
|
|
|
|
logger.SetLevel(logger.CefLog_Debug)
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//全局初始化 每个应用都必须调用的
|
2023-01-11 22:11:13 +08:00
|
|
|
|
cef.GlobalInit(nil, &resources)
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//创建应用
|
2023-02-28 18:41:12 +08:00
|
|
|
|
cefApp := cef.NewApplication()
|
|
|
|
|
cefApp.SetMultiThreadedMessageLoop(false)
|
|
|
|
|
cefApp.SetExternalMessagePump(false)
|
2023-03-01 13:44:47 +08:00
|
|
|
|
fmt.Println("TotalSystemMemory", cefApp.TotalSystemMemory(), cefApp.UsedMemory())
|
|
|
|
|
cefApp.SetRemoteDebuggingPort(33333)
|
2022-12-30 18:22:21 +08:00
|
|
|
|
//指定一个URL地址,或本地html文件目录
|
2023-01-03 17:53:01 +08:00
|
|
|
|
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
|
2023-03-01 13:38:43 +08:00
|
|
|
|
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
|
2023-06-16 12:53:02 +08:00
|
|
|
|
cef.BrowserWindow.Config.EnableHideCaption = true
|
2023-01-06 18:26:40 +08:00
|
|
|
|
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
|
2023-01-11 22:11:13 +08:00
|
|
|
|
//window.DisableResize()
|
2023-01-28 11:56:24 +08:00
|
|
|
|
window.SetCenterWindow(true)
|
2023-07-23 00:08:18 +08:00
|
|
|
|
//window.SetTitle("这里改变了窗口标题")
|
|
|
|
|
//window.SetSize(1024, 900)
|
|
|
|
|
//fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
|
|
|
|
|
//fmt.Println("LCL", window.AsLCLBrowserWindow(), "VF", window.AsViewsFrameworkBrowserWindow())
|
|
|
|
|
//window.AsViewsFrameworkBrowserWindow().SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
|
|
|
|
|
// fmt.Println("WindowCreated.window", window.WindowAppIcon().Width(), window.WindowAppIcon().Height())
|
|
|
|
|
// image := cef.ImageRef.New()
|
|
|
|
|
// cw, _ := os.Getwd()
|
|
|
|
|
// cw = path.Join(cw, "example", "dev-test", "vf-browser", "resources", "icon.png")
|
|
|
|
|
// byt, err := os.ReadFile(cw)
|
|
|
|
|
// fmt.Println("image icon.png", len(byt), err)
|
|
|
|
|
// image.AddPng(1.2, byt)
|
|
|
|
|
// fmt.Println("image", image.Width(), image.Height())
|
|
|
|
|
//})
|
2023-01-06 18:26:40 +08:00
|
|
|
|
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
|
|
|
|
|
fmt.Println("IsViewsFramework:", popupWindow.IsViewsFramework())
|
2023-07-23 00:08:18 +08:00
|
|
|
|
//popupWindow.SetTitle("修改了标题: " + beforePopupInfo.TargetUrl)
|
|
|
|
|
//popupWindow.EnableResize()
|
|
|
|
|
//popupWindow.DisableMaximize()
|
|
|
|
|
//popupWindow.DisableResize()
|
|
|
|
|
//popupWindow.DisableMinimize()
|
2023-02-15 22:57:45 +08:00
|
|
|
|
popupWindow.SetSize(800, 600)
|
2023-01-06 23:08:10 +08:00
|
|
|
|
browserWindow := popupWindow.AsViewsFrameworkBrowserWindow()
|
2023-07-23 00:08:18 +08:00
|
|
|
|
browserWindow.Chromium().Config().SetEnableMenu(false)
|
|
|
|
|
//browserWindow.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
|
|
|
|
|
// fmt.Println("popupWindow.SetOnWindowCreated", window.WindowAppIcon())
|
2023-03-01 13:38:43 +08:00
|
|
|
|
//})
|
2023-07-23 00:08:18 +08:00
|
|
|
|
////browserWindow.SetOnGetInitialBounds(func(sender lcl.IObject, window *cef.ICefWindow, aResult *cef.TCefRect) {
|
|
|
|
|
//// fmt.Println("popupWindow.SetOnGetInitialBounds", *aResult)
|
|
|
|
|
////})
|
|
|
|
|
////browserWindow.BrowserWindow().CreateTopLevelWindow()
|
|
|
|
|
browserWindow.BrowserWindow().HideTitle()
|
|
|
|
|
//fmt.Println("browserWindow:", browserWindow, browserWindow.WindowComponent().WindowHandle())
|
2023-01-06 18:26:40 +08:00
|
|
|
|
return false
|
|
|
|
|
})
|
2023-07-23 00:08:18 +08:00
|
|
|
|
return
|
2023-01-07 11:48:19 +08:00
|
|
|
|
window.AsViewsFrameworkBrowserWindow().WindowComponent().SetOnWindowActivationChanged(func(sender lcl.IObject, window *cef.ICefWindow, active bool) {
|
|
|
|
|
fmt.Println("SetOnWindowActivationChanged", active)
|
|
|
|
|
})
|
2023-02-28 21:52:13 +08:00
|
|
|
|
window.AsViewsFrameworkBrowserWindow().BrowserViewComponent().SetOnBrowserCreated(func(sender lcl.IObject, browserView *cef.ICefBrowserView, browser *cef.ICefBrowser) {
|
|
|
|
|
fmt.Println("BrowserViewComponent OnBrowserCreated Instance", browser.Identifier(), "Instance Identifier", browserView.Browser().Identifier())
|
|
|
|
|
})
|
2023-01-07 18:42:17 +08:00
|
|
|
|
window.Show()
|
2023-01-08 17:04:39 +08:00
|
|
|
|
fmt.Println("SetBrowserInit 结束")
|
2023-01-28 13:22:11 +08:00
|
|
|
|
if common.IsLinux() || common.IsDarwin() {
|
|
|
|
|
//在VF窗口组件中, 推荐linux和macosx中使用
|
|
|
|
|
traydemo.SysTrayDemo(window) //系统原生托盘,在windows下不如lcl组件的好用,
|
|
|
|
|
} else {
|
|
|
|
|
//不支持windows VF窗口组件中无法创建或使用LCL组件
|
2023-05-31 17:41:14 +08:00
|
|
|
|
//traydemo.LCLTrayDemo(window) //LCL托盘, VF窗口组件中无法创建或使用LCL组件
|
2023-01-28 13:22:11 +08:00
|
|
|
|
//traydemo.LCLCefTrayDemo(window) //对于LCL+CEF web端技术托盘实现无法在VF中使用
|
|
|
|
|
//支持windows
|
2023-05-31 17:41:14 +08:00
|
|
|
|
traydemo.LCLVFTrayDemo(window) //对于LCL+VF web端技术托盘实现
|
2023-01-28 13:22:11 +08:00
|
|
|
|
}
|
2023-01-07 21:29:08 +08:00
|
|
|
|
})
|
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)
|
|
|
|
|
}
|