Add 'ready-for-update-on-quit' event for auto-updater.
This commit is contained in:
parent
f435ed8667
commit
a1dc4b88be
6 changed files with 51 additions and 3 deletions
|
@ -23,16 +23,25 @@ AutoUpdater::~AutoUpdater() {
|
||||||
|
|
||||||
void AutoUpdater::WillInstallUpdate(const std::string& version,
|
void AutoUpdater::WillInstallUpdate(const std::string& version,
|
||||||
const base::Closure& install) {
|
const base::Closure& install) {
|
||||||
|
continue_update_ = install;
|
||||||
|
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendString(version);
|
args.AppendString(version);
|
||||||
bool prevent_default = Emit("will-install-update-raw", &args);
|
bool prevent_default = Emit("will-install-update-raw", &args);
|
||||||
|
|
||||||
if (prevent_default)
|
if (!prevent_default)
|
||||||
continue_update_ = install;
|
|
||||||
else
|
|
||||||
install.Run();
|
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
|
// static
|
||||||
v8::Handle<v8::Value> AutoUpdater::New(const v8::Arguments &args) {
|
v8::Handle<v8::Value> AutoUpdater::New(const v8::Arguments &args) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
@ -87,6 +96,13 @@ v8::Handle<v8::Value> AutoUpdater::ContinueUpdate(const v8::Arguments &args) {
|
||||||
return v8::Undefined();
|
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
|
// static
|
||||||
void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
|
void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
@ -109,6 +125,7 @@ void AutoUpdater::Initialize(v8::Handle<v8::Object> target) {
|
||||||
CheckForUpdatesInBackground);
|
CheckForUpdatesInBackground);
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "continueUpdate", ContinueUpdate);
|
NODE_SET_PROTOTYPE_METHOD(t, "continueUpdate", ContinueUpdate);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "quitAndInstall", QuitAndInstall);
|
||||||
|
|
||||||
target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction());
|
target->Set(v8::String::NewSymbol("AutoUpdater"), t->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ class AutoUpdater : public EventEmitter,
|
||||||
|
|
||||||
virtual void WillInstallUpdate(const std::string& version,
|
virtual void WillInstallUpdate(const std::string& version,
|
||||||
const base::Closure& install) OVERRIDE;
|
const base::Closure& install) OVERRIDE;
|
||||||
|
virtual void ReadyForUpdateOnQuit(
|
||||||
|
const std::string& version,
|
||||||
|
const base::Closure& quit_and_install) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
static v8::Handle<v8::Value> New(const v8::Arguments &args);
|
||||||
|
@ -40,8 +43,10 @@ class AutoUpdater : public EventEmitter,
|
||||||
const v8::Arguments &args);
|
const v8::Arguments &args);
|
||||||
|
|
||||||
static v8::Handle<v8::Value> ContinueUpdate(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 continue_update_;
|
||||||
|
base::Closure quit_and_install_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,5 +6,7 @@ AutoUpdater::__proto__ = EventEmitter.prototype
|
||||||
autoUpdater = new AutoUpdater
|
autoUpdater = new AutoUpdater
|
||||||
autoUpdater.on 'will-install-update-raw', (event, version) ->
|
autoUpdater.on 'will-install-update-raw', (event, version) ->
|
||||||
@emit 'will-install-update', event, version, => @continueUpdate()
|
@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
|
module.exports = autoUpdater
|
||||||
|
|
|
@ -13,4 +13,9 @@ void AutoUpdaterDelegate::WillInstallUpdate(const std::string& version,
|
||||||
install.Run();
|
install.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoUpdaterDelegate::ReadyForUpdateOnQuit(
|
||||||
|
const std::string& version,
|
||||||
|
const base::Closure& quit_and_install) {
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace auto_updater
|
} // namespace auto_updater
|
||||||
|
|
|
@ -13,9 +13,14 @@ namespace auto_updater {
|
||||||
|
|
||||||
class AutoUpdaterDelegate {
|
class AutoUpdaterDelegate {
|
||||||
public:
|
public:
|
||||||
|
// The application is going to relaunch to install update.
|
||||||
virtual void WillInstallUpdate(const std::string& version,
|
virtual void WillInstallUpdate(const std::string& version,
|
||||||
const base::Closure& install);
|
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:
|
protected:
|
||||||
virtual ~AutoUpdaterDelegate() {}
|
virtual ~AutoUpdaterDelegate() {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,6 +56,20 @@ void CallNSInvocation(ScopedNSInvocation invocation) {
|
||||||
return YES;
|
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
|
@end
|
||||||
|
|
||||||
namespace auto_updater {
|
namespace auto_updater {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue