1
0
mirror of synced 2024-11-16 19:17:13 +01:00

Add min / max inputNums on go to tab dialog

This commit is contained in:
j433866 2019-06-04 09:36:50 +01:00
parent 2575a762e1
commit 17b95f1609
2 changed files with 70 additions and 20 deletions

View File

@ -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);
}

View File

@ -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
}
});
};
/**