Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Add warning about running python code in the extension #102

Merged
merged 2 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"dialogResponses.agreeAndRun": "Agree and Run",
"dialogResponses.acceptPrivacy": "Got it",
"dialogResponses.cancel": "Cancel",
"dialogResponses.dontShowAgain": "Don't Show Again",
"dialogResponses.exampleCode": "Example Code on GitHub",
"dialogResponses.help": "I need help",
Expand Down Expand Up @@ -27,5 +29,6 @@
"info.thirdPartyWebsite": "You will be redirect to adafruit.com, a website outside Microsoft. Read the privacy statement on Adafruit:",
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n",
"label.webviewPanel": "Adafruit CPX",
"name": "Pacifica Simulator"
}
"name": "Pacifica Simulator",
"warning.agreeAndRun": "By selecting ‘Agree and Run’, you understand the extension executes Python code on your local computer, which may be a potential security risk."
}
11 changes: 10 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ export const CONSTANTS = {
TUTORIALS:
"https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library"
},
NAME: localize("name", "Pacifica Simulator")
NAME: localize("name", "Pacifica Simulator"),
WARNING: {
ACCEPT_AND_RUN: localize("warning.agreeAndRun", "By selecting ‘Agree and Run’, you understand the extension executes Python code on your local computer, which may be a potential security risk."),
}
};

// Need the different events we want to track and the name of it
Expand Down Expand Up @@ -161,6 +164,12 @@ export enum WebviewMessages {

// tslint:disable-next-line: no-namespace
export namespace DialogResponses {
export const ACCEPT_AND_RUN: MessageItem = {
title: localize("dialogResponses.agreeAndRun", "Agree and Run")
};
export const CANCEL: MessageItem = {
title: localize("dialogResponses.cancel", "Cancel")
}
export const HELP: MessageItem = {
title: localize("dialogResponses.help", "I need help")
};
Expand Down
20 changes: 20 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let pythonExecutableName: string = "python";
let firstTimeClosed: boolean = true;
let shouldShowNewProject: boolean = true;
let shouldShowInvalidFileNamePopup: boolean = true;
let shouldShowRunCodePopup: boolean = true;

function loadScript(context: vscode.ExtensionContext, scriptPath: string) {
return `<script src="${vscode.Uri.file(context.asAbsolutePath(scriptPath))
Expand Down Expand Up @@ -234,6 +235,25 @@ export async function activate(context: vscode.ExtensionContext) {
};

const runSimulatorCommand = async () => {
if (shouldShowRunCodePopup) {
const shouldExitCommand = await vscode.window
.showWarningMessage(
CONSTANTS.WARNING.ACCEPT_AND_RUN,
DialogResponses.ACCEPT_AND_RUN,
DialogResponses.CANCEL
)
.then((selection: vscode.MessageItem | undefined) => {
let hasAccepted = true;
if (selection === DialogResponses.ACCEPT_AND_RUN) {
shouldShowRunCodePopup = false;
hasAccepted = false;
}
return hasAccepted;
});
// Don't run users code if they don't accept
if (shouldExitCommand) { return; }
}

openWebview();

if (!currentPanel) {
Expand Down