UNPKG

teamsfx-extension

Version:

Create, debug, and deploy Teams apps with Teams Toolkit

116 lines 5.42 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. Object.defineProperty(exports, "__esModule", { value: true }); exports.registerTeamsfxTaskAndDebugEvents = exports.terminateAllRunningTeamsfxTasks = void 0; const teamsfx_api_1 = require("@microsoft/teamsfx-api"); const vscode = require("vscode"); const extensionVariables_1 = require("../extensionVariables"); const extTelemetry_1 = require("../telemetry/extTelemetry"); const extTelemetryEvents_1 = require("../telemetry/extTelemetryEvents"); const commonUtils_1 = require("../utils/commonUtils"); const allRunningTeamsfxTasks = new Map(); const allRunningDebugSessions = new Set(); function isTeamsfxTask(task) { // teamsfx: xxx start / xxx watch if (task) { if (task.source === teamsfx_api_1.ProductName && (task.name.trim().toLocaleLowerCase().endsWith("start") || task.name.trim().toLocaleLowerCase().endsWith("watch"))) { // provided by toolkit return true; } if (task.definition && task.definition.type === teamsfx_api_1.ProductName) { // defined by launch.json const command = task.definition.command; return (command !== undefined && (command.trim().toLocaleLowerCase().endsWith("start") || command.trim().toLocaleLowerCase().endsWith("watch"))); } } return false; } function onDidStartTaskProcessHandler(event) { if (extensionVariables_1.ext.workspaceUri && commonUtils_1.isWorkspaceSupported(extensionVariables_1.ext.workspaceUri.fsPath)) { const task = event.execution.task; if (task.scope !== undefined && isTeamsfxTask(task)) { allRunningTeamsfxTasks.set({ source: task.source, name: task.name, scope: task.scope }, event.processId); } } } function onDidEndTaskProcessHandler(event) { const task = event.execution.task; if (task.scope !== undefined && isTeamsfxTask(task)) { allRunningTeamsfxTasks.delete({ source: task.source, name: task.name, scope: task.scope }); } } function onDidStartDebugSessionHandler(event) { if (extensionVariables_1.ext.workspaceUri && commonUtils_1.isWorkspaceSupported(extensionVariables_1.ext.workspaceUri.fsPath)) { const debugConfig = event.configuration; if (debugConfig && debugConfig.name && (debugConfig.url || debugConfig.port) && // it's from launch.json !debugConfig.postRestartTask) { // and not a restart one // send f5 event telemetry try { const remoteAppId = commonUtils_1.getTeamsAppId(); extTelemetry_1.ExtTelemetry.sendTelemetryEvent(extTelemetryEvents_1.TelemetryEvent.DebugStart, { [extTelemetryEvents_1.TelemetryProperty.DebugSessionId]: event.id, [extTelemetryEvents_1.TelemetryProperty.DebugType]: debugConfig.type, [extTelemetryEvents_1.TelemetryProperty.DebugRequest]: debugConfig.request, [extTelemetryEvents_1.TelemetryProperty.DebugPort]: debugConfig.port + "", [extTelemetryEvents_1.TelemetryProperty.DebugRemote]: debugConfig.url && remoteAppId && debugConfig.url.includes(remoteAppId) ? "true" : "false", }); } catch (_a) { // ignore telemetry error } allRunningDebugSessions.add(event.id); } } } function terminateAllRunningTeamsfxTasks() { for (const task of allRunningTeamsfxTasks) { try { process.kill(task[1], "SIGINT"); } catch (e) { // ignore and keep killing others } } allRunningTeamsfxTasks.clear(); } exports.terminateAllRunningTeamsfxTasks = terminateAllRunningTeamsfxTasks; function onDidTerminateDebugSessionHandler(event) { if (allRunningDebugSessions.has(event.id)) { // a valid debug session // send stop-debug event telemetry try { extTelemetry_1.ExtTelemetry.sendTelemetryEvent(extTelemetryEvents_1.TelemetryEvent.DebugStop, { [extTelemetryEvents_1.TelemetryProperty.DebugSessionId]: event.id, }); } catch (_a) { // ignore telemetry error } const extConfig = vscode.workspace.getConfiguration("fx-extension"); if (extConfig.get("stopTeamsToolkitTasksPostDebug", true)) { terminateAllRunningTeamsfxTasks(); } allRunningDebugSessions.delete(event.id); allRunningTeamsfxTasks.clear(); } } function registerTeamsfxTaskAndDebugEvents() { extensionVariables_1.ext.context.subscriptions.push(vscode.tasks.onDidStartTaskProcess(onDidStartTaskProcessHandler)); extensionVariables_1.ext.context.subscriptions.push(vscode.tasks.onDidEndTaskProcess(onDidEndTaskProcessHandler)); extensionVariables_1.ext.context.subscriptions.push(vscode.debug.onDidStartDebugSession(onDidStartDebugSessionHandler)); extensionVariables_1.ext.context.subscriptions.push(vscode.debug.onDidTerminateDebugSession(onDidTerminateDebugSessionHandler)); } exports.registerTeamsfxTaskAndDebugEvents = registerTeamsfxTaskAndDebugEvents; //# sourceMappingURL=teamsfxTaskHandler.js.map