Mask app on restart and shutdown
This commit is contained in:
1 parent
668b95353f
commit
dc58859596
5 files changed
+59
-11
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
from couchpotato import app
|
from couchpotato import app
|
||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import fireEvent, addEvent
|
from couchpotato.core.event import fireEvent, addEvent
|
||||||
|
from couchpotato.core.helpers.request import jsonified
|
||||||
from couchpotato.core.helpers.variable import cleanHost
|
from couchpotato.core.helpers.variable import cleanHost
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
@@ -21,6 +22,7 @@ class Core(Plugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
addApiView('app.shutdown', self.shutdown)
|
addApiView('app.shutdown', self.shutdown)
|
||||||
addApiView('app.restart', self.restart)
|
addApiView('app.restart', self.restart)
|
||||||
|
addApiView('app.available', self.available)
|
||||||
|
|
||||||
addEvent('app.crappy_restart', self.crappyRestart)
|
addEvent('app.crappy_restart', self.crappyRestart)
|
||||||
addEvent('app.load', self.launchBrowser, priority = 100)
|
addEvent('app.load', self.launchBrowser, priority = 100)
|
||||||
@@ -28,6 +30,11 @@ class Core(Plugin):
|
|||||||
|
|
||||||
self.removeRestartFile()
|
self.removeRestartFile()
|
||||||
|
|
||||||
|
def available(self):
|
||||||
|
return jsonified({
|
||||||
|
'succes': True
|
||||||
|
})
|
||||||
|
|
||||||
def crappyRestart(self):
|
def crappyRestart(self):
|
||||||
ctx = app.test_request_context()
|
ctx = app.test_request_context()
|
||||||
ctx.push()
|
ctx.push()
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class Plugin(object):
|
|||||||
|
|
||||||
data = urllib2.urlopen(request).read()
|
data = urllib2.urlopen(request).read()
|
||||||
except IOError:
|
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
|
raise
|
||||||
|
|
||||||
self.http_last_use[host] = time.time()
|
self.http_last_use[host] = time.time()
|
||||||
|
|||||||
@@ -109,11 +109,56 @@ var CouchPotato = new Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
shutdown: function(){
|
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(){
|
restart: function(){
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.blockPage('Restarting... please wait. If this takes to long, something must have gone wrong.');
|
||||||
Api.request('app.restart');
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ var AboutSettingTab = new Class({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
self.fillVersion(Updater.getInfo());
|
if(!self.fillVersion(Updater.getInfo()))
|
||||||
Updater.addEvent('loaded', self.fillVersion.bind(self))
|
Updater.addEvent('loaded', self.fillVersion.bind(self))
|
||||||
|
|
||||||
self.settings.createGroup({
|
self.settings.createGroup({
|
||||||
'name': 'actions'
|
'name': 'actions'
|
||||||
|
|||||||
@@ -112,8 +112,9 @@ form {
|
|||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.spinner{
|
body > .spinner, .mask{
|
||||||
background: #4e5969 url('../images/spinner.gif') no-repeat center;
|
background: rgba(0,0,0, 0.9);
|
||||||
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
@@ -380,11 +381,6 @@ form {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mask {
|
|
||||||
background: rgba(0,0,0, 0.7);
|
|
||||||
z-index: 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
.question {
|
.question {
|
||||||
display: block;
|
display: block;
|
||||||
width: 600px;
|
width: 600px;
|
||||||
|
|||||||
Reference in new issue
Block a user