Path: blob/main/extensions/microsoft-authentication/src/extension.ts
3314 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { commands, ExtensionContext, l10n, window, workspace } from 'vscode';6import * as extensionV1 from './extensionV1';7import * as extensionV2 from './extensionV2';8import { MicrosoftAuthenticationTelemetryReporter } from './common/telemetryReporter';910let implementation: 'msal' | 'msal-no-broker' | 'classic' = 'msal';11const getImplementation = () => workspace.getConfiguration('microsoft-authentication').get<'msal' | 'msal-no-broker' | 'classic'>('implementation') ?? 'msal';1213export async function activate(context: ExtensionContext) {14const mainTelemetryReporter = new MicrosoftAuthenticationTelemetryReporter(context.extension.packageJSON.aiKey);15implementation = getImplementation();16context.subscriptions.push(workspace.onDidChangeConfiguration(async e => {17if (!e.affectsConfiguration('microsoft-authentication')) {18return;19}20if (implementation === getImplementation()) {21return;22}2324// Allow for the migration to be re-attempted if the user switches back to the MSAL implementation25context.globalState.update('msalMigration', undefined);2627const reload = l10n.t('Reload');28const result = await window.showInformationMessage(29'Reload required',30{31modal: true,32detail: l10n.t('Microsoft Account configuration has been changed.'),33},34reload35);3637if (result === reload) {38commands.executeCommand('workbench.action.reloadWindow');39}40}));41const isNodeEnvironment = typeof process !== 'undefined' && typeof process?.versions?.node === 'string';4243// Only activate the new extension if we are not running in a browser environment44if (!isNodeEnvironment) {45mainTelemetryReporter.sendActivatedWithClassicImplementationEvent('web');46return await extensionV1.activate(context, mainTelemetryReporter.telemetryReporter);47}4849switch (implementation) {50case 'msal-no-broker':51mainTelemetryReporter.sendActivatedWithMsalNoBrokerEvent();52await extensionV2.activate(context, mainTelemetryReporter);53break;54case 'classic':55mainTelemetryReporter.sendActivatedWithClassicImplementationEvent('setting');56await extensionV1.activate(context, mainTelemetryReporter.telemetryReporter);57break;58case 'msal':59default:60await extensionV2.activate(context, mainTelemetryReporter);61break;62}63}6465export function deactivate() {66if (implementation !== 'classic') {67extensionV2.deactivate();68} else {69extensionV1.deactivate();70}71}727374