Cleanup shutdown and fix potential crashes
* src/explorer-events.cpp (Close): Unregister sink with addin. * src/explorers-events.cpp (NewInstance): Register sink. * src/gpgoladdin.cpp (GpgolAddin::~GpgolAddin): Remove shutdown logic. (GpgolAddin::OnConnection): Mark shutdown state as false. (GpgolAddin::OnDisconnection): Call shutdown. (install_explorer_sinks): Register created sinks. (GpgolAddin::shutdown): New. Handle shutdown. (GpgolAddin::registerExplorerSink), (GpgolAddin::unregisterExplorerSink): Track explorer sinks. * src/gpgoladdin.h: Update accordingly. * src/mail.cpp (Mail::closeAllMails_o): Fix folder events detach and do it earlier. (Mail::installFolderEventHandler_o): Use sink instead of folder to track event handler. * src/windowmessages.cpp (add_explorer, remove_explorer): removed. (gpgol_hook): Interate over actual explorers instead of variables. * src/windowmessages.h: Update accordingly.
This fixes Explorer events release / deletion on unload / shutdown.
Previously this was only done on close, which came after GpgOL
was unloaded. Maybe this resulted in a jump to an unmapped location?
It also fixes that the gpgol_hook was only enabled for all explorers
at start time. Maybe we will see a regression now that it works
as intended on all explorers.
Explorers Events and Application Events were never deleted / released
because they were not detached before release. (But the release
then didn't delete them).
Definitely fixed is a race condition on shutdown which would be:
-> Shutdown detected
-> Close all mails
-> The currently visible mail is closed
-> Outlook loads it again because it is currently visible
-> But we are in shutdown mode.
Now we would start to parse while actually shutting down. This
could lead to hangs / crashes. The reason for this was that
we closed the mails before we detached the Application event
handler and thus captured the item load again.