Skip to content

Commit

Permalink
Add feature to be able to set a device as the current active device v…
Browse files Browse the repository at this point in the history
…ia the Deive tree view. (#597)

Also added command to clear the active device.

Co-authored-by: Bronley Plumb <[email protected]>
  • Loading branch information
spoyser and TwitchBronBron authored Oct 2, 2024
1 parent 657ae24 commit 923a317
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,12 @@
"description": "Clear the BrightScript extension's global state.",
"category": "Brightscript"
},
{
"command": "extension.brightscript.clearActiveDevice",
"title": "Clear Active Device",
"description": "Clear the BrightScript extension's active device.",
"category": "Brightscript"
},
{
"command": "extension.brightscript.toggleXML",
"title": "Toggle XML/BRS",
Expand Down
17 changes: 17 additions & 0 deletions src/BrightScriptCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ export class BrightScriptCommands {
}
});

this.registerCommand('setActiveDevice', async (device: string) => {
if (!device) {
device = await this.userInputManager.promptForHost();
}
if (!device) {
throw new Error('Tried to set active device but failed.');
} else {
await this.context.workspaceState.update('remoteHost', device);
await vscode.window.showInformationMessage(`BrightScript Language extension active device set to: ${device}`);
}
});

this.registerCommand('clearActiveDevice', async () => {
await this.context.workspaceState.update('remoteHost', '');
await vscode.window.showInformationMessage('BrightScript Language extension active device cleared');
});

this.registerCommand('showReleaseNotes', () => {
this.whatsNewManager.showReleaseNotes();
});
Expand Down
14 changes: 14 additions & 0 deletions src/viewProviders/OnlineDevicesViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ export class OnlineDevicesViewProvider implements vscode.TreeDataProvider<vscode
})
);

result.unshift(
this.createDeviceInfoTreeItem({
label: '⭐ Set as Active Device',
parent: element,
collapsibleState: vscode.TreeItemCollapsibleState.None,
tooltip: 'Set as active device',
command: {
command: 'extension.brightscript.setActiveDevice',
title: 'Set Active Device',
arguments: [device.ip]
}
})
);

if (semver.satisfies(element.details['software-version'], '>=11')) {
// TODO: add ECP system hooks here in the future (like registry call, etc...)
result.unshift(
Expand Down

0 comments on commit 923a317

Please sign in to comment.