Skip to content

Commit

Permalink
refactor: use isAmazonQ() #4858
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 authored Apr 27, 2024
1 parent 6bbeaf2 commit 338e868
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
8 changes: 2 additions & 6 deletions packages/core/src/shared/telemetry/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { isAutomation, isReleaseVersion } from '../vscode/env'
import { AWSProduct } from './clienttelemetry'
import { DefaultTelemetryClient } from './telemetryClient'
import { Commands } from '../vscode/commands2'
import { VSCODE_EXTENSION_ID } from '../utilities'

export const noticeResponseViewSettings = localize('AWS.telemetry.notificationViewSettings', 'Settings')
export const noticeResponseOk = localize('AWS.telemetry.notificationOk', 'OK')
Expand Down Expand Up @@ -53,17 +52,14 @@ export async function activate(
globals.telemetry.telemetryEnabled = config.isEnabled()

extensionContext.subscriptions.push(
(globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq
? config.amazonQConfig
: config.toolkitConfig
).onDidChange(event => {
(isAmazonQ() ? config.amazonQConfig : config.toolkitConfig).onDidChange(event => {
if (event.key === 'telemetry') {
globals.telemetry.telemetryEnabled = config.isEnabled()
}
})
)

if (extensionContext.extension.id === VSCODE_EXTENSION_ID.amazonq) {
if (isAmazonQ()) {
extensionContext.subscriptions.push(
Commands.register('aws.amazonq.setupTelemetryId', async () => {
await setupTelemetryId(extensionContext)
Expand Down
15 changes: 6 additions & 9 deletions packages/core/src/shared/telemetry/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { mapMetadata } from './telemetryLogger'
import { Result } from './telemetry.gen'
import { MetricDatum } from './clienttelemetry'
import { isValidationExemptMetric } from './exemptMetrics'
import { isCloud9, isSageMaker } from '../../shared/extensionUtilities'
import { isAmazonQ, isCloud9, isSageMaker } from '../../shared/extensionUtilities'
import { isExtensionInstalled, VSCODE_EXTENSION_ID } from '../utilities'
import { randomUUID } from '../../common/crypto'
import { activateExtension } from '../utilities/vsCodeUtils'
Expand Down Expand Up @@ -55,9 +55,7 @@ export class TelemetryConfig {
}

public isEnabled(): boolean {
return (
globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq ? this.amazonQConfig : this.toolkitConfig
).get(`telemetry`, true)
return (isAmazonQ() ? this.amazonQConfig : this.toolkitConfig).get(`telemetry`, true)
}

public async initAmazonQSetting() {
Expand Down Expand Up @@ -119,10 +117,9 @@ export async function getUserAgent(
opt?: { includePlatform?: boolean; includeClientId?: boolean },
globalState = globals.context.globalState
): Promise<string> {
const pairs =
globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq
? [`AmazonQ-For-VSCode/${extensionVersion}`]
: [`AWS-Toolkit-For-VSCode/${extensionVersion}`]
const pairs = isAmazonQ()
? [`AmazonQ-For-VSCode/${extensionVersion}`]
: [`AWS-Toolkit-For-VSCode/${extensionVersion}`]

if (opt?.includePlatform) {
pairs.push(platformPair())
Expand Down Expand Up @@ -225,7 +222,7 @@ export async function setupTelemetryId(extensionContext: vscode.ExtensionContext
await vscode.commands.executeCommand('aws.amazonq.setupTelemetryId')
})
}
} else if (extensionContext.extension.id === VSCODE_EXTENSION_ID.amazonq) {
} else if (isAmazonQ()) {
getLogger().debug(`telemetry: Set telemetry client id to ${storedClientId}`)
await globals.context.globalState.update(telemetryClientIdGlobalStatekey, storedClientId)
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/vscode/commands2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ToolkitError } from '../errors'
import crypto from 'crypto'
import { keysAsInt } from '../utilities/tsUtils'
import { partialClone } from '../utilities/collectionUtils'
import { VSCODE_EXTENSION_ID } from '../utilities'
import { isAmazonQ } from '../extensionUtilities'

type Callback = (...args: any[]) => any
type CommandFactory<T extends Callback, U extends any[]> = (...parameters: U) => T
Expand Down Expand Up @@ -636,7 +636,7 @@ async function runCommand<T extends Callback>(fn: T, info: CommandInfo<T>): Prom

try {
if (info.autoconnect === true) {
const prefix = globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq ? 'amazonq' : 'toolkit'
const prefix = isAmazonQ() ? 'amazonq' : 'toolkit'
await vscode.commands.executeCommand(`_aws.${prefix}.auth.autoConnect`)
}

Expand Down

0 comments on commit 338e868

Please sign in to comment.