Skip to content

Commit

Permalink
move flash/clean to title commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 25, 2023
1 parent 132d010 commit 966a659
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
17 changes: 17 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@
"when": "view == extension.devicescript.jdom && extension.devicescript.console.data",
"group": "navigation"
},
{
"command": "extension.devicescript.device.flash",
"when": "!inDebugMode && view == extension.devicescript.jdom"
},
{
"command": "extension.devicescript.device.clean",
"when": "!inDebugMode && view == extension.devicescript.jdom"
},
{
"command": "extension.devicescript.watch.clear",
"when": "view =~ /extension\\.devicescript\\.(dbg)?watch/",
Expand Down Expand Up @@ -521,6 +529,10 @@
"command": "extension.devicescript.device.flash",
"when": "workbenchState != empty"
},
{
"command": "extension.devicescript.device.clean",
"when": "workbenchState != empty"
},
{
"command": "extension.devicescript.simulator.start",
"when": "workbenchState != empty"
Expand Down Expand Up @@ -651,6 +663,11 @@
"title": "Flash Firmware...",
"category": "DeviceScript"
},
{
"command": "extension.devicescript.device.clean",
"title": "Clean Flash...",
"category": "DeviceScript"
},
{
"command": "extension.devicescript.sims.add",
"title": "Add Sim...",
Expand Down
9 changes: 9 additions & 0 deletions vscode/src/activateDeviceScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export function activateDeviceScript(context: vscode.ExtensionContext) {
: device
)
),
vscode.commands.registerCommand(
"extension.devicescript.device.clean",
(device?: JDomDeviceTreeItem | JDDevice) =>
extensionState.cleanFirmware(
device instanceof JDomDeviceTreeItem
? device.device
: device
)
),
vscode.commands.registerCommand(
"extension.devicescript.connect",
async () => extensionState.connect()
Expand Down
58 changes: 22 additions & 36 deletions vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,16 @@ export class DeviceScriptExtensionState extends JDEventSource {
}

async cleanFirmware(device?: JDDevice) {
const board = await this.resolveBoardDefinition(device)
if (!board) return
if (
!(await showConfirmBox(
`The entire flash on ${board.devName} will be erased. There is NO undo. Confirm?`
`The entire flash will be erased. There is NO undo. Confirm?`
))
)
return

const board = await this.resolveBoardDefinition(device)
if (!board) return

// force disconnect
await this.disconnect()

Expand Down Expand Up @@ -652,7 +653,10 @@ export class DeviceScriptExtensionState extends JDEventSource {
get isRemote() {
const config = vscode.workspace.getConfiguration("devicescript.connect")
const { extensionKind } = this.context.extension
return extensionKind === vscode.ExtensionKind.Workspace || !!config.get("web")
return (
extensionKind === vscode.ExtensionKind.Workspace ||
!!config.get("web")
)
}

async connect() {
Expand All @@ -675,20 +679,19 @@ export class DeviceScriptExtensionState extends JDEventSource {
transport: "web",
label: "WebSerial/WebUSB",
detail: "ESP32, RP2040, ...",
description: "Connect through an external web page running client side."
description:
"Connect through an external web page running client side.",
})

} else {
const serial = transports.find(t => t.type === "serial")
items.push(
{
transport: "serial",
label: "Serial",
detail: "ESP32, RP2040, ...",
description: serial
? `${serial.description || ""}(${serial.connectionState})`
: "",
})
items.push({
transport: "serial",
label: "Serial",
detail: "ESP32, RP2040, ...",
description: serial
? `${serial.description || ""}(${serial.connectionState})`
: "",
})
}
items.push(
!!connecteds.length && {
Expand All @@ -707,20 +710,6 @@ export class DeviceScriptExtensionState extends JDEventSource {
description: `Simulator`,
detail: `A virtual DeviceScript interpreter running in a separate process.`,
transport: simulatorScriptManagerId,
},
{
label: "Firmware Tools",
kind: vscode.QuickPickItemKind.Separator,
},
{
label: "Flash Firmware...",
transport: "flash",
detail: "Flash the DeviceScript runtime on new devices.",
},
{
label: "Clean Flash...",
transport: "clean",
detail: "Erase the entire flash.",
}
)
items = items.filter(m => !!m)
Expand All @@ -730,8 +719,6 @@ export class DeviceScriptExtensionState extends JDEventSource {
if (res === undefined || !res.transport) return

if (res.transport === "web") await this.openExternalConnect()
else if (res.transport === "flash") await this.flashFirmware()
else if (res.transport === "clean") await this.cleanFirmware()
else if (res.transport === simulatorScriptManagerId)
await this.startSimulator()
else
Expand All @@ -747,9 +734,7 @@ export class DeviceScriptExtensionState extends JDEventSource {

private async openExternalConnect() {
const darkMode = resolveDarkMode()
const connectUri = await resolveDevtoolsPath(
`connect?${darkMode}=1`
)
const connectUri = await resolveDevtoolsPath(`connect?${darkMode}=1`)
console.log({ connectUri })
await vscode.env.openExternal(connectUri)
}
Expand Down Expand Up @@ -900,8 +885,9 @@ export class DeviceScriptExtensionState extends JDEventSource {
.register(ControlReg.DeviceDescription)
await description.refresh(true)

return `${description.stringValue || ""} (${runtimeVersion || "?"
})`
return `${description.stringValue || ""} (${
runtimeVersion || "?"
})`
}
const items: DeviceQuickItem[] = await Promise.all(
services.map(
Expand Down

0 comments on commit 966a659

Please sign in to comment.