diff --git a/agkyra/nwgui/menu.html b/agkyra/nwgui/menu.html index 2be192df99fdce5ff94d42ed28c53ec4375580e5..ad41503c3c60580e22f93a993b14b92b448fd59f 100644 --- a/agkyra/nwgui/menu.html +++ b/agkyra/nwgui/menu.html @@ -190,28 +190,40 @@ function deactivate_menu() { } } +function notify(level) { + if (globals.notification !== globals.status.code) { + // Notification has changed, raise notifier box + globals.notification = globals.status.code; + notify_user(NOTIFICATION[globals.status.code], level); + } +} + // Update progress window.setInterval(function() { - var new_progress = notification[globals.status.code]; + var new_progress = NOTIFICATION[globals.status.code]; var new_pause = ''; switch(globals.status.code) { case STATUS['UNINITIALIZED']: case STATUS['INITIALIZING']: case STATUS['SHUTING DOWN']: + notify('info'); deactivate_menu(); new_pause = 'inactive'; break; case STATUS['SYNCING']: + notify('info'); activate_menu(); new_progress += ', ' + remaining(globals.status) + ' remaining'; - new_pause = 'Pause' + new_pause = 'Pause'; break; case STATUS['PAUSING']: + notify('info'); new_progress += ', ' + remaining(globals.status) + ' remaining'; - new_pause = 'waiting...' + new_pause = 'waiting...'; pause_item.enabled = false; break; case STATUS['PAUSED']: + notify('info'); activate_menu(); new_pause = 'Start syncing'; if (remaining(globals.status) > 0) @@ -225,7 +237,9 @@ window.setInterval(function() { deactivate_menu(); new_pause = 'inactive'; settings_menu.enabled = true; + notify('error'); break; + default: notify('warning'); break; } if (globals.open_settings) { diff --git a/agkyra/nwgui/notify.js b/agkyra/nwgui/notify.js index 93adbc2fe2b45d376f6758db4668aee5f021f6c6..a3fde132ab7ea3b99b0c2328eb321664fdf40b58 100644 --- a/agkyra/nwgui/notify.js +++ b/agkyra/nwgui/notify.js @@ -1,6 +1,6 @@ var gui = require('nw.gui'); -var notification = { +var NOTIFICATION = { 0: 'Not initialized', 1: 'Initializing ...', 2: 'Shutting down', @@ -12,7 +12,7 @@ var notification = { 202: 'Authentication error', 203: 'Local directory error', 204: 'Remote container error', - 1000: 'Critical error' + 1000: 'error error' } function is_up(code) { return (code / 100 >> 0) === 1; } @@ -20,30 +20,31 @@ function has_settings_error(code) { return (code / 200 >> 0) === 2; } function remaining(status) { return status.unsynced - status.synced; } var ntf_title = { - 'info': 'Notification', - 'warning': 'Warning', - 'critical': 'Critical Error' + 'info': 'Agkyra Notification', + 'warning': 'Agkyra Warning', + 'error': 'Agkyra Error' } var ntf_icon = { 'info': 'static/images/ntf_info.png', 'warning': 'static/images/ntf_warning.png', - 'critical': 'static/images/ntf_critical.png', + 'error': 'static/images/ntf_error.png', +} + +var ntf_timeout = { + 'info': 1000, + 'warning': 1500, + 'error': 4000 } var notify_menu = new gui.MenuItem({ label: 'Notifications', icon: 'static/images/play_pause.png', iconIsTemplate: false, - click: function() { - console.log('Notification is clicked'); - } }); function notify_user(msg, level) { var n = new Notification(ntf_title[level], { - lang: 'utf-8', - body: msg, - icon: ntf_icon[level] + lang: 'utf-8', body: msg, icon: ntf_icon[level] }); - setTimeout(n.close.bind(n), 4000); + setTimeout(n.close.bind(n), ntf_timeout[level]); } \ No newline at end of file diff --git a/agkyra/nwgui/protocol.js b/agkyra/nwgui/protocol.js index bf4a61a61566d952769dbf02e9db906d7e6fecce..e33110f9ff9fec58c20921abfe33fbba368703ef 100644 --- a/agkyra/nwgui/protocol.js +++ b/agkyra/nwgui/protocol.js @@ -42,7 +42,8 @@ var globals = { status: {synced: 0, unsynced: 0, code: STATUS['UNINITIALIZED']}, authenticated: false, open_settings: false, - settings_are_open: false + settings_are_open: false, + notification: STATUS['UNINITIALIZED'] } // Protocol: requests ::: responses diff --git a/agkyra/nwgui/static/images/ntf_critical.png b/agkyra/nwgui/static/images/ntf_error.png similarity index 100% rename from agkyra/nwgui/static/images/ntf_critical.png rename to agkyra/nwgui/static/images/ntf_error.png diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 946be599eb7641e64bb69be1afb8c0d7702b0560..5dd0aa73bb23a1eecd82ebc8c129367eca02d747 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -447,8 +447,10 @@ class WebSocketProtocol(WebSocket): d.update(unsynced=0, synced=0) while msg: if isinstance(msg, messaging.SyncMessage): + LOG.error('UNSYNCED +1') self.set_status(unsynced=self.get_status('unsynced') + 1) elif isinstance(msg, messaging.AckSyncMessage): + LOG.error('SYNCED +1') self.set_status(synced=self.get_status('synced') + 1) elif isinstance(msg, messaging.LocalfsSyncDisabled): self.set_status(code=STATUS['DIRECTORY ERROR']) @@ -457,11 +459,12 @@ class WebSocketProtocol(WebSocket): self.set_status(code=STATUS['CONTAINER ERROR']) self.syncer.stop_all_daemons() LOG.debug('Backend message: %s' % msg.name) - msg = self.syncer.get_next_message() # Limit the amount of messages consumed each time max_consumption -= 1 if not max_consumption: break + else: + msg = self.syncer.get_next_message() def can_sync(self): """Check if settings are enough to setup a syncing proccess""" @@ -562,10 +565,13 @@ class WebSocketProtocol(WebSocket): syncer_.wait_sync_threads() def pause_sync(self): - syncer_ = self.syncer - if syncer_ and not syncer_.paused: - Thread(target=self._pause_syncer).start() + if self.syncer: + self.syncer.stop_decide() self.set_status(code=STATUS['PAUSING']) + # syncer_ = self.syncer + # if syncer_ and not syncer_.paused: + # Thread(target=self._pause_syncer).start() + # self.set_status(code=STATUS['PAUSING']) def start_sync(self): self.syncer.start_decide()