Skip to content

Commit 9b388ef

Browse files
authored
codewhisperer: fix potential use of undefined var #3060
1 parent 7cd2a2d commit 9b388ef

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/codewhisperer/activation.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,15 @@ export async function activate(context: ExtContext): Promise<void> {
244244
context.extensionContext.globalState.get<boolean>(
245245
CodeWhispererConstants.accessTokenMigrationDoNotShowAgainKey
246246
) || false
247-
const notificationLastShown =
248-
context.extensionContext.globalState.get<Date>(
247+
const notificationLastShown: number =
248+
context.extensionContext.globalState.get<number | undefined>(
249249
CodeWhispererConstants.accessTokenMigrationDoNotShowAgainLastShown
250-
) || t
250+
) || 1
251251

252252
//Add 7 days to notificationLastShown to determine whether warn message should show
253-
notificationLastShown.setDate(notificationLastShown.getDate() + 7)
254-
if (doNotShowAgain || notificationLastShown <= t) {
253+
if (doNotShowAgain || notificationLastShown + (1000 * 60 * 60 * 24 * 7) >= Date.now()) {
255254
return
256-
}
257-
if (t <= CodeWhispererConstants.accessTokenCutOffDate) {
255+
} else if (t <= CodeWhispererConstants.accessTokenCutOffDate) {
258256
vscode.window
259257
.showWarningMessage(
260258
CodeWhispererConstants.accessTokenMigrationWarningMessage,
@@ -274,12 +272,12 @@ export async function activate(context: ExtContext): Promise<void> {
274272
CodeWhispererConstants.accessTokenMigrationDoNotShowAgainKey,
275273
true
276274
)
277-
await context.extensionContext.globalState.update(
278-
CodeWhispererConstants.accessTokenMigrationDoNotShowAgainLastShown,
279-
t
280-
)
281275
}
282276
})
277+
context.extensionContext.globalState.update(
278+
CodeWhispererConstants.accessTokenMigrationDoNotShowAgainLastShown,
279+
Date.now()
280+
)
283281
} else {
284282
await globals.context.globalState.update(CodeWhispererConstants.accessToken, undefined)
285283
await vscode.commands.executeCommand('aws.codeWhisperer.refreshRootNode')

src/codewhisperer/models/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,6 @@ export const accessTokenMigrationDoNotShowAgain = `Don\'t Show Again`
241241
export const accessTokenMigrationDoNotShowAgainKey = 'CODEWHISPERER_ACCESS_TOKEN_MIGRATION_DO_NOT_SHOW_AGAIN'
242242

243243
export const accessTokenMigrationDoNotShowAgainLastShown =
244-
'CODEWHISPERER_ACCESS_TOKEN_MIGRATION_DO_NOT_SHOW_AGAIN_LAST_SHOWN'
244+
'CODEWHISPERER_ACCESS_TOKEN_MIGRATION_DO_NOT_SHOW_AGAIN_LAST_SHOWN_TIME'
245245

246246
export const accessTokenMigrationDoNotShowAgainInfo = `You will not receive this notification again. If you would like to continue using CodeWhisperer after January 31, 2023, you can still connect with AWS. [Learn More](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/codewhisper-setup-general.html).`

0 commit comments

Comments
 (0)