main.go
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
fmt.Println(window.IsLCL())
if window.IsLCL() {
trayx.TrayDemo(window)
}
//window.Hide() 初始化回调无法使用hide ,但是可以使用show
lcl.Application.SetShowMainForm(false)
fmt.Println("win_id:", window.Id())
event.SetOnKeyEvent(func(sender lcl.IObject, browser *cef.ICefBrowser, event *cef.TCefKeyEvent, osEvent *consts.TCefEventHandle, window cef.IBrowserWindow, result *bool) {
//fmt.Printf("%s KeyEvent:%+v osEvent:%+v\n", string(rune(event.Character)), event, osEvent)
fmt.Println(window.Id())
wintool.KeyEvents(event, browser, window)
})
//重写主窗口关闭事件 实现关闭窗口不退出托盘
lcl.Application.MainForm().SetOnCloseQuery(func(sender lcl.IObject, canClose *bool) {
fmt.Println("关闭主窗口")
fmt.Println(sender)
*canClose = false
window.Hide()
})
//login
wintool.CreateWindow(window, "登录", "http://localhost:22022/login/", 400, 250)
//ipcs
ipctool.AppIPC(window)
})
wintool.go
func login(context context.IContext, window cef.IBrowserWindow) {
browserWindow := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
browserWindow.Close()
//关闭登录窗口,显示主窗口
window.Show()
//获取焦点 否则无法进行快捷键操作
window.Chromium().SetFocus(true)
}