# HG changeset patch
# User t_mrc-ct@users.sourceforge.jp
# Date 1382187878 -32400
#      Sat Oct 19 22:04:38 2013 +0900
# Branch THUNDERBIRD3880_2016050308_RELBRANCH
# Node ID 7218d22c96c8423b105b08d67f253817b49a9436
# Parent  70c06b42fe0d5df32d9645d3aae54ccc71969e6a
properly restore dock icon when quit app. (tiger)

diff --git a/mailnews/base/src/nsMessengerOSXIntegration.mm b/mailnews/base/src/nsMessengerOSXIntegration.mm
--- a/mailnews/base/src/nsMessengerOSXIntegration.mm
+++ b/mailnews/base/src/nsMessengerOSXIntegration.mm
@@ -193,16 +193,21 @@
   mNewMailReceivedAtom = MsgGetAtom("NewMailReceived");
   mUnreadTotal = 0;
   mUnreadChat = 0;
   mOnLeopardOrLater = OnLeopardOrLater();
 }
 
 nsMessengerOSXIntegration::~nsMessengerOSXIntegration()
 {
+  nsresult rv;
+  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
+  if (NS_SUCCEEDED(rv)) {
+    observerService->RemoveObserver(this, "quit-application");
+  }
   RestoreDockIcon();
 }
 
 NS_IMPL_ADDREF(nsMessengerOSXIntegration)
 NS_IMPL_RELEASE(nsMessengerOSXIntegration)
 
 NS_INTERFACE_MAP_BEGIN(nsMessengerOSXIntegration)
    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessengerOSIntegration)
@@ -214,16 +219,17 @@
 
 
 nsresult
 nsMessengerOSXIntegration::Init()
 {
   nsresult rv;
   nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
+  observerService->AddObserver(this, "quit-application", false);
   return observerService->AddObserver(this, "mail-startup-done", false);
 }
 
 NS_IMETHODIMP
 nsMessengerOSXIntegration::OnItemPropertyChanged(nsIMsgFolder *, nsIAtom *, char const *, char const *)
 {
   return NS_OK;
 }
@@ -286,16 +292,25 @@
     // register with the mail sesson for folder events
     // we care about new count, biff status
     nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return mailSession->AddFolderListener(this, nsIFolderListener::boolPropertyChanged | nsIFolderListener::intPropertyChanged);
   }
 
+  if (!strcmp(aTopic, "quit-application")) {
+    nsresult rv;
+    nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
+    if (NS_SUCCEEDED(rv)) {
+      observerService->RemoveObserver(this, "quit-application");
+    }
+    return RestoreDockIcon();
+  }
+
   if (!strcmp(aTopic, kNewChatMessageTopic)) {
     // We don't have to bother about checking if the window is already focused
     // before attempting to bounce the dock icon, as BounceDockIcon is
     // implemented by a getAttention call which won't do anything if the window
     // requesting attention is already focused.
     return BounceDockIcon();
   }
 
