Thank you for the example. I am trying to implement this example in the front-end, inside MenuContribution, like this:
@injectable()
export class SerialMenuContribution implements MenuContribution {
@inject(CommandRegistry)
commands: CommandRegistry;
// Constructor creating instance of backend
constructor(@inject(SerialService) protected readonly serialService: SerialService) { }
readonly disposeMenuUpdate = new DisposableCollection();
async registerMenus(menus: MenuModelRegistry): Promise<void> {
const subMenuPath = [...MAIN_MENU_BAR, 'sample-menu'];
menus.registerSubmenu(subMenuPath, 'Sample Menu', {
order: '2' // that should put the menu right next to the File menu
});
// Data being fetched from the backend. Returns array of objects.
const devices = await this.serialService.getUsbDevices()
this.disposeMenuUpdate.dispose();
devices.forEach((item: any) => {
this.disposeMenuUpdate.push(this.commands.registerCommand(
{ id: item.path }, { execute: () => console.log("Hello" + item.path) }
));
menus.registerMenuAction(subMenuPath, { commandId: item.path })
this.disposeMenuUpdate.push(
Disposable.create(() => menus.unregisterMenuNode(item.path))
);
})