mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 14:11:02 +01:00
Add and remove chefworkers when adding or removing inputs.
This increases the responsiveness of baking as it means we don't have to... spin up workers when bake is clicked
This commit is contained in:
parent
7528065d4d
commit
6c711ec211
@ -284,6 +284,9 @@ class InputWaiter {
|
||||
case "getInput":
|
||||
this.callbacks[r.data.id](r.data);
|
||||
break;
|
||||
case "removeChefWorker":
|
||||
this.removeChefWorker();
|
||||
break;
|
||||
default:
|
||||
log.error(`Unknown action ${r.action}.`);
|
||||
}
|
||||
@ -1200,6 +1203,17 @@ class InputWaiter {
|
||||
inputAdded(changeTab, inputNum) {
|
||||
this.addTab(inputNum, changeTab);
|
||||
this.manager.output.addOutput(inputNum, changeTab);
|
||||
|
||||
this.manager.worker.addChefWorker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a chefWorker from the workerWaiter if we remove an input
|
||||
*/
|
||||
removeChefWorker() {
|
||||
const workerIdx = this.manager.worker.getInactiveChefWorker(true);
|
||||
const worker = this.manager.worker.chefWorkers[workerIdx];
|
||||
this.manager.worker.removeChefWorker(worker);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1258,7 +1272,8 @@ class InputWaiter {
|
||||
action: "removeInput",
|
||||
data: {
|
||||
inputNum: inputNum,
|
||||
refreshTabs: refresh
|
||||
refreshTabs: refresh,
|
||||
removeChefWorker: true
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -716,7 +716,11 @@ self.loadFiles = function(filesData) {
|
||||
const inputNums = [];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (i === 0 && self.getInputValue(activeTab) === "") {
|
||||
self.removeInput(activeTab);
|
||||
self.removeInput({
|
||||
inputNum: activeTab,
|
||||
refreshTabs: false,
|
||||
removeChefWorker: false
|
||||
});
|
||||
lastInputNum = self.addInput(false, "file", {
|
||||
name: files[i].name,
|
||||
size: files[i].size.toLocaleString(),
|
||||
@ -805,6 +809,7 @@ self.addInput = function(changeTab=false, type, fileData={name: "unknown", size:
|
||||
* @param {object} removeInputData
|
||||
* @param {number} removeInputData.inputNum - The number of the input to be removed
|
||||
* @param {boolean} removeInputData.refreshTabs - If true, refresh the tabs after removing the input
|
||||
* @param {boolean} removeInputData.removeChefWorker - If true, remove a chefWorker from the WorkerWaiter
|
||||
*/
|
||||
self.removeInput = function(removeInputData) {
|
||||
const inputNum = removeInputData.inputNum;
|
||||
@ -830,13 +835,15 @@ self.removeInput = function(removeInputData) {
|
||||
|
||||
delete self.inputs[inputNum];
|
||||
|
||||
if (Object.keys(self.inputs).length === 0) {
|
||||
self.addInput(true, "string");
|
||||
}
|
||||
|
||||
if (refreshTabs) {
|
||||
self.refreshTabs(inputNum, "left");
|
||||
}
|
||||
|
||||
if (self.numInputs < self.maxWorkers && removeInputData.removeChefWorker) {
|
||||
self.postMessage({
|
||||
action: "removeChefWorker"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ class WorkerWaiter {
|
||||
const newWorkerObj = {
|
||||
worker: newWorker,
|
||||
active: false,
|
||||
inputNum: this.manager.input.getActiveTab()
|
||||
inputNum: -1
|
||||
};
|
||||
|
||||
this.chefWorkers.push(newWorkerObj);
|
||||
@ -141,6 +141,7 @@ class WorkerWaiter {
|
||||
}
|
||||
|
||||
if (this.chefWorkers.length > 1 || this.chefWorkers[index].active) {
|
||||
log.debug(`Removing ChefWorker at index ${index}`);
|
||||
this.chefWorkers[index].worker.terminate();
|
||||
this.chefWorkers.splice(index, 1);
|
||||
}
|
||||
@ -230,7 +231,6 @@ class WorkerWaiter {
|
||||
this.app.options[r.data.option] = r.data.value;
|
||||
break;
|
||||
case "setRegisters":
|
||||
// Should this update with the tabs?
|
||||
this.manager.recipe.setRegisters(r.data.opIndex, r.data.numPrevRegisters, r.data.registers);
|
||||
break;
|
||||
case "highlightsCalculated":
|
||||
|
Loading…
Reference in New Issue
Block a user