Skip to content

Commit

Permalink
telemetry(messages): maybeShowMinVscodeWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 committed Oct 9, 2024
1 parent d697f44 commit addc4fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
25 changes: 12 additions & 13 deletions packages/core/src/shared/extensionStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { fs } from '../shared/fs/fs'
import { getIdeProperties, getIdeType, isAmazonQ, isCloud9, isCn, productName } from './extensionUtilities'
import * as localizedText from './localizedText'
import { AmazonQPromptSettings, ToolkitPromptSettings } from './settings'
import { showMessage } from './utilities/messages'

const localize = nls.loadMessageBundle()

Expand All @@ -27,19 +28,17 @@ export async function maybeShowMinVscodeWarning(minVscode: string) {
}
const updateButton = `Update ${vscode.env.appName}`
if (getIdeType() === 'vscode' && semver.lt(vscode.version, minVscode)) {
void vscode.window
.showWarningMessage(
`${productName()} will soon require VS Code ${minVscode} or newer. The currently running version ${vscode.version} will no longer receive updates.`,
updateButton,
localizedText.dontShow
)
.then(async (resp) => {
if (resp === updateButton) {
await vscode.commands.executeCommand('update.checkForUpdate')
} else if (resp === localizedText.dontShow) {
void settings.disablePrompt('minIdeVersion')
}
})
void showMessage(
'warn',
`${productName()} will soon require VS Code ${minVscode} or newer. The currently running version ${vscode.version} will no longer receive updates.`,
[updateButton, localizedText.dontShow]
).then(async (resp) => {
if (resp === updateButton) {
await vscode.commands.executeCommand('update.checkForUpdate')
} else if (resp === localizedText.dontShow) {
void settings.disablePrompt('minIdeVersion')
}
})
}
}

Expand Down
32 changes: 18 additions & 14 deletions packages/core/src/shared/utilities/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ export function makeFailedWriteMessage(filename: string): string {
return message
}

function showMessageWithItems(
message: string,
export function showMessage(
kind: 'info' | 'warn' | 'error' = 'error',
message: string,
items: string[] = [],
useModal: boolean = false
options: vscode.MessageOptions & { telemetry?: boolean } = {}
): Thenable<string | undefined> {
switch (kind) {
case 'info':
return vscode.window.showInformationMessage(message, { modal: useModal }, ...items)
case 'warn':
return vscode.window.showWarningMessage(message, { modal: useModal }, ...items)
case 'error':
default:
return vscode.window.showErrorMessage(message, { modal: useModal }, ...items)
}
return telemetry.toolkit_showNotification.run(async (span) => {
span.record({ passive: true })

switch (kind) {
case 'info':
return vscode.window.showInformationMessage(message, options, ...items)
case 'warn':
return vscode.window.showWarningMessage(message, options, ...items)
case 'error':
default:
return vscode.window.showErrorMessage(message, options, ...items)
}
})
}

/**
Expand All @@ -75,7 +79,7 @@ export async function showMessageWithUrl(
const uri = typeof url === 'string' ? vscode.Uri.parse(url) : url
const items = [...extraItems, urlItem]

const p = showMessageWithItems(message, kind, items, useModal)
const p = showMessage(kind, message, items, { modal: useModal })
return p.then<string | undefined>((selection) => {
if (selection === urlItem) {
void openUrl(uri)
Expand All @@ -102,7 +106,7 @@ export async function showViewLogsMessage(
const logsItem = localize('AWS.generic.message.viewLogs', 'View Logs...')
const items = [...extraItems, logsItem]

const p = showMessageWithItems(message, kind, items)
const p = showMessage(kind, message, items)
return p.then<string | undefined>((selection) => {
if (selection === logsItem) {
globals.logOutputChannel.show(true)
Expand Down

0 comments on commit addc4fb

Please sign in to comment.