mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: guard against duplicate TouchBarItem IDs (#22272)
* feat: Add OtherItemsProxy touchbar item * review! * fix: guard against duplicate TouchBarItem IDs * add spec
This commit is contained in:
@@ -53,6 +53,7 @@ class TouchBar extends EventEmitter {
|
||||
}
|
||||
|
||||
let hasOtherItemsProxy = false
|
||||
const idSet = new Set()
|
||||
items.forEach((item) => {
|
||||
if (!(item instanceof TouchBarItem)) {
|
||||
throw new Error('Each item must be an instance of TouchBarItem')
|
||||
@@ -65,6 +66,12 @@ class TouchBar extends EventEmitter {
|
||||
throw new Error('Must only have one OtherItemsProxy per TouchBar')
|
||||
}
|
||||
}
|
||||
|
||||
if (!idSet.has(item.id)) {
|
||||
idSet.add(item.id)
|
||||
} else {
|
||||
throw new Error('Cannot add a single instance of TouchBarItem multiple times in a TouchBar')
|
||||
}
|
||||
})
|
||||
|
||||
// register in separate loop after all items are validated
|
||||
|
||||
Reference in New Issue
Block a user