Simple growl-like notifications
This commit is contained in:
1 parent
3b441d2942
commit
cf3041c848
6 files changed
+80
-15
No files matched your search
@@ -136,23 +136,24 @@ class CoreNotifier(Notification):
|
||||
#db.close()
|
||||
return True
|
||||
|
||||
def frontend(self, type = 'notification', data = {}):
|
||||
def frontend(self, type = 'notification', data = {}, message = None):
|
||||
|
||||
self.m_lock.acquire()
|
||||
message = {
|
||||
notification = {
|
||||
'message_id': str(uuid.uuid4()),
|
||||
'time': time.time(),
|
||||
'type': type,
|
||||
'data': data,
|
||||
'message': message,
|
||||
}
|
||||
self.messages.append(message)
|
||||
self.messages.append(notification)
|
||||
|
||||
while len(self.listeners) > 0 and not self.shuttingDown():
|
||||
try:
|
||||
listener, last_id = self.listeners.pop()
|
||||
listener({
|
||||
'success': True,
|
||||
'result': [message],
|
||||
'result': [notification],
|
||||
})
|
||||
except:
|
||||
break
|
||||
|
||||
@@ -126,11 +126,12 @@ var NotificationBase = new Class({
|
||||
processData: function(json){
|
||||
var self = this;
|
||||
|
||||
|
||||
// Process data
|
||||
if(json){
|
||||
Array.each(json.result, function(result){
|
||||
App.fireEvent(result.type, result)
|
||||
App.fireEvent(result.type, result);
|
||||
if(result.message && result.read === undefined)
|
||||
self.showMessage(result.message);
|
||||
})
|
||||
|
||||
if(json.result.length > 0)
|
||||
@@ -140,7 +141,31 @@ var NotificationBase = new Class({
|
||||
// Restart poll
|
||||
self.startPoll()
|
||||
},
|
||||
|
||||
|
||||
showMessage: function(message){
|
||||
var self = this;
|
||||
|
||||
if(!self.message_container)
|
||||
self.message_container = new Element('div.messages').inject(document.body);
|
||||
|
||||
var new_message = new Element('div.message', {
|
||||
'text': message
|
||||
}).inject(self.message_container);
|
||||
|
||||
setTimeout(function(){
|
||||
new_message.addClass('show')
|
||||
}, 10);
|
||||
|
||||
setTimeout(function(){
|
||||
new_message.addClass('hide')
|
||||
setTimeout(function(){
|
||||
new_message.destroy();
|
||||
}, 1000);
|
||||
}, 4000);
|
||||
|
||||
},
|
||||
|
||||
// Notification setting tests
|
||||
addTestButtons: function(){
|
||||
var self = this;
|
||||
|
||||
|
||||
@@ -240,7 +240,6 @@ class MoviePlugin(Plugin):
|
||||
db = get_session()
|
||||
|
||||
for id in getParam('id').split(','):
|
||||
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True)
|
||||
movie = db.query(Movie).filter_by(id = id).first()
|
||||
|
||||
if movie:
|
||||
@@ -250,6 +249,7 @@ class MoviePlugin(Plugin):
|
||||
for title in movie.library.titles:
|
||||
if title.default: default_title = title.title
|
||||
|
||||
fireEvent('notify.frontend', type = 'movie.busy.%s' % id, data = True, message = 'Updating "%s"' % default_title)
|
||||
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True, on_complete = self.createOnComplete(id))
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ class MoviePlugin(Plugin):
|
||||
onComplete()
|
||||
|
||||
if added:
|
||||
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict)
|
||||
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = 'Successfully added "%s" to your wanted list.' % params.get('title', ''))
|
||||
|
||||
#db.close()
|
||||
return movie_dict
|
||||
|
||||
@@ -17,10 +17,13 @@ var Movie = new Class({
|
||||
self.parent(self, options);
|
||||
|
||||
App.addEvent('movie.update.'+data.id, self.update.bind(self));
|
||||
App.addEvent('movie.busy.'+data.id, function(notification){
|
||||
if(notification.data)
|
||||
self.busy(true)
|
||||
});
|
||||
|
||||
['movie.busy', 'searcher.started'].each(function(listener){
|
||||
App.addEvent(listener+'.'+data.id, function(notification){
|
||||
if(notification.data)
|
||||
self.busy(true)
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
busy: function(set_busy){
|
||||
|
||||
@@ -84,7 +84,7 @@ class Searcher(Plugin):
|
||||
if not default_title:
|
||||
return
|
||||
|
||||
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True)
|
||||
fireEvent('notify.frontend', type = 'searcher.started.%s' % movie['id'], data = True, message = 'Searching for "%s"' % default_title)
|
||||
|
||||
ret = False
|
||||
for quality_type in movie['profile']['types']:
|
||||
|
||||
Reference in new issue
Block a user