remote-save: let the server notify the client if it worked or not

This commit is contained in:
jean-emmanuel 2019-01-05 17:08:51 +01:00
parent 5374a91325
commit 8c59676e2b
3 changed files with 35 additions and 22 deletions

View file

@ -46,9 +46,9 @@ module.exports = {
},
sessionAllowRemoteSave: function(data){
sessionSaved: function(data){
session.allowRemoteSave = data
editor.unsavedSession = false
},
@ -180,6 +180,20 @@ module.exports = {
})
},
notify: function(data) {
var message = data.message || ''
if (data.locale) message = locales(data.locale) + message
notifications.add({
icon: data.icon,
class: data.class,
message: message
})
}
}

View file

@ -97,23 +97,7 @@ var SessionManager = class SessionManager {
save() {
if (this.allowRemoteSave) {
ipc.send('sessionSave', JSON.stringify(this.session, null, ' '))
notifications.add({
icon: 'save',
message: locales('session_savesuccess')
})
editor.unsavedSession = false
} else {
ipc.send('log', 'Could not save session file')
notifications.add({
class: 'error',
message: locales('session_saveerror')
})
}
ipc.send('sessionSave', JSON.stringify(this.session, null, ' '))
}

View file

@ -126,7 +126,6 @@ module.exports = {
ipc.clients[clientId].sessionPath = data.path
if (!settings.read('readOnly')) {
this.sessionAddToHistory(data.path)
ipc.send('sessionAllowRemoteSave', true, clientId)
}
})
@ -134,13 +133,19 @@ module.exports = {
sessionSave: function(data, clientId) {
var path = ipc.clients[clientId].sessionPath
var path = ipc.clients[clientId].sessionPath,
error
if (path) {
fs.writeFile(path, data, function(err, data) {
if (err) throw err
if (err) return error = err
console.log('Session file saved in '+ path)
ipc.send('sessionSaved', clientId)
ipc.send('notify', {
icon: 'save',
locale: 'session_savesuccess'
}, clientId)
for (var id in ipc.clients) {
if (id !== clientId && ipc.clients[id].sessionPath === path) {
module.exports.sessionOpen({path: path}, id)
@ -150,6 +155,16 @@ module.exports = {
}
if (!path || error) {
ipc.send('notify', {
class: 'error',
locale: 'session_saveerror',
message: error
}, clientId)
}
},
syncOsc: function(shortdata, clientId) {