]> khamidou — GitHub mirrors - electron.git/commitdiff
Wrap Sparkle's minimum interface with C++.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 2 Jun 2013 12:23:04 +0000 (20:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 2 Jun 2013 12:26:03 +0000 (20:26 +0800)
atom.gyp
browser/auto_updater.cc [new file with mode: 0644]
browser/auto_updater.h [new file with mode: 0644]
browser/auto_updater_delegate.cc [new file with mode: 0644]
browser/auto_updater_delegate.h [new file with mode: 0644]
browser/auto_updater_mac.mm [new file with mode: 0644]

index 12bdd98d8d00bbed3419bab40105a2da84373f3d..c9e7a50e97370ebd1fa06a1037fb0a93dae9101a 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'browser/api/atom_api_window.h',
       'browser/api/atom_browser_bindings.cc',
       'browser/api/atom_browser_bindings.h',
+      'browser/auto_updater.cc',
+      'browser/auto_updater.h',
+      'browser/auto_updater_delegate.cc',
+      'browser/auto_updater_delegate.h',
+      'browser/auto_updater_mac.mm',
       'browser/atom_application_mac.h',
       'browser/atom_application_mac.mm',
       'browser/atom_application_delegate_mac.h',
diff --git a/browser/auto_updater.cc b/browser/auto_updater.cc
new file mode 100644 (file)
index 0000000..ef6f3ad
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/auto_updater.h"
+
+namespace auto_updater {
+
+AutoUpdaterDelegate* AutoUpdater::delegate_ = NULL;
+
+AutoUpdaterDelegate* AutoUpdater::GetDelegate() {
+  return delegate_;
+}
+
+void AutoUpdater::SetDelegate(AutoUpdaterDelegate* delegate) {
+  delegate_ = delegate;
+}
+
+}  // namespace auto_updater
diff --git a/browser/auto_updater.h b/browser/auto_updater.h
new file mode 100644 (file)
index 0000000..8426c03
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_AUTO_UPDATER_H_
+#define ATOM_BROWSER_AUTO_UPDATER_H_
+
+#include "base/basictypes.h"
+
+namespace auto_updater {
+
+class AutoUpdaterDelegate;
+
+class AutoUpdater {
+ public:
+  // Gets/Sets the delegate.
+  static AutoUpdaterDelegate* GetDelegate();
+  static void SetDelegate(AutoUpdaterDelegate* delegate);
+
+  static void Init();
+
+  static void SetAutomaticallyChecksForUpdates(bool yes);
+  static void SetAutomaticallyDownloadsUpdates(bool yes);
+  static void CheckForUpdatesInBackground();
+
+ private:
+  static AutoUpdaterDelegate* delegate_;
+
+  DISALLOW_IMPLICIT_CONSTRUCTORS(AutoUpdater);
+};
+
+}  // namespace auto_updater
+
+#endif  // ATOM_BROWSER_AUTO_UPDATER_H_
diff --git a/browser/auto_updater_delegate.cc b/browser/auto_updater_delegate.cc
new file mode 100644 (file)
index 0000000..671413e
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/auto_updater_delegate.h"
+
+#include "base/callback.h"
+
+namespace auto_updater {
+
+void AutoUpdaterDelegate::WillInstallUpdate(const std::string& version,
+                                            const base::Closure& install) {
+  install.Run();
+}
+
+}  // namespace auto_updater
diff --git a/browser/auto_updater_delegate.h b/browser/auto_updater_delegate.h
new file mode 100644 (file)
index 0000000..09f29d2
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_AUTO_UPDATER_DELEGATE_H_
+#define ATOM_BROWSER_AUTO_UPDATER_DELEGATE_H_
+
+#include <string>
+
+#include "base/callback_forward.h"
+
+namespace auto_updater {
+
+class AutoUpdaterDelegate {
+ public:
+  virtual void WillInstallUpdate(const std::string& version,
+                                 const base::Closure& install);
+
+ protected:
+  virtual ~AutoUpdaterDelegate() {}
+};
+
+}  // namespace auto_updater
+
+#endif  // ATOM_BROWSER_AUTO_UPDATER_DELEGATE_H_
diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm
new file mode 100644 (file)
index 0000000..3ac390d
--- /dev/null
@@ -0,0 +1,89 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/auto_updater.h"
+
+// Sparkle's headers are throwing compilation warnings, supress them.
+#pragma GCC diagnostic ignored "-Wmissing-method-return-type"
+#import <Sparkle/Sparkle.h>
+
+#include "base/bind.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/sys_string_conversions.h"
+#include "browser/auto_updater_delegate.h"
+
+using auto_updater::AutoUpdaterDelegate;
+
+namespace {
+
+struct NSInvocationDeleter {
+  inline void operator()(NSInvocation* invocation) const {
+    [invocation release];
+  }
+};
+
+typedef scoped_ptr<NSInvocation, NSInvocationDeleter> ScopedNSInvocation;
+
+// We are passing the NSInvocation as scoped_ptr, because we want to make sure
+// whether or not the callback is called, the NSInvocation should alwasy be
+// released, the only way to ensure it is to use scoped_ptr.
+void CallNSInvocation(ScopedNSInvocation invocation) {
+  [invocation.get() invoke];
+}
+
+}  // namespace
+
+@interface SUUpdaterDelegate : NSObject {
+}
+@end
+
+@implementation SUUpdaterDelegate
+
+- (void)updater:(SUUpdater*)updater
+        willInstallUpdateOnQuit:(SUAppcastItem*)update
+        immediateInstallationInvocation:(NSInvocation*)invocation {
+  AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate();
+  if (!delegate) {
+    [invocation invoke];
+    return;
+  }
+
+  std::string version(base::SysNSStringToUTF8([update versionString]));
+  ScopedNSInvocation invocation_ptr([invocation retain]);
+  delegate->WillInstallUpdate(
+      version,
+      base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass())));
+}
+
+- (void)updaterWillRelaunchApplication:(SUUpdater*)updater {
+  [[SUUpdater sharedUpdater] setDelegate:nil];
+}
+
+@end
+
+namespace auto_updater {
+
+// static
+void AutoUpdater::Init() {
+  SUUpdaterDelegate* delegate = [[SUUpdaterDelegate alloc] init];
+  [delegate autorelease];
+  [[SUUpdater sharedUpdater] setDelegate:delegate];
+}
+
+// static
+void AutoUpdater::SetAutomaticallyChecksForUpdates(bool yes) {
+  [[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:yes];
+}
+
+// static
+void AutoUpdater::SetAutomaticallyDownloadsUpdates(bool yes) {
+  [[SUUpdater sharedUpdater] setAutomaticallyDownloadsUpdates:yes];
+}
+
+// static
+void AutoUpdater::CheckForUpdatesInBackground() {
+  [[SUUpdater sharedUpdater] checkForUpdatesInBackground];
+}
+
+}  // namespace auto_updater