]> khamidou — GitHub mirrors - electron.git/commitdiff
Add 'ready-for-update-on-quit' event for auto-updater.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 3 Jun 2013 13:51:46 +0000 (21:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 3 Jun 2013 13:51:46 +0000 (21:51 +0800)
browser/api/atom_api_auto_updater.cc
browser/api/atom_api_auto_updater.h
browser/api/lib/auto-updater.coffee
browser/auto_updater_delegate.cc
browser/auto_updater_delegate.h
browser/auto_updater_mac.mm

index 6bd9555233ecd3b4d82034600c904d7669faff7d..e5e2013b6ad11358b31467df0590a4a0eb30cde5 100644 (file)
@@ -23,16 +23,25 @@ AutoUpdater::~AutoUpdater() {
 
 void AutoUpdater::WillInstallUpdate(const std::string& version,
                                     const base::Closure& install) {
+  continue_update_ = install;
+
   base::ListValue args;
   args.AppendString(version);
   bool prevent_default = Emit("will-install-update-raw", &args);
 
-  if (prevent_default)
-    continue_update_ = install;
-  else
+  if (!prevent_default)
     install.Run();
 }
 
+void AutoUpdater::ReadyForUpdateOnQuit(const std::string& version,
+                                       const base::Closure& quit_and_install) {
+  quit_and_install_ = quit_and_install;
+
+  base::ListValue args;
+  args.AppendString(version);
+  Emit("ready-for-update-on-quit-raw", &args);
+}
+
 // static
 v8::Handle<v8::Value> AutoUpdater::New(const v8::Arguments &args) {
   v8::HandleScope scope;
@@ -87,6 +96,13 @@ v8::Handle<v8::Value> AutoUpdater::ContinueUpdate(const v8::Arguments &args) {
   return v8::Undefined();
 }
 
+// static
+v8::Handle<v8::Value> AutoUpdater::QuitAndInstall(const v8::Arguments &args) {
+  AutoUpdater* self = AutoUpdater::Unwrap<AutoUpdater>(args.This());
+  self->quit_and_install_.Run();
+  return v8::Undefined();
+}
+
 // static
 void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
   v8::HandleScope scope;
@@ -109,6 +125,7 @@ void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
                             CheckForUpdatesInBackground);
 
   NODE_SET_PROTOTYPE_METHOD(t, "continueUpdate", ContinueUpdate);
+  NODE_SET_PROTOTYPE_METHOD(t, "quitAndInstall", QuitAndInstall);
 
   target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction());
 }
index 7493112d53574af53688e1afd1b10d916f468a16..d473624e36f7be4fa0a2f9eaba2a3f8433aebaeb 100644 (file)
@@ -26,6 +26,9 @@ class AutoUpdater : public EventEmitter,
 
   virtual void WillInstallUpdate(const std::string& version,
                                  const base::Closure& install) OVERRIDE;
+  virtual void ReadyForUpdateOnQuit(
+      const std::string& version,
+      const base::Closure& quit_and_install) OVERRIDE;
 
  private:
   static v8::Handle<v8::Value> New(const v8::Arguments &args);
@@ -40,8 +43,10 @@ class AutoUpdater : public EventEmitter,
       const v8::Arguments &args);
 
   static v8::Handle<v8::Value> ContinueUpdate(const v8::Arguments &args);
+  static v8::Handle<v8::Value> QuitAndInstall(const v8::Arguments &args);
 
   base::Closure continue_update_;
+  base::Closure quit_and_install_;
 
   DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
 };
index f7bb28981618f5455c5035035cc6a0bbd7a2ea1f..9d0e998b40d0dd6b5eeae5eda1b0a5075a8c407e 100644 (file)
@@ -6,5 +6,7 @@ AutoUpdater::__proto__ = EventEmitter.prototype
 autoUpdater = new AutoUpdater
 autoUpdater.on 'will-install-update-raw', (event, version) ->
   @emit 'will-install-update', event, version, => @continueUpdate()
+autoUpdater.on 'ready-for-update-on-quit-raw', (event, version) ->
+  @emit 'ready-for-update-on-quit', event, version, => @quitAndInstall()
 
 module.exports = autoUpdater
index 671413ef7a862007f42b8eaa107f35c3ee4eb75d..7b5853ff0803682df0a6c97e9319fd9ce1742a0d 100644 (file)
@@ -13,4 +13,9 @@ void AutoUpdaterDelegate::WillInstallUpdate(const std::string& version,
   install.Run();
 }
 
+void AutoUpdaterDelegate::ReadyForUpdateOnQuit(
+    const std::string& version,
+    const base::Closure& quit_and_install) {
+}
+
 }  // namespace auto_updater
index 09f29d283141154bb1d5d01489505e535f18b152..2c0e450db866d885d245389329968998814e40a6 100644 (file)
@@ -13,9 +13,14 @@ namespace auto_updater {
 
 class AutoUpdaterDelegate {
  public:
+  // The application is going to relaunch to install update.
   virtual void WillInstallUpdate(const std::string& version,
                                  const base::Closure& install);
 
+  // User has chosen to update on quit.
+  virtual void ReadyForUpdateOnQuit(const std::string& version,
+                                    const base::Closure& quit_and_install);
+
  protected:
   virtual ~AutoUpdaterDelegate() {}
 };
index eae85ffc4427c65f540a3b4ac9c66d459d5cc9fe..2c622e8f26d7c6452abefa95fa9f8e311dec4b84 100644 (file)
@@ -56,6 +56,20 @@ void CallNSInvocation(ScopedNSInvocation invocation) {
   return YES;
 }
 
+- (void)updater:(SUUpdater*)updater
+        willInstallUpdateOnQuit:(SUAppcastItem*)update
+        immediateInstallationInvocation:(NSInvocation*)invocation {
+  AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate();
+  if (!delegate)
+    return;
+
+  std::string version(base::SysNSStringToUTF8([update versionString]));
+  ScopedNSInvocation invocation_ptr([invocation retain]);
+  delegate->ReadyForUpdateOnQuit(
+      version,
+      base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass())));
+}
+
 @end
 
 namespace auto_updater {