From 22a7cfb02219506880ceff16480c466780acf3a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Mar 2020 15:59:14 -0700 Subject: [PATCH 1/6] first commit --- locales/en/out/constants.i18n.json | 4 +- locales/en/package.i18n.json | 5 +- package.json | 12 +-- package.nls.json | 3 +- src/clue/adafruit_clue.py | 4 + src/constants.ts | 23 ++++- src/device.py | 20 ++-- src/extension.ts | 142 ++++++++++++++++++----------- src/python_constants.py | 6 +- 9 files changed, 136 insertions(+), 83 deletions(-) diff --git a/locales/en/out/constants.i18n.json b/locales/en/out/constants.i18n.json index 461de0056..109169527 100644 --- a/locales/en/out/constants.i18n.json +++ b/locales/en/out/constants.i18n.json @@ -14,7 +14,8 @@ "error.debuggerServerInitFailed": "Warning : The Debugger Server cannot be opened. Please try to free the port {0} if it's already in use or select another one in your Settings 'Device Simulator Express: Debugger Server Port' and start another debug session.\n You can still debug your code but you won't be able to use the Simulator.", "error.debuggingSessionInProgress": "[ERROR] A debugging session is currently in progress, please stop it before running your code. \n", "error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted", - "error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples\n", + "error.noFileToRun": "\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples\n", + "error.noFileToDeploy": "\n[ERROR] We can't find a Python file to deploy to your device.\n", "error.noFolderCreated": "In order to use the Serial Monitor, you need to open a folder and reload VS Code.", "error.noProgramFoundDebug": "Cannot find a program to debug.", "error.noPythonPath": "We found that you don't have Python 3 installed on your computer, please install the latest version, add it to your PATH and try again.", @@ -28,6 +29,7 @@ "info.installPythonDependencies": "Do you want us to try and install this extensions dependencies for you?", "error.invalidFileExtensionDebug": "The file you tried to run isn\\'t a Python file.", "info.newFile": "New to Python or the Circuit Playground Express? We are here to help!", + "info.noDeviceChosenToDeployTo": "\n[INFO] No device was selected to deploy to.\n", "info.redirect": "You are being redirected.", "info.runningCode": "Running user code", "info.privacyStatement": "Privacy Statement", diff --git a/locales/en/package.i18n.json b/locales/en/package.i18n.json index c31357dfe..f85718a6d 100644 --- a/locales/en/package.i18n.json +++ b/locales/en/package.i18n.json @@ -7,10 +7,9 @@ "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", + "deviceSimulatorExpressExtension.commands.common.deployToDevice": "Deploy to Device", "deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator", "deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File", - "deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device", - "deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device", "deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator", "deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File", "deviceSimulatorExpressExtension.commands.clue.openSimulator": "[Clue] Open Simulator", @@ -18,5 +17,5 @@ "deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration", "deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.", "deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.", - "deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files." + "deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask for dependency downloads. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files." } \ No newline at end of file diff --git a/package.json b/package.json index 9ba36b931..12ae8eef1 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,9 @@ "onCommand:deviceSimulatorExpress.common.runSimulator", "onCommand:deviceSimulatorExpress.common.selectSerialPort", "onCommand:deviceSimulatorExpress.common.gettingStarted", - "onCommand:deviceSimulatorExpress.cpx.deployToDevice", + "onCommand:deviceSimulatorExpress.common.deployToDevice", "onCommand:deviceSimulatorExpress.cpx.newFile", "onCommand:deviceSimulatorExpress.cpx.openSimulator", - "onCommand:deviceSimulatorExpress.microbit.deployToDevice", "onCommand:deviceSimulatorExpress.microbit.newFile", "onCommand:deviceSimulatorExpress.microbit.openSimulator", "onCommand:deviceSimulatorExpress.clue.newFile", @@ -84,8 +83,8 @@ "category": "%deviceSimulatorExpressExtension.commands.common.label%" }, { - "command": "deviceSimulatorExpress.cpx.deployToDevice", - "title": "%deviceSimulatorExpressExtension.commands.cpx.deployToDevice%", + "command": "deviceSimulatorExpress.common.deployToDevice", + "title": "%deviceSimulatorExpressExtension.commands.common.deployToDevice%", "category": "%deviceSimulatorExpressExtension.commands.common.label%" }, { @@ -98,11 +97,6 @@ "title": "%deviceSimulatorExpressExtension.commands.cpx.openSimulator%", "category": "%deviceSimulatorExpressExtension.commands.common.label%" }, - { - "command": "deviceSimulatorExpress.microbit.deployToDevice", - "title": "%deviceSimulatorExpressExtension.commands.microbit.deployToDevice%", - "category": "%deviceSimulatorExpressExtension.commands.common.label%" - }, { "command": "deviceSimulatorExpress.microbit.openSimulator", "title": "%deviceSimulatorExpressExtension.commands.microbit.openSimulator%", diff --git a/package.nls.json b/package.nls.json index ff37663a8..f85718a6d 100644 --- a/package.nls.json +++ b/package.nls.json @@ -7,10 +7,9 @@ "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", + "deviceSimulatorExpressExtension.commands.common.deployToDevice": "Deploy to Device", "deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator", "deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File", - "deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device", - "deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device", "deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator", "deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File", "deviceSimulatorExpressExtension.commands.clue.openSimulator": "[Clue] Open Simulator", diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index bb4ef83b7..ae42b3994 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -203,6 +203,10 @@ def __init__(self): pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB ) + @property + def accerleration(self): + return [1, 2, 2] + @property def pixel(self): """The NeoPixel RGB LED. diff --git a/src/constants.ts b/src/constants.ts index bb00ac516..a5de987b1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -88,12 +88,16 @@ export const CONSTANTS = { ), NO_DEVICE: localize( "error.noDevice", - "No plugged in boards detected. Please double check if your board is connected and/or properly formatted" + "The device is not detected. Please double check if your board is connected and/or properly formatted" ), NO_FILE_TO_RUN: localize( "error.noFileToRun", '[ERROR] We can\'t find a Python file to run. Please make sure you select or open a new ".py" code file, or use the "New File" command to get started and see useful links.\n' ), + NO_FILE_TO_DEPLOY: localize( + "error.noFileToDeploy", + '[ERROR] We can\'t find a Python file to deploy to your device.\n' + ), NO_FOLDER_OPENED: localize( "error.noFolderCreated", "In order to use the Serial Monitor, you need to open a folder and reload VS Code." @@ -189,6 +193,10 @@ export const CONSTANTS = { "info.newFile", "New to Python or the Circuit Playground Express? We are here to help!" ), + NO_DEVICE_CHOSEN_TO_DEPLOY_TO: localize( + "info.noDeviceChosenToDeployTo", + "\n[INFO] No device was selected to deploy to.\n" + ), OPENED_SERIAL_PORT: (port: string) => { return localize( "info.openedSerialPort", @@ -243,8 +251,10 @@ export const CONSTANTS = { DOWNLOAD_PYTHON: "https://www.python.org/downloads/", EXAMPLE_CODE: "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples", - HELP: + CPX_HELP: "https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart", + CLUE_HELP: + "https://learn.adafruit.com/adafruit-clue/circuitpython", INSTALL: "https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/docs/install.md", PRIVACY: "https://www.adafruit.com/privacy", @@ -335,6 +345,9 @@ export enum TelemetryEventName { MICROBIT_COMMAND_NEW_FILE = "MICROBIT.COMMAND.NEW.FILE", MICROBIT_COMMAND_OPEN_SIMULATOR = "MICROBIT.COMMAND.OPEN.SIMULATOR", + CLUE_COMMAND_DEPLOY_DEVICE = "CLUE.COMMAND.DEPLOY.DEVICE", + + // Simulator interaction CPX_SIMULATOR_BUTTON_A = "CPX.SIMULATOR.BUTTON.A", CPX_SIMULATOR_BUTTON_B = "CPX.SIMULATOR.BUTTON.B", @@ -373,6 +386,10 @@ export enum TelemetryEventName { MICROBIT_ERROR_PYTHON_DEVICE_PROCESS = "MICROBIT.ERROR.PYTHON.DEVICE.PROCESS", MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE = "MICROBIT.SUCCESS.COMMAND.DEPLOY.DEVICE", + CLUE_ERROR_DEPLOY_WITHOUT_DEVICE = "CLUE.ERROR.DEPLOY.WITHOUT.DEVICE", + CLUE_ERROR_PYTHON_DEVICE_PROCESS = "CLUE.ERROR.PYTHON.DEVICE.PROCESS", + CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE = "CLUE.SUCCESS.COMMAND.DEPLOY.DEVICE", + // Performance CPX_PERFORMANCE_DEPLOY_DEVICE = "CPX.PERFORMANCE.DEPLOY.DEVICE", CPX_PERFORMANCE_NEW_FILE = "CPX.PERFORMANCE.NEW.FILE", @@ -382,6 +399,8 @@ export enum TelemetryEventName { MICROBIT_PERFORMANCE_NEW_FILE = "MICROBIT.PERFORMANCE.NEW.FILE", MICROBIT_PERFORMANCE_OPEN_SIMULATOR = "MICROBIT.PERFORMANCE.OPEN.SIMULATOR", + CLUE_PERFORMANCE_DEPLOY_DEVICE = "CLUE.PERFORMANCE.DEPLOY.DEVICE", + // Venv options SETUP_VENV_CREATION_ERR = "SETUP.VENV.CREATION.ERR", SETUP_NO_PIP = "SETUP.NO.PIP", diff --git a/src/device.py b/src/device.py index cc6e035ff..def9673b0 100644 --- a/src/device.py +++ b/src/device.py @@ -22,9 +22,9 @@ def __init__(self, name, file_path): self.connected = False self.error_message = None - def find_cpx_directory(self): + def find_adafruit_device_directory(self): """ - Check if the Circuit Playground Express is available/plugged in + Check if the Adafruit Device is available/plugged in """ found_directory = None @@ -39,7 +39,7 @@ def find_cpx_directory(self): ) for mount in mounted: drive_path = mount.split()[2] if mount else "" - if drive_path.endswith(CONSTANTS.CPX_DRIVE_NAME): + if drive_path.endswith(CONSTANTS.ADAFRUIT_DRIVE_NAME): found_directory = drive_path break elif sys.platform == CONSTANTS.WINDOWS_OS: @@ -48,7 +48,7 @@ def find_cpx_directory(self): drive_path = "{}:{}".format(drive_letter, os.sep) if os.path.exists(drive_path): drive_name = win32api.GetVolumeInformation(drive_path)[0] - if drive_name == CONSTANTS.CPX_DRIVE_NAME: + if drive_name == CONSTANTS.ADAFRUIT_DRIVE_NAME: found_directory = drive_path break else: @@ -57,16 +57,16 @@ def find_cpx_directory(self): if not found_directory: self.connected = False self.error_message = ( - CONSTANTS.NO_CPX_DETECTED_ERROR_TITLE, - CONSTANTS.NO_CPX_DETECTED_ERROR_DETAIL.format(sys.platform), + CONSTANTS.NO_ADAFRUIT_DEVICE_DETECTED_ERROR_TITLE, + CONSTANTS.NO_ADAFRUIT_DEVICE_DETECTED_ERROR_DETAIL.format(sys.platform), ) else: self.connected = True self.error_message = None return found_directory - def deployToCPX(self): - device_directory = self.find_cpx_directory() + def deployToAdafruitDevice(self): + device_directory = self.find_adafruit_device_directory() if self.error_message: print( "{}:\t{}".format(self.error_message[0], self.error_message[1]), @@ -109,8 +109,8 @@ def deployToMicrobit(self): def deploy(self): if self.name == CONSTANTS.MICROBIT: return self.deployToMicrobit() - elif self.name == CONSTANTS.CPX: - return self.deployToCPX() + elif self.name == CONSTANTS.CPX or self.name == CONSTANTS.CLUE: + return self.deployToAdafruitDevice() else: return {"type": "no-device"} diff --git a/src/extension.ts b/src/extension.ts index d91b1a6de..ea84ba63b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,16 +3,13 @@ import * as cp from "child_process"; import * as fs from "fs"; -import { registerDefaultFontFaces } from "office-ui-fabric-react"; import * as open from "open"; -import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; import { CONFIG, CONSTANTS, CPX_CONFIG_FILE, - DEFAULT_DEVICE, DialogResponses, GLOBAL_ENV_VARS, HELPER_FILES, @@ -704,12 +701,12 @@ export async function activate(context: vscode.ExtensionContext) { if (fileSelectionService.getCurrentFileAbsPath() === "") { utils.logToOutputChannel( outChannel, - CONSTANTS.ERROR.NO_FILE_TO_RUN, + CONSTANTS.ERROR.NO_FILE_TO_DEPLOY, true ); vscode.window.showErrorMessage( - CONSTANTS.ERROR.NO_FILE_TO_RUN, - DialogResponses.MESSAGE_UNDERSTOOD + CONSTANTS.ERROR.NO_FILE_TO_DEPLOY, + DialogResponses.MESSAGE_UNDERSTOOD ); } else { await fileSelectionService.getCurrentTextDocument().save(); @@ -747,7 +744,7 @@ export async function activate(context: vscode.ExtensionContext) { true ); } - handleDeployToDeviceTelemetry(messageToWebview, device); + handleDeployToDeviceFinishedTelemetry(messageToWebview, device); } catch (err) { console.log( `Non-JSON output from the process : ${dataFromTheProcess}` @@ -775,42 +772,79 @@ export async function activate(context: vscode.ExtensionContext) { } }; + const getTelemetryEventsForStartingDeployToDevice = (device: string) => { + let deployTelemetryEvent: string; + let deployPerformanceTelemetryEvent: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + deployTelemetryEvent = TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + deployTelemetryEvent = TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + deployTelemetryEvent = TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + break; + } + return { + deployTelemetryEvent: deployTelemetryEvent, + deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent + } + } + const handleDeployToDeviceErrorTelemetry = ( data: string, device: string ) => { let telemetryErrorName: string; - if (device === CONSTANTS.DEVICE_NAME.CPX) { - telemetryErrorName = - TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; - } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { - telemetryErrorName = - TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + telemetryErrorName = TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + telemetryErrorName = + TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; + case CONSTANTS.DEVICE_NAME.CLUE: + telemetryErrorName = + TelemetryEventName.CLUE_ERROR_PYTHON_DEVICE_PROCESS; } telemetryAI.trackFeatureUsage(telemetryErrorName, { error: `${data}` }); }; - const handleDeployToDeviceTelemetry = (message: any, device: string) => { + const handleDeployToDeviceFinishedTelemetry = (message: any, device: string) => { let successCommandDeployDevice: string; let errorCommandDeployWithoutDevice: string; - if (device === CONSTANTS.DEVICE_NAME.CPX) { - successCommandDeployDevice = - TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; - } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { - successCommandDeployDevice = - TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + successCommandDeployDevice = + TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + successCommandDeployDevice = + TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + successCommandDeployDevice = + TelemetryEventName.CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CLUE_ERROR_DEPLOY_WITHOUT_DEVICE; + break; } + switch (message.type) { case "complete": telemetryAI.trackFeatureUsage(successCommandDeployDevice); break; case "no-device": telemetryAI.trackFeatureUsage(errorCommandDeployWithoutDevice); - if (device === CONSTANTS.DEVICE_NAME.CPX) { + if (device === CONSTANTS.DEVICE_NAME.CPX || device === CONSTANTS.DEVICE_NAME.CLUE) { vscode.window .showErrorMessage( CONSTANTS.ERROR.NO_DEVICE, @@ -819,9 +853,18 @@ export async function activate(context: vscode.ExtensionContext) { .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.HELP) { const okAction = () => { - open(CONSTANTS.LINKS.HELP); + let helpLink: string; + let helpTelemetryEvent: string; + if (device === CONSTANTS.DEVICE_NAME.CPX) { + helpLink = CONSTANTS.LINKS.CPX_HELP; + helpTelemetryEvent = CONSTANTS.LINKS.CPX_HELP; + } else if (device === CONSTANTS.DEVICE_NAME.CLUE) { + helpLink = CONSTANTS.LINKS.CLUE_HELP; + helpTelemetryEvent = CONSTANTS.LINKS.CLUE_HELP; + } + open(helpLink); telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE + helpTelemetryEvent ); }; utils.showPrivacyModal( @@ -847,36 +890,30 @@ export async function activate(context: vscode.ExtensionContext) { } }; - const cpxDeployCodeToDevice = () => { - deployCode(CONSTANTS.DEVICE_NAME.CPX); - }; + const deployToDevice: vscode.Disposable = vscode.commands.registerCommand( + "deviceSimulatorExpress.common.deployToDevice", + async () => { + const chosen_device = await vscode.window.showQuickPick( + Object.values(CONSTANTS.DEVICE_NAME) + ); - const microbitDeployCodeToDevice = () => { - deployCode(CONSTANTS.DEVICE_NAME.MICROBIT); - }; + if (!chosen_device) { + utils.logToOutputChannel( + outChannel, + CONSTANTS.INFO.NO_DEVICE_CHOSEN_TO_DEPLOY_TO, + true + ); + return; + } - const cpxDeployToDevice: vscode.Disposable = vscode.commands.registerCommand( - "deviceSimulatorExpress.cpx.deployToDevice", - () => { - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE - ); - telemetryAI.runWithLatencyMeasure( - cpxDeployCodeToDevice, - TelemetryEventName.CPX_PERFORMANCE_DEPLOY_DEVICE - ); - } - ); + const telemetryEvents = getTelemetryEventsForStartingDeployToDevice(chosen_device); - const microbitDeployToDevice: vscode.Disposable = vscode.commands.registerCommand( - "deviceSimulatorExpress.microbit.deployToDevice", - () => { telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE + telemetryEvents.deployTelemetryEvent ); telemetryAI.runWithLatencyMeasure( - microbitDeployCodeToDevice, - TelemetryEventName.MICROBIT_PERFORMANCE_DEPLOY_DEVICE + () => {deployCode(chosen_device);}, + telemetryEvents.deployPerformanceTelemetryEvent ); } ); @@ -1081,14 +1118,13 @@ export async function activate(context: vscode.ExtensionContext) { runSimulator, changeBaudRate, closeSerialMonitor, - cpxDeployToDevice, + deployToDevice, cpxNewFile, openSerialMonitor, cpxOpenSimulator, selectSerialPort, microbitOpenSimulator, microbitNewFile, - microbitDeployToDevice, clueOpenSimulator, clueNewFile, gettingStartedOpen, diff --git a/src/python_constants.py b/src/python_constants.py index 357b7b06a..dfb8143dd 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -3,7 +3,7 @@ ACTIVE_DEVICE_FIELD = "active_device" -CPX_DRIVE_NAME = "CIRCUITPY" +ADAFRUIT_DRIVE_NAME = "CIRCUITPY" DEPEND_ERR = 'The required dependencies aren\'t downloaded. Please use CTRL+SHIFT+P to open the command palette and select "Device Simulator Express: Install Extension Dependencies".' @@ -24,8 +24,8 @@ MAC_OS = "darwin" MOUNT_COMMAND = "mount" -NO_CPX_DETECTED_ERROR_TITLE = "No Circuit Playground Express detected" -NO_CPX_DETECTED_ERROR_DETAIL = ( +NO_ADAFRUIT_DEVICE_DETECTED_ERROR_TITLE = "No Adafruit device (Circuit Playground Express or Clue) detected" +NO_ADAFRUIT_DEVICE_DETECTED_ERROR_DETAIL = ( "Could not find drive with name 'CIRCUITPYTHON'. Detected OS: {}" ) NO_MICROBIT_DETECTED_ERROR_TITLE = "No micro:bit detected" From 45c0da42dd3dfa5ae67affa8021f99fac65b259b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Mar 2020 16:03:13 -0700 Subject: [PATCH 2/6] formatted and removed unnecessary changes --- locales/en/package.i18n.json | 2 +- src/clue/adafruit_clue.py | 4 --- src/constants.ts | 6 ++-- src/extension.ts | 69 +++++++++++++++++++++++------------- src/python_constants.py | 4 ++- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/locales/en/package.i18n.json b/locales/en/package.i18n.json index f85718a6d..0a678fa83 100644 --- a/locales/en/package.i18n.json +++ b/locales/en/package.i18n.json @@ -17,5 +17,5 @@ "deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration", "deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.", "deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.", - "deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask for dependency downloads. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files." + "deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files." } \ No newline at end of file diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index ae42b3994..bb4ef83b7 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -203,10 +203,6 @@ def __init__(self): pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB ) - @property - def accerleration(self): - return [1, 2, 2] - @property def pixel(self): """The NeoPixel RGB LED. diff --git a/src/constants.ts b/src/constants.ts index a5de987b1..81a9baf22 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -96,7 +96,7 @@ export const CONSTANTS = { ), NO_FILE_TO_DEPLOY: localize( "error.noFileToDeploy", - '[ERROR] We can\'t find a Python file to deploy to your device.\n' + "[ERROR] We can't find a Python file to deploy to your device.\n" ), NO_FOLDER_OPENED: localize( "error.noFolderCreated", @@ -253,8 +253,7 @@ export const CONSTANTS = { "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples", CPX_HELP: "https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart", - CLUE_HELP: - "https://learn.adafruit.com/adafruit-clue/circuitpython", + CLUE_HELP: "https://learn.adafruit.com/adafruit-clue/circuitpython", INSTALL: "https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/docs/install.md", PRIVACY: "https://www.adafruit.com/privacy", @@ -347,7 +346,6 @@ export enum TelemetryEventName { CLUE_COMMAND_DEPLOY_DEVICE = "CLUE.COMMAND.DEPLOY.DEVICE", - // Simulator interaction CPX_SIMULATOR_BUTTON_A = "CPX.SIMULATOR.BUTTON.A", CPX_SIMULATOR_BUTTON_B = "CPX.SIMULATOR.BUTTON.B", diff --git a/src/extension.ts b/src/extension.ts index ea84ba63b..3d90c71f7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -706,7 +706,7 @@ export async function activate(context: vscode.ExtensionContext) { ); vscode.window.showErrorMessage( CONSTANTS.ERROR.NO_FILE_TO_DEPLOY, - DialogResponses.MESSAGE_UNDERSTOOD + DialogResponses.MESSAGE_UNDERSTOOD ); } else { await fileSelectionService.getCurrentTextDocument().save(); @@ -744,7 +744,10 @@ export async function activate(context: vscode.ExtensionContext) { true ); } - handleDeployToDeviceFinishedTelemetry(messageToWebview, device); + handleDeployToDeviceFinishedTelemetry( + messageToWebview, + device + ); } catch (err) { console.log( `Non-JSON output from the process : ${dataFromTheProcess}` @@ -777,23 +780,29 @@ export async function activate(context: vscode.ExtensionContext) { let deployPerformanceTelemetryEvent: string; switch (device) { case CONSTANTS.DEVICE_NAME.CPX: - deployTelemetryEvent = TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + deployTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; break; case CONSTANTS.DEVICE_NAME.MICROBIT: - deployTelemetryEvent = TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + deployTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; break; case CONSTANTS.DEVICE_NAME.CLUE: - deployTelemetryEvent = TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + deployTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; break; } return { deployTelemetryEvent: deployTelemetryEvent, - deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent - } - } + deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, + }; + }; const handleDeployToDeviceErrorTelemetry = ( data: string, @@ -802,7 +811,8 @@ export async function activate(context: vscode.ExtensionContext) { let telemetryErrorName: string; switch (device) { case CONSTANTS.DEVICE_NAME.CPX: - telemetryErrorName = TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; + telemetryErrorName = + TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; break; case CONSTANTS.DEVICE_NAME.MICROBIT: telemetryErrorName = @@ -814,7 +824,10 @@ export async function activate(context: vscode.ExtensionContext) { telemetryAI.trackFeatureUsage(telemetryErrorName, { error: `${data}` }); }; - const handleDeployToDeviceFinishedTelemetry = (message: any, device: string) => { + const handleDeployToDeviceFinishedTelemetry = ( + message: any, + device: string + ) => { let successCommandDeployDevice: string; let errorCommandDeployWithoutDevice: string; switch (device) { @@ -844,7 +857,10 @@ export async function activate(context: vscode.ExtensionContext) { break; case "no-device": telemetryAI.trackFeatureUsage(errorCommandDeployWithoutDevice); - if (device === CONSTANTS.DEVICE_NAME.CPX || device === CONSTANTS.DEVICE_NAME.CLUE) { + if ( + device === CONSTANTS.DEVICE_NAME.CPX || + device === CONSTANTS.DEVICE_NAME.CLUE + ) { vscode.window .showErrorMessage( CONSTANTS.ERROR.NO_DEVICE, @@ -857,10 +873,14 @@ export async function activate(context: vscode.ExtensionContext) { let helpTelemetryEvent: string; if (device === CONSTANTS.DEVICE_NAME.CPX) { helpLink = CONSTANTS.LINKS.CPX_HELP; - helpTelemetryEvent = CONSTANTS.LINKS.CPX_HELP; - } else if (device === CONSTANTS.DEVICE_NAME.CLUE) { + helpTelemetryEvent = + CONSTANTS.LINKS.CPX_HELP; + } else if ( + device === CONSTANTS.DEVICE_NAME.CLUE + ) { helpLink = CONSTANTS.LINKS.CLUE_HELP; - helpTelemetryEvent = CONSTANTS.LINKS.CLUE_HELP; + helpTelemetryEvent = + CONSTANTS.LINKS.CLUE_HELP; } open(helpLink); telemetryAI.trackFeatureUsage( @@ -906,15 +926,14 @@ export async function activate(context: vscode.ExtensionContext) { return; } - const telemetryEvents = getTelemetryEventsForStartingDeployToDevice(chosen_device); - - telemetryAI.trackFeatureUsage( - telemetryEvents.deployTelemetryEvent - ); - telemetryAI.runWithLatencyMeasure( - () => {deployCode(chosen_device);}, - telemetryEvents.deployPerformanceTelemetryEvent + const telemetryEvents = getTelemetryEventsForStartingDeployToDevice( + chosen_device ); + + telemetryAI.trackFeatureUsage(telemetryEvents.deployTelemetryEvent); + telemetryAI.runWithLatencyMeasure(() => { + deployCode(chosen_device); + }, telemetryEvents.deployPerformanceTelemetryEvent); } ); diff --git a/src/python_constants.py b/src/python_constants.py index dfb8143dd..947578942 100644 --- a/src/python_constants.py +++ b/src/python_constants.py @@ -24,7 +24,9 @@ MAC_OS = "darwin" MOUNT_COMMAND = "mount" -NO_ADAFRUIT_DEVICE_DETECTED_ERROR_TITLE = "No Adafruit device (Circuit Playground Express or Clue) detected" +NO_ADAFRUIT_DEVICE_DETECTED_ERROR_TITLE = ( + "No Adafruit device (Circuit Playground Express or Clue) detected" +) NO_ADAFRUIT_DEVICE_DETECTED_ERROR_DETAIL = ( "Could not find drive with name 'CIRCUITPYTHON'. Detected OS: {}" ) From c2736271ca910df45ababf795fbbc40f86aaa708 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Mar 2020 16:28:15 -0700 Subject: [PATCH 3/6] moved code --- src/extension.ts | 270 +++++++++++++++++++++++------------------------ 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3d90c71f7..e4106692b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -775,141 +775,6 @@ export async function activate(context: vscode.ExtensionContext) { } }; - const getTelemetryEventsForStartingDeployToDevice = (device: string) => { - let deployTelemetryEvent: string; - let deployPerformanceTelemetryEvent: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - deployTelemetryEvent = - TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - deployTelemetryEvent = - TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.CLUE: - deployTelemetryEvent = - TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; - break; - } - return { - deployTelemetryEvent: deployTelemetryEvent, - deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, - }; - }; - - const handleDeployToDeviceErrorTelemetry = ( - data: string, - device: string - ) => { - let telemetryErrorName: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - telemetryErrorName = - TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - telemetryErrorName = - TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; - case CONSTANTS.DEVICE_NAME.CLUE: - telemetryErrorName = - TelemetryEventName.CLUE_ERROR_PYTHON_DEVICE_PROCESS; - } - telemetryAI.trackFeatureUsage(telemetryErrorName, { error: `${data}` }); - }; - - const handleDeployToDeviceFinishedTelemetry = ( - message: any, - device: string - ) => { - let successCommandDeployDevice: string; - let errorCommandDeployWithoutDevice: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - successCommandDeployDevice = - TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - successCommandDeployDevice = - TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.CLUE: - successCommandDeployDevice = - TelemetryEventName.CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.CLUE_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - } - - switch (message.type) { - case "complete": - telemetryAI.trackFeatureUsage(successCommandDeployDevice); - break; - case "no-device": - telemetryAI.trackFeatureUsage(errorCommandDeployWithoutDevice); - if ( - device === CONSTANTS.DEVICE_NAME.CPX || - device === CONSTANTS.DEVICE_NAME.CLUE - ) { - vscode.window - .showErrorMessage( - CONSTANTS.ERROR.NO_DEVICE, - DialogResponses.HELP - ) - .then((selection: vscode.MessageItem | undefined) => { - if (selection === DialogResponses.HELP) { - const okAction = () => { - let helpLink: string; - let helpTelemetryEvent: string; - if (device === CONSTANTS.DEVICE_NAME.CPX) { - helpLink = CONSTANTS.LINKS.CPX_HELP; - helpTelemetryEvent = - CONSTANTS.LINKS.CPX_HELP; - } else if ( - device === CONSTANTS.DEVICE_NAME.CLUE - ) { - helpLink = CONSTANTS.LINKS.CLUE_HELP; - helpTelemetryEvent = - CONSTANTS.LINKS.CLUE_HELP; - } - open(helpLink); - telemetryAI.trackFeatureUsage( - helpTelemetryEvent - ); - }; - utils.showPrivacyModal( - okAction, - CONSTANTS.INFO.THIRD_PARTY_WEBSITE_ADAFRUIT - ); - } - }); - } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { - vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_DEVICE); - } - break; - case "low-python-version": - vscode.window.showErrorMessage( - CONSTANTS.ERROR.LOW_PYTHON_VERSION_FOR_MICROBIT_DEPLOYMENT - ); - break; - default: - console.log( - `Non-state JSON output from the process : ${message}` - ); - break; - } - }; - const deployToDevice: vscode.Disposable = vscode.commands.registerCommand( "deviceSimulatorExpress.common.deployToDevice", async () => { @@ -1358,6 +1223,141 @@ const handleNewFileErrorTelemetry = () => { } }; +const getTelemetryEventsForStartingDeployToDevice = (device: string) => { + let deployTelemetryEvent: string; + let deployPerformanceTelemetryEvent: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + deployTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + deployTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + deployTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + break; + } + return { + deployTelemetryEvent: deployTelemetryEvent, + deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, + }; +}; + +const handleDeployToDeviceErrorTelemetry = ( + data: string, + device: string +) => { + let telemetryErrorName: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + telemetryErrorName = + TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + telemetryErrorName = + TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; + case CONSTANTS.DEVICE_NAME.CLUE: + telemetryErrorName = + TelemetryEventName.CLUE_ERROR_PYTHON_DEVICE_PROCESS; + } + telemetryAI.trackFeatureUsage(telemetryErrorName, { error: `${data}` }); +}; + +const handleDeployToDeviceFinishedTelemetry = ( + message: any, + device: string +) => { + let successCommandDeployDevice: string; + let errorCommandDeployWithoutDevice: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + successCommandDeployDevice = + TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + successCommandDeployDevice = + TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + successCommandDeployDevice = + TelemetryEventName.CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CLUE_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + } + + switch (message.type) { + case "complete": + telemetryAI.trackFeatureUsage(successCommandDeployDevice); + break; + case "no-device": + telemetryAI.trackFeatureUsage(errorCommandDeployWithoutDevice); + if ( + device === CONSTANTS.DEVICE_NAME.CPX || + device === CONSTANTS.DEVICE_NAME.CLUE + ) { + vscode.window + .showErrorMessage( + CONSTANTS.ERROR.NO_DEVICE, + DialogResponses.HELP + ) + .then((selection: vscode.MessageItem | undefined) => { + if (selection === DialogResponses.HELP) { + const okAction = () => { + let helpLink: string; + let helpTelemetryEvent: string; + if (device === CONSTANTS.DEVICE_NAME.CPX) { + helpLink = CONSTANTS.LINKS.CPX_HELP; + helpTelemetryEvent = + CONSTANTS.LINKS.CPX_HELP; + } else if ( + device === CONSTANTS.DEVICE_NAME.CLUE + ) { + helpLink = CONSTANTS.LINKS.CLUE_HELP; + helpTelemetryEvent = + CONSTANTS.LINKS.CLUE_HELP; + } + open(helpLink); + telemetryAI.trackFeatureUsage( + helpTelemetryEvent + ); + }; + utils.showPrivacyModal( + okAction, + CONSTANTS.INFO.THIRD_PARTY_WEBSITE_ADAFRUIT + ); + } + }); + } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { + vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_DEVICE); + } + break; + case "low-python-version": + vscode.window.showErrorMessage( + CONSTANTS.ERROR.LOW_PYTHON_VERSION_FOR_MICROBIT_DEPLOYMENT + ); + break; + default: + console.log( + `Non-state JSON output from the process : ${message}` + ); + break; + } +}; + const updatePythonExtraPaths = () => { updateConfigLists( "python.autoComplete.extraPaths", From a389d47120a790010ded12b524f97a1d2658582a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Mar 2020 17:05:29 -0700 Subject: [PATCH 4/6] Refactored to remove telemetry handling to its own service --- src/constants.ts | 2 + src/extension.ts | 368 ++----------------------- src/service/telemetryHandlerService.ts | 361 ++++++++++++++++++++++++ 3 files changed, 386 insertions(+), 345 deletions(-) create mode 100644 src/service/telemetryHandlerService.ts diff --git a/src/constants.ts b/src/constants.ts index 81a9baf22..f2c354d29 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -373,6 +373,8 @@ export enum TelemetryEventName { CPX_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CPX.CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE", CPX_CLICK_DIALOG_TUTORIALS = "CPX.CLICK.DIALOG.TUTORIALS", + CLUE_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CLUE.CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE", + ERROR_PYTHON_PROCESS = "ERROR.PYTHON.PROCESS", CPX_ERROR_COMMAND_NEW_FILE = "CPX.ERROR.COMMAND.NEW.FILE", CPX_ERROR_DEPLOY_WITHOUT_DEVICE = "CPX.ERROR.DEPLOY.WITHOUT.DEVICE", diff --git a/src/extension.ts b/src/extension.ts index e4106692b..d8c793622 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,6 +32,7 @@ import { WebviewService } from "./service/webviewService"; import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider"; import getPackageInfo from "./telemetry/getPackageInfo"; import TelemetryAI from "./telemetry/telemetryAI"; +import { TelemetryHandlerService } from "./service/telemetryHandlerService"; import { UsbDetector } from "./usbDetector"; import { VSCODE_MESSAGES_TO_WEBVIEW, @@ -72,6 +73,10 @@ export async function activate(context: vscode.ExtensionContext) { let messageListener: vscode.Disposable; let activeEditorListener: vscode.Disposable; const webviewService = new WebviewService(context, deviceSelectionService); + const telemetryHandlerService = new TelemetryHandlerService( + telemetryAI, + deviceSelectionService + ); // Add our library path to settings.json for autocomplete functionality updatePythonExtraPaths(); @@ -175,7 +180,9 @@ export async function activate(context: vscode.ExtensionContext) { switch (message.command) { case WEBVIEW_MESSAGES.BUTTON_PRESS: // Send input to the Python process - handleButtonPressTelemetry(message.text); + telemetryHandlerService.handleButtonPressTelemetry( + message.text + ); console.log(`About to write ${messageJson} \n`); if ( inDebugMode && @@ -214,7 +221,9 @@ export async function activate(context: vscode.ExtensionContext) { break; case WEBVIEW_MESSAGES.GESTURE: case WEBVIEW_MESSAGES.SENSOR_CHANGED: - handleGestureTelemetry(message.text); + telemetryHandlerService.handleGestureTelemetry( + message.text + ); console.log(`Sensor changed ${messageJson} \n`); if ( inDebugMode && @@ -234,7 +243,9 @@ export async function activate(context: vscode.ExtensionContext) { runSimulatorCommand(); break; case WEBVIEW_MESSAGES.SLIDER_TELEMETRY: - handleSensorTelemetry(message.text); + telemetryHandlerService.handleSensorTelemetry( + message.text + ); break; case WEBVIEW_MESSAGES.SWITCH_DEVICE: deviceSelectionService.setCurrentActiveDevice( @@ -426,7 +437,7 @@ export async function activate(context: vscode.ExtensionContext) { }), // tslint:disable-next-line: no-unused-expression (error: any) => { - handleNewFileErrorTelemetry(); + telemetryHandlerService.handleNewFileErrorTelemetry(); console.error(`Failed to open a new text document: ${error}`); }; }; @@ -744,7 +755,7 @@ export async function activate(context: vscode.ExtensionContext) { true ); } - handleDeployToDeviceFinishedTelemetry( + telemetryHandlerService.handleDeployToDeviceFinishedTelemetry( messageToWebview, device ); @@ -757,7 +768,10 @@ export async function activate(context: vscode.ExtensionContext) { // Std error output deviceProcess.stderr.on("data", data => { - handleDeployToDeviceErrorTelemetry(data, device); + telemetryHandlerService.handleDeployToDeviceErrorTelemetry( + data, + device + ); console.error( `Error from the Python device process through stderr: ${data}` ); @@ -791,7 +805,7 @@ export async function activate(context: vscode.ExtensionContext) { return; } - const telemetryEvents = getTelemetryEventsForStartingDeployToDevice( + const telemetryEvents = telemetryHandlerService.getTelemetryEventsForStartingDeployToDevice( chosen_device ); @@ -942,7 +956,7 @@ export async function activate(context: vscode.ExtensionContext) { ) ); - handleDebuggerTelemetry(); + telemetryHandlerService.handleDebuggerTelemetry(); openWebview(); if (currentPanel) { @@ -960,7 +974,7 @@ export async function activate(context: vscode.ExtensionContext) { `Error trying to init the server on port ${utils.getServerPortConfig()}` ); - handleDebuggerFailTelemetry(); + telemetryHandlerService.handleDebuggerFailTelemetry(); vscode.window.showErrorMessage( CONSTANTS.ERROR.DEBUGGER_SERVER_INIT_FAILED( @@ -1022,342 +1036,6 @@ export async function activate(context: vscode.ExtensionContext) { ); } -const handleDebuggerTelemetry = () => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_DEBUGGER_INIT_SUCCESS - ); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_DEBUGGER_INIT_SUCCESS - ); - break; - default: - break; - } -}; - -const handleDebuggerFailTelemetry = () => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_DEBUGGER_INIT_FAIL - ); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_DEBUGGER_INIT_FAIL - ); - break; - default: - break; - } -}; - -const handleButtonPressTelemetry = (buttonState: any) => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - handleCPXButtonPressTelemetry(buttonState); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - handleMicrobitButtonPressTelemetry(buttonState); - break; - default: - break; - } -}; - -const handleGestureTelemetry = (sensorState: any) => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - handleCPXGestureTelemetry(sensorState); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - break; - default: - break; - } -}; - -const handleSensorTelemetry = (sensor: string) => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - handleCPXSensorTelemetry(sensor); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - handleMicrobitSensorTelemetry(sensor); - break; - default: - break; - } -}; - -const handleCPXButtonPressTelemetry = (buttonState: any) => { - if (buttonState.button_a && buttonState.button_b) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_BUTTON_AB - ); - } else if (buttonState.button_a) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_BUTTON_A - ); - } else if (buttonState.button_b) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_BUTTON_B - ); - } else if (buttonState.switch) { - telemetryAI.trackFeatureUsage(TelemetryEventName.CPX_SIMULATOR_SWITCH); - } -}; - -const handleCPXGestureTelemetry = (sensorState: any) => { - if (sensorState.shake) { - handleCPXSensorTelemetry("shake"); - } else if (sensorState.touch) { - handleCPXSensorTelemetry("touch"); - } -}; - -const handleCPXSensorTelemetry = (sensor: string) => { - switch (sensor) { - case "temperature": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_TEMPERATURE_SENSOR - ); - break; - case "light": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_LIGHT_SENSOR - ); - break; - case "motion_x": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR - ); - break; - case "motion_y": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR - ); - break; - case "motion_z": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR - ); - break; - case "shake": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_SHAKE - ); - break; - case "touch": - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_SIMULATOR_CAPACITIVE_TOUCH - ); - break; - } -}; - -const handleMicrobitButtonPressTelemetry = (buttonState: any) => { - if (buttonState.button_a && buttonState.button_b) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_AB - ); - } else if (buttonState.button_a) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_A - ); - } else if (buttonState.button_b) { - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_B - ); - } -}; - -const handleMicrobitSensorTelemetry = (sensor: string) => { - switch (sensor) { - case "temperature": - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_TEMPERATURE_SENSOR - ); - break; - case "light": - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_LIGHT_SENSOR - ); - break; - case "motion_x": - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR - ); - break; - case "motion_y": - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR - ); - break; - case "motion_z": - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR - ); - break; - } -}; - -const handleNewFileErrorTelemetry = () => { - switch (deviceSelectionService.getCurrentActiveDevice()) { - case CONSTANTS.DEVICE_NAME.CPX: - telemetryAI.trackFeatureUsage( - TelemetryEventName.CPX_ERROR_COMMAND_NEW_FILE - ); - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - telemetryAI.trackFeatureUsage( - TelemetryEventName.MICROBIT_ERROR_COMMAND_NEW_FILE - ); - break; - default: - break; - } -}; - -const getTelemetryEventsForStartingDeployToDevice = (device: string) => { - let deployTelemetryEvent: string; - let deployPerformanceTelemetryEvent: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - deployTelemetryEvent = - TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - deployTelemetryEvent = - TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.CLUE: - deployTelemetryEvent = - TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; - deployPerformanceTelemetryEvent = - TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; - break; - } - return { - deployTelemetryEvent: deployTelemetryEvent, - deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, - }; -}; - -const handleDeployToDeviceErrorTelemetry = ( - data: string, - device: string -) => { - let telemetryErrorName: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - telemetryErrorName = - TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - telemetryErrorName = - TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; - case CONSTANTS.DEVICE_NAME.CLUE: - telemetryErrorName = - TelemetryEventName.CLUE_ERROR_PYTHON_DEVICE_PROCESS; - } - telemetryAI.trackFeatureUsage(telemetryErrorName, { error: `${data}` }); -}; - -const handleDeployToDeviceFinishedTelemetry = ( - message: any, - device: string -) => { - let successCommandDeployDevice: string; - let errorCommandDeployWithoutDevice: string; - switch (device) { - case CONSTANTS.DEVICE_NAME.CPX: - successCommandDeployDevice = - TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.MICROBIT: - successCommandDeployDevice = - TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - case CONSTANTS.DEVICE_NAME.CLUE: - successCommandDeployDevice = - TelemetryEventName.CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE; - errorCommandDeployWithoutDevice = - TelemetryEventName.CLUE_ERROR_DEPLOY_WITHOUT_DEVICE; - break; - } - - switch (message.type) { - case "complete": - telemetryAI.trackFeatureUsage(successCommandDeployDevice); - break; - case "no-device": - telemetryAI.trackFeatureUsage(errorCommandDeployWithoutDevice); - if ( - device === CONSTANTS.DEVICE_NAME.CPX || - device === CONSTANTS.DEVICE_NAME.CLUE - ) { - vscode.window - .showErrorMessage( - CONSTANTS.ERROR.NO_DEVICE, - DialogResponses.HELP - ) - .then((selection: vscode.MessageItem | undefined) => { - if (selection === DialogResponses.HELP) { - const okAction = () => { - let helpLink: string; - let helpTelemetryEvent: string; - if (device === CONSTANTS.DEVICE_NAME.CPX) { - helpLink = CONSTANTS.LINKS.CPX_HELP; - helpTelemetryEvent = - CONSTANTS.LINKS.CPX_HELP; - } else if ( - device === CONSTANTS.DEVICE_NAME.CLUE - ) { - helpLink = CONSTANTS.LINKS.CLUE_HELP; - helpTelemetryEvent = - CONSTANTS.LINKS.CLUE_HELP; - } - open(helpLink); - telemetryAI.trackFeatureUsage( - helpTelemetryEvent - ); - }; - utils.showPrivacyModal( - okAction, - CONSTANTS.INFO.THIRD_PARTY_WEBSITE_ADAFRUIT - ); - } - }); - } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { - vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_DEVICE); - } - break; - case "low-python-version": - vscode.window.showErrorMessage( - CONSTANTS.ERROR.LOW_PYTHON_VERSION_FOR_MICROBIT_DEPLOYMENT - ); - break; - default: - console.log( - `Non-state JSON output from the process : ${message}` - ); - break; - } -}; - const updatePythonExtraPaths = () => { updateConfigLists( "python.autoComplete.extraPaths", diff --git a/src/service/telemetryHandlerService.ts b/src/service/telemetryHandlerService.ts new file mode 100644 index 000000000..b0ecc9a53 --- /dev/null +++ b/src/service/telemetryHandlerService.ts @@ -0,0 +1,361 @@ +import * as open from "open"; +import * as vscode from "vscode"; +import { CONSTANTS, DialogResponses, TelemetryEventName } from "../constants"; +import * as utils from "../extension_utils/utils"; +import { DeviceSelectionService } from "./deviceSelectionService"; +import TelemetryAI from "../telemetry/telemetryAI"; + +export class TelemetryHandlerService { + private telemetryAI: TelemetryAI; + private deviceSelectionService: DeviceSelectionService; + + constructor( + telemetryAI: TelemetryAI, + deviceSelectionService: DeviceSelectionService + ) { + this.telemetryAI = telemetryAI; + this.deviceSelectionService = deviceSelectionService; + } + + public handleDebuggerTelemetry = () => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_DEBUGGER_INIT_SUCCESS + ); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_DEBUGGER_INIT_SUCCESS + ); + break; + default: + break; + } + }; + + public handleDebuggerFailTelemetry = () => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_DEBUGGER_INIT_FAIL + ); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_DEBUGGER_INIT_FAIL + ); + break; + default: + break; + } + }; + + public handleButtonPressTelemetry = (buttonState: any) => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.handleCPXButtonPressTelemetry(buttonState); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + this.handleMicrobitButtonPressTelemetry(buttonState); + break; + default: + break; + } + }; + + public handleGestureTelemetry = (sensorState: any) => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.handleCPXGestureTelemetry(sensorState); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + break; + default: + break; + } + }; + + public handleSensorTelemetry = (sensor: string) => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.handleCPXSensorTelemetry(sensor); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + this.handleMicrobitSensorTelemetry(sensor); + break; + default: + break; + } + }; + + public handleCPXButtonPressTelemetry = (buttonState: any) => { + if (buttonState.button_a && buttonState.button_b) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_BUTTON_AB + ); + } else if (buttonState.button_a) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_BUTTON_A + ); + } else if (buttonState.button_b) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_BUTTON_B + ); + } else if (buttonState.switch) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_SWITCH + ); + } + }; + + public handleCPXGestureTelemetry = (sensorState: any) => { + if (sensorState.shake) { + this.handleCPXSensorTelemetry("shake"); + } else if (sensorState.touch) { + this.handleCPXSensorTelemetry("touch"); + } + }; + + public handleCPXSensorTelemetry = (sensor: string) => { + switch (sensor) { + case "temperature": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_TEMPERATURE_SENSOR + ); + break; + case "light": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_LIGHT_SENSOR + ); + break; + case "motion_x": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR + ); + break; + case "motion_y": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR + ); + break; + case "motion_z": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_MOTION_SENSOR + ); + break; + case "shake": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_SHAKE + ); + break; + case "touch": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_SIMULATOR_CAPACITIVE_TOUCH + ); + break; + } + }; + + public handleMicrobitButtonPressTelemetry = (buttonState: any) => { + if (buttonState.button_a && buttonState.button_b) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_AB + ); + } else if (buttonState.button_a) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_A + ); + } else if (buttonState.button_b) { + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_BUTTON_B + ); + } + }; + + public handleMicrobitSensorTelemetry = (sensor: string) => { + switch (sensor) { + case "temperature": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_TEMPERATURE_SENSOR + ); + break; + case "light": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_LIGHT_SENSOR + ); + break; + case "motion_x": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR + ); + break; + case "motion_y": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR + ); + break; + case "motion_z": + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_SIMULATOR_MOTION_SENSOR + ); + break; + } + }; + + public handleNewFileErrorTelemetry = () => { + switch (this.deviceSelectionService.getCurrentActiveDevice()) { + case CONSTANTS.DEVICE_NAME.CPX: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.CPX_ERROR_COMMAND_NEW_FILE + ); + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + this.telemetryAI.trackFeatureUsage( + TelemetryEventName.MICROBIT_ERROR_COMMAND_NEW_FILE + ); + break; + default: + break; + } + }; + + public getTelemetryEventsForStartingDeployToDevice = (device: string) => { + let deployTelemetryEvent: string; + let deployPerformanceTelemetryEvent: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + deployTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CPX_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + deployTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.MICROBIT_COMMAND_DEPLOY_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + deployTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + deployPerformanceTelemetryEvent = + TelemetryEventName.CLUE_COMMAND_DEPLOY_DEVICE; + break; + } + return { + deployTelemetryEvent: deployTelemetryEvent, + deployPerformanceTelemetryEvent: deployPerformanceTelemetryEvent, + }; + }; + + public handleDeployToDeviceErrorTelemetry = ( + data: string, + device: string + ) => { + let telemetryErrorName: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + telemetryErrorName = + TelemetryEventName.CPX_ERROR_PYTHON_DEVICE_PROCESS; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + telemetryErrorName = + TelemetryEventName.MICROBIT_ERROR_PYTHON_DEVICE_PROCESS; + case CONSTANTS.DEVICE_NAME.CLUE: + telemetryErrorName = + TelemetryEventName.CLUE_ERROR_PYTHON_DEVICE_PROCESS; + } + this.telemetryAI.trackFeatureUsage(telemetryErrorName, { + error: `${data}`, + }); + }; + + public handleDeployToDeviceFinishedTelemetry = ( + message: any, + device: string + ) => { + let successCommandDeployDevice: string; + let errorCommandDeployWithoutDevice: string; + switch (device) { + case CONSTANTS.DEVICE_NAME.CPX: + successCommandDeployDevice = + TelemetryEventName.CPX_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CPX_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.MICROBIT: + successCommandDeployDevice = + TelemetryEventName.MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + case CONSTANTS.DEVICE_NAME.CLUE: + successCommandDeployDevice = + TelemetryEventName.CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE; + errorCommandDeployWithoutDevice = + TelemetryEventName.CLUE_ERROR_DEPLOY_WITHOUT_DEVICE; + break; + } + + switch (message.type) { + case "complete": + this.telemetryAI.trackFeatureUsage(successCommandDeployDevice); + break; + case "no-device": + this.telemetryAI.trackFeatureUsage( + errorCommandDeployWithoutDevice + ); + if ( + device === CONSTANTS.DEVICE_NAME.CPX || + device === CONSTANTS.DEVICE_NAME.CLUE + ) { + vscode.window + .showErrorMessage( + CONSTANTS.ERROR.NO_DEVICE, + DialogResponses.HELP + ) + .then((selection: vscode.MessageItem | undefined) => { + if (selection === DialogResponses.HELP) { + const okAction = () => { + let helpLink: string; + let helpTelemetryEvent: string; + if (device === CONSTANTS.DEVICE_NAME.CPX) { + helpLink = CONSTANTS.LINKS.CPX_HELP; + helpTelemetryEvent = + TelemetryEventName.CPX_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE; + } else if ( + device === CONSTANTS.DEVICE_NAME.CLUE + ) { + helpLink = CONSTANTS.LINKS.CLUE_HELP; + helpTelemetryEvent = + TelemetryEventName.CLUE_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE; + } + open(helpLink); + this.telemetryAI.trackFeatureUsage( + helpTelemetryEvent + ); + }; + utils.showPrivacyModal( + okAction, + CONSTANTS.INFO.THIRD_PARTY_WEBSITE_ADAFRUIT + ); + } + }); + } else if (device === CONSTANTS.DEVICE_NAME.MICROBIT) { + vscode.window.showErrorMessage(CONSTANTS.ERROR.NO_DEVICE); + } + break; + case "low-python-version": + vscode.window.showErrorMessage( + CONSTANTS.ERROR.LOW_PYTHON_VERSION_FOR_MICROBIT_DEPLOYMENT + ); + break; + default: + console.log( + `Non-state JSON output from the process : ${message}` + ); + break; + } + }; +} From 565ffa2675ab88eeb9bf53a47abd0644e2712256 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Mar 2020 14:02:32 -0700 Subject: [PATCH 5/6] Changed names that display on dropdown --- src/constants.ts | 5 +++++ src/extension.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f2c354d29..049484a5a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -35,6 +35,11 @@ export const CONSTANTS = { MICROBIT: "micro:bit", CLUE: "CLUE", }, + DEVICE_NAME_FORMAL: { + CPX: "Circuit Playground Express", + MICROBIT: "micro:bit", + CLUE: "CLUE", + }, ERROR: { BAD_PYTHON_PATH: 'Your interpreter is not pointing to a valid Python executable. Please select a different interpreter (CTRL+SHIFT+P and type "python.selectInterpreter") and restart the application', diff --git a/src/extension.ts b/src/extension.ts index d8c793622..3b93309c8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -793,8 +793,14 @@ export async function activate(context: vscode.ExtensionContext) { "deviceSimulatorExpress.common.deployToDevice", async () => { const chosen_device = await vscode.window.showQuickPick( - Object.values(CONSTANTS.DEVICE_NAME) + Object.values(CONSTANTS.DEVICE_NAME_FORMAL) ); + + const formalNameToNickNameMapping = { + [CONSTANTS.DEVICE_NAME_FORMAL.CPX]: CONSTANTS.DEVICE_NAME.CPX, + [CONSTANTS.DEVICE_NAME_FORMAL.MICROBIT]: CONSTANTS.DEVICE_NAME.MICROBIT, + [CONSTANTS.DEVICE_NAME_FORMAL.CLUE]: CONSTANTS.DEVICE_NAME.CLUE, + } if (!chosen_device) { utils.logToOutputChannel( @@ -804,14 +810,16 @@ export async function activate(context: vscode.ExtensionContext) { ); return; } + + const device = formalNameToNickNameMapping[chosen_device]; const telemetryEvents = telemetryHandlerService.getTelemetryEventsForStartingDeployToDevice( - chosen_device + device ); telemetryAI.trackFeatureUsage(telemetryEvents.deployTelemetryEvent); telemetryAI.runWithLatencyMeasure(() => { - deployCode(chosen_device); + deployCode(device); }, telemetryEvents.deployPerformanceTelemetryEvent); } ); From d319c2b62e764e14e296b847c9e48921b9a26065 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Mar 2020 15:04:55 -0700 Subject: [PATCH 6/6] formatted --- src/extension.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3b93309c8..dc677cefc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -795,12 +795,13 @@ export async function activate(context: vscode.ExtensionContext) { const chosen_device = await vscode.window.showQuickPick( Object.values(CONSTANTS.DEVICE_NAME_FORMAL) ); - + const formalNameToNickNameMapping = { [CONSTANTS.DEVICE_NAME_FORMAL.CPX]: CONSTANTS.DEVICE_NAME.CPX, - [CONSTANTS.DEVICE_NAME_FORMAL.MICROBIT]: CONSTANTS.DEVICE_NAME.MICROBIT, + [CONSTANTS.DEVICE_NAME_FORMAL.MICROBIT]: + CONSTANTS.DEVICE_NAME.MICROBIT, [CONSTANTS.DEVICE_NAME_FORMAL.CLUE]: CONSTANTS.DEVICE_NAME.CLUE, - } + }; if (!chosen_device) { utils.logToOutputChannel( @@ -810,7 +811,7 @@ export async function activate(context: vscode.ExtensionContext) { ); return; } - + const device = formalNameToNickNameMapping[chosen_device]; const telemetryEvents = telemetryHandlerService.getTelemetryEventsForStartingDeployToDevice(