With your code, if you manage to click Cancel after exeModal and before the batchProcess is called, then it should work, because execution context then would have isCanceled as true. If you want to perform something whenever Cancel is clicked, use onCancel (again, please check the docs)
Could you elaborate the “not working” part? What happens? What do you get in console if you break on different lines? What does “returning from 2nd line only” mean? Do you get into the callback at all when you click “Cancel”?
Test what exactly? There’s nothing to close, because none of the files are opened. What do you expect from this piece of script and what do you actually get?
@Karmalakas Suppose plugin has opened one document and doing some process on it, in the meanwhile user clicked on progress bar “Cancel” button to stop the process. So, on click “Cancel” button I want to close the current active document in photoshop and stop the current plugin execution process. I tried with below code but It is not working. Unable to close the active doc and process.
async function batchProcess(ctx) {
ctx.onCancel = async() => {
await app.activeDocument.closeWithoutSaving();
console.log("done");
}
for (const file of files) {
if (ctx.isCancelled) {
return
}
await app.open(file);
await checkDocSize();
}
}