mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-15 23:25:49 +01:00
* remove systray add retry loop * correct setTooltip truncation * track Windows tray icon ownership to avoid destroying shared handles * fix incorrect warning call * stop leaking Windows tray theme listener after destroy * fix default app icon loading * fix incorrect truncation * harden system tray flow * implement windows tray show/hide * improved readability * updateIcon call path * improve error handling * systray clock example * added changelog --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"runtime"
|
|
"time"
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
"github.com/wailsapp/wails/v3/pkg/icons"
|
|
)
|
|
|
|
func main() {
|
|
app := application.New(application.Options{
|
|
Name: "Systray Clock",
|
|
Description: "System tray clock with live tooltip updates",
|
|
Assets: application.AlphaAssets,
|
|
Mac: application.MacOptions{
|
|
ActivationPolicy: application.ActivationPolicyAccessory,
|
|
},
|
|
Windows: application.WindowsOptions{
|
|
DisableQuitOnLastWindowClosed: true,
|
|
},
|
|
})
|
|
|
|
systemTray := app.SystemTray.New()
|
|
|
|
// Use the template icon on macOS so the clock respects light/dark modes.
|
|
if runtime.GOOS == "darwin" {
|
|
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
|
}
|
|
|
|
menu := app.NewMenu()
|
|
menu.Add("Quit").OnClick(func(ctx *application.Context) {
|
|
app.Quit()
|
|
})
|
|
systemTray.SetMenu(menu)
|
|
|
|
updateTooltip := func() {
|
|
systemTray.SetTooltip(time.Now().Format("15:04:05"))
|
|
}
|
|
updateTooltip()
|
|
|
|
go func() {
|
|
ticker := time.NewTicker(time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
updateTooltip()
|
|
case <-app.Context().Done():
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
|
|
if err := app.Run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|