diff --git a/agkyra/agkyra/gui/menu.html b/agkyra/agkyra/gui/menu.html index 7ba6e4f50e46a70ec5870b37a55a64c05eb61a50..bcba22bbcafb643bebd7e71c2038a9330d92d8dd 100644 --- a/agkyra/agkyra/gui/menu.html +++ b/agkyra/agkyra/gui/menu.html @@ -42,7 +42,7 @@ menu.append(new gui.MenuItem({type: 'separator'})); pause_item = new gui.MenuItem({ // pause menu item icon: 'images/play_pause.png', - label: '', + label: 'NOT READY', type: 'normal', click: function() { if (paused) {post_start(socket);} else {post_pause(socket);} @@ -51,84 +51,43 @@ pause_item = new gui.MenuItem({ pause_item.enabled = false; menu.append(pause_item); -// Update progress -window.setInterval(function() { - var status = globals['status']; - var new_progress = progress_item.label; - var new_pause = pause_item.label; - var menu_modified = false; - if (status['paused'] !== null) { - switch(pause_item.label) { - case pause_syncing: if (status['paused']) { - // Update to "Paused - start syncing" - paused = true; - new_pause = start_syncing; - menu_modified = true; - } // else continue syncing - new_progress = status['progress'] + '%' + ' synced'; - break; - case start_syncing: if (status['paused']) return; - // else update to "Syncing - pause syncing" - paused = false; - new_pause = pause_syncing; - new_progress = status['progress'] + '%' + ' synced'; - menu_modified = true; - break; - default: - if (status['paused']) {new_pause = start_syncing; paused=true;} - else {new_pause = pause_syncing; paused=false;} - new_progress = status['progress'] + '%' + ' synced'; - pause_item.enabled = true; - menu_modified = true; - } - } - if (new_pause != pause_item.label) { - pause_item.label = new_pause; - menu_modified = true; - } - if (new_progress != progress_item.label) { - progress_item.label = new_progress; - menu_modified = true; - } - if (menu_modified) { - if (paused) progress_item.label += ' - paused'; - tray.menu = menu; - } - get_status(socket); -}, 1500); - // Menu actions contents -menu.append(new gui.MenuItem({ +var local_folder_menu = new gui.MenuItem({ label: 'Open local folder', icon: 'images/folder.png', + enabled: false, click: function () { var dir = globals['settings']['directory']; console.log('Open ' + dir); gui.Shell.showItemInFolder(dir); } -})); +}) +menu.append(local_folder_menu); -menu.append(new gui.MenuItem({ +var pithos_page_menu = new gui.MenuItem({ label: 'Launch Pithos+ page', icon: 'images/pithos.png', + enabled: false, click: function () { var pithos_ui = globals['settings']['pithos_ui']; console.log('Visit ' + pithos_ui); gui.Shell.openExternal(pithos_ui); } -})); +}); +menu.append(pithos_page_menu); // Settings and About menu.append(new gui.MenuItem({type: 'separator'})); -menu.append(new gui.MenuItem({ +var settings_menu = new gui.MenuItem({ label: 'Settings', icon: 'images/settings.png', + enabled: false, click: function () { export_settings(globals.settings); if (windows['settings']) windows['settings'].close(); windows['settings'] = gui.Window.open("settings.html", { toolbar: false, focus: true, - width: 841, height: 520, + width: 841, height: 520 }); windows['settings'].on('closed', function() { new_settings = import_settings(); @@ -137,7 +96,8 @@ menu.append(new gui.MenuItem({ get_settings(socket); }); }, -})); +}); +menu.append(settings_menu); menu.append(new gui.MenuItem({ label: 'About', @@ -159,6 +119,72 @@ menu.append(new gui.MenuItem({ click: function() {post_shutdown(socket);} })); + +// Update progress +var client_ready = false; +window.setInterval(function() { + if (!client_ready) { + if (globals.authenticated) { + settings_menu.enabled = true; + client_ready = true; + } else return; + } + + if (client_ready) { + if (!pithos_page_menu.enabled) { + // GET pithos page with tokenless operations + } + if (!local_folder_menu.enabled) { + if (globals.settings.directory) { + local_folder_menu.enabled = true; + } + } + } + + var status = globals['status']; + var new_progress = progress_item.label; + var new_pause = pause_item.label; + var menu_modified = false; + if (status['paused'] !== null) { + switch(pause_item.label) { + case pause_syncing: if (status['paused']) { + // Update to "Paused - start syncing" + paused = true; + new_pause = start_syncing; + menu_modified = true; + } // else continue syncing + new_progress = status['progress'] + '%' + ' synced'; + break; + case start_syncing: if (status['paused']) return; + // else update to "Syncing - pause syncing" + paused = false; + new_pause = pause_syncing; + new_progress = status['progress'] + '%' + ' synced'; + menu_modified = true; + break; + default: + if (status['paused']) {new_pause = start_syncing; paused=true;} + else {new_pause = pause_syncing; paused=false;} + new_progress = status['progress'] + '%' + ' synced'; + pause_item.enabled = true; + menu_modified = true; + } + } + if (new_pause != pause_item.label) { + pause_item.label = new_pause; + menu_modified = true; + } + if (new_progress != progress_item.label) { + progress_item.label = new_progress; + menu_modified = true; + } + if (menu_modified) { + if (paused) progress_item.label += ' - paused'; + tray.menu = menu; + } + get_status(socket); +}, 1500); + tray.menu = menu; </script> diff --git a/agkyra/agkyra/gui/protocol.js b/agkyra/agkyra/gui/protocol.js index 44f79a25ee36993c2c7dafd63a513e66152aac23..87b56e8877c023255210ecf6d45d85009fd3e0e1 100644 --- a/agkyra/agkyra/gui/protocol.js +++ b/agkyra/agkyra/gui/protocol.js @@ -19,7 +19,8 @@ var globals = { 'pithos_ui': null, 'exclude': null }, - 'status': {"progress": null, "paused": null} + 'status': {"progress": null, "paused": null}, + 'authenticated': false } // Protocol: requests ::: responses @@ -71,6 +72,7 @@ socket.onmessage = function(e) { if (r['ACCEPTED'] === 202) { get_settings(this); get_status(this); + globals.authenticated = true; } else { console.log('Helper: ' + JSON.stringify(r)); closeWindows(); diff --git a/agkyra/agkyra/gui/settings.html b/agkyra/agkyra/gui/settings.html index adf0661b388360d5984a8dcf5dcaff6c552af405..597573468df557b723c91a9fae55d615ae5b298d 100644 --- a/agkyra/agkyra/gui/settings.html +++ b/agkyra/agkyra/gui/settings.html @@ -18,9 +18,11 @@ if (container) $('#container').val(container); var directory = get_setting('directory'); if (directory) $('#directory').html(directory); - exclude = get_setting('exclude'); - if (exclude) $('#exclude').val( - fs.readFileSync(exclude, encoding='utf-8')); + var exclude = get_setting('exclude'); + if (exclude) try { + $('#exclude').val( + fs.readFileSync(exclude, encoding='utf-8')); + } catch (err) {console.log(err);} var pithos_ui = get_setting('pithos_ui'); if (pithos_ui) { $('#get_creds').show(); diff --git a/agkyra/agkyra/protocol.py b/agkyra/agkyra/protocol.py index 9cde1f73c644f90ba29797497ead0195130266db..d5700aaab085d94accda18c77ad9b7d94b3f379c 100644 --- a/agkyra/agkyra/protocol.py +++ b/agkyra/agkyra/protocol.py @@ -72,6 +72,7 @@ class WebSocketProtocol(WebSocket): cnf = AgkyraConfig() def _load_settings(self): + LOG.debug('Start loading settings') sync = self.cnf.get('global', 'default_sync') cloud = self.cnf.get_sync(sync, 'cloud') @@ -94,7 +95,10 @@ class WebSocketProtocol(WebSocket): for option in ('container', 'directory', 'exclude'): self.settings[option] = self.cnf.get_sync(sync, option) + LOG.debug('Finished loading settings') + def _dump_settings(self): + LOG.debug('Saving settings') sync = self.cnf.get('global', 'default_sync') cloud = self.cnf.get_sync(sync, 'cloud') @@ -113,6 +117,9 @@ class WebSocketProtocol(WebSocket): for option in ('directory', 'container', 'exclude'): self.cnf.set_sync(sync, option, self.settings[option]) + self.cnf.write() + LOG.debug('Settings saved') + # Syncer-related methods def get_status(self): from random import randint @@ -121,7 +128,6 @@ class WebSocketProtocol(WebSocket): return self.status def get_settings(self): - self._load_settings() return self.settings def set_settings(self, new_settings): @@ -137,7 +143,6 @@ class WebSocketProtocol(WebSocket): # WebSocket connection methods def opened(self): LOG.debug('Helper: connection established') - self._load_settings() def closed(self, *args): LOG.debug('Helper: connection closed') @@ -149,7 +154,6 @@ class WebSocketProtocol(WebSocket): # Protocol handling methods def _post(self, r): """Handle POST requests""" - LOG.debug('CALLED with %s' % r) if self.accepted: action = r['path'] if action == 'shutdown': @@ -161,6 +165,7 @@ class WebSocketProtocol(WebSocket): }[action]() self.send_json({'OK': 200, 'action': 'post %s' % action}) elif r['gui_id'] == self.gui_id: + self._load_settings() self.accepted = True self.send_json({'ACCEPTED': 202, 'action': 'post gui_id'}) else: @@ -170,16 +175,16 @@ class WebSocketProtocol(WebSocket): def _put(self, r): """Handle PUT requests""" - if not self.accepted: - action = r['path'] - self.send_json({'UNAUTHORIZED': 401, 'action': 'put %s' % action}) - self.terminate() - else: + if self.accepted: LOG.debug('put %s' % r) action = r.pop('path') self.set_settings(r) r.update({'CREATED': 201, 'action': 'put %s' % action}) self.send_json(r) + else: + action = r['path'] + self.send_json({'UNAUTHORIZED': 401, 'action': 'put %s' % action}) + self.terminate() def _get(self, r): """Handle GET requests"""