diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 445d16d9..77204b9e 100644 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -50,7 +50,6 @@ class InputWaiter { this.workerId = 0; this.maxWorkers = navigator.hardwareConcurrency || 4; this.maxTabs = 4; - this.inputTimeout = null; this.callbacks = {}; this.callbackID = 0; } @@ -292,6 +291,7 @@ class InputWaiter { this.manager.output.inputSwitch(r.data); break; case "getInput": + case "getInputNums": this.callbacks[r.data.id](r.data); break; case "removeChefWorker": @@ -576,6 +576,39 @@ class InputWaiter { }); } + /** + * Gets the number of inputs from the inputWorker + * + * @returns {object} + */ + async getInputNums() { + return await new Promise(resolve => { + this.getNums(r => { + resolve({ + inputNums: r.inputNums, + min: r.min, + max: r.max + }); + }); + }); + } + + /** + * Gets a list of inputNums from the inputWorker, and sends + * them back to the specified callback + */ + getNums(callback) { + const id = this.callbackID++; + + this.callbacks[id] = callback; + + this.inputWorker.postMessage({ + action: "getInputNums", + data: id + }); + } + + /** * Displays information about the input. * @@ -1346,8 +1379,9 @@ class InputWaiter { /** * Handler for go to tab button clicked */ - goToTab() { - const tabNum = parseInt(window.prompt("Enter tab number:", this.getActiveTab().toString()), 10); + async goToTab() { + const inputNums = await this.getInputNums(); + const tabNum = parseInt(window.prompt(`Enter tab number (${inputNums.min} - ${inputNums.max}):`, this.getActiveTab().toString()), 10); this.changeTab(tabNum, this.app.options.syncTabs); } diff --git a/src/web/InputWorker.mjs b/src/web/InputWorker.mjs index 51d5f4f2..1044ed80 100644 --- a/src/web/InputWorker.mjs +++ b/src/web/InputWorker.mjs @@ -105,6 +105,9 @@ self.addEventListener("message", function(e) { case "getInput": self.getInput(r.data); break; + case "getInputNums": + self.getInputNums(r.data); + break; default: log.error(`Unknown action '${r.action}'.`); } @@ -250,23 +253,36 @@ self.getInputValue = function(inputNum) { * @param {number} inputData.id - The callback ID for the callback to run when returned to the inputWaiter */ self.getInput = function(inputData) { - if (inputData.getObj) { - self.postMessage({ - action: "getInput", - data: { - data: self.getInputObj(inputData.inputNum), - id: inputData.id - } - }); - } else { - self.postMessage({ - action: "getInput", - data: { - data: self.getInputValue(inputData.inputNum), - id: inputData.id - } - }); - } + const inputNum = inputData.inputNum, + data = (inputData.getObj) ? self.getInputObj(inputNum) : self.getInputValue(inputNum); + self.postMessage({ + action: "getInput", + data: { + data: data, + id: inputData.id + } + }); +}; + +/** + * Gets a list of the stored inputNums, along with the minimum and maximum + * + * @param {number} id - The callback ID to be executed when returned to the inputWaiter + */ +self.getInputNums = function(id) { + const inputNums = Object.keys(self.inputs), + min = self.getSmallestInputNum(inputNums), + max = self.getLargestInputNum(inputNums); + + self.postMessage({ + action: "getInputNums", + data: { + inputNums: inputNums, + min: min, + max: max, + id: id + } + }); }; /**