mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Fix stepping.
Move stepping logic into App. Change toggleBakeButtonFunction to use a str instead of booleans. Tidy up handleLoaderMessage in InputWaiter.
This commit is contained in:
parent
3dc57c4a4a
commit
a9f8dac656
5 changed files with 77 additions and 55 deletions
|
@ -166,6 +166,34 @@ class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the next step of the recipe.
|
||||||
|
*/
|
||||||
|
step() {
|
||||||
|
if (this.baking) return;
|
||||||
|
|
||||||
|
// Reset status using cancelBake
|
||||||
|
this.manager.worker.cancelBake(true, false);
|
||||||
|
|
||||||
|
const activeTab = this.manager.tabs.getActiveInputTab();
|
||||||
|
if (activeTab === -1) return;
|
||||||
|
|
||||||
|
let progress = 0;
|
||||||
|
if (this.manager.output.outputs[activeTab].progress !== false) {
|
||||||
|
log.error(this.manager.output.outputs[activeTab]);
|
||||||
|
progress = this.manager.output.outputs[activeTab].progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.manager.input.inputWorker.postMessage({
|
||||||
|
action: "step",
|
||||||
|
data: {
|
||||||
|
activeTab: activeTab,
|
||||||
|
progress: progress + 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a silent bake, forcing the browser to load and cache all the relevant JavaScript code needed
|
* Runs a silent bake, forcing the browser to load and cache all the relevant JavaScript code needed
|
||||||
* to do a real bake.
|
* to do a real bake.
|
||||||
|
|
|
@ -68,23 +68,8 @@ class ControlsWaiter {
|
||||||
/**
|
/**
|
||||||
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
||||||
*/
|
*/
|
||||||
async stepClick() {
|
stepClick() {
|
||||||
if (this.app.baking) return;
|
this.app.step();
|
||||||
// Reset status using cancelBake
|
|
||||||
this.manager.worker.cancelBake(true, false);
|
|
||||||
const activeTab = this.manager.tabs.getActiveInputTab();
|
|
||||||
let progress = 0;
|
|
||||||
if (this.manager.output.outputs[activeTab].progress !== false) {
|
|
||||||
progress = this.manager.output.outputs[activeTab].progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.manager.input.inputWorker.postMessage({
|
|
||||||
action: "step",
|
|
||||||
data: {
|
|
||||||
activeTab: activeTab,
|
|
||||||
progress: progress + 1
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,30 +379,32 @@ ${navigator.userAgent}
|
||||||
/**
|
/**
|
||||||
* Switches the Bake button between 'Bake', 'Cancel' and 'Loading' functions.
|
* Switches the Bake button between 'Bake', 'Cancel' and 'Loading' functions.
|
||||||
*
|
*
|
||||||
* @param {boolean} cancel - Whether to change to cancel or not
|
* @param {string} func - The function to change to. Either "cancel", "loading" or "bake"
|
||||||
* @param {boolean} loading - Whether to change to loading or not
|
|
||||||
*/
|
*/
|
||||||
toggleBakeButtonFunction(cancel, loading) {
|
toggleBakeButtonFunction(func) {
|
||||||
const bakeButton = document.getElementById("bake"),
|
const bakeButton = document.getElementById("bake"),
|
||||||
btnText = bakeButton.querySelector("span");
|
btnText = bakeButton.querySelector("span");
|
||||||
|
|
||||||
if (cancel) {
|
switch (func) {
|
||||||
btnText.innerText = "Cancel";
|
case "cancel":
|
||||||
bakeButton.classList.remove("btn-success");
|
btnText.innerText = "Cancel";
|
||||||
bakeButton.classList.remove("btn-warning");
|
bakeButton.classList.remove("btn-success");
|
||||||
bakeButton.classList.add("btn-danger");
|
bakeButton.classList.remove("btn-warning");
|
||||||
} else if (loading) {
|
bakeButton.classList.add("btn-danger");
|
||||||
bakeButton.style.background = "";
|
break;
|
||||||
btnText.innerText = "Loading...";
|
case "loading":
|
||||||
bakeButton.classList.remove("btn-success");
|
bakeButton.style.background = "";
|
||||||
bakeButton.classList.remove("btn-danger");
|
btnText.innerText = "Loading...";
|
||||||
bakeButton.classList.add("btn-warning");
|
bakeButton.classList.remove("btn-success");
|
||||||
} else {
|
bakeButton.classList.remove("btn-danger");
|
||||||
bakeButton.style.background = "";
|
bakeButton.classList.add("btn-warning");
|
||||||
btnText.innerText = "Bake!";
|
break;
|
||||||
bakeButton.classList.remove("btn-danger");
|
default:
|
||||||
bakeButton.classList.remove("btn-warning");
|
bakeButton.style.background = "";
|
||||||
bakeButton.classList.add("btn-success");
|
btnText.innerText = "Bake!";
|
||||||
|
bakeButton.classList.remove("btn-danger");
|
||||||
|
bakeButton.classList.remove("btn-warning");
|
||||||
|
bakeButton.classList.add("btn-success");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ class InputWaiter {
|
||||||
this.maxWorkers = 1;
|
this.maxWorkers = 1;
|
||||||
if (navigator.hardwareConcurrency !== undefined &&
|
if (navigator.hardwareConcurrency !== undefined &&
|
||||||
navigator.hardwareConcurrency > 1) {
|
navigator.hardwareConcurrency > 1) {
|
||||||
|
// Subtract 1 from hardwareConcurrency value to avoid using
|
||||||
|
// the entire available resources
|
||||||
this.maxWorkers = navigator.hardwareConcurrency - 1;
|
this.maxWorkers = navigator.hardwareConcurrency - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,17 +225,11 @@ class InputWaiter {
|
||||||
this.manager.tabs.updateInputTabProgress(r.inputNum, 100, 100);
|
this.manager.tabs.updateInputTabProgress(r.inputNum, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.hasOwnProperty("fileBuffer")) {
|
const transferable = r.hasOwnProperty("fileBuffer") ? [r.fileBuffer] : undefined;
|
||||||
this.inputWorker.postMessage({
|
this.inputWorker.postMessage({
|
||||||
action: "loaderWorkerMessage",
|
action: "loaderWorkerMessage",
|
||||||
data: r
|
data: r
|
||||||
}, [r.fileBuffer]);
|
}, transferable);
|
||||||
} else {
|
|
||||||
this.inputWorker.postMessage({
|
|
||||||
action: "loaderWorkerMessage",
|
|
||||||
data: r
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,7 +314,7 @@ class InputWaiter {
|
||||||
*/
|
*/
|
||||||
bakeAll() {
|
bakeAll() {
|
||||||
this.app.progress = 0;
|
this.app.progress = 0;
|
||||||
this.manager.controls.toggleBakeButtonFunction(false, true);
|
this.manager.controls.toggleBakeButtonFunction("loading");
|
||||||
this.inputWorker.postMessage({
|
this.inputWorker.postMessage({
|
||||||
action: "bakeAll"
|
action: "bakeAll"
|
||||||
});
|
});
|
||||||
|
|
|
@ -233,7 +233,9 @@ class OutputWaiter {
|
||||||
if (!this.outputExists(inputNum)) return;
|
if (!this.outputExists(inputNum)) return;
|
||||||
this.outputs[inputNum].progress = progress;
|
this.outputs[inputNum].progress = progress;
|
||||||
|
|
||||||
this.manager.tabs.updateOutputTabProgress(inputNum, progress, total);
|
if (progress !== false) {
|
||||||
|
this.manager.tabs.updateOutputTabProgress(inputNum, progress, total);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,7 @@ class WorkerWaiter {
|
||||||
} else {
|
} else {
|
||||||
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
|
this.updateOutput(r.data, r.data.inputNum, r.data.bakeId, r.data.progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.progress = r.data.progress;
|
this.app.progress = r.data.progress;
|
||||||
|
|
||||||
if (r.data.progress === this.recipeConfig.length) {
|
if (r.data.progress === this.recipeConfig.length) {
|
||||||
|
@ -258,11 +259,16 @@ class WorkerWaiter {
|
||||||
if (progress === this.recipeConfig.length) {
|
if (progress === this.recipeConfig.length) {
|
||||||
progress = false;
|
progress = false;
|
||||||
}
|
}
|
||||||
this.manager.output.updateOutputProgress(progress, inputNum);
|
this.manager.output.updateOutputProgress(progress, this.recipeConfig.length, inputNum);
|
||||||
this.manager.output.updateOutputValue(data, inputNum, false);
|
this.manager.output.updateOutputValue(data, inputNum, false);
|
||||||
|
|
||||||
if (progress !== false) {
|
if (progress !== false) {
|
||||||
this.manager.output.updateOutputStatus("error", inputNum);
|
this.manager.output.updateOutputStatus("error", inputNum);
|
||||||
|
|
||||||
|
if (inputNum === this.manager.tabs.getActiveInputTab()) {
|
||||||
|
this.manager.recipe.updateBreakpointIndicator(progress);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.manager.output.updateOutputStatus("baked", inputNum);
|
this.manager.output.updateOutputStatus("baked", inputNum);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +281,7 @@ class WorkerWaiter {
|
||||||
*/
|
*/
|
||||||
setBakingStatus(bakingStatus) {
|
setBakingStatus(bakingStatus) {
|
||||||
this.app.baking = bakingStatus;
|
this.app.baking = bakingStatus;
|
||||||
this.manager.controls.toggleBakeButtonFunction(bakingStatus);
|
this.manager.controls.toggleBakeButtonFunction(bakingStatus ? "cancel" : "bake");
|
||||||
|
|
||||||
if (bakingStatus) this.manager.output.hideMagicButton();
|
if (bakingStatus) this.manager.output.hideMagicButton();
|
||||||
}
|
}
|
||||||
|
@ -403,6 +409,7 @@ class WorkerWaiter {
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("bake-info").style.display = "none";
|
document.getElementById("bake-info").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("bake").style.background = "";
|
document.getElementById("bake").style.background = "";
|
||||||
this.totalOutputs = 0; // Reset for next time
|
this.totalOutputs = 0; // Reset for next time
|
||||||
log.debug("--- Bake complete ---");
|
log.debug("--- Bake complete ---");
|
||||||
|
@ -431,9 +438,11 @@ class WorkerWaiter {
|
||||||
|
|
||||||
if (this.step) {
|
if (this.step) {
|
||||||
// Remove all breakpoints from the recipe up to progress
|
// Remove all breakpoints from the recipe up to progress
|
||||||
for (let i = 0; i < this.app.progress; i++) {
|
if (nextInput.progress !== false) {
|
||||||
if (recipeConfig[i].hasOwnProperty("breakpoint")) {
|
for (let i = 0; i < nextInput.progress; i++) {
|
||||||
delete recipeConfig[i].breakpoint;
|
if (recipeConfig[i].hasOwnProperty("breakpoint")) {
|
||||||
|
delete recipeConfig[i].breakpoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue