diff --git a/locales/en/out/constants.i18n.json b/locales/en/out/constants.i18n.json index 4080d1866..7d728b9ec 100644 --- a/locales/en/out/constants.i18n.json +++ b/locales/en/out/constants.i18n.json @@ -3,6 +3,10 @@ "dialogResponses.exampleCode": "Example Code on GitHub", "dialogResponses.help": "I need help", "dialogResponses.tutorials": "Tutorials on Adafruit", + " error.incorrectFileNameForDevice":"[ERROR] Can\\'t deploy to your Circuit Playground Express device, please rename your file to \"code.py\" or \"main.py\". \n", + "error.incorrectFileNameForDevicePopup":"Seems like you have a different file name than what the CPX requires, please rename it to \"code.py\" or \"main.py\".", + "error.incorrectFileNameForSimulatorPopup":"We want your code to work on your actual board as well. Make sure you name your file \"code.py\" or \"main.py\" to be able to run your code on an actual physical device.", + "error.invalidFileNameDebug":"The file you tried to debug isn\\'t named \"code.py\" or \"main.py\\. Rename your file if you want your code to work on your actual device.", "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.stderr": "\n[ERROR] {0} \n", @@ -12,9 +16,10 @@ "info.deploySuccess": "\n[INFO] Code successfully deployed\n", "info.extensionActivated": "Congratulations, your extension Adafruit_Simulator is now active!", "info.firstTimeWebview": "To reopen the simulator click on the \"Open Simulator\" button on the upper right corner of the text editor, or select the command \"Open Simulator\" from command palette.", + "error.invalidFileExtensionDebug":"The file you tried to run isn\\'t a Python file.", "info.newProject": "New to Python or Circuit Playground Express project? We are here to help!", "info.runningCode": "Running user code", "info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n", "label.webviewPanel": "Adafruit CPX", "name": "Pacifica Simulator" -} \ No newline at end of file +} diff --git a/src/constants.ts b/src/constants.ts index 1efe8f56f..d188e1f7c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -11,9 +11,17 @@ const localize: nls.LocalizeFunc = nls.config({ export const CONSTANTS = { DEBUG_CONFIGURATION_NAME: "Pacifica Simulator Debugger", ERROR: { - INVALID_FILE_NAME_DEBUG: localize( - "error.invalidFileNameDebug", - 'The file you tried to run isn\'t named "code.py" or "main.py". Rename your file if you wish to debug it.' + INCORRECT_FILE_NAME_FOR_DEVICE: localize( + "error.incorrectFileNameForDevice", + '[ERROR] Can\'t deploy to your Circuit Playground Express device, please rename your file to "code.py" or "main.py". \n' + ), + INCORRECT_FILE_NAME_FOR_DEVICE_POPUP: localize( + "error.incorrectFileNameForDevicePopup", + 'Seems like you have a different file name than what CPX requires, please rename it to "code.py" or "main.py".' + ), + INVALID_FILE_EXTENSION_DEBUG: localize( + "error.invalidFileExtensionDebug", + "The file you tried to run isn't a Python file." ), NO_DEVICE: localize( "error.noDevice", @@ -21,7 +29,7 @@ export const CONSTANTS = { ), NO_FILE_TO_RUN: localize( "error.noFileToRun", - "\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples to start with: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples\n" + '[ERROR] We can\'t find the .py file to run. Open up a new .py file, or run the "New Project" command to get started and see useful links\n' ), NO_PROGRAM_FOUND_DEBUG: localize( "error.noProgramFoundDebug", @@ -53,6 +61,7 @@ export const CONSTANTS = { "info.extensionActivated", "Congratulations, your extension Adafruit_Simulator is now active!" ), + FILE_SELECTED: (filePath: string) => { return localize( "info.fileSelected", @@ -63,6 +72,14 @@ export const CONSTANTS = { "info.firstTimeWebview", 'To reopen the simulator click on the "Open Simulator" button on the upper right corner of the text editor, or select the command "Open Simulator" from command palette.' ), + INCORRECT_FILE_NAME_FOR_SIMULATOR_POPUP: localize( + "info.incorrectFileNameForSimulatorPopup", + 'We want your code to work on your actual board as well. Make sure you name your file "code.py" or "main.py" to be able to run your code on an actual physical device' + ), + INVALID_FILE_NAME_DEBUG: localize( + "info.invalidFileNameDebug", + 'The file you tried to debug isn\'t named "code.py" or "main.py". Rename your file if you want your code to work on your actual device.' + ), NEW_PROJECT: localize( "info.newProject", "New to Python or Circuit Playground Express project? We are here to help!" @@ -143,6 +160,9 @@ export namespace DialogResponses { export const EXAMPLE_CODE: MessageItem = { title: localize("dialogResponses.exampleCode", "Example Code on GitHub") }; + export const MESSAGE_UNDERSTOOD: MessageItem = { + title: localize("dialogResponses.messageUnderstood", "Got It") + }; } export const USER_CODE_NAMES = { diff --git a/src/extension.ts b/src/extension.ts index a5b026c11..199d77f28 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,6 +20,7 @@ let currentFileAbsPath: string = ""; // Notification booleans let firstTimeClosed: boolean = true; let shouldShowNewProject: boolean = true; +let shouldShowInvalidFileNamePopup: boolean = true; let telemetryAI: TelemetryAI; function loadScript(context: vscode.ExtensionContext, scriptPath: string) { @@ -83,14 +84,14 @@ export function activate(context: vscode.ExtensionContext) { // Send input to the Python process handleButtonPressTelemetry(message.text); console.log("About to write"); - console.log(messageJson + "\n"); + console.log(messageJson + "\n"); if (childProcess) { - childProcess.stdin.write(messageJson + "\n"); + childProcess.stdin.write(messageJson + "\n"); } break; case WebviewMessages.PLAY_SIMULATOR: console.log("Play button"); - console.log(messageJson + "\n"); + console.log(messageJson + "\n"); if (message.text as boolean) { runSimulatorCommand(); } else { @@ -99,9 +100,9 @@ export function activate(context: vscode.ExtensionContext) { break; case WebviewMessages.SENSOR_CHANGED: console.log("sensor changed"); - console.log(messageJson + "\n"); + console.log(messageJson + "\n"); if (childProcess) { - childProcess.stdin.write(messageJson + "\n"); + childProcess.stdin.write(messageJson + "\n"); } break; case WebviewMessages.REFRESH_SIMULATOR: @@ -158,9 +159,9 @@ export function activate(context: vscode.ExtensionContext) { vscode.window .showInformationMessage( CONSTANTS.INFO.NEW_PROJECT, - DialogResponses.DONT_SHOW, - DialogResponses.EXAMPLE_CODE, - DialogResponses.TUTORIALS + DialogResponses.DONT_SHOW, + DialogResponses.EXAMPLE_CODE, + DialogResponses.TUTORIALS ) .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.DONT_SHOW) { @@ -246,6 +247,27 @@ export function activate(context: vscode.ExtensionContext) { CONSTANTS.INFO.FILE_SELECTED(currentFileAbsPath) ); + if ( + !utils.validCodeFileName(currentFileAbsPath) && + shouldShowInvalidFileNamePopup + ) { + // to the popup + vscode.window + .showInformationMessage( + CONSTANTS.INFO.INCORRECT_FILE_NAME_FOR_SIMULATOR_POPUP, + DialogResponses.DONT_SHOW, + DialogResponses.MESSAGE_UNDERSTOOD + ) + .then((selection: vscode.MessageItem | undefined) => { + if (selection === DialogResponses.DONT_SHOW) { + shouldShowInvalidFileNamePopup = false; + telemetryAI.trackFeatureUsage( + TelemetryEventName.CLICK_DIALOG_DONT_SHOW + ); + } + }); + } + childProcess = cp.spawn("python", [ utils.getPathToScript(context, "out", "process_user_code.py"), currentFileAbsPath @@ -327,6 +349,17 @@ export function activate(context: vscode.ExtensionContext) { if (currentFileAbsPath === "") { logToOutputChannel(outChannel, CONSTANTS.ERROR.NO_FILE_TO_RUN, true); + } else if (!utils.validCodeFileName(currentFileAbsPath)) { + // Output panel + logToOutputChannel( + outChannel, + CONSTANTS.ERROR.INCORRECT_FILE_NAME_FOR_DEVICE, + true + ); + // Popup + vscode.window.showErrorMessage( + CONSTANTS.ERROR.INCORRECT_FILE_NAME_FOR_DEVICE_POPUP + ); } else { logToOutputChannel( outChannel, @@ -363,7 +396,7 @@ export function activate(context: vscode.ExtensionContext) { vscode.window .showErrorMessage( CONSTANTS.ERROR.NO_DEVICE, - DialogResponses.HELP + DialogResponses.HELP ) .then((selection: vscode.MessageItem | undefined) => { if (selection === DialogResponses.HELP) { diff --git a/src/simulatorDebugConfigurationProvider.ts b/src/simulatorDebugConfigurationProvider.ts index 4d03bc99b..4f27ff2fd 100644 --- a/src/simulatorDebugConfigurationProvider.ts +++ b/src/simulatorDebugConfigurationProvider.ts @@ -3,7 +3,9 @@ import * as vscode from "vscode"; import { validCodeFileName } from "./utils"; -import { CONSTANTS } from "./constants"; +import { CONSTANTS,DialogResponses } from "./constants"; + +let shouldShowInvalidFileNamePopup: boolean = true; export class SimulatorDebugConfigurationProvider implements vscode.DebugConfigurationProvider { @@ -25,14 +27,25 @@ export class SimulatorDebugConfigurationProvider // Check file type and name if ( - !(activeTextEditor.document.languageId === "python") || - !validCodeFileName(currentFilePath) + !(activeTextEditor.document.languageId === "python") ) { return vscode.window - .showErrorMessage(CONSTANTS.ERROR.INVALID_FILE_NAME_DEBUG) + .showErrorMessage(CONSTANTS.ERROR.INVALID_FILE_EXTENSION_DEBUG) .then(() => { return undefined; // Abort launch }); + }else if(!validCodeFileName(currentFilePath) && shouldShowInvalidFileNamePopup){ + vscode.window + .showInformationMessage(CONSTANTS.INFO.INVALID_FILE_NAME_DEBUG, + ...[ + DialogResponses.DONT_SHOW, + DialogResponses.MESSAGE_UNDERSTOOD + ]) + .then((selection: vscode.MessageItem | undefined) => { + if (selection === DialogResponses.DONT_SHOW) { + shouldShowInvalidFileNamePopup = false; + } + }); } // Set process_user_code path as program config.program = this.pathToScript; diff --git a/src/view/components/toolbar/InputSlider.tsx b/src/view/components/toolbar/InputSlider.tsx index 0c2eccdbf..a698bf335 100644 --- a/src/view/components/toolbar/InputSlider.tsx +++ b/src/view/components/toolbar/InputSlider.tsx @@ -105,7 +105,6 @@ class InputSlider extends React.Component { } private writeMessage(event: React.ChangeEvent) { - parseInt(event.target.value, 10); return this.props.type && this.state.value && event.target.value ? { temperature: parseInt(event.target.value, 10) } : undefined; diff --git a/src/view/components/toolbar/TemperatureSensorBar.tsx b/src/view/components/toolbar/TemperatureSensorBar.tsx index a7ee96360..a3b5cf150 100644 --- a/src/view/components/toolbar/TemperatureSensorBar.tsx +++ b/src/view/components/toolbar/TemperatureSensorBar.tsx @@ -35,7 +35,9 @@ class TemperatureSensorBar extends React.Component {
- {`${TEMPERATURE_SENSOR_PROPERTIES.LABEL} ${CELSIUS_STATE.unitLabel}`} + {`${TEMPERATURE_SENSOR_PROPERTIES.LABEL} ${ + CELSIUS_STATE.unitLabel + }`}