1

I'm currently working on integrating MacBook TouchBar on a basic Electron Project (like a Hello World :p ).

My project is very simple: I had an array of String which represent each a Directory name, I want to create a TouchBarButton for each item in the array.

But I'm facing a problem with the TouchBarButton click callback: when I touch a Button it always return me the last object from my array (items2 in my case) even if I click the first one!

Note: it works very well for the icon !

var dirs = ['item1', 'items2']
var barItems = [ ];

for(var i = 0; i < dirs.length; i++) {
  var aDir = dirs[i]
  var button = new TouchBarButton({
    icon: `${aDir}/icon.png`,
    click: () => {
      console.log(`Dir ${aDir}`) // Always return me Dir items2 even if I select the first one in the Touch Bar...
    },
  })

  barItems.push(button)
}

return new TouchBar({
  items: barItems,
});

Any help would be greatly appreciated !

iStornZ
  • 603
  • 1
  • 8
  • 19

0 Answers0