wails/v3/examples/systray-clock/main.go
DeltaLaboratory d58d4ba758
[v3 alpha] windows tray minor refactor (#4653)
* 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>
2025-11-04 07:44:58 +11:00

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)
}
}