Widget on Mac built with Mac Catalyst failed to load when first click on notification center. Looking for a way to run code when Mac wake up

I am building a widget on Mac with Mac Catalyst. I notice that when I put my MacBook to sleep for roughly more than 2 hours, then after I wake the MacBook up, click on notification center, my widget shows Failed to Load. Then after a few seconds I click on notification center again, my widget shows up correctly.

My widget uses data from calendar and reminder. So I expect that the widget failed to load because of the data is not available.

I am thinking if I can execute a code (from my app) after MacBook wake up, I might be able to resolve this problem. Of course, this assumes that the app is still open (showing on a dock). Basically if I can detect when MacBook. wake up I can run some codes to refresh data.

Any advice is much appreciated.

Thanks, Boon