From 7c415dc1cc2cd578f0fdafb11de18154079781b0 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Wed, 15 Feb 2023 15:29:16 -0800 Subject: [PATCH] Show warning when no boards are installed --- CHANGELOG.md | 1 + src/arduino/arduinoContentProvider.ts | 16 ++++++++++ src/views/app/actions/api.ts | 6 ++++ src/views/app/components/BoardConfig.tsx | 40 +++++++++++++++--------- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0075433b..f9ab9392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Added - [Arduino CLI](https://arduino.github.io/arduino-cli/0.30/) version 0.30.0 is now bundled with the extension [#1584](https://github.com/microsoft/vscode-arduino/pull/1584). To use the bundled version of Arduino CLI, `arduino.useArduinoCli` should be `true`, and `arduino.path` and `arduino.commandPath` should be empty or unset. Additionally, prompts will appear to switch to the bundled version whenever the legacy Arduino IDE is used or manually specified Arduino tools cannot be found. +- A warning will appear in the Board Configuration view when no boards are installed. This warning links to the Board Manager view to install boards. [#1592](https://github.com/microsoft/vscode-arduino/pull/1584) ### Changed diff --git a/src/arduino/arduinoContentProvider.ts b/src/arduino/arduinoContentProvider.ts index 1818ae9d..c29d1956 100644 --- a/src/arduino/arduinoContentProvider.ts +++ b/src/arduino/arduinoContentProvider.ts @@ -41,6 +41,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide this.addHandlerWithLogger("load-configitems", "/api/configitems", async (req, res) => await this.getBoardConfig(req, res)); this.addHandlerWithLogger("update-selectedboard", "/api/updateselectedboard", (req, res) => this.updateSelectedBoard(req, res), true); this.addHandlerWithLogger("update-config", "/api/updateconfig", async (req, res) => await this.updateConfig(req, res), true); + this.addHandlerWithLogger("run-command", "/api/runcommand", (req, res) => this.runCommand(req, res), true); // Arduino Examples TreeView this.addHandlerWithLogger("show-examplesview", "/examples", (req, res) => this.getHtmlView(req, res)); @@ -170,6 +171,21 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide } } + public async runCommand(req, res) { + if (!req.body.command) { + return res.status(400).send("BAD Request! Missing { command } parameter!"); + } else { + try { + await vscode.commands.executeCommand(req.body.command); + return res.json({ + status: "OK", + }); + } catch (error) { + return res.status(500).send(`Cannot run command with error message "${error}"`); + } + } + } + public async getLibraries(req, res) { await ArduinoContext.arduinoApp.libraryManager.loadLibraries(req.query.update === "true"); return res.json({ diff --git a/src/views/app/actions/api.ts b/src/views/app/actions/api.ts index c9ee7897..64caa61b 100644 --- a/src/views/app/actions/api.ts +++ b/src/views/app/actions/api.ts @@ -43,6 +43,12 @@ export function openSettings(query) { }).then((response) => response.json()); } +export function runCommand(command) { + return postHTTP("/api/runcommand", { + command, + }).then((response) => response.json()); +} + export function getLibraries(update) { return window.fetch(`/api/libraries?update=${update}`).then((response) => response.json()); } diff --git a/src/views/app/components/BoardConfig.tsx b/src/views/app/components/BoardConfig.tsx index 372102d3..e01c13a6 100644 --- a/src/views/app/components/BoardConfig.tsx +++ b/src/views/app/components/BoardConfig.tsx @@ -5,6 +5,7 @@ import * as React from "react"; import { Grid, Row } from "react-bootstrap"; import { connect } from "react-redux"; import * as actions from "../actions"; +import * as API from "../actions/api"; import BoardConfigItemView from "./BoardConfigItemView"; import BoardSelector from "./BoardSelector"; @@ -41,20 +42,31 @@ class BoardConfig extends React.Component> { } public render() { - return (
- - - - - { - this.props.configitems.map((configitem, index) => { - return ( - - ); - }) - } - -
); + let installWarning; + if (this.props.installedBoards.length === 0) { + installWarning = (
+ No boards are installed. API.runCommand("arduino.showBoardManager")}>Install a board with the Boards Manager. +
); + } + return ( +
+ {installWarning} +
+ + + + + { + this.props.configitems.map((configitem, index) => { + return ( + + ); + }) + } + +
+
); } }