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;
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;
CheckForUpdatesInBackground);
NODE_SET_PROTOTYPE_METHOD(t, "continueUpdate", ContinueUpdate);
+ NODE_SET_PROTOTYPE_METHOD(t, "quitAndInstall", QuitAndInstall);
target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction());
}
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);
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);
};
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
install.Run();
}
+void AutoUpdaterDelegate::ReadyForUpdateOnQuit(
+ const std::string& version,
+ const base::Closure& quit_and_install) {
+}
+
} // 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() {}
};
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 {