From a0b3e13d81f4e29140bbdd443b9a645db0a46519 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 4 Jun 2011 21:34:18 +0200 Subject: [PATCH] Front end notification listener --- couchpotato/core/notifications/core/main.py | 14 ++++++++------ .../core/notifications/core/static/notification.js | 4 ++-- couchpotato/core/plugins/library/main.py | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/couchpotato/core/notifications/core/main.py b/couchpotato/core/notifications/core/main.py index d7d260ba..43bfce29 100644 --- a/couchpotato/core/notifications/core/main.py +++ b/couchpotato/core/notifications/core/main.py @@ -13,9 +13,9 @@ class CoreNotifier(Plugin): messages = [] def __init__(self): + addEvent('notify', self.notify) - addEvent('notify.core_notifier', self.notify) - addEvent('core_notifier.frontend', self.frontend) + addEvent('notify.core', self.frontend) addApiView('core_notifier.listener', self.listener) @@ -29,7 +29,6 @@ class CoreNotifier(Plugin): }) def frontend(self, type = 'notification', data = {}): - self.messages.append({ 'time': time.time(), 'type': type, @@ -38,12 +37,15 @@ class CoreNotifier(Plugin): def listener(self): + messages = [] for message in self.messages: + print message['time'], (time.time() - 5) #delete message older then 15s - if message['time'] < (time.time() - 15): - del message + if message['time'] > (time.time() - 15): + messages.append(message) + self.messages = [] return jsonified({ 'success': True, - 'result': self.messages, + 'result': messages, }) diff --git a/couchpotato/core/notifications/core/static/notification.js b/couchpotato/core/notifications/core/static/notification.js index caa2f227..891d7e8a 100644 --- a/couchpotato/core/notifications/core/static/notification.js +++ b/couchpotato/core/notifications/core/static/notification.js @@ -7,7 +7,7 @@ var NotificationBase = new Class({ var self = this; self.setOptions(options); - //App.addEvent('load', self.request.bind(self)); + App.addEvent('load', self.request.bind(self)); self.addEvent('notification', self.notify.bind(self)) @@ -33,7 +33,7 @@ var NotificationBase = new Class({ var self = this; Array.each(json.result, function(result){ - self.fireEvent(result.type, result.data) + App.fireEvent(result.type, result.data) }) } diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index 28b93334..a68f9c53 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -100,5 +100,6 @@ class LibraryPlugin(Plugin): #log.debug('Failed to attach to library: %s' % traceback.format_exc()) fireEvent('library.update.after') + fireEvent('notify.core', type = 'library.update', data = library_dict) return library.to_dict({'titles': {}, 'files':{}})