From bf69fcbdcf6b7a10b4987b8679371b0da1a31b73 Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 23 Feb 2026 04:56:48 -0800 Subject: [PATCH] Hide apply-update command until update is available --- Sources/ContentView.swift | 9 ++++++++- tests/test_command_palette_update_commands.py | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index f8efb60a..21b5f01b 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -1275,6 +1275,8 @@ struct ContentView: View { static let panelHasCustomName = "panel.hasCustomName" static let panelShouldPin = "panel.shouldPin" static let panelHasUnread = "panel.hasUnread" + + static let updateHasAvailable = "update.hasAvailable" } private struct CommandPaletteCommandContribution { @@ -3190,6 +3192,10 @@ struct ContentView: View { snapshot.setBool(CommandPaletteContextKeys.panelHasUnread, hasUnread) } + if case .updateAvailable = updateViewModel.effectiveState { + snapshot.setBool(CommandPaletteContextKeys.updateHasAvailable, true) + } + return snapshot } @@ -3335,7 +3341,8 @@ struct ContentView: View { commandId: "palette.applyUpdateIfAvailable", title: constant("Apply Update (If Available)"), subtitle: constant("Global"), - keywords: ["apply", "install", "update", "available"] + keywords: ["apply", "install", "update", "available"], + when: { $0.bool(CommandPaletteContextKeys.updateHasAvailable) } ) ) contributions.append( diff --git a/tests/test_command_palette_update_commands.py b/tests/test_command_palette_update_commands.py index b126d6e8..f5035037 100755 --- a/tests/test_command_palette_update_commands.py +++ b/tests/test_command_palette_update_commands.py @@ -53,8 +53,20 @@ def main() -> int: expect_regex( content_view, - r'commandId:\s*"palette\.applyUpdateIfAvailable".*?title:\s*constant\("Apply Update \(If Available\)"\).*?keywords:\s*\[[^\]]*"apply"[^\]]*"install"[^\]]*"update"[^\]]*"available"[^\]]*\]', - "Missing or incomplete `palette.applyUpdateIfAvailable` contribution", + r'static\s+let\s+updateHasAvailable\s*=\s*"update\.hasAvailable"', + "Missing `CommandPaletteContextKeys.updateHasAvailable`", + failures, + ) + expect_regex( + content_view, + r'if\s+case\s+\.updateAvailable\s*=\s*updateViewModel\.effectiveState\s*\{\s*snapshot\.setBool\(CommandPaletteContextKeys\.updateHasAvailable,\s*true\)\s*\}', + "Command palette context no longer tracks update-available state", + failures, + ) + expect_regex( + content_view, + r'commandId:\s*"palette\.applyUpdateIfAvailable".*?title:\s*constant\("Apply Update \(If Available\)"\).*?keywords:\s*\[[^\]]*"apply"[^\]]*"install"[^\]]*"update"[^\]]*"available"[^\]]*\].*?when:\s*\{\s*\$0\.bool\(CommandPaletteContextKeys\.updateHasAvailable\)\s*\}', + "Missing or incomplete `palette.applyUpdateIfAvailable` contribution visibility gating", failures, ) expect_regex(