[v3 windows] Refactor events + mappings. Fix app.Quit(). Make systray example work slightly better

This commit is contained in:
Lea Anthony
2023-07-05 20:35:45 +10:00
parent 10144adf61
commit f0bf8cd827
10 changed files with 188 additions and 71 deletions
+10 -11
View File
@@ -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)