Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3d52299
Initialize a webview service
xnkevinnguyen Mar 9, 2020
f49c8e9
Add command for getting started
xnkevinnguyen Mar 9, 2020
c9bf221
Initialize html page for getting started
xnkevinnguyen Mar 13, 2020
59a39db
Merge branch 'dev' into users/t-xunguy/getting-started
xnkevinnguyen Mar 13, 2020
e4cfd3c
Add placeholder content
xnkevinnguyen Mar 13, 2020
86fc862
Complete tutorials for microbit
xnkevinnguyen Mar 13, 2020
9f93e5e
Complete tutorial for cpx
xnkevinnguyen Mar 13, 2020
412d3f2
Merge branch 'dev' into users/t-xunguy/getting-started
xnkevinnguyen Mar 18, 2020
12746e5
Update webview service
xnkevinnguyen Mar 18, 2020
ccddc67
Merge branch 'users/t-xunguy/getting-started' of https://github.com/m…
xnkevinnguyen Mar 18, 2020
688d698
Working webview service for getting started type
xnkevinnguyen Mar 19, 2020
11d8119
Load entire getting started from react
xnkevinnguyen Mar 19, 2020
2d9459f
Remove inconsistency cpx microbit getting started
xnkevinnguyen Mar 19, 2020
74f0d54
Add tests for getting started
xnkevinnguyen Mar 19, 2020
0195172
Merge branch 'dev' into users/t-xunguy/getting-started
xnkevinnguyen Mar 19, 2020
db00df7
Update with dev
xnkevinnguyen Mar 19, 2020
56c4afd
Align left the getting started
xnkevinnguyen Mar 19, 2020
3d9f2b2
Format files
xnkevinnguyen Mar 19, 2020
f028216
Update ui tests
xnkevinnguyen Mar 19, 2020
ac940ff
Remove deleted ressources import
xnkevinnguyen Mar 19, 2020
3a20712
Update with dev
xnkevinnguyen Mar 19, 2020
602ec9b
update tests
xnkevinnguyen Mar 19, 2020
4ad66da
Feedback for additional copy instruction
xnkevinnguyen Mar 19, 2020
61f0a11
Merge branch 'dev' into users/t-xunguy/getting-started
xnkevinnguyen Mar 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
@@ -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."
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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%",
Expand Down
36 changes: 19 additions & 17 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -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."
}
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const CONFIG = {
};

export const CONSTANTS = {
WEBVIEW_TYPE: {
SIMULATOR: "simulator",
TUTORIAL: "tutorial",
},
DEBUG_CONFIGURATION_TYPE: "deviceSimulatorExpress",
DEVICE_NAME: {
CPX: "CPX",
Expand Down Expand Up @@ -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",
Expand Down
57 changes: 23 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,14 +58,6 @@ const fileSelectionService = new FileSelectionService(messagingService);

export let outChannel: vscode.OutputChannel | undefined;

function loadScript(context: vscode.ExtensionContext, scriptPath: string) {
return `<script initialDevice=${deviceSelectionService.getCurrentActiveDevice()} src="${vscode.Uri.file(
context.asAbsolutePath(scriptPath)
)
.with({ scheme: "vscode-resource" })
.toString()}"></script>`;
}

const sendCurrentDeviceMessage = (currentPanel: vscode.WebviewPanel) => {
if (currentPanel) {
currentPanel.webview.postMessage({
Expand All @@ -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();
Expand Down Expand Up @@ -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 },
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1059,6 +1068,7 @@ export async function activate(context: vscode.ExtensionContext) {
microbitOpenSimulator,
microbitNewFile,
microbitDeployToDevice,
gettingStartedOpen,
vscode.debug.registerDebugConfigurationProvider(
CONSTANTS.DEBUG_CONFIGURATION_TYPE,
simulatorDebugConfiguration
Expand Down Expand Up @@ -1321,27 +1331,6 @@ const updateConfigLists = (
.update(section, Array.from(extraItemsSet), scope);
};

function getWebviewContent(context: vscode.ExtensionContext) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>${CONSTANTS.NAME}</title>
</head>
<body>
<div id="root"></div>
<script >
const vscode = acquireVsCodeApi();
</script>
<script ></script>
${loadScript(context, "out/vendor.js")}
${loadScript(context, "out/simulator.js")}
</body>
</html>`;
}

// this method is called when your extension is deactivated
export async function deactivate() {
const monitor: SerialMonitor = SerialMonitor.getInstance();
Expand Down
104 changes: 104 additions & 0 deletions src/service/webviewService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import * as path from "path";
import * as vscode from "vscode";
import CONSTANTS from "../constants";
import { WEBVIEW_ATTRIBUTES_KEY, WEBVIEW_TYPES } from "../view/constants";
import { DeviceSelectionService } from "./deviceSelectionService";

// Manages different type of webview
export class WebviewService {
private tutorialPanel: vscode.WebviewPanel | undefined;
private context: vscode.ExtensionContext;
private deviceSelectionService: DeviceSelectionService;

constructor(
context: vscode.ExtensionContext,
deviceSelectionService: DeviceSelectionService
) {
this.context = context;
this.deviceSelectionService = deviceSelectionService;
}

public openTutorialPanel() {
if (this.tutorialPanel) {
this.tutorialPanel.reveal(vscode.ViewColumn.Beside);
} else {
this.createTutorialPanel();
}
}

public getWebviewContent(webviewType: string, hasDevice: boolean) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>${CONSTANTS.NAME}</title>
</head>
<body>
<div id="root"></div>
<script >
const vscode = acquireVsCodeApi();
</script>
<script ></script>
${this.loadScript(
this.context,
webviewType,
"out/vendor.js",
hasDevice
)}
${this.loadScript(
this.context,
webviewType,
"out/simulator.js",
hasDevice
)}
</body>
</html>`;
}

private createTutorialPanel() {
this.tutorialPanel = vscode.window.createWebviewPanel(
CONSTANTS.WEBVIEW_TYPE.TUTORIAL,
CONSTANTS.LABEL.WEBVIEW_PANEL,
{ preserveFocus: true, viewColumn: vscode.ViewColumn.One },
{
enableScripts: true,
}
);
this.tutorialPanel.webview.html = this.getWebviewContent(
WEBVIEW_TYPES.GETTING_STARTED,
false
);
this.tutorialPanel.onDidDispose(() => {
this.disposeTutorialPanel();
});
}

private disposeTutorialPanel() {
this.tutorialPanel = undefined;
}

private loadScript(
context: vscode.ExtensionContext,
attributeValue: string,
scriptPath: string,
hasDevice: boolean
) {
let attributeString: string;
if (hasDevice) {
attributeString = `${
WEBVIEW_ATTRIBUTES_KEY.TYPE
}=${attributeValue} ${
WEBVIEW_ATTRIBUTES_KEY.INITIAL_DEVICE
}=${this.deviceSelectionService.getCurrentActiveDevice()}`;
} else {
attributeString = `${WEBVIEW_ATTRIBUTES_KEY.TYPE}=${attributeValue} `;
}
return `<script ${attributeString} src="${vscode.Uri.file(
context.asAbsolutePath(scriptPath)
)
.with({ scheme: "vscode-resource" })
.toString()}"></script>`;
}
}
Loading