v2.2.6 Fixed Chinese input and gtk3 issues for linux packaging

This commit is contained in:
杨红岩 2023-01-07 16:12:00 +08:00
parent 4c05cbd475
commit 6de1e29e74
10 changed files with 207 additions and 162 deletions

View File

@ -24,8 +24,8 @@ import (
)
const (
IPC_FN_TYPE_IPCJSEmitGo = 1 // JS fires the Go registerEvent
IPC_FN_TYPE_IPCGoEmitJSRet = 2 // Go fires the JS registerEvent
IPC_FN_TYPE_IPCJSEmitGo = 1 // JS fires the Go registerChromiumEvent
IPC_FN_TYPE_IPCGoEmitJSRet = 2 // Go fires the JS registerChromiumEvent
)
var (

View File

@ -27,6 +27,7 @@ type ITray interface {
SetOnMouseUp(fn TMouseEvent) //up事件 linux 和 macos 可能不启作用
SetOnMouseDown(fn lcl.TMouseEvent) //down事件 linux 和 macos 可能不启作用
SetOnMouseMove(fn lcl.TMouseMoveEvent) //move事件 linux 和 macos 可能不启作用
SetIconFS(iconResourcePath string) //设置托盘图标
SetIcon(iconResourcePath string) //设置托盘图标
SetHint(value string) //设置托盘hint(鼠标移动到托盘图标显示的文字)
ShowBalloon() //显示托盘气泡
@ -103,10 +104,15 @@ func (m *Tray) TrayMenu() *lcl.TPopupMenu {
}
//设置托盘图标
func (m *Tray) SetIcon(iconResourcePath string) {
func (m *Tray) SetIconFS(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFSFile(iconResourcePath)
}
//设置托盘图标
func (m *Tray) SetIcon(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFile(iconResourcePath)
}
func (m *Tray) SetHint(value string) {
m.trayIcon.SetHint(value)
}

View File

@ -45,8 +45,8 @@ func newLCLTrayWindow(owner lcl.IComponent, width, height int32, url string) *tL
trayForm.w = width
trayForm.h = height
trayForm.url = url
trayForm.onmMouse()
trayForm.createCefTrayWindow()
trayForm.onMouseEvent()
trayForm.createTrayWindow()
return trayForm
}
@ -74,6 +74,7 @@ func (m *tLCLTrayWindow) close() {
return
}
m.Hide()
m.trayIcon.SetVisible(false)
m.TForm.Close()
}
@ -111,7 +112,7 @@ func (m *tLCLTrayWindow) SetTitle(title string) {
m.TForm.SetCaption(title)
}
func (m *tLCLTrayWindow) onmMouse() {
func (m *tLCLTrayWindow) onMouseEvent() {
QueueAsyncCall(func(id int) {
m.trayIcon.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
var monitor = m.TForm.Monitor()
@ -160,7 +161,7 @@ func (m *tLCLTrayWindow) ShowBalloon() {
m.trayIcon.ShowBalloonHint()
}
func (m *tLCLTrayWindow) createCefTrayWindow() {
func (m *tLCLTrayWindow) createTrayWindow() {
m.TForm.SetBorderStyle(types.BsNone)
m.TForm.SetFormStyle(types.FsStayOnTop)
m.TForm.SetBounds(-(m.w * 2), -(m.h * 2), m.w, m.h)
@ -243,6 +244,11 @@ func (m *tLCLTrayWindow) createCefTrayWindow() {
}
//设置托盘图标
func (m *tLCLTrayWindow) SetIcon(iconResourcePath string) {
func (m *tLCLTrayWindow) SetIconFS(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFSFile(iconResourcePath)
}
//设置托盘图标
func (m *tLCLTrayWindow) SetIcon(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFile(iconResourcePath)
}

View File

@ -12,7 +12,10 @@
package cef
import (
"fmt"
"github.com/energye/energy/common/assetserve"
"github.com/energye/energy/consts"
"github.com/energye/energy/ipc"
"github.com/energye/energy/logger"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
)
@ -27,35 +30,35 @@ type tViewsFrameTrayWindow struct {
}
func newViewsFrameTray(owner lcl.IComponent, width, height int32, url string) *tViewsFrameTrayWindow {
var trayForm = &tViewsFrameTrayWindow{}
var tray = &tViewsFrameTrayWindow{}
cc := NewChromiumConfig()
cc.SetEnableMenu(false)
wp := NewWindowProperty()
wp.Title = ""
wp.Url = url
wp.Width = width
wp.Height = height
wp.X = 100
wp.Y = 100
wp.X = -width
wp.Y = -height
wp.AlwaysOnTop = true
wp.CanMaximize = false
wp.CanMinimize = false
wp.CanResize = false
wp.CenterWindow = false
trayForm.trayWindow = NewViewsFrameworkBrowserWindow(cc, wp, func(event *BrowserEvent, window IBrowserWindow) {
fmt.Println("tray.NewViewsFrameworkBrowserWindow")
window.Show()
tray.trayWindow = NewViewsFrameworkBrowserWindow(cc, wp, func(event *BrowserEvent, window IBrowserWindow) {
window.Hide()
})
trayForm.trayIcon = lcl.NewTrayIcon(owner)
trayForm.trayIcon.SetVisible(true)
trayForm.x = wp.X
trayForm.y = wp.Y
trayForm.w = wp.Width
trayForm.h = wp.Height
trayForm.onmMouse()
//trayForm.createCefTrayWindow()
fmt.Println("newViewsFrameTray")
trayForm.trayWindow.CreateTopLevelWindow()
trayForm.trayWindow.HideTitle()
return trayForm
tray.trayWindow.windowId = BrowserWindow.GetNextWindowNum()
tray.trayWindow.putChromiumWindowInfo()
tray.trayIcon = lcl.NewTrayIcon(owner)
tray.trayIcon.SetVisible(true)
tray.x = wp.X
tray.y = wp.Y
tray.w = wp.Width
tray.h = wp.Height
tray.registerMouseEvent()
tray.registerChromiumEvent()
return tray
}
func (m *tViewsFrameTrayWindow) Tray() *Tray {
@ -63,18 +66,18 @@ func (m *tViewsFrameTrayWindow) Tray() *Tray {
}
func (m *tViewsFrameTrayWindow) Show() {
if BrowserWindow.mainBrowserWindow.Chromium() == nil || !BrowserWindow.mainBrowserWindow.Chromium().Initialized() {
return
}
m.trayWindow.Show()
}
func (m *tViewsFrameTrayWindow) Hide() {
m.trayWindow.Hide()
}
func (m *tViewsFrameTrayWindow) close() {
if m.isClosing {
return
}
m.trayIcon.SetVisible(false)
m.Hide()
}
@ -113,36 +116,73 @@ func (m *tViewsFrameTrayWindow) SetHint(value string) {
func (m *tViewsFrameTrayWindow) SetTitle(title string) {
}
func (m *tViewsFrameTrayWindow) onmMouse() {
func (m *tViewsFrameTrayWindow) registerMouseEvent() {
m.trayWindow.WindowComponent().SetOnWindowActivationChanged(func(sender lcl.IObject, window *ICefWindow, active bool) {
if active {
m.trayWindow.Show()
} else {
m.trayWindow.Hide()
}
})
var IsCreateTopLevelWindow = true
m.trayIcon.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) {
fmt.Println("SetOnMouseUp")
m.trayWindow.WindowComponent().SetPosition(NewCefPoint(400, 400))
//var monitor = m.TForm.Monitor()
//var monitorWidth = monitor.Width()
//width, height := m.TForm.Width(), m.TForm.Height()
//var mx = x + width
//var my = y + height
//if mx < monitorWidth {
// mx = x
//} else {
// mx = x - width
//}
//if my > m.h {
// my = y
//}
//if my > height {
// my = y - height
//}
//m.TForm.SetBounds(mx, my, width, height)
//var ret bool
//if m.mouseUp != nil {
// ret = m.mouseUp(sender, button, shift, x, y)
//}
//if !ret {
// if button == types.MbRight {
// m.Show()
// }
//}
if IsCreateTopLevelWindow {
IsCreateTopLevelWindow = false
m.trayWindow.CreateTopLevelWindow()
m.trayWindow.HideTitle()
m.trayWindow.SetNotInTaskBar()
m.trayWindow.WindowComponent().SetAlwaysOnTop(true)
}
display := m.trayWindow.WindowComponent().Display()
bounds := display.Bounds()
var monitorWidth = bounds.Width
width, height := m.w, m.h
var mx = x + width
var my = y + height
if mx < monitorWidth {
mx = x
} else {
mx = x - width
}
if my > m.h {
my = y
}
if my > height {
my = y - height
}
var ret bool
if m.mouseUp != nil {
ret = m.mouseUp(sender, button, shift, x, y)
}
if !ret {
if button == types.MbRight {
m.trayWindow.WindowComponent().SetBounds(NewCefRect(mx, my, width, height))
m.trayWindow.Show()
m.trayWindow.BrowserViewComponent().RequestFocus()
}
}
})
}
func (m *tViewsFrameTrayWindow) registerChromiumEvent() {
m.trayWindow.Chromium().SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
model.Clear()
})
m.trayWindow.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool {
BrowserWindow.setOrIncNextWindowNum(browser.Identifier() + 1)
return false
})
m.trayWindow.Chromium().SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *consts.TCefReturnValue) {
if assetserve.AssetsServerHeaderKeyValue != "" {
request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
}
})
m.trayWindow.Chromium().SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
logger.Debug("tray.chromium.onBeforeClose")
m.close()
})
m.trayWindow.Chromium().SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ipc.ICefProcessMessage) bool {
return false
})
}
@ -162,89 +202,12 @@ func (m *tViewsFrameTrayWindow) ShowBalloon() {
m.trayIcon.ShowBalloonHint()
}
func (m *tViewsFrameTrayWindow) createCefTrayWindow() {
//m.TForm.SetBorderStyle(types.BsNone)
//m.TForm.SetFormStyle(types.FsStayOnTop)
//m.TForm.SetBounds(-(m.w * 2), -(m.h * 2), m.w, m.h)
//m.TForm.SetOnActivate(func(sender lcl.IObject) {
// m.chromium.Initialized()
// m.chromium.CreateBrowser(m.windowParent)
//})
//m.TForm.SetOnWndProc(func(msg *types.TMessage) {
// m.TForm.InheritedWndProc(msg)
// if msg.Msg == 6 && msg.WParam == 0 && msg.LParam == 0 {
// QueueAsyncCall(func(id int) {
// if m.isClosing {
// return
// }
// m.TForm.Hide()
// })
// }
//})
//m.TForm.SetOnDeactivate(func(sender lcl.IObject) {
// if m.isClosing {
// return
// }
// m.TForm.Hide()
//})
//
//m.TForm.SetOnCloseQuery(func(sender lcl.IObject, canClose *bool) {
// *canClose = true
// logger.Debug("tray.window.onCloseQuery canClose:", *canClose)
// if m.isClosing {
// return
// }
// m.isClosing = true
// m.Hide()
// m.chromium.CloseBrowser(true)
// m.trayIcon.Free()
//})
//m.TForm.SetOnClose(func(sender lcl.IObject, action *types.TCloseAction) {
// *action = types.CaFree
// logger.Debug("tray.window.onClose action:", *action)
//})
//m.TForm.SetOnShow(func(sender lcl.IObject) {
// if m.windowParent != nil {
// QueueAsyncCall(func(id int) {
// m.windowParent.UpdateSize()
// })
// }
//})
//m.windowParent = NewCEFWindow(m.TForm)
//m.windowParent.SetParent(m.TForm)
//m.windowParent.SetAlign(types.AlClient)
//m.windowParent.SetAnchors(types.NewSet(types.AkTop, types.AkLeft, types.AkRight, types.AkBottom))
//m.chromium = NewChromium(m.windowParent, nil)
//m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
// model.Clear()
//})
//m.chromium.SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool {
// BrowserWindow.setOrIncNextWindowNum(browser.Identifier() + 1)
// return false
//})
//m.chromium.SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *TCefReturnValue) {
// if assetserve.AssetsServerHeaderKeyValue != "" {
// request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
// }
//})
//m.chromium.SetOnClose(func(sender lcl.IObject, browser *ICefBrowser, aAction *TCefCloseBrowsesAction) {
// logger.Debug("tray.chromium.onClose")
// if IsDarwin() {
// m.windowParent.DestroyChildWindow()
// }
// *aAction = CbaClose
//})
//m.chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
// logger.Debug("tray.chromium.onBeforeClose")
//})
//m.chromium.SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess CefProcessId, message *ipc.ICefProcessMessage) bool {
// return false
//})
//m.windowParent.SetChromium(m.chromium, 0)
//m.chromium.SetDefaultURL(m.url)
//设置托盘图标
func (m *tViewsFrameTrayWindow) SetIconFS(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFSFile(iconResourcePath)
}
//设置托盘图标
func (m *tViewsFrameTrayWindow) SetIcon(iconResourcePath string) {
m.trayIcon.Icon().LoadFromFSFile(iconResourcePath)
m.trayIcon.Icon().LoadFromFile(iconResourcePath)
}

View File

@ -53,11 +53,12 @@ func NewViewsFrameworkBrowserWindow(chromiumConfig *tCefChromiumConfig, windowPr
browserViewComponent: NewBrowserViewComponent(component),
}
m.chromium.SetEnableMultiBrowserMode(true)
m.registerPopupEvent()
m.windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *ICefWindow) {
if m.chromium.CreateBrowserByBrowserViewComponent(windowProperty.Url, m.browserViewComponent) {
m.windowComponent.AddChildView(m.browserViewComponent)
m.windowComponent.SetTitle(windowProperty.Title)
if windowProperty.Title != "" {
m.windowComponent.SetTitle(windowProperty.Title)
}
if windowProperty.CenterWindow {
m.windowComponent.CenterWindow(NewCefSize(windowProperty.Width, windowProperty.Height))
}
@ -387,6 +388,28 @@ func (m *ViewsFrameworkBrowserWindow) HideTitle() {
}
}
func (m *ViewsFrameworkBrowserWindow) SetDefaultInTaskBar() {
if common.IsWindows() {
m.SetShowInTaskBar()
}
}
func (m *ViewsFrameworkBrowserWindow) SetShowInTaskBar() {
if common.IsWindows() {
handle := m.WindowComponent().WindowHandle()
win.ShowWindow(handle.ToPtr(), win.SW_SHOW)
win.SetWindowLong(handle.ToPtr(), win.GWL_EXSTYLE, win.WS_EX_APPWINDOW)
}
}
func (m *ViewsFrameworkBrowserWindow) SetNotInTaskBar() {
if common.IsWindows() {
handle := m.WindowComponent().WindowHandle()
win.ShowWindow(handle.ToPtr(), win.SW_HIDE)
win.SetWindowLong(handle.ToPtr(), win.GWL_EXSTYLE, uintptr(win.GetWindowLong(handle.ToPtr(), win.GWL_EXSTYLE)|win.WS_EX_TOOLWINDOW&^win.WS_EX_APPWINDOW))
}
}
func (m *ViewsFrameworkBrowserWindow) Hide() {
m.WindowComponent().Hide()
}

View File

@ -83,6 +83,9 @@ type IBrowserWindow interface {
NewCefTray(width, height int32, url string) ITray
NewTray() ITray
HideTitle()
SetDefaultInTaskBar()
SetShowInTaskBar()
SetNotInTaskBar()
}
type ILCLBrowserWindow interface {
@ -90,9 +93,6 @@ type ILCLBrowserWindow interface {
BrowserWindow() *LCLBrowserWindow
EnableDefaultCloseEvent()
EnableAllDefaultEvent()
SetDefaultInTaskBar()
SetShowInTaskBar()
SetNotInTaskBar()
WindowParent() ITCefWindowParent
DisableTransparent()
EnableTransparent(value uint8)

View File

@ -603,4 +603,17 @@ const (
type TCefShowState = types.Int32
const (
CEF_SHOW_STATE_NORMAL = TCefShowState(1)
CEF_SHOW_STATE_MINIMIZED = TCefShowState(2)
CEF_SHOW_STATE_MAXIMIZED = TCefShowState(3)
CEF_SHOW_STATE_FULLSCREEN = TCefShowState(4)
)
type TCefChromeToolbarType = types.Int32
const (
CEF_CTT_NONE = TCefChromeToolbarType(1)
CEF_CTT_NORMAL = TCefChromeToolbarType(2)
CEF_CTT_LOCATION = TCefChromeToolbarType(3)
)

View File

@ -78,9 +78,9 @@ func cefTray(browserWindow cef.IBrowserWindow) {
tray := browserWindow.NewCefTray(250, 300, url)
tray.SetTitle("任务管理器里显示的标题")
tray.SetHint("这里是文字\n文字啊")
tray.SetIcon("resources/icon.ico")
tray.SetIconFS("resources/icon.ico")
tray.SetOnClick(func(sender lcl.IObject) {
//browserWindow.SetVisible(!browserWindow.Visible())
browserWindow.Show()
})
tray.SetBalloon("气泡标题", "气泡内容", 2000)
ipc.IPC.Browser().On("tray-show-balloon", func(context ipc.IIPCContext) {
@ -89,23 +89,15 @@ func cefTray(browserWindow cef.IBrowserWindow) {
tray.Hide()
})
ipc.IPC.Browser().On("tray-show-main-window", func(context ipc.IIPCContext) {
//vb := !browserWindow.Visible()
//browserWindow.SetVisible(vb)
//if vb {
// if browserWindow.WindowState() == types.WsMinimized {
// browserWindow.SetWindowState(types.WsNormal)
// }
// browserWindow.Focused()
//}
browserWindow.Hide()
tray.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 提示消息")
})
//无法使用lcl组件
//lcl.ShowMessage("提示?") //直接异常退出
tray.Hide()
})
//托盘 end
@ -116,7 +108,7 @@ func tray(browserWindow cef.IBrowserWindow) {
//托盘 windows linux macos 系统托盘
newTray := browserWindow.NewTray()
tray := newTray.Tray()
tray.SetIcon("resources/icon.ico")
tray.SetIconFS("resources/icon.ico")
tray.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) bool {
fmt.Println("SetOnMouseUp", button, shift, x, y)
return false

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
a, button {
margin: 15px;
}
body {
overflow: hidden;
height: 400px;
}
</style>
<script>
function trayShowMessageBox() {
ipc.emit("tray-show-message-box");
}
function trayShowBalloon() {
ipc.emit("tray-show-balloon");
}
function trayShowMainWindow() {
ipc.emit("tray-show-main-window");
}
function trayCloseMainWindow() {
ipc.emit("tray-close-main-window");
}
</script>
</head>
<body id="bodyId" style="border: 0; padding: 0;margin:0;overflow-x: hidden;overflow-y: hidden;">
<button onclick="trayShowBalloon()">显示托盘汽泡</button>
<br>
<button onclick="trayShowMainWindow()">显示窗口</button>
<br>
<button onclick="trayCloseMainWindow()">退出</button>
<button onclick="trayShowMessageBox()">显示消息弹窗</button>
</body>
</html>

View File

@ -191,7 +191,7 @@ func AppBrowserInit() {
//browserWindow.EnableTransparent(100) //窗口透明
//设置窗口样式,无标题 ,最大化按钮等
window := browserWindow.AsLCLBrowserWindow()
browserWindow.HideTitle()
//browserWindow.HideTitle()
//window.BrowserWindow().SetBorderStyle(types.BsNone)
//window.BrowserWindow().SetFormStyle(types.FsNormal)
//window.BrowserWindow().SetFormStyle(types.FsSystemStayOnTop)
@ -402,7 +402,7 @@ func cefTray(browserWindow cef.ILCLBrowserWindow) {
tray := browserWindow.NewCefTray(250, 300, url)
tray.SetTitle("任务管理器里显示的标题")
tray.SetHint("这里是文字\n文字啊")
tray.SetIcon("resources/icon.ico")
tray.SetIconFS("resources/icon.ico")
tray.SetOnClick(func(sender lcl.IObject) {
window.SetVisible(!window.Visible())
})
@ -441,7 +441,7 @@ func tray(browserWindow cef.ILCLBrowserWindow) {
//托盘 windows linux macos 系统托盘
newTray := browserWindow.NewTray()
tray := newTray.Tray()
tray.SetIcon("resources/icon.ico")
tray.SetIconFS("resources/icon.ico")
menu1 := tray.AddMenuItem("父菜单", nil)
menu1.Add(tray.NewMenuItem("子菜单", func(object lcl.IObject) {
lcl.ShowMessage("子菜单点击 提示消息")