diff --git a/src/constants.ts b/src/constants.ts index 6b2025389..546790e07 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -68,20 +68,31 @@ export const CONSTANTS = { export enum TelemetryEventName { FAILED_TO_OPEN_SIMULATOR = "SIMULATOR.FAILED_TO_OPEN", + // Extension commands COMMAND_DEPLOY_DEVICE = "COMMAND.DEPLOY.DEVICE", COMMAND_NEW_PROJECT = "COMMAND.NEW.PROJECT", COMMAND_OPEN_SIMULATOR = "COMMAND.OPEN.SIMULATOR", COMMAND_RUN_SIMULATOR = "COMMAND.RUN.SIMULATOR", + // Simulator interaction SIMULATOR_BUTTON_A = "SIMULATOR.BUTTON.A", SIMULATOR_BUTTON_B = "SIMULATOR.BUTTON.B", SIMULATOR_BUTTON_AB = "SIMULATOR.BUTTON.AB", SIMULATOR_SWITCH = "SIMULATOR.SWITCH", + // Pop-up dialog CLICK_DIALOG_DONT_SHOW = "CLICK.DIALOG.DONT.SHOW", CLICK_DIALOG_EXAMPLE_CODE = "CLICK.DIALOG.EXAMPLE.CODE", - CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS" -} + CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE", + CLICK_DIALOG_TUTORIALS = "CLICK.DIALOG.TUTORIALS", + + ERROR_PYTHON_DEVICE_PROCESS = "ERROR.PYTHON.DEVICE.PROCESS", + ERROR_PYTHON_PROCESS = "ERROR.PYTHON.PROCESS", + ERROR_COMMAND_NEW_PROJECT = "ERROR.COMMAND.NEW.PROJECT", + ERROR_DEPLOY_WITHOUT_DEVICE = "ERROR.DEPLOY.WITHOUT.DEVICE", + + SUCCESS_COMMAND_DEPLOY_DEVICE = "SUCCESS.COMMAND.DEPLOY.DEVICE" + } // tslint:disable-next-line: no-namespace export namespace DialogResponses { diff --git a/src/extension.ts b/src/extension.ts index fba3e8e47..85a49c413 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -66,7 +66,7 @@ export function activate(context: vscode.ExtensionContext) { }; // Open Simulator on the webview - const openSimulator = vscode.commands.registerCommand( + const openSimulator: vscode.Disposable = vscode.commands.registerCommand( "pacifica.openSimulator", () => { TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_OPEN_SIMULATOR); @@ -74,7 +74,7 @@ export function activate(context: vscode.ExtensionContext) { } ); - const newProject = vscode.commands.registerCommand( + const newProject: vscode.Disposable = vscode.commands.registerCommand( "pacifica.newProject", () => { TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_PROJECT); @@ -117,13 +117,14 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showTextDocument(template, 1, false); }), (error: any) => { + TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_COMMAND_NEW_PROJECT); console.error(`Failed to open a new text document: ${error}`); }; } ); // Send message to the webview - const runSimulator = vscode.commands.registerCommand( + const runSimulator: vscode.Disposable = vscode.commands.registerCommand( "pacifica.runSimulator", () => { openWebview(); @@ -210,6 +211,7 @@ export function activate(context: vscode.ExtensionContext) { // Std error output childProcess.stderr.on("data", data => { console.error(`Error from the Python process through stderr: ${data}`); + TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_PYTHON_PROCESS); logToOutputChannel(outChannel, CONSTANTS.ERROR.STDERR(data), true); if (currentPanel) { console.log("Sending clearing state command"); @@ -229,6 +231,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.splice(index, 1); } } + // Handle messages from webview messageListener = currentPanel.webview.onDidReceiveMessage( message => { @@ -254,7 +257,7 @@ export function activate(context: vscode.ExtensionContext) { ); // Send message to the webview - const runDevice = vscode.commands.registerCommand("pacifica.runDevice", () => { + const runDevice: vscode.Disposable = vscode.commands.registerCommand("pacifica.runDevice", () => { console.info("Sending code to device"); TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE); @@ -291,10 +294,12 @@ export function activate(context: vscode.ExtensionContext) { // Check the JSON is a state switch (messageToWebview.type) { case "complete": + TelemetryAI.trackFeatureUsage(TelemetryEventName.SUCCESS_COMMAND_DEPLOY_DEVICE); logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_SUCCESS); break; case "no-device": + TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_DEPLOY_WITHOUT_DEVICE); vscode.window .showErrorMessage( CONSTANTS.ERROR.NO_DEVICE, @@ -302,6 +307,7 @@ export function activate(context: vscode.ExtensionContext) { ) .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.HELP) { + TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE); open(CONSTANTS.LINKS.HELP); } }); @@ -322,6 +328,7 @@ export function activate(context: vscode.ExtensionContext) { // Std error output deviceProcess.stderr.on("data", data => { + TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_PYTHON_DEVICE_PROCESS, { error: `${data}` }); console.error( `Error from the Python device process through stderr: ${data}` ); diff --git a/src/view/components/Simulator.tsx b/src/view/components/Simulator.tsx index 283109df8..a77af88ce 100644 --- a/src/view/components/Simulator.tsx +++ b/src/view/components/Simulator.tsx @@ -129,9 +129,13 @@ class Simulator extends React.Component { newState = this.handleButtonClick(button, active); } else if (button.id.includes("SWITCH")) { newState = this.handleSwitchClick(button); - } else return; + } else { + return; + } - if (newState) sendMessage(newState); + if (newState) { + sendMessage(newState); + } } private handleButtonClick(button: HTMLElement, active: boolean) { @@ -183,7 +187,7 @@ class Simulator extends React.Component { svg.addClass(switchInner, "sim-slide-switch-inner"); - let switchIsOn: boolean = !this.state.switch; + const switchIsOn: boolean = !this.state.switch; if (switchIsOn) { svg.addClass(switchInner, "on");