I’m not sure why it’s such a pain to catch the closing of a UWP application (specifically, I’m talking about the [X] button, which is kind of easy to mistakenly hit with a fat finger). Certainly WPF applications don’t have this same kind of difficulty.
But really, doesn’t it seem that it should be a given that if you’re working on something and accidentally (or forgetfully) try to close the app that you be given a chance to save your work?
When I first started working on eclecdec, the answer was “no”, and it’s been something that’s been on my bug list for ages. I decided to dig into it again, and the answer now is “yes, with some work”.
As of Windows 1703 (yeah, that’s a while ago, but how often to you go and see if new restricted capabilities have been added), your app can use the confirmAppClose restricted capability, catch the on-close-requested event, do whatever you need to do to clean up (like prompt the user) and then exit the app. Or not. In eclecdec 184.108.40.206, I added this to prompt to save changes. Works great, and there’s a comprehensive how-to article here:
Okay, so this is all wonderful. The annoying bit after making use of this restricted capability is all of the warnings you get validating and submitting your package. Scary warnings:
Turns out you have to justify your use of it:
I really hope this is enough justification. Like I said earlier, it seems to me that this should just be a capability (and an easy to find and use one) – certainly not a restricted capability that requires justification.