optimized filtering of found blinksticks
This commit is contained in:
parent
4aa965fece
commit
b3b123bea8
1 changed files with 8 additions and 9 deletions
|
@ -18,6 +18,14 @@ let blinksticks;
|
|||
async function findBlinkstick(index, ignoreFilter) {
|
||||
if (!global.config.blinkstick?.cache || blinksticks === undefined) {
|
||||
blinksticks = blinkstick.findAll();
|
||||
if (global.config.blinkstick?.serials?.length > 0) {
|
||||
blinksticks = blinksticks.filter((blinkstick) => {
|
||||
return global.config.blinkstick.serials.includes(blinkstick.serial);
|
||||
});
|
||||
if (blinksticks.length === 0) {
|
||||
throw new Error('could not find any blinkstick matching the defined serial(s)');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (blinksticks.length === 0) {
|
||||
throw new Error('could not find any blinkstick, make sure at least one blinkstick is connected');
|
||||
|
@ -30,15 +38,6 @@ async function findBlinkstick(index, ignoreFilter) {
|
|||
if (isNaN(index)) {
|
||||
index = 0;
|
||||
}
|
||||
if (global.config.blinkstick?.serials?.length > 0) {
|
||||
blinksticks = blinksticks.filter((blinkstick) => {
|
||||
return global.config.blinkstick.serials.includes(blinkstick.serial);
|
||||
});
|
||||
if (blinksticks.length === 0) {
|
||||
throw new Error('could not find any blinkstick matching the defined serial(s)');
|
||||
}
|
||||
}
|
||||
|
||||
if (index > blinksticks.length - 1) {
|
||||
throw new Error('there is no blinkstick for index \'' + index + '\'');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue