提交 926609a9 编写于 作者: yanghye's avatar yanghye

v2.3.67 tray,notice optimize

上级 dcfa6597
...@@ -61,7 +61,7 @@ type WindowProperty struct { ...@@ -61,7 +61,7 @@ type WindowProperty struct {
//定义了常用函数 //定义了常用函数
type IBrowserWindow interface { type IBrowserWindow interface {
Id() int32 //窗口ID Id() int32 //窗口ID
Handle() types.HWND // Handle() types.HWND //窗口句柄
Show() //显示窗口 Show() //显示窗口
Hide() //隐藏窗口 Hide() //隐藏窗口
Maximize() //窗口最大化 Maximize() //窗口最大化
...@@ -100,10 +100,10 @@ type IBrowserWindow interface { ...@@ -100,10 +100,10 @@ type IBrowserWindow interface {
SetCenterWindow(value bool) //设置窗口居中 SetCenterWindow(value bool) //设置窗口居中
ShowTitle() //显示窗口标题栏 ShowTitle() //显示窗口标题栏
HideTitle() //隐藏窗口标题栏 HideTitle() //隐藏窗口标题栏
SetDefaultInTaskBar() //窗口默认在任务栏上显示图标 SetDefaultInTaskBar() //默认窗口在任务栏上显示按钮
SetShowInTaskBar() //强制窗口在任务栏上显示图标 SetShowInTaskBar() //强制窗口在任务栏上显示按钮
SetNotInTaskBar() //强制不在任务栏上显示窗口图标 SetNotInTaskBar() //强制窗口不在任务栏上显示按钮
NewCefTray(width, height int32, url string) ITray //创建托盘CEF自定义html NewCefTray(width, height int32, url string) ITray //创建托盘LCL+CEF(使用web端技术自定义实现)
NewSysTray() ITray //systray系统原生 NewSysTray() ITray //systray系统原生
} }
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
package cef package cef
//只适用于windows的无菜单托盘 //只适用于windows的无菜单托盘, 需使用web端技术实现
//
//不支持Linux和MacOSX
func (m *LCLBrowserWindow) NewCefTray(width, height int32, url string) ITray { func (m *LCLBrowserWindow) NewCefTray(width, height int32, url string) ITray {
if m == nil { if m == nil {
return nil return nil
...@@ -22,7 +24,9 @@ func (m *LCLBrowserWindow) NewCefTray(width, height int32, url string) ITray { ...@@ -22,7 +24,9 @@ func (m *LCLBrowserWindow) NewCefTray(width, height int32, url string) ITray {
return m.tray return m.tray
} }
//只适用于windows的无菜单托盘 //只适用于windows的无菜单托盘, 需使用web端技术实现
//
//不支持Linux和MacOSX
func (m *ViewsFrameworkBrowserWindow) NewCefTray(width, height int32, url string) ITray { func (m *ViewsFrameworkBrowserWindow) NewCefTray(width, height int32, url string) ITray {
if m == nil { if m == nil {
return nil return nil
......
...@@ -148,20 +148,15 @@ func (m *CEFTray) onMouseEvent() { ...@@ -148,20 +148,15 @@ func (m *CEFTray) onMouseEvent() {
}) })
} }
//设置托盘气泡 //显示系统通知
//title 气泡标题 //
//content 气泡内容 //title 标题
//
//content 内容
//
//timeout 显示时间(毫秒) //timeout 显示时间(毫秒)
func (m *CEFTray) SetBalloon(title, content string, timeout int32) ITray { func (m *CEFTray) Notice(title, content string, timeout int32) {
m.trayIcon.SetBalloonTitle(title) notification(m.trayIcon, title, content, timeout)
m.trayIcon.SetBalloonHint(content)
m.trayIcon.SetBalloonTimeout(timeout)
return m
}
//显示托盘气泡
func (m *CEFTray) ShowBalloon() {
m.trayIcon.ShowBalloonHint()
} }
func (m *CEFTray) createTrayWindow() { func (m *CEFTray) createTrayWindow() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package cef package cef
import ( import (
"energye/notice"
"energye/systray" "energye/systray"
"github.com/energye/golcl/lcl" "github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types" "github.com/energye/golcl/lcl/types"
...@@ -33,18 +34,19 @@ type TrayICONClick func() ...@@ -33,18 +34,19 @@ type TrayICONClick func()
// //
//4. SysTray 对Windows、MacOSX和Linux支持较好 //4. SysTray 对Windows、MacOSX和Linux支持较好
type ITray interface { type ITray interface {
SetTitle(title string) //SetTitle 设置标题 SetTitle(title string) //SetTitle 设置标题
Show() //Show 显示/启动 托盘 Show() //Show 显示/启动 托盘
close() // close() //
SetOnClick(fn TrayICONClick) //SetOnClick 单击事件 SetOnClick(fn TrayICONClick) //SetOnClick 单击事件
SetOnDblClick(fn TrayICONClick) //SetOnDblClick 双击事件 SetOnDblClick(fn TrayICONClick) //SetOnDblClick 双击事件
SetIconFS(iconResourcePath string) //SetIconFS 设置托盘图标 SetIconFS(iconResourcePath string) //SetIconFS 设置托盘图标
SetIcon(iconResourcePath string) //SetIcon 设置托盘图标 SetIcon(iconResourcePath string) //SetIcon 设置托盘图标
SetHint(value string) //SetHint 设置托盘hint(鼠标移动到托盘图标显示的文字) SetHint(value string) //SetHint 设置托盘hint(鼠标移动到托盘图标显示的文字)
AsSysTray() *SysTray //AsSysTray 尝试转换为 SysTray 组件托盘,如果创建的是其它类型托盘返回nil AsSysTray() *SysTray //AsSysTray 尝试转换为 SysTray 组件托盘,如果创建的是其它类型托盘返回nil
AsViewsFrameTray() *ViewsFrameTray //AsViewsFrameTray 尝试转换为 views framework 组件托盘, 如果创建的是其它类型托盘返回nil AsViewsFrameTray() *ViewsFrameTray //AsViewsFrameTray 尝试转换为 views framework 组件托盘, 如果创建的是其它类型托盘返回nil
AsCEFTray() *CEFTray //AsCEFTray 尝试转换为 LCL+CEF 组件托盘, 如果创建的是其它类型托盘返回nil AsCEFTray() *CEFTray //AsCEFTray 尝试转换为 LCL+CEF 组件托盘, 如果创建的是其它类型托盘返回nil
AsLCLTray() *LCLTray //AsLCLTray 尝试转换为 LCL 组件托盘, 如果创建的是其它类型托盘返回nil AsLCLTray() *LCLTray //AsLCLTray 尝试转换为 LCL 组件托盘, 如果创建的是其它类型托盘返回nil
Notice(title, content string, timeout int32) //Notice 托盘系统通知
} }
//LCLTray LCL组件 托盘 //LCLTray LCL组件 托盘
...@@ -87,3 +89,26 @@ type SysTray struct { ...@@ -87,3 +89,26 @@ type SysTray struct {
rClick func(menu systray.IMenu) rClick func(menu systray.IMenu)
start, stop func() start, stop func()
} }
func notification(tray lcl.IComponent, title, content string, timeout int32) {
var lclTrayNotice *lcl.TTrayIcon
if tray != nil {
lclTrayNotice = tray.(*lcl.TTrayIcon)
}
var lclNotice = func() {
lclTrayNotice.SetBalloonTitle(title)
lclTrayNotice.SetBalloonHint(content)
lclTrayNotice.SetBalloonTimeout(timeout)
lclTrayNotice.ShowBalloonHint()
}
var sysNotice = func() {
notify := notice.NewNotification(title, content)
notify.SetTimeout(timeout)
notice.SendNotification(notify)
}
if lclTrayNotice != nil {
lclNotice()
} else {
sysNotice()
}
}
...@@ -112,23 +112,15 @@ func (m *LCLTray) SetTitle(title string) { ...@@ -112,23 +112,15 @@ func (m *LCLTray) SetTitle(title string) {
m.trayIcon.SetHint(title) m.trayIcon.SetHint(title)
} }
//设置托盘气泡 //显示系统通知
// //
//title 气泡标题 //title 标题
// //
//content 气泡内容 //content 内容
// //
//timeout 显示时间(毫秒) //timeout 显示时间(毫秒)
func (m *LCLTray) SetBalloon(title, content string, timeout int32) ITray { func (m *LCLTray) Notice(title, content string, timeout int32) {
m.trayIcon.SetBalloonTitle(title) notification(m.trayIcon, title, content, timeout)
m.trayIcon.SetBalloonHint(content)
m.trayIcon.SetBalloonTimeout(timeout)
return m
}
//显示托盘气泡
func (m *LCLTray) ShowBalloon() {
m.trayIcon.ShowBalloonHint()
} }
//创建一个菜单,还未添加到托盘 //创建一个菜单,还未添加到托盘
......
...@@ -155,6 +155,17 @@ func (m *SysTray) SetTitle(title string) { ...@@ -155,6 +155,17 @@ func (m *SysTray) SetTitle(title string) {
} }
} }
//显示系统通知
//
//title 标题
//
//content 内容
//
//timeout 显示时间(毫秒)
func (m *SysTray) Notice(title, content string, timeout int32) {
notification(nil, title, content, timeout)
}
//SetIconFS 设置托盘图标 //SetIconFS 设置托盘图标
func (m *SysTray) SetIconFS(iconResourcePath string) { func (m *SysTray) SetIconFS(iconResourcePath string) {
if emfs.IsExist(iconResourcePath) { if emfs.IsExist(iconResourcePath) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
package cef package cef
import ( import (
"github.com/energye/energy/common"
"github.com/energye/energy/common/assetserve" "github.com/energye/energy/common/assetserve"
"github.com/energye/energy/consts" "github.com/energye/energy/consts"
"github.com/energye/energy/ipc" "github.com/energye/energy/ipc"
...@@ -193,20 +194,19 @@ func (m *ViewsFrameTray) SetHint(value string) { ...@@ -193,20 +194,19 @@ func (m *ViewsFrameTray) SetHint(value string) {
func (m *ViewsFrameTray) SetTitle(title string) { func (m *ViewsFrameTray) SetTitle(title string) {
} }
//设置托盘气泡 //显示系统通知
//title 气泡标题 //
//content 气泡内容 //title 标题
//
//content 内容
//
//timeout 显示时间(毫秒) //timeout 显示时间(毫秒)
func (m *ViewsFrameTray) SetBalloon(title, content string, timeout int32) ITray { func (m *ViewsFrameTray) Notice(title, content string, timeout int32) {
m.trayIcon.SetBalloonTitle(title) if common.IsWindows() {
m.trayIcon.SetBalloonHint(content) notification(m.trayIcon, title, content, timeout)
m.trayIcon.SetBalloonTimeout(timeout) } else {
return m notification(nil, title, content, timeout)
} }
//显示托盘气泡
func (m *ViewsFrameTray) ShowBalloon() {
m.trayIcon.ShowBalloonHint()
} }
//设置托盘图标 //设置托盘图标
......
...@@ -580,7 +580,7 @@ const ( ...@@ -580,7 +580,7 @@ const (
WOD_NEW_PICTURE_IN_PICTURE WOD_NEW_PICTURE_IN_PICTURE
) )
// Browser Window Type //WINDOW_TYPE 窗口类型
type WINDOW_TYPE = types.Int8 type WINDOW_TYPE = types.Int8
const ( const (
......
...@@ -403,8 +403,6 @@ func AppBrowserInit() { ...@@ -403,8 +403,6 @@ func AppBrowserInit() {
}) })
//添加子窗口初始化 //添加子窗口初始化
cef.BrowserWindow.SetBrowserInitAfter(func(browserWindow cef.IBrowserWindow) { cef.BrowserWindow.SetBrowserInitAfter(func(browserWindow cef.IBrowserWindow) {
lclTray(browserWindow)
return
//在这里创建 一些子窗口 子组件 等 //在这里创建 一些子窗口 子组件 等
//托盘 //托盘
if common.IsWindows() { if common.IsWindows() {
...@@ -427,10 +425,9 @@ func lclCefTray(browserWindow cef.IBrowserWindow) { ...@@ -427,10 +425,9 @@ func lclCefTray(browserWindow cef.IBrowserWindow) {
tray.SetOnClick(func() { tray.SetOnClick(func() {
fmt.Println("SetOnClick") fmt.Println("SetOnClick")
}) })
asCEFTray.SetBalloon("气泡标题", "气泡内容", 2000)
ipc.IPC.Browser().On("tray-show-balloon", func(context ipc.IIPCContext) { ipc.IPC.Browser().On("tray-show-balloon", func(context ipc.IIPCContext) {
fmt.Println("tray-show-balloon") fmt.Println("tray-show-balloon")
asCEFTray.ShowBalloon() asCEFTray.Notice("气泡标题", "气泡内容", 2000)
asCEFTray.Hide() asCEFTray.Hide()
}) })
ipc.IPC.Browser().On("tray-show-main-window", func(context ipc.IIPCContext) { ipc.IPC.Browser().On("tray-show-main-window", func(context ipc.IIPCContext) {
...@@ -470,7 +467,8 @@ func lclTray(browserWindow cef.IBrowserWindow) { ...@@ -470,7 +467,8 @@ func lclTray(browserWindow cef.IBrowserWindow) {
lcl.ShowMessage("子菜单点击 提示消息") lcl.ShowMessage("子菜单点击 提示消息")
})) }))
tray.AddMenuItem("显示气泡", func() { tray.AddMenuItem("显示气泡", func() {
tray.ShowBalloon() //linux下有些问题
tray.Notice("气泡标题", "气泡内容", 2000)
}) })
tray.AddMenuItem("显示/隐藏", func() { tray.AddMenuItem("显示/隐藏", func() {
vis := window.Visible() vis := window.Visible()
...@@ -480,8 +478,6 @@ func lclTray(browserWindow cef.IBrowserWindow) { ...@@ -480,8 +478,6 @@ func lclTray(browserWindow cef.IBrowserWindow) {
tray.AddMenuItem("退出", func() { tray.AddMenuItem("退出", func() {
browserWindow.CloseBrowserWindow() browserWindow.CloseBrowserWindow()
}) })
//linux下有些问题
tray.SetBalloon("气泡标题", "气泡内容", 2000)
//托盘 end //托盘 end
tray.Show() tray.Show()
} }
......
...@@ -10,7 +10,6 @@ package main ...@@ -10,7 +10,6 @@ package main
import ( import (
"embed" "embed"
"energye/notice"
"fmt" "fmt"
"github.com/energye/energy/cef" "github.com/energye/energy/cef"
"github.com/energye/energy/common/assetserve" "github.com/energye/energy/common/assetserve"
...@@ -73,7 +72,6 @@ func main() { ...@@ -73,7 +72,6 @@ func main() {
}) })
cef.BrowserWindow.SetBrowserInitAfter(func(window cef.IBrowserWindow) { cef.BrowserWindow.SetBrowserInitAfter(func(window cef.IBrowserWindow) {
sysTray(window) sysTray(window)
//sys_tray.TrayMain()
return return
}) })
cef.SetBrowserProcessStartAfterCallback(func(b bool) { cef.SetBrowserProcessStartAfterCallback(func(b bool) {
...@@ -101,7 +99,7 @@ func sysTray(browserWindow cef.IBrowserWindow) { ...@@ -101,7 +99,7 @@ func sysTray(browserWindow cef.IBrowserWindow) {
check.Check() check.Check()
not := tray.AddMenuItem("通知") not := tray.AddMenuItem("通知")
not.Click(func() { not.Click(func() {
notice.SendNotification(notice.NewNotification("标题", "内容内容内容内容内容内容内容内容内容内容内容内容内容内容\n内容内容内容内容内容内容内容内容内容内容内容内容内容内")) sysTray.Notice("标题", "内容内容内容内容内容内容内容内容内容内容内容内容内容内容\n内容内容内容内容内容内容内容内容内容内容内容内容内容内", 1000)
}) })
enable := tray.AddMenuItem("启用/禁用") enable := tray.AddMenuItem("启用/禁用")
enable.Click(func() { enable.Click(func() {
......
...@@ -10,7 +10,6 @@ package main ...@@ -10,7 +10,6 @@ package main
import ( import (
"embed" "embed"
"energye/notice"
"fmt" "fmt"
"github.com/energye/energy/cef" "github.com/energye/energy/cef"
"github.com/energye/energy/common" "github.com/energye/energy/common"
...@@ -102,7 +101,7 @@ func sysTray(browserWindow cef.IBrowserWindow) { ...@@ -102,7 +101,7 @@ func sysTray(browserWindow cef.IBrowserWindow) {
check.Check() check.Check()
not := tray.AddMenuItem("通知") not := tray.AddMenuItem("通知")
not.Click(func() { not.Click(func() {
notice.SendNotification(notice.NewNotification("标题", "notice 是一个跨平台的系统通知库")) tray.Notice("标题", "内notice 是一个跨平台的系统通知库\nnotice 是一个跨平台的系统通知库", 1000)
}) })
enable := tray.AddMenuItem("启用/禁用") enable := tray.AddMenuItem("启用/禁用")
enable.Click(func() { enable.Click(func() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册