Skip to content

Commit

Permalink
Merge pull request #29 from LedgerHQ/add-target-all
Browse files Browse the repository at this point in the history
Add command to toggle selection of all available targets
  • Loading branch information
agrojean-ledger authored Jan 24, 2024
2 parents ec7d37d + 84ccdd7 commit 0dc0854
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 76 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0]

### Added

* Add "select all targets" command with a button in the main tree view.

### Changed

* Replace `.png` icons with `vscode.ThemeIcon` icons.

### Fixed

* Fix app sideload task requirements installation on macOS.

## [0.3.4]

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ This extension contributes the following settings:

## Release Notes

## 0.4.0

* Add "select all targets" command with a button in the main tree view.
* Replace `.png` icons with `vscode.ThemeIcon` icons.
* Fix app sideload task requirements installation on macOS.

## 0.3.4

* Fix section titles in README.
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ledger-dev-tools",
"displayName": "Ledger Dev Tools",
"description": "Tools to accelerate development of apps for Ledger devices.",
"version": "0.3.4",
"version": "0.4.0",
"publisher": "LedgerHQ",
"license": "Apache",
"icon": "resources/ledger-square.png",
Expand All @@ -21,6 +21,15 @@
],
"main": "./dist/extension.js",
"contributes": {
"menus":{
"view/item/context": [
{
"command": "toggleAllTargets",
"when": "view == mainView && viewItem == selectTarget && ledgerDevTools.showToggleAllTargets",
"group": "inline"
}
]
},
"taskDefinitions": [
{
"type": "ledger",
Expand Down Expand Up @@ -69,6 +78,14 @@
"category": "Ledger",
"tooltip": "Select the device you want to build your app for."
},
{
"command": "toggleAllTargets",
"title": "Toggle selection of all targets",
"category": "Ledger",
"tooltip": "Toggle selection of all compatible targets of the current app, for eligible tasks.",
"icon": "$(check-all)",
"enablement": "ledgerDevTools.showToggleAllTargets"
},
{
"command": "showAppList",
"title": "Select app",
Expand Down
Binary file removed resources/device-dark.png
Binary file not shown.
Binary file removed resources/device-light.png
Binary file not shown.
Binary file removed resources/docker-dark.png
Binary file not shown.
Binary file removed resources/docker-light.png
Binary file not shown.
Binary file removed resources/test-dark.png
Binary file not shown.
Binary file removed resources/test-light.png
Binary file not shown.
Binary file removed resources/tool-dark.png
Binary file not shown.
Binary file removed resources/tool-light.png
Binary file not shown.
30 changes: 21 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,29 @@ export function activate(context: vscode.ExtensionContext) {

let containerManager = new ContainerManager(taskProvider);

// Event listener for container status.
// This event is fired when the container status changes
context.subscriptions.push(
containerManager.onStatusEvent((data) => {
statusBarManager.updateDevImageItem(data);
treeProvider.updateContainerLabel(data);
})
);

// Event listener for target selection.
// This event is fired when the user selects a target in the targetSelector menu
context.subscriptions.push(
targetSelector.onTargetSelectedEvent((data) => {
taskProvider.generateTasks();
statusBarManager.updateTargetItem(data);
treeProvider.updateAppAndTargetLabels();
containerManager.manageContainer();
})
);

context.subscriptions.push(
vscode.commands.registerCommand("selectTarget", () => {
targetSelector.showTargetSelectorMenu(statusBarManager, taskProvider, treeProvider);
targetSelector.showTargetSelectorMenu();
})
);

Expand All @@ -56,7 +69,13 @@ export function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(
vscode.commands.registerCommand("executeTask", (taskName: string) => {
executeTaskByName(taskProvider, taskName);
taskProvider.executeTaskByName(taskName);
})
);

context.subscriptions.push(
vscode.commands.registerCommand("toggleAllTargets", (taskName: string) => {
targetSelector.toggleAllTargetSelection();
})
);

Expand Down Expand Up @@ -146,10 +165,3 @@ export async function deactivate() {
// DO STUFF
console.log(`Ledger: extension deactivated`);
}

function executeTaskByName(taskProvider: TaskProvider, taskName: string) {
const task = taskProvider.getTaskByName(taskName);
if (task) {
vscode.tasks.executeTask(task);
}
}
72 changes: 50 additions & 22 deletions src/targetSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { getSelectedApp } from "./appSelector";
// Define valid devices
const devices = ["Nano S", "Nano S Plus", "Nano X", "Stax"] as const;

const specialAllDevice = "All";

type SpecialAllDevice = typeof specialAllDevice;

// Define the LedgerDevice type
export type LedgerDevice = (typeof devices)[number];

Expand Down Expand Up @@ -44,8 +48,10 @@ export class TargetSelector {
private selectedSpeculosModel: string = "";
private selectedSDKModel: string = "";
private selectedTargetId: string = "";
private targetsArray: LedgerDevice[] = [];
private targetsArray: (LedgerDevice | SpecialAllDevice)[] = [];
private sdkModelsArray: Record<string, string> = {};
private targetSelectedEmitter: vscode.EventEmitter<string> = new vscode.EventEmitter<string>();
private prevSelectedApp: string = "";

constructor() {
const conf = vscode.workspace.getConfiguration("ledgerDevTools");
Expand All @@ -55,7 +61,7 @@ export class TargetSelector {

// Type guard function to check if a string is a valid device
private isValidDevice(value: string): value is LedgerDevice {
return devices.includes(value as LedgerDevice);
return devices.includes(value as LedgerDevice) || value === specialAllDevice;
}

public setSelectedTarget(target: string) {
Expand All @@ -66,19 +72,21 @@ export class TargetSelector {

this.selectedTarget = target;

const currentApp = getSelectedApp();
if (currentApp && !currentApp.compatibleDevices.includes(this.selectedTarget as LedgerDevice)) {
// Fallback to compatible device
this.selectedTarget = currentApp.compatibleDevices[0];
vscode.window.showWarningMessage(
`Incompatible device set for current app. Fallback to compatible device (${this.selectedTarget})`
);
if (!(this.selectedTarget === specialAllDevice)) {
const currentApp = getSelectedApp();
if (currentApp && !currentApp.compatibleDevices.includes(this.selectedTarget as LedgerDevice)) {
// Fallback to compatible device
this.selectedTarget = currentApp.compatibleDevices[0];
vscode.window.showWarningMessage(
`Incompatible device set for current app. Fallback to compatible device (${this.selectedTarget})`
);
}

this.selectedSDK = targetSDKs[this.selectedTarget];
this.selectedSpeculosModel = speculosModels[this.selectedTarget];
this.selectedSDKModel = this.sdkModelsArray[this.selectedTarget];
this.selectedTargetId = targetIds[this.selectedTarget];
}

this.selectedSDK = targetSDKs[this.selectedTarget];
this.selectedSpeculosModel = speculosModels[this.selectedTarget];
this.selectedSDKModel = this.sdkModelsArray[this.selectedTarget];
this.selectedTargetId = targetIds[this.selectedTarget];
}

// Function that updates the targets infos based on the app language
Expand All @@ -93,23 +101,39 @@ export class TargetSelector {
this.sdkModelsArray[target] =
target === "Nano S Plus" && currentApp.language === "Rust" ? "nanosplus" : sdkModels[target];
});

if (this.targetsArray.length > 1) {
vscode.commands.executeCommand("setContext", "ledgerDevTools.showToggleAllTargets", true);
} else {
vscode.commands.executeCommand("setContext", "ledgerDevTools.showToggleAllTargets", false);
}
}
}

public async showTargetSelectorMenu(
statusManager: StatusBarManager,
taskProvider: TaskProvider,
treeDataProvider: TreeDataProvider
) {
public readonly onTargetSelectedEvent: vscode.Event<string> = this.targetSelectedEmitter.event;

private triggerTargetSelectedEvent(data: string) {
this.targetSelectedEmitter.fire(data);
}

public toggleAllTargetSelection() {
if (this.selectedTarget === specialAllDevice) {
this.setSelectedTarget(this.prevSelectedApp);
} else {
this.prevSelectedApp = this.selectedTarget;
this.setSelectedTarget(specialAllDevice);
}
this.triggerTargetSelectedEvent(this.selectedTarget);
}

public async showTargetSelectorMenu() {
const result = await vscode.window.showQuickPick(this.targetsArray, {
placeHolder: "Please select a target",
onDidSelectItem: (item) => {
this.setSelectedTarget(item.toString());
this.triggerTargetSelectedEvent(item.toString());
},
});
taskProvider.generateTasks();
statusManager.updateTargetItem(this.getSelectedTarget());
treeDataProvider.updateAppAndTargetLabels();
return result;
}

Expand All @@ -136,4 +160,8 @@ export class TargetSelector {
public getSelectedTargetId() {
return this.selectedTargetId;
}

public getTargetsArray() {
return this.targetsArray;
}
}
Loading

0 comments on commit 0dc0854

Please sign in to comment.