Skip to content

Commit

Permalink
Add provision button to serial view (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
lask authored Jun 17, 2021
1 parent 7d2d7ef commit e49f95b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
},
{
"command": "toit.serialProvision",
"title": "Provision a device connected via serial",
"title": "Provision",
"category": "Toit",
"icon": "$(add)",
"enablement": "toit.extensionActive"
},
{
Expand Down Expand Up @@ -142,6 +143,11 @@
}
],
"view/item/context": [
{
"command": "toit.serialProvision",
"when": "view == toitSerialView && viewItem == serial-port",
"group": "inline"
},
{
"command": "toit.uninstallApp",
"when": "view == toitDeviceView && viewItem == application",
Expand Down
1 change: 1 addition & 0 deletions vscode/src/serialPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DeviceInfo } from "./device";

export class SerialPort extends TreeItem {
iconPath = new ThemeIcon("plug");
contextValue = "serial-port";
name: string;
constructor(port: string) {
super(port, TreeItemCollapsibleState.Collapsed);
Expand Down
7 changes: 4 additions & 3 deletions vscode/src/toitProvision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
// found in the LICENSE file.

import { window as Window } from "vscode";
import { SerialPort } from "./serialPort";
import { Context, ensureAuth, promptForWiFiInfo, selectPort, WiFiInfo } from "./utils";

async function serialMonitor(ctx: Context) {
async function serialMonitor(ctx: Context, serialPort?: SerialPort) {
try {
await ensureAuth(ctx);
} catch (e) {
return Window.showErrorMessage(`Login failed: ${e.message}.`);
}

try {
const port = await selectPort(ctx);
const port = serialPort ? SerialPort.name : await selectPort(ctx);
const wifiInfo: WiFiInfo = await promptForWiFiInfo();
const terminal = ctx.serialTerminal(port);
terminal.show();
Expand All @@ -25,5 +26,5 @@ async function serialMonitor(ctx: Context) {
}

export function createSerialProvision(ctx: Context): () => void {
return () => serialMonitor(ctx);
return (port?: SerialPort) => serialMonitor(ctx, port);
}

0 comments on commit e49f95b

Please sign in to comment.