From dc5885959614dafe61bb1c673b0012bc80695971 Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 11 Nov 2011 17:38:52 +0100 Subject: [PATCH] Mask app on restart and shutdown --- couchpotato/core/_base/_core/main.py | 7 ++++ couchpotato/core/plugins/base.py | 2 +- couchpotato/static/scripts/couchpotato.js | 47 ++++++++++++++++++++++- couchpotato/static/scripts/page/about.js | 4 +- couchpotato/static/style/main.css | 10 ++--- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 4bfcf010..f17fa58f 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -1,6 +1,7 @@ from couchpotato import app from couchpotato.api import addApiView from couchpotato.core.event import fireEvent, addEvent +from couchpotato.core.helpers.request import jsonified from couchpotato.core.helpers.variable import cleanHost from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin @@ -21,6 +22,7 @@ class Core(Plugin): def __init__(self): addApiView('app.shutdown', self.shutdown) addApiView('app.restart', self.restart) + addApiView('app.available', self.available) addEvent('app.crappy_restart', self.crappyRestart) addEvent('app.load', self.launchBrowser, priority = 100) @@ -28,6 +30,11 @@ class Core(Plugin): self.removeRestartFile() + def available(self): + return jsonified({ + 'succes': True + }) + def crappyRestart(self): ctx = app.test_request_context() ctx.push() diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 10881c1e..225291bc 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -113,7 +113,7 @@ class Plugin(object): data = urllib2.urlopen(request).read() except IOError: - log.error('Failed opening url: %s' % (traceback.format_exc(1))) + log.error('Failed opening url: %s %s' % (url, traceback.format_exc(1))) raise self.http_last_use[host] = time.time() diff --git a/couchpotato/static/scripts/couchpotato.js b/couchpotato/static/scripts/couchpotato.js index 5afd3106..c1c35419 100644 --- a/couchpotato/static/scripts/couchpotato.js +++ b/couchpotato/static/scripts/couchpotato.js @@ -109,11 +109,56 @@ var CouchPotato = new Class({ }, shutdown: function(){ - Api.request('app.shutdown'); + var self = this; + + self.blockPage('You have shutdown. This is what suppose to happen ;)'); + Api.request('app.shutdown', { + 'onComplete': self.blockPage.bind(self) + }); + self.checkAvailable(); }, restart: function(){ + var self = this; + + self.blockPage('Restarting... please wait. If this takes to long, something must have gone wrong.'); Api.request('app.restart'); + self.checkAvailable(); + }, + + checkAvailable: function(){ + var self = this; + + Api.request('app.available', { + 'onFailure': function(){ + self.checkAvailable.delay(1000, self); + self.fireEvent('unload'); + }, + 'onSuccess': function(){ + self.unBlockPage(); + self.fireEvent('load'); + } + }); + }, + + blockPage: function(message){ + var self = this; + + if(!self.mask){ + var body = $(document.body); + self.mask = new Spinner(document.body, { + 'message': new Element('div').adopt( + new Element('h1', {'text': 'Unavailable.'}), + new Element('div', {'text': message || 'Something must have crashed.. check the logs ;)'}) + ) + }); + } + self.mask.show(); + }, + + unBlockPage: function(){ + var self = this; + self.mask.hide(); } }); diff --git a/couchpotato/static/scripts/page/about.js b/couchpotato/static/scripts/page/about.js index c6e334d1..3e6db116 100644 --- a/couchpotato/static/scripts/page/about.js +++ b/couchpotato/static/scripts/page/about.js @@ -95,8 +95,8 @@ var AboutSettingTab = new Class({ ) ); - self.fillVersion(Updater.getInfo()); - Updater.addEvent('loaded', self.fillVersion.bind(self)) + if(!self.fillVersion(Updater.getInfo())) + Updater.addEvent('loaded', self.fillVersion.bind(self)) self.settings.createGroup({ 'name': 'actions' diff --git a/couchpotato/static/style/main.css b/couchpotato/static/style/main.css index 3c61bd4d..754cf642 100644 --- a/couchpotato/static/style/main.css +++ b/couchpotato/static/style/main.css @@ -112,8 +112,9 @@ form { margin:0; } -.spinner{ - background: #4e5969 url('../images/spinner.gif') no-repeat center; +body > .spinner, .mask{ + background: rgba(0,0,0, 0.9); + z-index: 100; } .button { @@ -380,11 +381,6 @@ form { ); } -.mask { - background: rgba(0,0,0, 0.7); - z-index: 100; -} - .question { display: block; width: 600px;