Hi everybody
I’m not able to use executionContext.isCancelled to grab the user cancellation (ESC key) happening while executing a function
This is the code, any suggestion ?
const suspendHistory = async (theSuspendName, functionName) => {
async function doStuff(executionContext){
let hostControl = executionContext.hostControl;
let documentID = await app.activeDocument._id;
// Suspend history state on the target document
let suspensionID = await hostControl.suspendHistory({
"historyStateInfo": {
"name": theSuspendName,
"target": [ {_ref: "document", _id: documentID}]
}
});
await core.executeAsModal(functionName);
if (executionContext.isCancelled) {
console.log("TEST User has pressed ESC")
return
}
await hostControl.resumeHistory(suspensionID);
};
await core.executeAsModal(doStuff, {"commandName" : children });
};
const clickHandler = async () => {
let historyName = "PS_FLOW: " + t(children);
await suspendHistory(historyName, FunctionToBeExecuted);
}
Instead it works if executionContext.isCancelled is inserted inside a loop
similar to the example present in the Adobe documentation
[https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/executeasmodal/](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/executeasmodal/)
but obviously I don't need to repeatedly execute the same function until the user presses ESC !
const suspendHistory = async (theSuspendName, functionName) => {
async function doStuff(executionContext){
let hostControl = executionContext.hostControl;
let documentID = await app.activeDocument._id;
// Suspend history state on the target document
let suspensionID = await hostControl.suspendHistory({
"historyStateInfo": {
"name": theSuspendName,
"target": [ {_ref: "document", _id: documentID}]
}
});
await core.executeAsModal(functionName);
while (true) {
await core.executeAsModal(functionName);
if (executionContext.isCancelled) {
app.showAlert("TEST User has pressed ESC")
break
}
}
await hostControl.resumeHistory(suspensionID);
};
await core.executeAsModal(doStuff, {"commandName" : children });
};
const clickHandler = async () => {
let historyName = "PS_FLOW: " + t(children);
await suspendHistory(historyName, FunctionToBeExecuted);
}