diff options
| author | Mitchell Hashimoto <m@mitchellh.com> | 2025-10-10 07:11:22 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <m@mitchellh.com> | 2025-10-10 08:27:30 -0700 |
| commit | 6993947a3a8a8c92d849fa1fa23a9e9fa4016ea8 (patch) | |
| tree | e5a9023ebec40486a5907d32588f8be156bfd8fb /macos/Sources/Features/Update/UpdatePill.swift | |
| parent | ba8eae027e7f5496df37bdd6acf30bf8f8b72854 (diff) | |
macOS: Make a lot of things more robust
Diffstat (limited to 'macos/Sources/Features/Update/UpdatePill.swift')
| -rw-r--r-- | macos/Sources/Features/Update/UpdatePill.swift | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/macos/Sources/Features/Update/UpdatePill.swift b/macos/Sources/Features/Update/UpdatePill.swift index b975e81c9..3b48ac218 100644 --- a/macos/Sources/Features/Update/UpdatePill.swift +++ b/macos/Sources/Features/Update/UpdatePill.swift @@ -8,6 +8,9 @@ struct UpdatePill: View { /// Whether the update popover is currently visible @State private var showPopover = false + /// Task for auto-dismissing the "No Updates" state + @State private var resetTask: Task<Void, Never>? + /// The font used for the pill text private let textFont = NSFont.systemFont(ofSize: 11, weight: .medium) @@ -19,13 +22,15 @@ struct UpdatePill: View { } .transition(.opacity.combined(with: .scale(scale: 0.95))) .onChange(of: model.state) { newState in + resetTask?.cancel() if case .notFound = newState { - Task { + resetTask = Task { [weak model] in try? await Task.sleep(for: .seconds(5)) - if case .notFound = model.state { - model.state = .idle - } + guard !Task.isCancelled, case .notFound? = model?.state else { return } + model?.state = .idle } + } else { + resetTask = nil } } } |
