| 1 | package main |
| 2 | |
| 3 | import goruntime "runtime" |
| 4 | |
| 5 | type DesktopShellStatusView struct { |
| 6 | TrayState string `json:"trayState"` |
| 7 | BackgroundCloseAvailable bool `json:"backgroundCloseAvailable"` |
| 8 | Reason string `json:"reason,omitempty"` |
| 9 | } |
| 10 | |
| 11 | func (a *App) GetDesktopShellStatus() DesktopShellStatusView { |
| 12 | if a == nil { |
| 13 | return DesktopShellStatusView{TrayState: "unavailable", Reason: "shell_unavailable"} |
| 14 | } |
| 15 | a.mu.RLock() |
| 16 | state := a.desktopShell.trayState |
| 17 | reason := a.desktopShell.trayReason |
| 18 | ready := a.trayReady |
| 19 | a.mu.RUnlock() |
| 20 | if state == "" { |
| 21 | state = "probing" |
| 22 | } |
| 23 | return DesktopShellStatusView{ |
| 24 | TrayState: state, |
| 25 | BackgroundCloseAvailable: backgroundCloseUsesApplicationHide(goruntime.GOOS) || ready, |
| 26 | Reason: reason, |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func (a *App) setTrayHealth(t *desktopTray, state, reason string) { |
| 31 | if a == nil { |
| 32 | return |
| 33 | } |
| 34 | if state != "probing" && state != "ready" && state != "unavailable" { |
| 35 | state = "unavailable" |
| 36 | reason = "invalid_state" |
| 37 | } |
| 38 | ready := state == "ready" |
| 39 | a.mu.Lock() |
| 40 | if t != nil && a.tray != t { |
| 41 | a.mu.Unlock() |
| 42 | return |
| 43 | } |
| 44 | changed := a.desktopShell.trayState != state || a.desktopShell.trayReason != reason || a.trayReady != ready |
| 45 | a.desktopShell.trayState = state |
| 46 | a.desktopShell.trayReason = reason |
| 47 | a.trayReady = ready |
| 48 | ctx := a.ctx |
| 49 | a.mu.Unlock() |
| 50 | |
| 51 | if ready && t != nil { |
| 52 | t.markReady() |
| 53 | } |
| 54 | if changed { |
| 55 | bucket := reason |
| 56 | if ready { |
| 57 | bucket = "ready" |
| 58 | } |
| 59 | a.recordDiagnosticMetric("desktop_tray", metricBucket(bucket)) |
| 60 | if a.desktopShell.coordinator != nil && !a.shuttingDown.Load() && !a.forceQuit.Load() { |
| 61 | a.desktopShell.coordinator.trayStateChanged(ready) |
| 62 | } |
| 63 | a.runtimeEvents.Emit(ctx, desktopShellEvent, a.GetDesktopShellStatus()) |
| 64 | } |
| 65 | } |
| 66 |