mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3 windows] Refactor events + mappings. Fix app.Quit(). Make systray example work slightly better
This commit is contained in:
+10
-11
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/wailsapp/wails/v3/pkg/icons"
|
||||
"log"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
@@ -31,12 +32,15 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
var justClosed bool
|
||||
|
||||
window.On(events.Common.WindowLostFocus, func(ctx *application.WindowEventContext) {
|
||||
window.Hide()
|
||||
})
|
||||
|
||||
app.On(events.Mac.ApplicationDidResignActiveNotification, func() {
|
||||
window.Hide()
|
||||
justClosed = true
|
||||
go func() {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
justClosed = false
|
||||
}()
|
||||
})
|
||||
|
||||
systemTray := app.NewSystemTray()
|
||||
@@ -79,15 +83,10 @@ func main() {
|
||||
}
|
||||
|
||||
showWindow := func() {
|
||||
if window.IsVisible() {
|
||||
window.Hide()
|
||||
return
|
||||
}
|
||||
err := systemTray.PositionWindow(window, 5)
|
||||
if err != nil {
|
||||
application.InfoDialog().SetTitle("Error").SetMessage(err.Error()).Show()
|
||||
if justClosed {
|
||||
return
|
||||
}
|
||||
_ = systemTray.PositionWindow(window, 5)
|
||||
window.Show().Focus()
|
||||
}
|
||||
systemTray.OnClick(showWindow)
|
||||
|
||||
Reference in New Issue
Block a user