diff --git a/locales/en/package.i18n.json b/locales/en/package.i18n.json index b74373674..7e0bdc747 100644 --- a/locales/en/package.i18n.json +++ b/locales/en/package.i18n.json @@ -1,19 +1,21 @@ { - "deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies", - "deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express", - "deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator", - "deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate", - "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", - "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", - "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", - "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.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.commands.common.installDependencies": "Install Extension Dependencies", + "deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express", + "deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator", + "deviceSimulatorExpressExtension.commands.common.gettingStarted": "Getting Started", + + "deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate", + "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", + "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", + "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", + "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.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." } diff --git a/package.json b/package.json index 66f094cc0..0f9c222c5 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "onCommand:deviceSimulatorExpress.common.openSerialMonitor", "onCommand:deviceSimulatorExpress.common.runSimulator", "onCommand:deviceSimulatorExpress.common.selectSerialPort", + "onCommand:deviceSimulatorExpress.common.gettingStarted", "onCommand:deviceSimulatorExpress.cpx.deployToDevice", "onCommand:deviceSimulatorExpress.cpx.newFile", "onCommand:deviceSimulatorExpress.cpx.openSimulator", @@ -75,6 +76,11 @@ "title": "%deviceSimulatorExpressExtension.commands.common.runSimulator%", "category": "%deviceSimulatorExpressExtension.commands.common.label%" }, + { + "command": "deviceSimulatorExpress.common.gettingStarted", + "title": "%deviceSimulatorExpressExtension.commands.common.gettingStarted%", + "category": "%deviceSimulatorExpressExtension.commands.common.label%" + }, { "command": "deviceSimulatorExpress.cpx.deployToDevice", "title": "%deviceSimulatorExpressExtension.commands.cpx.deployToDevice%", diff --git a/package.nls.json b/package.nls.json index ad2a9ce7b..924645d32 100644 --- a/package.nls.json +++ b/package.nls.json @@ -1,19 +1,21 @@ { - "deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies", - "deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express", - "deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator", - "deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate", - "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", - "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", - "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", - "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.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.commands.common.installDependencies": "Install Extension Dependencies", + "deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express", + "deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator", + "deviceSimulatorExpressExtension.commands.common.gettingStarted": "Getting Started", + + "deviceSimulatorExpressExtension.commands.common.changeBaudRate": "Change Baud Rate", + "deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor", + "deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor", + "deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port", + "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.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." } diff --git a/src/constants.ts b/src/constants.ts index fa4e3e1e0..b66330e55 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -25,6 +25,10 @@ export const CONFIG = { }; export const CONSTANTS = { + WEBVIEW_TYPE: { + SIMULATOR: "simulator", + TUTORIAL: "tutorial", + }, DEBUG_CONFIGURATION_TYPE: "deviceSimulatorExpress", DEVICE_NAME: { CPX: "CPX", @@ -320,6 +324,7 @@ export enum TelemetryEventName { COMMAND_SERIAL_MONITOR_OPEN = "COMMAND.SERIAL_MONITOR.OPEN", COMMAND_SERIAL_MONITOR_BAUD_RATE = "COMMAND.SERIAL_MONITOR.BAUD_RATE", COMMAND_SERIAL_MONITOR_CLOSE = "COMMAND.SERIAL_MONITOR.CLOSE", + COMMAND_GETTING_STARTED = "COMMAND.GETTING_STARTED", CPX_COMMAND_DEPLOY_DEVICE = "CPX.COMMAND.DEPLOY.DEVICE", CPX_COMMAND_NEW_FILE = "CPX.COMMAND.NEW.FILE.CPX", diff --git a/src/extension.ts b/src/extension.ts index 2098041b7..d555a0826 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -35,7 +35,12 @@ import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurati import getPackageInfo from "./telemetry/getPackageInfo"; import TelemetryAI from "./telemetry/telemetryAI"; import { UsbDetector } from "./usbDetector"; -import { VSCODE_MESSAGES_TO_WEBVIEW, WEBVIEW_MESSAGES } from "./view/constants"; +import { + VSCODE_MESSAGES_TO_WEBVIEW, + WEBVIEW_MESSAGES, + WEBVIEW_TYPES, +} from "./view/constants"; +import { WebviewService } from "./service/webviewService"; let telemetryAI: TelemetryAI; let pythonExecutablePath: string = GLOBAL_ENV_VARS.PYTHON; @@ -53,14 +58,6 @@ const fileSelectionService = new FileSelectionService(messagingService); export let outChannel: vscode.OutputChannel | undefined; -function loadScript(context: vscode.ExtensionContext, scriptPath: string) { - return ``; -} - const sendCurrentDeviceMessage = (currentPanel: vscode.WebviewPanel) => { if (currentPanel) { currentPanel.webview.postMessage({ @@ -71,14 +68,13 @@ const sendCurrentDeviceMessage = (currentPanel: vscode.WebviewPanel) => { }; // Extension activation export async function activate(context: vscode.ExtensionContext) { - console.info(CONSTANTS.INFO.EXTENSION_ACTIVATED); - telemetryAI = new TelemetryAI(context); setupService = new SetupService(telemetryAI); let currentPanel: vscode.WebviewPanel | undefined; let childProcess: cp.ChildProcess | undefined; let messageListener: vscode.Disposable; let activeEditorListener: vscode.Disposable; + const webviewService = new WebviewService(context, deviceSelectionService); // Add our library path to settings.json for autocomplete functionality updatePythonExtraPaths(); @@ -130,7 +126,7 @@ export async function activate(context: vscode.ExtensionContext) { currentPanel.reveal(vscode.ViewColumn.Beside); } else { currentPanel = vscode.window.createWebviewPanel( - "adafruitSimulator", + CONSTANTS.WEBVIEW_TYPE.SIMULATOR, CONSTANTS.LABEL.WEBVIEW_PANEL, { preserveFocus: true, viewColumn: vscode.ViewColumn.Beside }, { @@ -147,7 +143,10 @@ export async function activate(context: vscode.ExtensionContext) { } ); - currentPanel.webview.html = getWebviewContent(context); + currentPanel.webview.html = webviewService.getWebviewContent( + WEBVIEW_TYPES.SIMULATOR, + true + ); messagingService.setWebview(currentPanel.webview); if (messageListener !== undefined) { @@ -303,6 +302,16 @@ export async function activate(context: vscode.ExtensionContext) { openWebview(); }; + const gettingStartedOpen: vscode.Disposable = vscode.commands.registerCommand( + "deviceSimulatorExpress.common.gettingStarted", + () => { + telemetryAI.trackFeatureUsage( + TelemetryEventName.COMMAND_GETTING_STARTED + ); + webviewService.openTutorialPanel(); + } + ); + // Open Simulator on the webview const cpxOpenSimulator: vscode.Disposable = vscode.commands.registerCommand( "deviceSimulatorExpress.cpx.openSimulator", @@ -1059,6 +1068,7 @@ export async function activate(context: vscode.ExtensionContext) { microbitOpenSimulator, microbitNewFile, microbitDeployToDevice, + gettingStartedOpen, vscode.debug.registerDebugConfigurationProvider( CONSTANTS.DEBUG_CONFIGURATION_TYPE, simulatorDebugConfiguration @@ -1321,27 +1331,6 @@ const updateConfigLists = ( .update(section, Array.from(extraItemsSet), scope); }; -function getWebviewContent(context: vscode.ExtensionContext) { - return ` - -
- - - -+ from microbit import * ++ +
+ display.show(Image.HEART) ++ +
+ while True: ++
+ if button_a.is_pressed(): ++
+ display.show(Image.HAPPY) ++
+ if button_b.is_pressed(): ++
+ display.show(Image.SAD) ++ +
+ while True: ++
+ temp = temperature() ++
+ display.show(temp) ++ +
+ from adafruit_circuitplayground import cp ++ +
+ while True: ++
+ cp.red_led = True ++ +
+ while True: ++
+ if cp.button_a: ++
+ cp.red_led = True ++ +
+ cp.pixels[0] = (0, 0, 255) ++ +
from microbit import *+ +
display.show(Image.HEART)+ +
while True:+
if button_a.is_pressed():+
display.show(Image.HAPPY)+
if button_b.is_pressed():+
display.show(Image.SAD)+ +
while True:+
temp = temperature()+
display.show(temp)+ +
from adafruit_circuitplayground import cp+ +
while True:+
cp.red_led = True+ +
while True:+
if cp.button_a:+
cp.red_led = True+ +
cp.pixels[0] = (0, 0, 255)+ +