From 5741bad918220bd5c643a1d3d17c2640c378c8e6 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 20 Jan 2014 16:22:32 -0800 Subject: [PATCH 01/19] :lipstick: --- browser/auto_updater_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 2c622e8f26d7..afde309f8c73 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -26,7 +26,7 @@ struct NSInvocationDeleter { typedef scoped_ptr 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 +// whether or not the callback is called, the NSInvocation should always be // released, the only way to ensure it is to use scoped_ptr. void CallNSInvocation(ScopedNSInvocation invocation) { [invocation.get() invoke]; From 2a7244a366418fe00b184a413ca50cabe88b3d36 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 20 Jan 2014 16:22:49 -0800 Subject: [PATCH 02/19] Remove references to Sparkle --- browser/auto_updater_mac.mm | 100 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index afde309f8c73..31fb5e45bf19 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -4,9 +4,7 @@ #include "browser/auto_updater.h" -// Sparkle's headers are throwing compilation warnings, supress them. -#pragma GCC diagnostic ignored "-Wmissing-method-return-type" -#import +#import #include "base/bind.h" #include "base/memory/scoped_ptr.h" @@ -28,82 +26,82 @@ typedef scoped_ptr 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 always be // released, the only way to ensure it is to use scoped_ptr. -void CallNSInvocation(ScopedNSInvocation invocation) { - [invocation.get() invoke]; -} +// void CallNSInvocation(ScopedNSInvocation invocation) { +// [invocation.get() invoke]; +// } } // namespace -@interface SUUpdaterDelegate : NSObject { -} -@end - -@implementation SUUpdaterDelegate - -- (BOOL)updater:(SUUpdater*)updater - shouldPostponeRelaunchForUpdate:(SUAppcastItem*)update - untilInvoking:(NSInvocation*)invocation { - AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate(); - if (!delegate) - return NO; - - std::string version(base::SysNSStringToUTF8([update versionString])); - ScopedNSInvocation invocation_ptr([invocation retain]); - delegate->WillInstallUpdate( - version, - base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass()))); - - 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 +// @interface SUUpdaterDelegate : NSObject { +// } +// @end +// +// @implementation SUUpdaterDelegate +// +// - (BOOL)updater:(SUUpdater*)updater +// shouldPostponeRelaunchForUpdate:(SUAppcastItem*)update +// untilInvoking:(NSInvocation*)invocation { +// AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate(); +// if (!delegate) +// return NO; +// +// std::string version(base::SysNSStringToUTF8([update versionString])); +// ScopedNSInvocation invocation_ptr([invocation retain]); +// delegate->WillInstallUpdate( +// version, +// base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass()))); +// +// 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 { // static void AutoUpdater::Init() { - SUUpdaterDelegate* delegate = [[SUUpdaterDelegate alloc] init]; - [[SUUpdater sharedUpdater] setDelegate:delegate]; + // SUUpdaterDelegate* delegate = [[SUUpdaterDelegate alloc] init]; + // [[SUUpdater sharedUpdater] setDelegate:delegate]; } // static void AutoUpdater::SetFeedURL(const std::string& url) { - NSString* url_str(base::SysUTF8ToNSString(url)); - [[SUUpdater sharedUpdater] setFeedURL:[NSURL URLWithString:url_str]]; + // NSString* url_str(base::SysUTF8ToNSString(url)); + // [[SUUpdater sharedUpdater] setFeedURL:[NSURL URLWithString:url_str]]; } // static void AutoUpdater::SetAutomaticallyChecksForUpdates(bool yes) { - [[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:yes]; + // [[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:yes]; } // static void AutoUpdater::SetAutomaticallyDownloadsUpdates(bool yes) { - [[SUUpdater sharedUpdater] setAutomaticallyDownloadsUpdates:yes]; + // [[SUUpdater sharedUpdater] setAutomaticallyDownloadsUpdates:yes]; } // static void AutoUpdater::CheckForUpdates() { - [[SUUpdater sharedUpdater] checkForUpdates:nil]; + // [[SUUpdater sharedUpdater] checkForUpdates:nil]; } // static void AutoUpdater::CheckForUpdatesInBackground() { - [[SUUpdater sharedUpdater] checkForUpdatesInBackground]; + // [[SUUpdater sharedUpdater] checkForUpdatesInBackground]; } } // namespace auto_updater From 400e963b8b3dcbe816e470495071c9cfc07418f3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 20 Jan 2014 16:25:33 -0800 Subject: [PATCH 03/19] Download Squirrel frameworks instead of Sparkle --- script/update-frameworks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script/update-frameworks.py b/script/update-frameworks.py index e6c311946967..f465d01072a8 100755 --- a/script/update-frameworks.py +++ b/script/update-frameworks.py @@ -7,13 +7,15 @@ from lib.util import safe_mkdir, extract_zip, tempdir, download SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -FRAMEWORKS_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/frameworks' +FRAMEWORKS_URL = 'http://atom-alpha.s3.amazonaws.com' def main(): os.chdir(SOURCE_ROOT) safe_mkdir('frameworks') - download_and_unzip('Sparkle') + download_and_unzip('Mantle') + download_and_unzip('ReactiveCocoa') + download_and_unzip('Squirrel') def download_and_unzip(framework): From a6c92f20c8ef08b187dcf1b40cf0389966dbbeb3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 20 Jan 2014 16:25:48 -0800 Subject: [PATCH 04/19] Link Sparkle frameworks --- atom.gyp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/atom.gyp b/atom.gyp index 88d9755d3827..0864b6507c42 100644 --- a/atom.gyp +++ b/atom.gyp @@ -199,11 +199,12 @@ }], # OS=="win" ], 'fix_framework_link_command': [ - 'install_name_tool', - '-change', - '@loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle', - '@rpath/Sparkle.framework/Versions/A/Sparkle', - '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}' + # TODO: I have no idea if this is needed for Squirrel + # 'install_name_tool', + # '-change', + # '@loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle', + # '@rpath/Sparkle.framework/Versions/A/Sparkle', + # '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}' ], 'atom_source_root': ' Date: Mon, 20 Jan 2014 16:29:34 -0800 Subject: [PATCH 05/19] I don't think `fix_framework_link_command` is needed anymore. tool -L says Squirrel (and its dependencies) already use @rpath ``` @rpath/Squirrel.framework/Squirrel (compatibility version 1.0.0, current version 1.0.0) @rpath/ReactiveCocoa.framework/ReactiveCocoa (compatibility version 1.0.0, current version 1.0.0) @rpath/Mantle.framework/Mantle (compatibility version 1.0.0, current version 1.0.0) ``` --- atom.gyp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/atom.gyp b/atom.gyp index 0864b6507c42..765c8004cd66 100644 --- a/atom.gyp +++ b/atom.gyp @@ -198,14 +198,6 @@ ], }], # OS=="win" ], - 'fix_framework_link_command': [ - # TODO: I have no idea if this is needed for Squirrel - # 'install_name_tool', - # '-change', - # '@loader_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle', - # '@rpath/Sparkle.framework/Versions/A/Sparkle', - # '${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}' - ], 'atom_source_root': ' Date: Tue, 21 Jan 2014 22:13:34 +0800 Subject: [PATCH 06/19] Implement auto_updater with Squirrel. --- atom.gyp | 1 - browser/api/atom_api_auto_updater.cc | 66 +++------------- browser/api/atom_api_auto_updater.h | 17 ++-- browser/api/lib/auto-updater.coffee | 7 +- browser/auto_updater.h | 5 -- browser/auto_updater_delegate.cc | 21 ----- browser/auto_updater_delegate.h | 17 ++-- browser/auto_updater_mac.mm | 111 ++++++++------------------- 8 files changed, 63 insertions(+), 182 deletions(-) delete mode 100644 browser/auto_updater_delegate.cc diff --git a/atom.gyp b/atom.gyp index 765c8004cd66..306733e4671d 100644 --- a/atom.gyp +++ b/atom.gyp @@ -65,7 +65,6 @@ '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/auto_updater_win.cc', diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index bfb55252e3f9..f7b5f8e3cfc2 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -4,6 +4,7 @@ #include "browser/api/atom_api_auto_updater.h" +#include "base/time/time.h" #include "base/values.h" #include "browser/auto_updater.h" #include "common/v8/native_type_conversions.h" @@ -17,32 +18,25 @@ namespace api { AutoUpdater::AutoUpdater(v8::Handle wrapper) : EventEmitter(wrapper) { auto_updater::AutoUpdater::SetDelegate(this); - auto_updater::AutoUpdater::Init(); } AutoUpdater::~AutoUpdater() { auto_updater::AutoUpdater::SetDelegate(NULL); } -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) - install.Run(); -} - -void AutoUpdater::ReadyForUpdateOnQuit(const std::string& version, - const base::Closure& quit_and_install) { +void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, + const std::string& release_name, + const base::Time& release_date, + const std::string& update_url, + 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); + args.AppendString(release_notes); + args.AppendString(release_name); + args.AppendDouble(release_date.ToJsTime()); + args.AppendString(update_url); + Emit("update-downloaded-raw", &args); } // static @@ -60,39 +54,12 @@ void AutoUpdater::SetFeedURL(const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::SetFeedURL(FromV8Value(args[0])); } -// static -void AutoUpdater::SetAutomaticallyChecksForUpdates( - const v8::FunctionCallbackInfo& args) { - auto_updater::AutoUpdater::SetAutomaticallyChecksForUpdates( - FromV8Value(args[0])); -} - -// static -void AutoUpdater::SetAutomaticallyDownloadsUpdates( - const v8::FunctionCallbackInfo& args) { - auto_updater::AutoUpdater::SetAutomaticallyDownloadsUpdates( - FromV8Value(args[0])); -} - // static void AutoUpdater::CheckForUpdates( const v8::FunctionCallbackInfo& args) { auto_updater::AutoUpdater::CheckForUpdates(); } -// static -void AutoUpdater::CheckForUpdatesInBackground( - const v8::FunctionCallbackInfo& args) { - auto_updater::AutoUpdater::CheckForUpdatesInBackground(); -} - -// static -void AutoUpdater::ContinueUpdate( - const v8::FunctionCallbackInfo& args) { - AutoUpdater* self = AutoUpdater::Unwrap(args.This()); - self->continue_update_.Run(); -} - // static void AutoUpdater::QuitAndInstall( const v8::FunctionCallbackInfo& args) { @@ -110,18 +77,7 @@ void AutoUpdater::Initialize(v8::Handle target) { t->SetClassName(v8::String::NewSymbol("AutoUpdater")); NODE_SET_PROTOTYPE_METHOD(t, "setFeedUrl", SetFeedURL); - NODE_SET_PROTOTYPE_METHOD(t, - "setAutomaticallyChecksForUpdates", - SetAutomaticallyChecksForUpdates); - NODE_SET_PROTOTYPE_METHOD(t, - "setAutomaticallyDownloadsUpdates", - SetAutomaticallyDownloadsUpdates); NODE_SET_PROTOTYPE_METHOD(t, "checkForUpdates", CheckForUpdates); - NODE_SET_PROTOTYPE_METHOD(t, - "checkForUpdatesInBackground", - CheckForUpdatesInBackground); - - NODE_SET_PROTOTYPE_METHOD(t, "continueUpdate", ContinueUpdate); NODE_SET_PROTOTYPE_METHOD(t, "quitAndInstall", QuitAndInstall); target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction()); diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index 03d649e2ba66..55d44c4ebc26 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -24,28 +24,23 @@ class AutoUpdater : public EventEmitter, protected: explicit AutoUpdater(v8::Handle wrapper); - virtual void WillInstallUpdate(const std::string& version, - const base::Closure& install) OVERRIDE; - virtual void ReadyForUpdateOnQuit( - const std::string& version, + // AutoUpdaterDelegate implementations. + virtual void OnUpdateDownloaded( + const std::string& release_notes, + const std::string& release_name, + const base::Time& release_date, + const std::string& update_url, const base::Closure& quit_and_install) OVERRIDE; private: static void New(const v8::FunctionCallbackInfo& args); static void SetFeedURL(const v8::FunctionCallbackInfo& args); - static void SetAutomaticallyChecksForUpdates( - const v8::FunctionCallbackInfo& args); - static void SetAutomaticallyDownloadsUpdates( - const v8::FunctionCallbackInfo& args); static void CheckForUpdates(const v8::FunctionCallbackInfo& args); - static void CheckForUpdatesInBackground( - const v8::FunctionCallbackInfo& args); static void ContinueUpdate(const v8::FunctionCallbackInfo& args); static void QuitAndInstall(const v8::FunctionCallbackInfo& args); - base::Closure continue_update_; base::Closure quit_and_install_; DISALLOW_COPY_AND_ASSIGN(AutoUpdater); diff --git a/browser/api/lib/auto-updater.coffee b/browser/api/lib/auto-updater.coffee index 9d0e998b40d0..fc29bd3d9647 100644 --- a/browser/api/lib/auto-updater.coffee +++ b/browser/api/lib/auto-updater.coffee @@ -4,9 +4,8 @@ EventEmitter = require('events').EventEmitter 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() +autoUpdater.on 'update-downloaded-raw', (args...) -> + args[2] = new Date(args[2]) # releaseDate + @emit 'update-downloaded', args..., => @quitAndInstall() module.exports = autoUpdater diff --git a/browser/auto_updater.h b/browser/auto_updater.h index 2166d49f71fd..9ddbd35b7ce3 100644 --- a/browser/auto_updater.h +++ b/browser/auto_updater.h @@ -19,13 +19,8 @@ class AutoUpdater { static AutoUpdaterDelegate* GetDelegate(); static void SetDelegate(AutoUpdaterDelegate* delegate); - static void Init(); - static void SetFeedURL(const std::string& url); - static void SetAutomaticallyChecksForUpdates(bool yes); - static void SetAutomaticallyDownloadsUpdates(bool yes); static void CheckForUpdates(); - static void CheckForUpdatesInBackground(); private: static AutoUpdaterDelegate* delegate_; diff --git a/browser/auto_updater_delegate.cc b/browser/auto_updater_delegate.cc deleted file mode 100644 index 7b5853ff0803..000000000000 --- a/browser/auto_updater_delegate.cc +++ /dev/null @@ -1,21 +0,0 @@ -// 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(); -} - -void AutoUpdaterDelegate::ReadyForUpdateOnQuit( - const std::string& version, - const base::Closure& quit_and_install) { -} - -} // namespace auto_updater diff --git a/browser/auto_updater_delegate.h b/browser/auto_updater_delegate.h index 2c0e450db866..ba6e4ec933f4 100644 --- a/browser/auto_updater_delegate.h +++ b/browser/auto_updater_delegate.h @@ -9,17 +9,20 @@ #include "base/callback_forward.h" +namespace base { +class Time; +} + 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); + // There is a new update which has been downloaded. + virtual void OnUpdateDownloaded(const std::string& release_notes, + const std::string& release_name, + const base::Time& release_date, + const std::string& update_url, + const base::Closure& quit_and_install) {} protected: virtual ~AutoUpdaterDelegate() {} diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 31fb5e45bf19..45c6e264fb16 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -4,104 +4,59 @@ #include "browser/auto_updater.h" +#import +#import #import #include "base/bind.h" -#include "base/memory/scoped_ptr.h" +#include "base/time/time.h" #include "base/strings/sys_string_conversions.h" #include "browser/auto_updater_delegate.h" -using auto_updater::AutoUpdaterDelegate; +namespace auto_updater { namespace { -struct NSInvocationDeleter { - inline void operator()(NSInvocation* invocation) const { - [invocation release]; - } -}; +// The gloal SQRLUpdater object. +static SQRLUpdater* g_updater = nil; -typedef scoped_ptr 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 always be -// released, the only way to ensure it is to use scoped_ptr. -// void CallNSInvocation(ScopedNSInvocation invocation) { -// [invocation.get() invoke]; -// } +static void RelaunchToInstallUpdate() { + if (g_updater != nil) + [g_updater relaunchToInstallUpdate]; +} } // namespace -// @interface SUUpdaterDelegate : NSObject { -// } -// @end -// -// @implementation SUUpdaterDelegate -// -// - (BOOL)updater:(SUUpdater*)updater -// shouldPostponeRelaunchForUpdate:(SUAppcastItem*)update -// untilInvoking:(NSInvocation*)invocation { -// AutoUpdaterDelegate* delegate = auto_updater::AutoUpdater::GetDelegate(); -// if (!delegate) -// return NO; -// -// std::string version(base::SysNSStringToUTF8([update versionString])); -// ScopedNSInvocation invocation_ptr([invocation retain]); -// delegate->WillInstallUpdate( -// version, -// base::Bind(&CallNSInvocation, base::Passed(invocation_ptr.Pass()))); -// -// 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 { - // static -void AutoUpdater::Init() { - // SUUpdaterDelegate* delegate = [[SUUpdaterDelegate alloc] init]; - // [[SUUpdater sharedUpdater] setDelegate:delegate]; -} +void AutoUpdater::SetFeedURL(const std::string& feed) { + if (g_updater == nil) { + // Initialize the SQRLUpdater. + NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; + NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; + g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; -// static -void AutoUpdater::SetFeedURL(const std::string& url) { - // NSString* url_str(base::SysUTF8ToNSString(url)); - // [[SUUpdater sharedUpdater] setFeedURL:[NSURL URLWithString:url_str]]; -} + // Subscribe to events. + [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { + AutoUpdaterDelegate* delegate = GetDelegate(); + if (!delegate) + return; -// static -void AutoUpdater::SetAutomaticallyChecksForUpdates(bool yes) { - // [[SUUpdater sharedUpdater] setAutomaticallyChecksForUpdates:yes]; -} - -// static -void AutoUpdater::SetAutomaticallyDownloadsUpdates(bool yes) { - // [[SUUpdater sharedUpdater] setAutomaticallyDownloadsUpdates:yes]; + SQRLUpdate* update = downloadedUpdate.update; + delegate->OnUpdateDownloaded( + base::SysNSStringToUTF8(update.releaseNotes), + base::SysNSStringToUTF8(update.releaseName), + base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), + base::SysNSStringToUTF8(update.updateURL.absoluteString), + base::Bind(RelaunchToInstallUpdate)); + }]; + } } // static void AutoUpdater::CheckForUpdates() { - // [[SUUpdater sharedUpdater] checkForUpdates:nil]; -} - -// static -void AutoUpdater::CheckForUpdatesInBackground() { - // [[SUUpdater sharedUpdater] checkForUpdatesInBackground]; + if (g_updater != nil) { + [g_updater.checkForUpdatesCommand execute:nil]; + } } } // namespace auto_updater From d4e362ec890b7a8acd77032415d789558551d780 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Jan 2014 22:50:46 +0800 Subject: [PATCH 07/19] Add error and update-not-available events for auto updater. --- browser/api/atom_api_auto_updater.cc | 10 ++++++++ browser/api/atom_api_auto_updater.h | 2 ++ browser/auto_updater_delegate.h | 6 +++++ browser/auto_updater_mac.mm | 37 +++++++++++++++++++--------- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index f7b5f8e3cfc2..5360a3151fb0 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -24,6 +24,16 @@ AutoUpdater::~AutoUpdater() { auto_updater::AutoUpdater::SetDelegate(NULL); } +void AutoUpdater::OnError(const std::string& error) { + base::ListValue args; + args.AppendString(error); + Emit("error", &args); +} + +void AutoUpdater::OnUpdateNotAvailable() { + Emit("update-not-available"); +} + void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, const std::string& release_name, const base::Time& release_date, diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index 55d44c4ebc26..2bb830c27679 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -25,6 +25,8 @@ class AutoUpdater : public EventEmitter, explicit AutoUpdater(v8::Handle wrapper); // AutoUpdaterDelegate implementations. + virtual void OnError(const std::string& error) OVERRIDE; + virtual void OnUpdateNotAvailable() OVERRIDE; virtual void OnUpdateDownloaded( const std::string& release_notes, const std::string& release_name, diff --git a/browser/auto_updater_delegate.h b/browser/auto_updater_delegate.h index ba6e4ec933f4..063cc79d5e7f 100644 --- a/browser/auto_updater_delegate.h +++ b/browser/auto_updater_delegate.h @@ -17,6 +17,12 @@ namespace auto_updater { class AutoUpdaterDelegate { public: + // An error happened. + virtual void OnError(const std::string& error) {} + + // There is no available update. + virtual void OnUpdateNotAvailable() {} + // There is a new update which has been downloaded. virtual void OnUpdateDownloaded(const std::string& release_notes, const std::string& release_name, diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 45c6e264fb16..63747e9f3b52 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -35,19 +35,32 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; - // Subscribe to events. - [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - AutoUpdaterDelegate* delegate = GetDelegate(); - if (!delegate) - return; + AutoUpdaterDelegate* delegate = GetDelegate(); + if (!delegate) + return; - SQRLUpdate* update = downloadedUpdate.update; - delegate->OnUpdateDownloaded( - base::SysNSStringToUTF8(update.releaseNotes), - base::SysNSStringToUTF8(update.releaseName), - base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), - base::SysNSStringToUTF8(update.updateURL.absoluteString), - base::Bind(RelaunchToInstallUpdate)); + // Subscribe to events. + __block bool has_update = false; + [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { + has_update = true; + + // There is a new update that has been downloaded. + SQRLUpdate* update = downloadedUpdate.update; + delegate->OnUpdateDownloaded( + base::SysNSStringToUTF8(update.releaseNotes), + base::SysNSStringToUTF8(update.releaseName), + base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), + base::SysNSStringToUTF8(update.updateURL.absoluteString), + base::Bind(RelaunchToInstallUpdate)); + } error:^(NSError* error) { + // Something wrong happened. + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); + } completed:^() { + // When the completed event is sent with no update, then we know there + // is no update available. + if (!has_update) + delegate->OnUpdateNotAvailable(); + has_update = false; }]; } } From e8594b492eca5231d2ea91e4195df134c7146b1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 22 Jan 2014 12:00:34 +0800 Subject: [PATCH 08/19] It's safe to send message to nil. --- browser/auto_updater_mac.mm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 63747e9f3b52..9b69a0a137fd 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -21,8 +21,11 @@ namespace { static SQRLUpdater* g_updater = nil; static void RelaunchToInstallUpdate() { - if (g_updater != nil) - [g_updater relaunchToInstallUpdate]; + [[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) { + AutoUpdaterDelegate* delegate = AutoUpdater::GetDelegate(); + if (delegate) + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); + }]; } } // namespace @@ -67,9 +70,7 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { // static void AutoUpdater::CheckForUpdates() { - if (g_updater != nil) { - [g_updater.checkForUpdatesCommand execute:nil]; - } + [g_updater.checkForUpdatesCommand execute:nil]; } } // namespace auto_updater From a8f172752a72d93537820322b9ce62b601be6c5f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 31 Jan 2014 20:28:33 +0800 Subject: [PATCH 09/19] :lipstick: Fix cpplint warning. --- script/cpplint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/cpplint.py b/script/cpplint.py index 0bfbfaa6be3e..e4314142b27b 100755 --- a/script/cpplint.py +++ b/script/cpplint.py @@ -6,10 +6,10 @@ import subprocess import sys IGNORE_FILES = [ - 'app/win/resource.h', 'browser/atom_application_mac.h', 'browser/atom_application_delegate_mac.h', 'browser/native_window_mac.h', + 'browser/resources/win/resource.h', 'browser/ui/cocoa/event_processing_window.h', 'browser/ui/cocoa/atom_menu_controller.h', 'browser/ui/cocoa/nsalert_synchronous_sheet.h', From 73ec7783afee4099322a522c8e1c7156f0bd7da8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 31 Jan 2014 21:10:51 +0800 Subject: [PATCH 10/19] No need to add "static" for functions in anonymouse namespace. --- browser/auto_updater_mac.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 9b69a0a137fd..87fc684103dc 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -18,9 +18,9 @@ namespace auto_updater { namespace { // The gloal SQRLUpdater object. -static SQRLUpdater* g_updater = nil; +SQRLUpdater* g_updater = nil; -static void RelaunchToInstallUpdate() { +void RelaunchToInstallUpdate() { [[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) { AutoUpdaterDelegate* delegate = AutoUpdater::GetDelegate(); if (delegate) From 8ee1e1d208e76a27a0bdb119de345220e006bc1b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 31 Jan 2014 21:31:42 +0800 Subject: [PATCH 11/19] Subscribe to checkForUpdatesCommand's return value. --- browser/auto_updater_mac.mm | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 87fc684103dc..111dcdcf13e4 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -37,40 +37,40 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; - - AutoUpdaterDelegate* delegate = GetDelegate(); - if (!delegate) - return; - - // Subscribe to events. - __block bool has_update = false; - [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - has_update = true; - - // There is a new update that has been downloaded. - SQRLUpdate* update = downloadedUpdate.update; - delegate->OnUpdateDownloaded( - base::SysNSStringToUTF8(update.releaseNotes), - base::SysNSStringToUTF8(update.releaseName), - base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), - base::SysNSStringToUTF8(update.updateURL.absoluteString), - base::Bind(RelaunchToInstallUpdate)); - } error:^(NSError* error) { - // Something wrong happened. - delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); - } completed:^() { - // When the completed event is sent with no update, then we know there - // is no update available. - if (!has_update) - delegate->OnUpdateNotAvailable(); - has_update = false; - }]; } } // static void AutoUpdater::CheckForUpdates() { - [g_updater.checkForUpdatesCommand execute:nil]; + RACSignal* signal = [g_updater.checkForUpdatesCommand execute:nil]; + + AutoUpdaterDelegate* delegate = GetDelegate(); + if (!delegate) + return; + + // Subscribe to events. + __block bool has_update = false; + [signal subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { + has_update = true; + + // There is a new update that has been downloaded. + SQRLUpdate* update = downloadedUpdate.update; + delegate->OnUpdateDownloaded( + base::SysNSStringToUTF8(update.releaseNotes), + base::SysNSStringToUTF8(update.releaseName), + base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), + base::SysNSStringToUTF8(update.updateURL.absoluteString), + base::Bind(RelaunchToInstallUpdate)); + } error:^(NSError* error) { + // Something wrong happened. + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); + } completed:^() { + // When the completed event is sent with no update, then we know there + // is no update available. + if (!has_update) + delegate->OnUpdateNotAvailable(); + has_update = false; + }]; } } // namespace auto_updater From 50eb5454d4d7a87cb9af0e5b60a52f71aaf2685f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 31 Jan 2014 21:47:59 +0800 Subject: [PATCH 12/19] Still subscribe to "updates" for update notifications. It seems that we should subscribeError to checkForUpdatesCommand to catch all errors, and the "updates" would only work when there is no error happened. --- browser/auto_updater_mac.mm | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 111dcdcf13e4..be383ab47367 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -37,6 +37,31 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; + + AutoUpdaterDelegate* delegate = GetDelegate(); + if (!delegate) + return; + + // Subscribe to events. + __block bool has_update = false; + [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { + has_update = true; + + // There is a new update that has been downloaded. + SQRLUpdate* update = downloadedUpdate.update; + delegate->OnUpdateDownloaded( + base::SysNSStringToUTF8(update.releaseNotes), + base::SysNSStringToUTF8(update.releaseName), + base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), + base::SysNSStringToUTF8(update.updateURL.absoluteString), + base::Bind(RelaunchToInstallUpdate)); + } completed:^() { + // When the completed event is sent with no update, then we know there + // is no update available. + if (!has_update) + delegate->OnUpdateNotAvailable(); + has_update = false; + }]; } } @@ -48,28 +73,9 @@ void AutoUpdater::CheckForUpdates() { if (!delegate) return; - // Subscribe to events. - __block bool has_update = false; - [signal subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - has_update = true; - - // There is a new update that has been downloaded. - SQRLUpdate* update = downloadedUpdate.update; - delegate->OnUpdateDownloaded( - base::SysNSStringToUTF8(update.releaseNotes), - base::SysNSStringToUTF8(update.releaseName), - base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), - base::SysNSStringToUTF8(update.updateURL.absoluteString), - base::Bind(RelaunchToInstallUpdate)); - } error:^(NSError* error) { + [signal subscribeError:^(NSError* error) { // Something wrong happened. delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); - } completed:^() { - // When the completed event is sent with no update, then we know there - // is no update available. - if (!has_update) - delegate->OnUpdateNotAvailable(); - has_update = false; }]; } From da602a7c011e40eccecfdaf4d12cecf8d808dae3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Fri, 31 Jan 2014 16:02:38 -0800 Subject: [PATCH 13/19] Include the version with the update request --- browser/auto_updater_mac.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index be383ab47367..94c4bda279fc 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -34,7 +34,9 @@ void RelaunchToInstallUpdate() { void AutoUpdater::SetFeedURL(const std::string& feed) { if (g_updater == nil) { // Initialize the SQRLUpdater. - NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; + NSString *version = NSBundle.mainBundle.sqrl_bundleVersion; + NSString *urlString = [NSString stringWithFormat:@"%@?version=%@", base::SysUTF8ToNSString(feed), version]; + NSURL* url = [NSURL URLWithString:urlString]; NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; From 6949af542750742292b123e1cc93ca42696c28ee Mon Sep 17 00:00:00 2001 From: probablycorey Date: Fri, 31 Jan 2014 16:11:11 -0800 Subject: [PATCH 14/19] Emit 'update-available' and 'checking-for-update' events. --- browser/api/atom_api_auto_updater.cc | 8 ++++++++ browser/api/atom_api_auto_updater.h | 2 ++ browser/auto_updater_delegate.h | 6 ++++++ browser/auto_updater_mac.mm | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index a18fdebce9d0..69ed10089128 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -30,6 +30,14 @@ void AutoUpdater::OnError(const std::string& error) { Emit("error", &args); } +void AutoUpdater::OnCheckingForUpdate() { + Emit("checking-for-update"); +} + +void AutoUpdater::OnUpdateAvailable() { + Emit("update-available"); +} + void AutoUpdater::OnUpdateNotAvailable() { Emit("update-not-available"); } diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index 2bb830c27679..0207cbe6a99f 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -26,6 +26,8 @@ class AutoUpdater : public EventEmitter, // AutoUpdaterDelegate implementations. virtual void OnError(const std::string& error) OVERRIDE; + virtual void OnCheckingForUpdate() OVERRIDE; + virtual void OnUpdateAvailable() OVERRIDE; virtual void OnUpdateNotAvailable() OVERRIDE; virtual void OnUpdateDownloaded( const std::string& release_notes, diff --git a/browser/auto_updater_delegate.h b/browser/auto_updater_delegate.h index 063cc79d5e7f..280d3ed0f97a 100644 --- a/browser/auto_updater_delegate.h +++ b/browser/auto_updater_delegate.h @@ -20,6 +20,12 @@ class AutoUpdaterDelegate { // An error happened. virtual void OnError(const std::string& error) {} + // Checking to see if there is an update + virtual void OnCheckingForUpdate() {} + + // There is an update available and it is being downloaded + virtual void OnUpdateAvailable() {} + // There is no available update. virtual void OnUpdateNotAvailable() {} diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 94c4bda279fc..f2c55616a00e 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -6,6 +6,7 @@ #import #import +#import #import #include "base/bind.h" @@ -63,6 +64,15 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { if (!has_update) delegate->OnUpdateNotAvailable(); has_update = false; + [[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(); + } }]; } } From a59756485eda7d5b92585008bf1a742ca3297638 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Fri, 31 Jan 2014 16:13:01 -0800 Subject: [PATCH 15/19] Handle all download events in completed block. 'update-downloaded' and 'update-not-available' events are now called in the completed block. --- browser/auto_updater_mac.mm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index f2c55616a00e..66a532b2c98d 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -45,25 +45,29 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { if (!delegate) return; + __block SQRLUpdate* update = nil; // Subscribe to events. - __block bool has_update = false; [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - has_update = true; - - // There is a new update that has been downloaded. - SQRLUpdate* update = downloadedUpdate.update; - delegate->OnUpdateDownloaded( + update = downloadedUpdate.update; + } completed:^() { + if (update) { + // There is a new update that has been downloaded. + delegate->OnUpdateDownloaded( base::SysNSStringToUTF8(update.releaseNotes), base::SysNSStringToUTF8(update.releaseName), base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), base::SysNSStringToUTF8(update.updateURL.absoluteString), base::Bind(RelaunchToInstallUpdate)); - } completed:^() { - // When the completed event is sent with no update, then we know there - // is no update available. - if (!has_update) + } + else { + // When the completed event is sent with no update, then we know there + // is no update available. delegate->OnUpdateNotAvailable(); - has_update = false; + } + + update = nil; + }]; + [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater] subscribeNext:^(NSNumber *stateNumber) { int state = [stateNumber integerValue]; @@ -90,5 +94,4 @@ void AutoUpdater::CheckForUpdates() { delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); }]; } - } // namespace auto_updater From a8913f5ea03cc5ddb24aeabc4f9d2682dac052e7 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Fri, 31 Jan 2014 16:14:16 -0800 Subject: [PATCH 16/19] Remove version string from feed url --- browser/auto_updater_mac.mm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 66a532b2c98d..333461b5625a 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -35,9 +35,7 @@ void RelaunchToInstallUpdate() { void AutoUpdater::SetFeedURL(const std::string& feed) { if (g_updater == nil) { // Initialize the SQRLUpdater. - NSString *version = NSBundle.mainBundle.sqrl_bundleVersion; - NSString *urlString = [NSString stringWithFormat:@"%@?version=%@", base::SysUTF8ToNSString(feed), version]; - NSURL* url = [NSURL URLWithString:urlString]; + NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)]; NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url]; g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest]; From 5da1e9ed1055ff6cab0bf183e03eb03ef18ebe98 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Sat, 1 Feb 2014 15:55:57 -0800 Subject: [PATCH 17/19] Handle all download events from AutoUpdater::CheckForUpdates --- browser/auto_updater_mac.mm | 55 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 333461b5625a..e5bab41bf9c8 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -43,29 +43,6 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { if (!delegate) return; - __block SQRLUpdate* update = nil; - // Subscribe to events. - [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - update = downloadedUpdate.update; - } completed:^() { - if (update) { - // There is a new update that has been downloaded. - delegate->OnUpdateDownloaded( - base::SysNSStringToUTF8(update.releaseNotes), - base::SysNSStringToUTF8(update.releaseName), - base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), - base::SysNSStringToUTF8(update.updateURL.absoluteString), - base::Bind(RelaunchToInstallUpdate)); - } - else { - // When the completed event is sent with no update, then we know there - // is no update available. - delegate->OnUpdateNotAvailable(); - } - - update = nil; - }]; - [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater] subscribeNext:^(NSNumber *stateNumber) { int state = [stateNumber integerValue]; @@ -81,15 +58,35 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { // static void AutoUpdater::CheckForUpdates() { - RACSignal* signal = [g_updater.checkForUpdatesCommand execute:nil]; - AutoUpdaterDelegate* delegate = GetDelegate(); if (!delegate) return; - [signal subscribeError:^(NSError* error) { - // Something wrong happened. - delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); - }]; + [[[[g_updater.checkForUpdatesCommand + execute:nil] + // Send a `nil` after everything... + concat:[RACSignal return:nil]] + // But only take the first value. If an update is sent, we'll get that. + // Otherwise, we'll get our inserted `nil` value. + take:1] + subscribeNext:^(SQRLDownloadedUpdate *downloadedUpdate) { + if (downloadedUpdate) { + SQRLUpdate* update = downloadedUpdate.update; + // There is a new update that has been downloaded. + delegate->OnUpdateDownloaded( + base::SysNSStringToUTF8(update.releaseNotes), + base::SysNSStringToUTF8(update.releaseName), + base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), + base::SysNSStringToUTF8(update.updateURL.absoluteString), + base::Bind(RelaunchToInstallUpdate)); + } + else { + // When the completed event is sent with no update, then we know there + // is no update available. + delegate->OnUpdateNotAvailable(); + } + } error:^(NSError *error) { + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); + }]; } } // namespace auto_updater From c13724b342166228055aa99e3cfd077d189f1216 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 2 Feb 2014 19:58:25 +0800 Subject: [PATCH 18/19] Fix ci. --- browser/auto_updater_mac.mm | 6 ++---- script/cibuild | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index e5bab41bf9c8..094b599b1c08 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -48,8 +48,7 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { int state = [stateNumber integerValue]; if (state == SQRLUpdaterStateCheckingForUpdate) { delegate->OnCheckingForUpdate(); - } - else if (state == SQRLUpdaterStateDownloadingUpdate) { + } else if (state == SQRLUpdaterStateDownloadingUpdate) { delegate->OnUpdateAvailable(); } }]; @@ -79,8 +78,7 @@ void AutoUpdater::CheckForUpdates() { base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), base::SysNSStringToUTF8(update.updateURL.absoluteString), base::Bind(RelaunchToInstallUpdate)); - } - else { + } else { // When the completed event is sent with no update, then we know there // is no update available. delegate->OnUpdateNotAvailable(); diff --git a/script/cibuild b/script/cibuild index edabc2df9227..d9e8ceb68924 100755 --- a/script/cibuild +++ b/script/cibuild @@ -13,6 +13,7 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): rm_rf(os.path.join(SOURCE_ROOT, 'out')) rm_rf(os.path.join(SOURCE_ROOT, 'node_modules')) + rm_rf(os.path.join(SOURCE_ROOT, 'frameworks')) rm_rf(os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download', 'libchromiumcontent')) From 45b626e0cc6fa8411edf4681f110b4cf88d4bc34 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 2 Feb 2014 20:37:46 +0800 Subject: [PATCH 19/19] :memo: Add docs on new auto updater API. --- docs/api/browser/auto-updater.md | 52 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/api/browser/auto-updater.md b/docs/api/browser/auto-updater.md index d78a8720abe1..903dbc220f3a 100644 --- a/docs/api/browser/auto-updater.md +++ b/docs/api/browser/auto-updater.md @@ -1,42 +1,42 @@ # auto-updater -`auto-updater` module is a simple wrap around the Sparkle framework, it -provides auto update service for the application. +The `auto-updater` module is a simple wrap around the +[Squirrel](https://github.com/Squirrel/Squirrel.Mac) framework, you should +follow Squirrel's instructions on setting the server. -Before using this module, you should edit the `Info.plist` following -https://github.com/andymatuschak/Sparkle/wiki. +## Event: checking-for-update -## Event: will-install-update +Emitted when checking for update has started. + +## Event: update-available + +Emitted when there is an available update, the update would be downloaded +automatically. + +## Event: update-not-available + +Emitted when there is no available update. + +## Event: update-downloaded * `event` Event -* `version` String -* `continueUpdate` Function - -This event is emitted when the update is found and going to be installed. -Calling `event.preventDefault()` would pause it, and you can call -`continueUpdate` to continue the update. - -## Event: ready-for-update-on-quit - -* `event` Event -* `version` String +* `releaseNotes` String +* `releaseName` String +* `releaseDate` Date +* `updateUrl` String * `quitAndUpdate` Function -This event is emitted when user chose to delay the update until the quit. -Calling `quitAndUpdate()` would quit the application and install the update. +Emitted when update has been downloaded, calling `quitAndUpdate()` would restart +the application and install the update. ## autoUpdater.setFeedUrl(url) * `url` String -## autoUpdater.setAutomaticallyChecksForUpdates(flag) - -* `flag` Boolean - -## autoUpdater.setAutomaticallyDownloadsUpdates(flag) - -* `flag` Boolean +Set the `url` and initialize the auto updater. The `url` could not be changed +once it is set. ## autoUpdater.checkForUpdates() -## autoUpdater.checkForUpdatesInBackground() +Ask the server whether there is an update, you have to call `setFeedUrl` before +using this API.