v2.3.56 add new sys tray

This commit is contained in:
杨红岩 2023-01-24 18:55:02 +08:00
parent 71e0865ba9
commit 2d285d859b
8 changed files with 109 additions and 22 deletions

View File

@ -15,3 +15,10 @@ func (m *LCLBrowserWindow) NewTray() ITray {
}
return m.tray
}
func (m *LCLBrowserWindow) NewSysTray() ITray {
if m.tray == nil {
m.tray = newSysTray()
}
return m.tray
}

View File

@ -41,6 +41,10 @@ func (m *CEFTray) OnFormCreate(sender lcl.IObject) {
m.SetShowInTaskBar(types.StNever)
}
func (m *CEFTray) AsSysTray() *SysTray {
return nil
}
func (m *CEFTray) AsViewsFrameTray() *ViewsFrameTray {
return nil
}
@ -53,10 +57,6 @@ func (m *CEFTray) AsLCLTray() *LCLTray {
return nil
}
func (m *CEFTray) Tray() ITray {
return m
}
func (m *CEFTray) Show() {
if BrowserWindow.mainBrowserWindow.Chromium() == nil || !BrowserWindow.mainBrowserWindow.Chromium().Initialized() {
return

View File

@ -27,20 +27,17 @@ type ITray interface {
Show() //Show 显示托盘菜单窗口 windows有效
Hide() //Hide 隐藏托盘菜单窗口 windows有效
close() //close 关闭托盘菜单窗口 windows有效
SetOnDblClick(fn TrayICONClick) //SetOnDblClick 双击事件 linux 和 macos 可能不启作用
SetOnClick(fn TrayICONClick) //SetOnClick 单击事件
SetOnMouseUp(fn TMouseEvent) //SetOnMouseUp up事件 linux 和 macos 可能不启作用
SetOnMouseDown(fn lcl.TMouseEvent) //SetOnMouseDown down事件 linux 和 macos 可能不启作用
SetOnMouseMove(fn lcl.TMouseMoveEvent) //SetOnMouseMove move事件 linux 和 macos 可能不启作用
SetOnDblClick(fn TrayICONClick) //SetOnDblClick 双击事件 linux 和 macos 可能不启作用
SetIconFS(iconResourcePath string) //SetIconFS 设置托盘图标
SetIcon(iconResourcePath string) //SetIcon 设置托盘图标
SetHint(value string) //SetHint 设置托盘hint(鼠标移动到托盘图标显示的文字)
ShowBalloon() //ShowBalloon 显示托盘气泡
SetBalloon(title, content string, timeout int32) ITray //SetBalloon 设置托盘气泡内容
Tray() ITray //Tray 返回ITray接口
AsViewsFrameTray() *ViewsFrameTray //AsViewsFrameTray 尝试转换为 views framework 组件托盘, 如果当前创建的是其它类型托盘返回nil
AsCEFTray() *CEFTray //AsCEFTray 尝试转换为 LCL+CEF 组件托盘, 如果当前创建的是其它类型托盘返回nil
AsLCLTray() *LCLTray //AsLCLTray 尝试转换为 LCL 组件托盘, 如果当前创建的是其它类型托盘返回nil
AsSysTray() *SysTray //AsSysTray 尝试转换为 SysTray 组件托盘如果创建的是其它类型托盘返回nil
AsViewsFrameTray() *ViewsFrameTray //AsViewsFrameTray 尝试转换为 views framework 组件托盘, 如果创建的是其它类型托盘返回nil
AsCEFTray() *CEFTray //AsCEFTray 尝试转换为 LCL+CEF 组件托盘, 如果创建的是其它类型托盘返回nil
AsLCLTray() *LCLTray //AsLCLTray 尝试转换为 LCL 组件托盘, 如果创建的是其它类型托盘返回nil
}
//LCLTray LCL 托盘
@ -74,5 +71,6 @@ type CEFTray struct {
//SysTray 系统原生托盘
type SysTray struct {
menu *SysMenu
trayStart, trayStop func()
}

View File

@ -22,6 +22,10 @@ func newTray(owner lcl.IComponent) *LCLTray {
}
}
func (m *LCLTray) AsSysTray() *SysTray {
return nil
}
func (m *LCLTray) AsViewsFrameTray() *ViewsFrameTray {
return nil
}
@ -34,10 +38,6 @@ func (m *LCLTray) AsLCLTray() *LCLTray {
return m
}
func (m *LCLTray) Tray() ITray {
return m
}
func (m *LCLTray) SetVisible(v bool) {
m.trayIcon.SetVisible(v)
}

View File

@ -7,3 +7,78 @@
//----------------------------------------
package cef
import "energye/systray"
//创建系统托盘
func newSysTray() *SysTray {
return &SysTray{}
}
func (m *SysTray) AsSysTray() *SysTray {
return m
}
func (m *SysTray) AsViewsFrameTray() *ViewsFrameTray {
return nil
}
func (m *SysTray) AsCEFTray() *CEFTray {
return nil
}
func (m *SysTray) AsLCLTray() *LCLTray {
return nil
}
func (m *SysTray) Show() {
}
func (m *SysTray) Hide() {
}
func (m *SysTray) close() {
}
func (m *SysTray) SetOnDblClick(fn TrayICONClick) {
}
func (m *SysTray) SetOnClick(fn TrayICONClick) {
}
func (m *SysTray) Visible() bool {
return false
}
func (m *SysTray) SetVisible(v bool) {
}
func (m *SysTray) SetHint(value string) {
systray.SetTooltip(value)
}
func (m *SysTray) SetTitle(title string) {
systray.SetTitle(title)
}
//设置托盘气泡
//title 气泡标题
//content 气泡内容
//timeout 显示时间(毫秒)
func (m *SysTray) SetBalloon(title, content string, timeout int32) ITray {
return nil
}
//显示托盘气泡
func (m *SysTray) ShowBalloon() {
}
//设置托盘图标
func (m *SysTray) SetIconFS(iconResourcePath string) {
}
//设置托盘图标
func (m *SysTray) SetIcon(iconResourcePath string) {
}

View File

@ -121,6 +121,10 @@ func (m *ViewsFrameTray) registerChromiumEvent() {
})
}
func (m *ViewsFrameTray) AsSysTray() *SysTray {
return nil
}
func (m *ViewsFrameTray) AsViewsFrameTray() *ViewsFrameTray {
return m
}
@ -133,10 +137,6 @@ func (m *ViewsFrameTray) AsLCLTray() *LCLTray {
return nil
}
func (m *ViewsFrameTray) Tray() ITray {
return m
}
func (m *ViewsFrameTray) Show() {
m.trayWindow.Show()
}

View File

@ -6,6 +6,7 @@ import (
"github.com/energye/energy/cef"
"github.com/energye/energy/common"
"github.com/energye/energy/consts"
sys_tray "github.com/energye/energy/example/dev-test/sys-tray"
"github.com/energye/energy/ipc"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
@ -395,6 +396,9 @@ func AppBrowserInit() {
})
//添加子窗口初始化
cef.BrowserWindow.SetBrowserInitAfter(func(browserWindow cef.IBrowserWindow) {
tray(browserWindow)
sys_tray.TrayMain()
return
//在这里创建 一些子窗口 子组件 等
//托盘
if common.IsWindows() {
@ -451,6 +455,8 @@ func tray(browserWindow cef.IBrowserWindow) {
//托盘 windows linux macos 系统托盘
newTray := window.NewTray()
tray := newTray.AsLCLTray()
tray.SetTitle("任务管理器里显示的标题")
tray.SetHint("这里是文字\n文字啊")
tray.SetIconFS("resources/icon.ico")
menu1 := tray.AddMenuItem("父菜单", nil)
menu1.Add(tray.NewMenuItem("子菜单", func(object lcl.IObject) {

View File

@ -46,7 +46,8 @@ func addQuitItem() {
func onReady() {
fmt.Println("systray.onReady")
systray.SetTemplateIcon(icon.Data, icon.Data)
//systray.SetTemplateIcon(icon.Data, icon.Data)
systray.SetIcon(icon.Data)
systray.SetTitle("Energy Sys Tray")
systray.SetTooltip("这里是文字\nEnergy tooltip")
systray.SetOnClick(func() {
@ -56,8 +57,8 @@ func onReady() {
fmt.Println("SetOnDClick")
})
systray.SetOnRClick(func(menu systray.IMenu) {
menu.ShowMenu()
fmt.Println("SetOnRClick")
menu.ShowMenu()
})
systray.CreateMenu()
//return