mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-06 17:01:33 +08:00
[windows] Add systray.OpenMenu
This commit is contained in:
parent
013ec1d726
commit
fe48b9d03d
@ -18,12 +18,15 @@ func main() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
systemTray := app.NewSystemTray()
|
||||||
|
|
||||||
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||||
Width: 500,
|
Width: 500,
|
||||||
Height: 800,
|
Height: 800,
|
||||||
Frameless: true,
|
Frameless: true,
|
||||||
AlwaysOnTop: true,
|
AlwaysOnTop: true,
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
|
HTML: "<html><body><h1>This window should be centered to the icon!</h1><p>F12 should open the menu</p></body></html>",
|
||||||
ShouldClose: func(window *application.WebviewWindow) bool {
|
ShouldClose: func(window *application.WebviewWindow) bool {
|
||||||
window.Hide()
|
window.Hide()
|
||||||
return false
|
return false
|
||||||
@ -31,9 +34,13 @@ func main() {
|
|||||||
Windows: application.WindowsWindow{
|
Windows: application.WindowsWindow{
|
||||||
HiddenOnTaskbar: true,
|
HiddenOnTaskbar: true,
|
||||||
},
|
},
|
||||||
|
KeyBindings: map[string]func(window *application.WebviewWindow){
|
||||||
|
"F12": func(window *application.WebviewWindow) {
|
||||||
|
systemTray.OpenMenu()
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
systemTray := app.NewSystemTray()
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
||||||
systemTray.SetLabel("\u001B[1;31mW\u001B[1;32ma\u001B[1;33mi\u001B[1;34ml\u001B[1;35ms\u001B[0m")
|
systemTray.SetLabel("\u001B[1;31mW\u001B[1;32ma\u001B[1;33mi\u001B[1;34ml\u001B[1;35ms\u001B[0m")
|
||||||
|
@ -151,11 +151,7 @@ func NewApplicationMenu(parent w32.HWND, inputMenu *Menu) *Win32Menu {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Win32Menu) ShowAtCursor() {
|
func (p *Win32Menu) ShowAt(x int, y int) {
|
||||||
x, y, ok := w32.GetCursorPos()
|
|
||||||
if ok == false {
|
|
||||||
w32.Fatal("GetCursorPos failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
w32.SetForegroundWindow(p.parent)
|
w32.SetForegroundWindow(p.parent)
|
||||||
|
|
||||||
@ -177,6 +173,15 @@ func (p *Win32Menu) ShowAtCursor() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Win32Menu) ShowAtCursor() {
|
||||||
|
x, y, ok := w32.GetCursorPos()
|
||||||
|
if ok == false {
|
||||||
|
w32.Fatal("GetCursorPos failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
p.ShowAt(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Win32Menu) ProcessCommand(cmdMsgID int) bool {
|
func (p *Win32Menu) ProcessCommand(cmdMsgID int) bool {
|
||||||
item := p.menuMapping[cmdMsgID]
|
item := p.menuMapping[cmdMsgID]
|
||||||
if item == nil {
|
if item == nil {
|
||||||
|
@ -35,6 +35,7 @@ type systemTrayImpl interface {
|
|||||||
bounds() (*Rect, error)
|
bounds() (*Rect, error)
|
||||||
getScreen() (*Screen, error)
|
getScreen() (*Screen, error)
|
||||||
positionWindow(window *WebviewWindow, offset int) error
|
positionWindow(window *WebviewWindow, offset int) error
|
||||||
|
openMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
type PositionOptions struct {
|
type PositionOptions struct {
|
||||||
@ -150,7 +151,6 @@ func (s *SystemTray) SetDarkModeIcon(icon []byte) *SystemTray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SystemTray) SetMenu(menu *Menu) *SystemTray {
|
func (s *SystemTray) SetMenu(menu *Menu) *SystemTray {
|
||||||
fmt.Println("SystemTray.SetMenu", menu, s.impl)
|
|
||||||
if s.impl == nil {
|
if s.impl == nil {
|
||||||
s.menu = menu
|
s.menu = menu
|
||||||
} else {
|
} else {
|
||||||
@ -286,3 +286,13 @@ func (s *SystemTray) defaultClickHandler() {
|
|||||||
s.attachedWindow.Window.Show().Focus()
|
s.attachedWindow.Window.Show().Focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SystemTray) OpenMenu() {
|
||||||
|
if s.menu == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if s.impl == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
invokeSync(s.impl.openMenu)
|
||||||
|
}
|
||||||
|
@ -30,6 +30,21 @@ type windowsSystemTray struct {
|
|||||||
currentIcon w32.HICON
|
currentIcon w32.HICON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *windowsSystemTray) openMenu() {
|
||||||
|
if s.menu == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Get the system tray bounds
|
||||||
|
trayBounds, err := s.bounds()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the menu at the tray bounds
|
||||||
|
s.menu.ShowAt(trayBounds.X, trayBounds.Y)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (s *windowsSystemTray) positionWindow(window *WebviewWindow, offset int) error {
|
func (s *windowsSystemTray) positionWindow(window *WebviewWindow, offset int) error {
|
||||||
|
|
||||||
// Get the trayBounds of this system tray
|
// Get the trayBounds of this system tray
|
||||||
|
@ -64,6 +64,10 @@ type windowsWebviewWindow struct {
|
|||||||
focusingChromium bool
|
focusingChromium bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *windowsWebviewWindow) handleKeyEvent(_ string) {
|
||||||
|
// Unused on windows
|
||||||
|
}
|
||||||
|
|
||||||
func (w *windowsWebviewWindow) setAbsolutePosition(x int, y int) {
|
func (w *windowsWebviewWindow) setAbsolutePosition(x int, y int) {
|
||||||
// Set the window's absolute position
|
// Set the window's absolute position
|
||||||
w32.SetWindowPos(w.hwnd, 0, x, y, 0, 0, w32.SWP_NOSIZE|w32.SWP_NOZORDER)
|
w32.SetWindowPos(w.hwnd, 0, x, y, 0, 0, w32.SWP_NOSIZE|w32.SWP_NOZORDER)
|
||||||
|
Loading…
Reference in New Issue
Block a user