diff --git a/agkyra/nwgui/menu.html b/agkyra/nwgui/menu.html index a829e990e4c9820c442b97f943a3270cd7869580..cfc1f4a7a55c6ac270906aa7619cefdefe9c371c 100644 --- a/agkyra/nwgui/menu.html +++ b/agkyra/nwgui/menu.html @@ -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/>. --> <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> <script src="protocol.js"></script> <script src="settings.js"></script> + <script src="notify.js"></script> <script src="static/js/jquery.js"></script> <script type="text/javascript"> @@ -214,7 +218,14 @@ window.setInterval(function() { var status = globals['status']; var new_progress = progress_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...' else new_progress = 'Not able to sync' new_pause = 'inactive' diff --git a/agkyra/nwgui/notify.js b/agkyra/nwgui/notify.js new file mode 100644 index 0000000000000000000000000000000000000000..59735b1c23ae7882f519ee0d4c2fea4fd58a7648 --- /dev/null +++ b/agkyra/nwgui/notify.js @@ -0,0 +1,30 @@ +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 diff --git a/agkyra/nwgui/protocol.js b/agkyra/nwgui/protocol.js index 3ee6ccbe4ffd3b37bcfd809917c03de3c230042e..f760d2a0a376515919f4d57bdd5b314505a0e643 100644 --- a/agkyra/nwgui/protocol.js +++ b/agkyra/nwgui/protocol.js @@ -28,6 +28,13 @@ function send_json(socket, 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 = { settings: { token: null, @@ -36,7 +43,8 @@ var globals = { directory: 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, just_opened: false, open_settings: false, diff --git a/agkyra/nwgui/static/images/ntf_critical.png b/agkyra/nwgui/static/images/ntf_critical.png new file mode 100644 index 0000000000000000000000000000000000000000..9e4ba583076ad6b3015835168f174a6cadce0239 Binary files /dev/null and b/agkyra/nwgui/static/images/ntf_critical.png differ diff --git a/agkyra/nwgui/static/images/ntf_info.png b/agkyra/nwgui/static/images/ntf_info.png new file mode 100644 index 0000000000000000000000000000000000000000..88431183c7d4eff7e8fe8527ae06ed2e8bc94bed Binary files /dev/null and b/agkyra/nwgui/static/images/ntf_info.png differ diff --git a/agkyra/nwgui/static/images/ntf_warning.png b/agkyra/nwgui/static/images/ntf_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..74ff54f6634d5f8ac145cfaa46b71973dca60efb Binary files /dev/null and b/agkyra/nwgui/static/images/ntf_warning.png differ diff --git a/agkyra/protocol.py b/agkyra/protocol.py index 63c99d07644f54913329531d1517c602e8a5e38e..e651f73d3058c08a16058e9c4e37c46f526c1ada 100644 --- a/agkyra/protocol.py +++ b/agkyra/protocol.py @@ -437,7 +437,7 @@ class WebSocketProtocol(WebSocket): # LOG.info('Collision for "%s"' % msg.objname) # elif isinstance(msg, messaging.ConflictStashMessage): # LOG.info('Conflict for "%s"' % msg.objname) - if isinstance(msg, messaging.LocalfsSyncDisabled): + elif isinstance(msg, messaging.LocalfsSyncDisabled): # LOG.debug('Local FS is dissabled, noooo!') self.status['notification'] = 1 self.syncer.stop_all_daemons() @@ -485,12 +485,18 @@ class WebSocketProtocol(WebSocket): # while not msg: # time.sleep(0.2) # 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 isinstance(msg, messaging.LocalfsSyncDisabled): - LOG.debug('Local FS is dissabled, noooo!') + LOG.debug('Local FS is disabled') self.status['notification'] = 1 elif isinstance(msg, messaging.PithosSyncDisabled): - LOG.debug('Pithos sync is disabled, noooooo!') + LOG.debug('Pithos sync is disabled') self.status['notification'] = 2 else: LOG.debug("Unexpected message: %s" % msg)