Browse Source

mac: Fix crash when checking for update, fixes #575.

Cheng Zhao 10 years ago
parent
commit
e7647ba183
1 changed files with 8 additions and 5 deletions
  1. 8 5
      atom/browser/auto_updater_mac.mm

+ 8 - 5
atom/browser/auto_updater_mac.mm

@@ -48,11 +48,13 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
     [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
       subscribeNext:^(NSNumber *stateNumber) {
         int state = [stateNumber integerValue];
-        if (state == SQRLUpdaterStateCheckingForUpdate) {
-          delegate->OnCheckingForUpdate();
-        } else if (state == SQRLUpdaterStateDownloadingUpdate) {
-          delegate->OnUpdateAvailable();
-        }
+        // Dispatching the event on main thread.
+        dispatch_async(dispatch_get_main_queue(), ^{
+          if (state == SQRLUpdaterStateCheckingForUpdate)
+            delegate->OnCheckingForUpdate();
+          else if (state == SQRLUpdaterStateDownloadingUpdate)
+            delegate->OnUpdateAvailable();
+        });
     }];
   }
 }
@@ -89,4 +91,5 @@ void AutoUpdater::CheckForUpdates() {
         delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
       }];
 }
+
 }  // namespace auto_updater