Add 'ready-for-update-on-quit' event for auto-updater.

This commit is contained in:
Cheng Zhao 2013-06-03 21:51:46 +08:00
Родитель f435ed8667
Коммит a1dc4b88be
6 изменённых файлов: 51 добавлений и 3 удалений

Просмотреть файл

@ -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());
}

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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() {}
};

Просмотреть файл

@ -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 {