U: demo lcltray

This commit is contained in:
杨红岩 2023-12-16 20:15:10 +08:00
parent 28c300409a
commit 945e4086dd
5 changed files with 38 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
)
// LCLTray LCL组件托盘, 适用windows和macosx
@ -36,7 +37,6 @@ func LCLTray(browserWindow cef.IBrowserWindow) {
icon := lcl.NewPngImage()
icon.LoadFromFSFile("resources/icon.png")
iconItem.Bitmap().Assign(icon) //.Canvas().Draw(0, 0, icon) //画上去
icon.Free()
tray.TrayMenu().Items().Add(iconItem)
menu1.Add(tray.NewMenuItem("子菜单", func(s lcl.IObject) {
@ -94,6 +94,23 @@ func LCLTray(browserWindow cef.IBrowserWindow) {
tray.TrayMenu().Items().Add(radio3)
// --
tray.AddMenuItem("-", nil)
var (
showMenu *lcl.TMenuItem
wotMenu *lcl.TMenuItem
)
var wot = func(sender lcl.IObject) {
wotMenu.SetVisible(!wotMenu.Visible())
if wotMenu.Visible() {
showMenu.SetCaption("Hide WOT")
} else {
showMenu.SetCaption("Show WOT")
}
fmt.Println(wotMenu.Visible())
}
showMenu = tray.AddMenuItem("Hide WOT", wot)
wotMenu = tray.AddMenuItem("Me WOT", wot)
// --
tray.AddMenuItem("-", nil)
tray.AddMenuItem("退出", func(s lcl.IObject) {
// 关闭所有窗口
@ -103,4 +120,21 @@ func LCLTray(browserWindow cef.IBrowserWindow) {
})
//托盘 end
tray.Show()
var trayICON bool
timer := lcl.NewTimer(window)
timer.SetInterval(1000)
timer.SetOnTimer(func(sender lcl.IObject) {
if trayICON {
newTray.SetIconFS("resources/icon.png")
} else {
newTray.SetIconFS("resources/icon_red.png")
}
trayICON = !trayICON
})
timer.SetEnabled(true)
window.SetOnClose(func(sender lcl.IObject, action *types.TCloseAction) bool {
timer.SetEnabled(false)
timer.Free()
return false
})
}

View File

@ -1,28 +1,25 @@
package main
import (
"embed"
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/exception"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/cef/ipc/callback"
"github.com/energye/energy/v2/cef/ipc/target"
demoCommon "github.com/energye/energy/v2/examples/common"
"github.com/energye/energy/v2/examples/common/tray"
"github.com/energye/energy/v2/logger"
"github.com/energye/golcl/lcl"
"time"
)
//go:embed resources
var resources embed.FS
// go build -ldflags "-s -w"
func main() {
logger.SetEnable(true)
logger.SetLevel(logger.CefLog_Debug)
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
cef.GlobalInit(nil, demoCommon.ResourcesFS())
exception.SetOnException(func(message string) {
fmt.Println("Global Exception message", message)
})
@ -38,7 +35,7 @@ func main() {
//本地资源加载
cef.BrowserWindow.Config.LocalResource(cef.LocalLoadConfig{
ResRootDir: "resources",
FS: &resources,
FS: demoCommon.ResourcesFS(),
Home: "multiple-window.html",
}.Build())

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 765 B