Re-design the cleanup functionality of the tray icon

Instead of the tray icon thread trying to clean itself up, call the
destructor externally and wait until it closed itself.
This ensures all resources are free'ed and no race conditions can cause
invalid access later on.

Suggested by Lord.