From 85056348b2562ccce8dd9cb57c08614f5f589357 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sun, 31 Mar 2019 18:22:06 +0200 Subject: [PATCH] remote-files: more locales & generic server side file save --- src/client/app/locales/en.js | 7 ++-- src/client/app/locales/fr.js | 7 ++-- src/client/app/locales/ru.js | 7 ++-- src/server/callbacks.js | 65 ++++++++++++++++++++++++------------ 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/client/app/locales/en.js b/src/client/app/locales/en.js index b2a06980..14f4df64 100644 --- a/src/client/app/locales/en.js +++ b/src/client/app/locales/en.js @@ -34,6 +34,11 @@ module.exports = { fs_unnavailable: 'Fullscreen not available', fs_addtohome: 'You must add this page to your home screen to launch it in fullscreen', + // remote save + remotesave_fail: 'The file could not be saved on the server, use "export" instead', + remotesave_success: 'File saved successfully', + remotesave_forbidden: 'You\'re note allowed to save on server, use "export instead"', + // server server_disconnected: 'The connection to the server has been interrupted', server_connected: 'The connection to the server has been restored', @@ -44,8 +49,6 @@ module.exports = { session_malformed: 'Malformed session file.', session_parsingerror: 'Parsing error.', session_uploaderror: 'Failed to upload session file.', - session_savesuccess: 'Session saved successfully', - session_saveerror: 'The session file can\'t be saved remotely, use "export" instead', session_unsaved: 'Your changes will be lost if you close this session without saving, continue ?', // sidepanel diff --git a/src/client/app/locales/fr.js b/src/client/app/locales/fr.js index 4ebd603b..b7fa9db4 100644 --- a/src/client/app/locales/fr.js +++ b/src/client/app/locales/fr.js @@ -33,6 +33,11 @@ module.exports = { fs_unnavailable: 'Plein écran indisponible', fs_addtohome: 'Vous devez ajouter cette page à votre écran d\'accueil pour pouvoir l\'ouvrir en plein écran.', + // remote save + remotesave_fail: 'Le fichier n\'a pas pu être enregistré sur le serveur, utilisez la fonction "exporter"', + remotesave_success: 'Le fichier a été enregistré avec succès', + remotesave_forbidden: 'Vous n\'êtes pas autorisé à sauvegarder sur le serveur, utilisez la fonction "exporter"', + // server server_disconnected: 'La connexion avec le serveur a été interrompue', server_connected: 'La connexion avec le serveur a été rétablie', @@ -43,8 +48,6 @@ module.exports = { session_malformed: 'Fichier de session mal formé.', session_parsingerror: 'Erreur à l\'ouverture de la session.', session_uploaderror: 'Échec à l\'envoi du fichier de session.', - session_savesuccess: 'Session enregistrée avec succès', - session_saveerror: 'La session ne peut pas être enregistrée sur le serveur, utilisez la fonction "exporter"', session_unsaved: 'Vos modifications seront perdues si vous fermez la session actuelle sans sauvegarder, continuer ?', // sidepanel diff --git a/src/client/app/locales/ru.js b/src/client/app/locales/ru.js index 20356ee9..e6a57bbf 100644 --- a/src/client/app/locales/ru.js +++ b/src/client/app/locales/ru.js @@ -33,6 +33,11 @@ module.exports = { // @https://github.com/suhr fs_unnavailable: 'Полный экран не доступен', fs_addtohome: 'Необходимо добавить эту страницу на главный экран чтобы запустить её в полноэкранном режиме', + // remote save + remotesave_fail: 'The file could not be saved on the server, use "export" instead', + remotesave_success: 'File saved successfully', + remotesave_forbidden: 'You\'re note allowed to save on server, use "export instead"', + // server server_disconnected: 'The connection to the server has been interrupted', server_connected: 'The connection to the server has been restored', @@ -43,8 +48,6 @@ module.exports = { // @https://github.com/suhr session_malformed: 'Файл сессии повреждён.', session_parsingerror: 'Ошибка разбора.', session_uploaderror: 'Не удалось загрузить файл сессии.', - session_savesuccess: 'Session saved successfully', - session_saveerror: 'The session file can\'t be saved remotely, use "export" instead', session_unsaved: 'Your changes will be lost if you close this session without saving, continue ?', // sidepanel diff --git a/src/server/callbacks.js b/src/server/callbacks.js index 9f610102..53f340f2 100644 --- a/src/server/callbacks.js +++ b/src/server/callbacks.js @@ -126,13 +126,15 @@ module.exports = { }, - sessionSave: function(data, clientId) { + fileSave: function(data, clientId, ok, callback) { + + if (!ok) return if (!data.path || settings.read('remoteSaving') && !settings.read('remoteSaving').test(ipc.clients[clientId].address)) { return ipc.send('notify', { icon: 'save', - locale: 'session_save', + locale: 'remotesave_forbidden', class: 'error' }, clientId) @@ -145,39 +147,25 @@ module.exports = { try { JSON.parse(data.session) } catch(e) { - throw 'Could not save: invalid session file' - return + return console.error('Could not save: invalid file') } fs.writeFile(data.path, data.session, function(err, fdata) { if (err) return ipc.send('notify', { class: 'error', - locale: 'session_saveerror', + locale: 'remotesave_fail', message: err }, clientId) - console.log('Session file saved in '+ data.path) - ipc.send('sessionSaved', clientId) ipc.send('notify', { icon: 'save', - locale: 'session_savesuccess', - message: ' ('+ data.path +')' + locale: 'remotesave_success', + message: ' ('+ path.basename(data.path) +')' }, clientId) - // reload session in other clients - for (var id in ipc.clients) { - if (id !== clientId && ipc.clients[id].sessionPath === data.path) { - module.exports.sessionOpen({path: data.path}, id) - } - } - - if (!settings.read('readOnly')) { - module.exports.sessionAddToHistory(data.path) - } - - module.exports.sessionSetPath({path: data.path}, clientId) + callback() }) @@ -185,6 +173,41 @@ module.exports = { }, + sessionSave: function(data, clientId) { + + module.exports.fileSave(data, clientId, true, ()=>{ + + console.log('Session file saved in '+ data.path) + + ipc.send('sessionSaved', clientId) + + // reload session in other clients + for (var id in ipc.clients) { + if (id !== clientId && ipc.clients[id].sessionPath === data.path) { + module.exports.sessionOpen({path: data.path}, id) + } + } + + if (!settings.read('readOnly')) { + module.exports.sessionAddToHistory(data.path) + } + + module.exports.sessionSetPath({path: data.path}, clientId) + + }) + + }, + + stateSave: function(data, clientId) { + + module.exports.fileSave(data, clientId, true, ()=>{ + + console.log('State file saved in '+ data.path) + + }) + + }, + syncOsc: function(shortdata, clientId) { if (!(widgetHashTable[clientId] && widgetHashTable[clientId][shortdata.h])) return