Commit b6c2a013 authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Raise GUI notification box on status change

parent 21a07727
......@@ -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) {
......
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
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment