Reload UXP Panel when reopened?

Is there a way to automatically reload the panel when the panel window is closed and reopened?

location.reload(); works from a button to reset the panel. However, I would like to run this automatically whenever the panel is closed and reopened.

Not sure if this will do what you want.

//Determine if the panel is open or closed
document.addEventListener(‘uxpcommand’, (event) => {
const { commandId } = event
if (commandId === ‘uxpshowpanel’) {
console.log(“panel is showing”);
showAlert(“Open”)
} else if (commandId === ‘uxphidepanel’) {
console.log(‘panel is hiding’);
}
})

Maybe. What document did you find that in? I searched through the docs but didn’t see that.

I found it in the Guides How To…

https://www.adobe.io/photoshop/uxp/guides/how-to/

Thanks, I must have overlooked it in that document. I applied it like this and works exactly as I want it to. I like having the choice for the panel to stay persistent or to reload like this. With CEP, the panels always will reset. There are good use cases for each.

addEventListener('uxpcommand', (event) => {
const { commandId } = event;
if (commandId === 'uxpshowpanel') {location.reload();}
});
3 Likes