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

Open notification box on critical errors

parent 09b71df9
...@@ -16,10 +16,14 @@ You should have received a copy of the GNU General Public License ...@@ -16,10 +16,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<html> <html>
<head><title>GUI for Agkyra Pithos+ Syncing Client</title></head> <head>
<meta charset="UTF-8" />
<title>GUI for Agkyra Pithos+ Syncing Client</title>
</head>
<body> <body>
<script src="protocol.js"></script> <script src="protocol.js"></script>
<script src="settings.js"></script> <script src="settings.js"></script>
<script src="notify.js"></script>
<script src="static/js/jquery.js"></script> <script src="static/js/jquery.js"></script>
<script type="text/javascript"> <script type="text/javascript">
...@@ -214,7 +218,14 @@ window.setInterval(function() { ...@@ -214,7 +218,14 @@ window.setInterval(function() {
var status = globals['status']; var status = globals['status'];
var new_progress = progress_item.label; var new_progress = progress_item.label;
var new_pause = pause_item.label; var new_pause = pause_item.label;
if (!status.can_sync) { if (status.notification !== 0) {
new_progress = notifications[status.notification];
new_pause = 'inactive';
if (progress_item.label !== new_progress) {
notify_user(new_progress, 'critical');
}
}
else if (!status.can_sync) {
if (globals.just_opened) new_progress = 'Connecting...' if (globals.just_opened) new_progress = 'Connecting...'
else new_progress = 'Not able to sync' else new_progress = 'Not able to sync'
new_pause = 'inactive' new_pause = 'inactive'
......
var gui = require('nw.gui');
var ntf_title = {
'info': 'Notification',
'warning': 'Warning',
'critical': 'Critical Error'
}
var ntf_icon = {
'info': 'static/images/ntf_info.png',
'warning': 'static/images/ntf_warning.png',
'critical': 'static/images/ntf_critical.png',
}
var notify_menu = new gui.MenuItem({
label: 'Notifications',
icon: 'static/images/play_pause.png',
iconIsTemplate: false,
click: function() {
console.log('Notification is clecked');
}
});
function notify_user(msg, level) {
var n = new Notification(ntf_title[level], {
lang: 'utf-8',
body: msg,
icon: ntf_icon[level]
});
setTimeout(n.close.bind(n), 4000);
}
\ No newline at end of file
...@@ -28,6 +28,13 @@ function send_json(socket, msg) { ...@@ -28,6 +28,13 @@ function send_json(socket, msg) {
socket.send(JSON.stringify(msg)); socket.send(JSON.stringify(msg));
} }
var notifications = {
0: 'Syncer is consistent',
1: 'Local directory is not accessible',
2: 'Remote container is not accessible',
100: 'Unknown error'
}
var globals = { var globals = {
settings: { settings: {
token: null, token: null,
...@@ -36,7 +43,8 @@ var globals = { ...@@ -36,7 +43,8 @@ var globals = {
directory: null, directory: null,
exclude: null exclude: null
}, },
status: {synced: 0, unsynced: 0, paused: null, can_sync: false}, status: {
synced: 0, unsynced: 0, paused: null, can_sync: false, notification: 0},
authenticated: false, authenticated: false,
just_opened: false, just_opened: false,
open_settings: false, open_settings: false,
......
...@@ -437,7 +437,7 @@ class WebSocketProtocol(WebSocket): ...@@ -437,7 +437,7 @@ class WebSocketProtocol(WebSocket):
# LOG.info('Collision for "%s"' % msg.objname) # LOG.info('Collision for "%s"' % msg.objname)
# elif isinstance(msg, messaging.ConflictStashMessage): # elif isinstance(msg, messaging.ConflictStashMessage):
# LOG.info('Conflict for "%s"' % msg.objname) # LOG.info('Conflict for "%s"' % msg.objname)
if isinstance(msg, messaging.LocalfsSyncDisabled): elif isinstance(msg, messaging.LocalfsSyncDisabled):
# LOG.debug('Local FS is dissabled, noooo!') # LOG.debug('Local FS is dissabled, noooo!')
self.status['notification'] = 1 self.status['notification'] = 1
self.syncer.stop_all_daemons() self.syncer.stop_all_daemons()
...@@ -485,12 +485,18 @@ class WebSocketProtocol(WebSocket): ...@@ -485,12 +485,18 @@ class WebSocketProtocol(WebSocket):
# while not msg: # while not msg:
# time.sleep(0.2) # time.sleep(0.2)
# msg = syncer_.get_next_message() # msg = syncer_.get_next_message()
# This should be activated only on accepting a positive message
self.status['notification'] = 0
self.status['unsynced'] = 0
self.status['synced'] = 0
if msg: if msg:
if isinstance(msg, messaging.LocalfsSyncDisabled): if isinstance(msg, messaging.LocalfsSyncDisabled):
LOG.debug('Local FS is dissabled, noooo!') LOG.debug('Local FS is disabled')
self.status['notification'] = 1 self.status['notification'] = 1
elif isinstance(msg, messaging.PithosSyncDisabled): elif isinstance(msg, messaging.PithosSyncDisabled):
LOG.debug('Pithos sync is disabled, noooooo!') LOG.debug('Pithos sync is disabled')
self.status['notification'] = 2 self.status['notification'] = 2
else: else:
LOG.debug("Unexpected message: %s" % msg) LOG.debug("Unexpected message: %s" % msg)
......
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