app.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "context"
  4. "sync"
  5. "github.com/getlantern/systray"
  6. )
  7. // App owns the tray icon lifecycle and the registered features.
  8. type App struct {
  9. features []Feature
  10. }
  11. // newApp assembles the feature list. New features register here — nothing else
  12. // in the tray lifecycle needs to change.
  13. func newApp(cfg Config, dotenvPath string) *App {
  14. return &App{
  15. features: []Feature{
  16. newBalanceFeature(cfg, dotenvPath),
  17. // The harness daemon feature registers here in a later step.
  18. },
  19. }
  20. }
  21. // Run blocks until the tray is closed, then shuts every feature down.
  22. func (a *App) Run() {
  23. ctx, cancel := context.WithCancel(context.Background())
  24. defer cancel()
  25. var wg sync.WaitGroup
  26. systray.Run(func() {
  27. systray.SetIcon(appIcon)
  28. systray.SetTitle("DeepSeek")
  29. menu := &Menu{}
  30. for _, f := range a.features {
  31. f.Install(menu)
  32. }
  33. for _, f := range a.features {
  34. wg.Add(1)
  35. go func(f Feature) {
  36. defer wg.Done()
  37. f.Run(ctx)
  38. }(f)
  39. }
  40. }, func() {
  41. cancel()
  42. for _, f := range a.features {
  43. f.Stop()
  44. }
  45. wg.Wait()
  46. })
  47. }