mirror of
https://gitee.com/energye/energy.git
synced 2024-12-02 11:47:37 +08:00
v2.5.3 demos: tray
This commit is contained in:
parent
1450d74412
commit
e46ff7865d
117
example/tray/tray-demo.go
Normal file
117
example/tray/tray-demo.go
Normal file
@ -0,0 +1,117 @@
|
||||
package traydemo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/energye/energy/cef"
|
||||
"github.com/energye/energy/common"
|
||||
"github.com/energye/golcl/lcl"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LCL组件托盘, 适用windows和macosx, 不支持linux因GTK2和GTK3共存问题,
|
||||
func LCLTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
window := browserWindow.AsLCLBrowserWindow().BrowserWindow()
|
||||
//托盘 windows linux macos 系统托盘
|
||||
newTray := window.NewTray()
|
||||
newTray.SetTitle("任务管理器里显示的标题")
|
||||
newTray.SetHint("这里是文字\n文字啊")
|
||||
if common.IsLinux() {
|
||||
newTray.SetIconFS("resources/icon.png")
|
||||
} else {
|
||||
newTray.SetIconFS("resources/icon.ico")
|
||||
}
|
||||
tray := newTray.AsLCLTray()
|
||||
menu1 := tray.AddMenuItem("父菜单", nil)
|
||||
//带图标的菜单
|
||||
iconItem := tray.NewMenuItem("带个图标", nil)
|
||||
iconItem.Bitmap().SetSize(32, 32) //图标情况调整大小
|
||||
iconItem.Bitmap().SetTransparent(true) //透明
|
||||
icon := lcl.NewIcon()
|
||||
icon.LoadFromFSFile("resources/icon_1.ico")
|
||||
iconItem.Bitmap().Canvas().Draw(0, 0, icon) //画上去
|
||||
tray.TrayMenu().Items().Add(iconItem)
|
||||
|
||||
menu1.Add(tray.NewMenuItem("子菜单", func() {
|
||||
lcl.ShowMessage("子菜单点击 提示消息")
|
||||
}))
|
||||
tray.AddMenuItem("显示气泡", func() {
|
||||
tray.Notice("气泡标题", "气泡内容", 2000)
|
||||
})
|
||||
tray.AddMenuItem("显示/隐藏", func() {
|
||||
vis := window.Visible()
|
||||
cef.BrowserWindow.GetWindowInfo(1)
|
||||
window.SetVisible(!vis)
|
||||
})
|
||||
tray.AddMenuItem("退出", func() {
|
||||
browserWindow.CloseBrowserWindow()
|
||||
})
|
||||
//托盘 end
|
||||
tray.Show()
|
||||
}
|
||||
|
||||
//系统托盘 和LCL组件差不多,但不如LCL组件的好用,适用 windows,linux,macosx
|
||||
//
|
||||
//推荐linux中使用
|
||||
func SysTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
sysTray := browserWindow.NewSysTray()
|
||||
if common.IsLinux() {
|
||||
sysTray.SetIconFS("resources/icon.png")
|
||||
} else {
|
||||
sysTray.SetIconFS("resources/icon.ico")
|
||||
}
|
||||
sysTray.SetHint("中文hint\n换行中文")
|
||||
sysTray.SetOnClick(func() {
|
||||
fmt.Println("SetOnClick")
|
||||
})
|
||||
tray := sysTray.AsSysTray()
|
||||
check := tray.AddMenuItem("check")
|
||||
check.Check()
|
||||
not := tray.AddMenuItem("通知")
|
||||
not.Click(func() {
|
||||
tray.Notice("标题", "内notice 是一个跨平台的系统通知库\nnotice 是一个跨平台的系统通知库", 1000)
|
||||
})
|
||||
enable := tray.AddMenuItem("启用/禁用")
|
||||
enable.Click(func() {
|
||||
fmt.Println("启用/禁用 点击")
|
||||
})
|
||||
tray.AddSeparator()
|
||||
menuItem := tray.AddMenuItem("1级菜单1", func() {
|
||||
fmt.Println("1级菜单1")
|
||||
})
|
||||
menuItem.SetIconFS("resources/icon.ico")
|
||||
tray.AddSeparator()
|
||||
item := tray.AddMenuItem("1级菜单2")
|
||||
item.AddSubMenu("2级子菜单1")
|
||||
sub2Menu := item.AddSubMenu("2级子菜单2")
|
||||
sub2Menu.AddSubMenu("3级子菜单1")
|
||||
tray.AddSeparator()
|
||||
tray.AddMenuItem("退出", func() {
|
||||
fmt.Println("退出")
|
||||
browserWindow.CloseBrowserWindow()
|
||||
})
|
||||
|
||||
sysTray.Show()
|
||||
//测试图标切换
|
||||
go func() {
|
||||
var b bool
|
||||
for {
|
||||
time.Sleep(time.Second * 2)
|
||||
b = !b
|
||||
if b {
|
||||
sysTray.SetHint(fmt.Sprintf("%d\n%v", time.Now().Second(), b))
|
||||
sysTray.SetIconFS("resources/icon_1.ico")
|
||||
menuItem.SetIconFS("resources/icon_1.ico")
|
||||
enable.SetLabel(fmt.Sprintf("%d\n%v", time.Now().Second(), b))
|
||||
enable.Enable()
|
||||
check.Check()
|
||||
} else {
|
||||
sysTray.SetHint(fmt.Sprintf("%d\n%v", time.Now().Second(), b))
|
||||
sysTray.SetIconFS("resources/icon.ico")
|
||||
menuItem.SetIconFS("resources/icon.ico")
|
||||
enable.SetLabel(fmt.Sprintf("%d\n%v", time.Now().Second(), b))
|
||||
enable.Disable()
|
||||
check.Uncheck()
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
26
example/tray/tray-demo_other.go
Normal file
26
example/tray/tray-demo_other.go
Normal file
@ -0,0 +1,26 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package traydemo
|
||||
|
||||
import (
|
||||
"github.com/energye/energy/cef"
|
||||
)
|
||||
|
||||
// 仅适用windows
|
||||
//
|
||||
// LCL + [CEF] 托盘 只适用 windows 基于html 和 ipc 实现功能
|
||||
//
|
||||
//推荐在windows或macosx中使用
|
||||
func LCLCefTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
|
||||
}
|
||||
|
||||
// 仅适用windows
|
||||
//
|
||||
// LCL + [VF] 托盘 只适用 windows 基于html 和 ipc 实现功能
|
||||
//
|
||||
// VF组件托盘,无法使用LCL相关组件
|
||||
func LCLVFTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
|
||||
}
|
104
example/tray/tray-demo_windows.go
Normal file
104
example/tray/tray-demo_windows.go
Normal file
@ -0,0 +1,104 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package traydemo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/energye/energy/cef"
|
||||
"github.com/energye/energy/ipc"
|
||||
"github.com/energye/golcl/lcl"
|
||||
"github.com/energye/golcl/lcl/types"
|
||||
)
|
||||
|
||||
// 仅适用windows
|
||||
//
|
||||
// LCL + [CEF] 托盘 只适用 windows 基于html 和 ipc 实现功能
|
||||
//
|
||||
//推荐在windows或macosx中使用
|
||||
func LCLCefTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
lclBw := browserWindow.AsLCLBrowserWindow().BrowserWindow()
|
||||
var url = "http://localhost:22022/tray-lcl-vf.html"
|
||||
tray := browserWindow.NewCefTray(250, 300, url)
|
||||
cefTray := tray.AsCEFTray()
|
||||
tray.SetTitle("任务管理器里显示的标题")
|
||||
tray.SetHint("这里是文字\n文字啊")
|
||||
tray.SetIconFS("resources/icon.ico")
|
||||
tray.SetOnClick(func() {
|
||||
fmt.Println("SetOnClick")
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-show-balloon", func(context ipc.IIPCContext) {
|
||||
fmt.Println("tray-show-balloon")
|
||||
cefTray.Notice("气泡标题", "气泡内容", 2000)
|
||||
cefTray.Hide()
|
||||
fmt.Println("tray-show-balloon end")
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-show-main-window", func(context ipc.IIPCContext) {
|
||||
vb := !lclBw.Visible()
|
||||
lclBw.SetVisible(vb)
|
||||
if vb {
|
||||
if lclBw.WindowState() == types.WsMinimized {
|
||||
lclBw.SetWindowState(types.WsNormal)
|
||||
}
|
||||
lclBw.Focused()
|
||||
}
|
||||
cefTray.Hide()
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-close-main-window", func(context ipc.IIPCContext) {
|
||||
browserWindow.CloseBrowserWindow()
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-show-message-box", func(context ipc.IIPCContext) {
|
||||
cef.QueueAsyncCall(func(id int) {
|
||||
lcl.ShowMessage("tray-show-message-box 提示消息")
|
||||
})
|
||||
cefTray.Hide()
|
||||
})
|
||||
//托盘 end
|
||||
}
|
||||
|
||||
// 仅适用windows
|
||||
//
|
||||
// LCL + [VF] 托盘 只适用 windows 基于html 和 ipc 实现功能
|
||||
//
|
||||
// VF组件托盘,无法使用LCL相关组件
|
||||
func LCLVFTrayDemo(browserWindow cef.IBrowserWindow) {
|
||||
vfBw := browserWindow.AsViewsFrameworkBrowserWindow().BrowserWindow()
|
||||
var url = "http://localhost:22022/tray-lcl-vf.html"
|
||||
tray := browserWindow.NewCefTray(250, 300, url)
|
||||
vfTray := tray.AsViewsFrameTray()
|
||||
tray.SetTitle("任务管理器里显示的标题")
|
||||
tray.SetHint("这里是文字\n文字啊")
|
||||
tray.SetIconFS("resources/icon.ico")
|
||||
tray.SetOnClick(func() {
|
||||
fmt.Println("SetOnClick")
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-show-balloon", func(context ipc.IIPCContext) {
|
||||
fmt.Println("tray-show-balloon")
|
||||
vfTray.Notice("气泡标题", "气泡内容", 2000)
|
||||
vfTray.Hide()
|
||||
fmt.Println("tray-show-balloon end")
|
||||
})
|
||||
var vfBwVisible = true
|
||||
ipc.IPC.Browser().On("tray-show-main-window", func(context ipc.IIPCContext) {
|
||||
if vfBwVisible {
|
||||
vfBw.Hide()
|
||||
vfBwVisible = false
|
||||
} else {
|
||||
vfBw.Show()
|
||||
vfBwVisible = true
|
||||
}
|
||||
|
||||
vfTray.Hide()
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-close-main-window", func(context ipc.IIPCContext) {
|
||||
browserWindow.CloseBrowserWindow()
|
||||
})
|
||||
ipc.IPC.Browser().On("tray-show-message-box", func(context ipc.IIPCContext) {
|
||||
//在VF窗口组件中无法使用LCL组件
|
||||
//cef.QueueAsyncCall(func(id int) {
|
||||
// lcl.ShowMessage("tray-show-message-box 提示消息")
|
||||
//})
|
||||
vfTray.Hide()
|
||||
})
|
||||
//托盘 end
|
||||
}
|
Loading…
Reference in New Issue
Block a user