Compare commits

...

2 Commits

Author SHA1 Message Date
kvyb 573a38ac37 fix: simplify onDidShowAnnouncement 2025-07-22 14:28:51 +08:00
kvyb 7df1aa429a automate announcement display for major.minor releases 2025-07-21 23:00:25 +08:00
3 changed files with 10 additions and 14 deletions
+3 -1
View File
@@ -55,7 +55,9 @@ export class Controller {
mcpHub: McpHub
accountService: ClineAccountService
authService: AuthService
latestAnnouncementId = "june-25-2025_16:11:00" // update to some unique identifier when we add a new announcement
get latestAnnouncementId(): string {
return this.context.extension?.packageJSON?.version?.split(".").slice(0, 2).join(".") ?? ""
}
constructor(
readonly context: vscode.ExtensionContext,
@@ -1,28 +1,20 @@
import type { EmptyRequest } from "../../../shared/proto/common"
import { Boolean } from "../../../shared/proto/common"
import type { Controller } from "../index"
import { getGlobalState, updateGlobalState } from "../../storage/state"
import { updateGlobalState } from "../../storage/state"
/**
* Marks the current announcement as shown and returns the updated shouldShowAnnouncement value
* Marks the current announcement as shown
*
* @param controller The controller instance
* @param _request The empty request (not used)
* @returns Boolean indicating whether an announcement should be shown
* @returns Boolean indicating announcement should no longer be shown
*/
export async function onDidShowAnnouncement(controller: Controller, _request: EmptyRequest): Promise<Boolean> {
try {
// Update the lastShownAnnouncementId to the current latestAnnouncementId
await updateGlobalState(controller.context, "lastShownAnnouncementId", controller.latestAnnouncementId)
// Get the updated lastShownAnnouncementId value after the update
const lastShownAnnouncementId = await getGlobalState(controller.context, "lastShownAnnouncementId")
// Calculate the new shouldShowAnnouncement value
// This replicates the same logic used in getStateToPostToWebview()
const shouldShowAnnouncement = lastShownAnnouncementId !== controller.latestAnnouncementId
return Boolean.create({ value: shouldShowAnnouncement })
return Boolean.create({ value: false })
} catch (error) {
console.error("Failed to acknowledge announcement:", error)
return Boolean.create({ value: false })
@@ -30,7 +30,9 @@ const linkContainerStyle: CSSProperties = { margin: "0" }
const linkStyle: CSSProperties = { display: "inline" }
/*
You must update the latestAnnouncementId in ClineProvider for new announcements to show to users. This new id will be compared with what's in state for the 'last announcement shown', and if it's different then the announcement will render. As soon as an announcement is shown, the id will be updated in state. This ensures that announcements are not shown more than once, even if the user doesn't close it themselves.
Announcements are automatically shown when the major.minor version changes (for ex 3.19.x → 3.20.x or 4.0.x).
The latestAnnouncementId is now automatically generated from the extension's package.json version.
Patch releases (3.19.1 → 3.19.2) will not trigger new announcements.
*/
const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => {
const minorVersion = version.split(".").slice(0, 2).join(".") // 2.0.0 -> 2.0