Always do restart after update. fix #363

This commit is contained in:
Ruud
2012-05-28 20:50:21 +02:00
parent b2ccca9299
commit 523a1e7d63
4 changed files with 57 additions and 24 deletions
+28 -10
View File
@@ -28,7 +28,7 @@ class Updater(Plugin):
else:
self.updater = SourceUpdater()
fireEvent('schedule.interval', 'updater.check', self.check, hours = 6)
fireEvent('schedule.interval', 'updater.check', self.autoUpdate, hours = 6)
addEvent('app.load', self.check)
addEvent('updater.info', self.info)
@@ -48,17 +48,20 @@ class Updater(Plugin):
'return': {'type': 'see updater.info'}
})
def autoUpdate(self):
if self.check() and self.conf('automatic') and not self.updater.update_failed:
self.updater.doUpdate()
def check(self):
if self.isDisabled():
return
if self.updater.check():
if self.conf('automatic') and not self.updater.update_failed:
if self.updater.doUpdate():
fireEventAsync('app.restart')
else:
if self.conf('notification'):
fireEvent('updater.available', message = 'A new update is available', data = self.updater.info())
if self.conf('notification') and not self.conf('automatic'):
fireEvent('updater.available', message = 'A new update is available', data = self.updater.info())
return True
return False
def info(self):
return self.updater.info()
@@ -67,12 +70,22 @@ class Updater(Plugin):
return jsonified(self.updater.info())
def checkView(self):
self.check()
return self.updater.getInfo()
return jsonified({
'update_available': self.check(),
'info': self.updater.info()
})
def doUpdateView(self):
self.check()
if not self.update_version:
log.error('Trying to update when no update is available.')
success = False
else:
success = self.updater.doUpdate()
return jsonified({
'success': self.updater.doUpdate()
'success': success
})
@@ -137,6 +150,7 @@ class GitUpdater(BaseUpdater):
self.repo = LocalRepository(Env.get('app_dir'), command = git_command)
def doUpdate(self):
try:
log.debug('Stashing local changes')
self.repo.saveStash()
@@ -152,6 +166,8 @@ class GitUpdater(BaseUpdater):
version_date = datetime.fromtimestamp(info['update_version']['date'])
fireEvent('updater.updated', 'Updated to a new version with hash "%s", this version is from %s' % (info['update_version']['hash'], version_date), data = info)
fireEventAsync('app.restart')
return True
except:
log.error('Failed updating via GIT: %s' % traceback.format_exc())
@@ -243,6 +259,8 @@ class SourceUpdater(BaseUpdater):
# Write update version to file
self.createFile(self.version_file, json.dumps(self.update_version))
fireEventAsync('app.restart')
return True
except:
log.error('Failed updating: %s' % traceback.format_exc())
@@ -16,7 +16,15 @@ var UpdaterBase = new Class({
var self = this;
Api.request('updater.check', {
'onComplete': onComplete || Function.from()
'onComplete': function(json){
if(onComplete)
onComplete(json);
if(json.update_available)
self.doUpdate();
else
App.unBlockPage()
}
})
},
@@ -81,15 +89,19 @@ var UpdaterBase = new Class({
Api.request('updater.update', {
'onComplete': function(json){
if(json.success){
App.restart('Please wait while CouchPotato is being updated with more awesome stuff.', 'Updating');
App.checkAvailable.delay(500, App, [1000, function(){
window.location.reload();
}]);
if(self.message)
self.message.destroy();
self.updating();
}
}
});
},
updating: function(){
App.blockPage('Please wait while CouchPotato is being updated with more awesome stuff.', 'Updating');
App.checkAvailable.delay(500, App, [1000, function(){
window.location.reload();
}]);
if(self.message)
self.message.destroy();
}
});
+9 -6
View File
@@ -24,7 +24,7 @@ var CouchPotato = new Class({
if(window.location.hash)
History.handleInitialState();
self.openPage(window.location.pathname);
History.addEvent('change', self.openPage.bind(self));
@@ -211,10 +211,10 @@ var CouchPotato = new Class({
}]);
},
checkForUpdate: function(func){
checkForUpdate: function(onComplete){
var self = this;
Updater.check(func)
Updater.check(onComplete)
self.blockPage('Please wait. If this takes to long, something must have gone wrong.', 'Checking for updates');
self.checkAvailable(3000);
@@ -244,6 +244,8 @@ var CouchPotato = new Class({
blockPage: function(message, title){
var self = this;
self.unBlockPage();
var body = $(document.body);
self.mask = new Element('div.mask').adopt(
new Element('div').adopt(
@@ -259,9 +261,10 @@ var CouchPotato = new Class({
unBlockPage: function(){
var self = this;
self.mask.get('tween').start('opacity', 0).chain(function(){
this.element.destroy()
});
if(self.mask)
self.mask.get('tween').start('opacity', 0).chain(function(){
this.element.destroy()
});
},
createUrl: function(action, params){
+1 -1
View File
@@ -48,7 +48,7 @@ var AboutSettingTab = new Class({
'text': 'Getting version...',
'events': {
'click': App.checkForUpdate.bind(App, function(json){
self.fillVersion(json)
self.fillVersion(json.info)
}),
'mouseenter': function(){
this.set('text', 'Check for updates')