session: implement remote saving for session files located on the server
This commit is contained in:
parent
6b7bdcf0a0
commit
de09388f7e
9 changed files with 82 additions and 56 deletions
|
|
@ -209,6 +209,11 @@ var Editor = class Editor {
|
|||
sessionManager.save()
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + shift + s', (e)=>{
|
||||
e.preventDefault()
|
||||
sessionManager.saveAs()
|
||||
})
|
||||
|
||||
keyboardJS.bind('mod + o', (e)=>{
|
||||
e.preventDefault()
|
||||
sessionManager.browse()
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ module.exports = {
|
|||
|
||||
},
|
||||
|
||||
sessionAllowRemoteSave: function(data){
|
||||
|
||||
session.allowRemoteSave = data
|
||||
|
||||
},
|
||||
|
||||
stateLoad: function(data){
|
||||
|
||||
state.set(data.state, data.send)
|
||||
|
|
@ -166,6 +172,7 @@ module.exports = {
|
|||
DOM.get('.traversingEnable')[0].click()
|
||||
}
|
||||
|
||||
ipc.send('sessionSetPath', {path: data.sessionPath})
|
||||
ipc.send('deleteBackup', data.backupId)
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = {
|
|||
editor_root: 'Root',
|
||||
editor_load: 'Load',
|
||||
editor_save: 'Save',
|
||||
editor_save_as: 'Export',
|
||||
|
||||
// editor context-menu
|
||||
editor_editparent: 'Edit parent',
|
||||
|
|
@ -36,6 +37,8 @@ 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',
|
||||
|
||||
// sidepanel
|
||||
sidepanel_fs: 'Fullscreen',
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = {
|
|||
editor_root: 'Root',
|
||||
editor_load: 'Charger',
|
||||
editor_save: 'Sauver',
|
||||
editor_save_as: 'Exporter',
|
||||
|
||||
// editor context-menu
|
||||
editor_editparent: 'Éditer parent',
|
||||
|
|
@ -36,6 +37,8 @@ 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"',
|
||||
|
||||
// sidepanel
|
||||
sidepanel_fs: 'Plein Écran',
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = { // @https://github.com/suhr
|
|||
editor_root: 'Корень',
|
||||
editor_load: 'Загрузить',
|
||||
editor_save: 'Сохранить',
|
||||
editor_save_as: 'Экспорт',
|
||||
|
||||
// editor context-menu
|
||||
editor_editparent: 'К родителю',
|
||||
|
|
@ -36,6 +37,8 @@ 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',
|
||||
|
||||
// sidepanel
|
||||
sidepanel_fs: 'Полный экран',
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ var SessionManager = class SessionManager {
|
|||
this.session = []
|
||||
this.lock = false
|
||||
|
||||
this.allowRemoteSave = false
|
||||
|
||||
}
|
||||
|
||||
load(session, callback) {
|
||||
|
|
@ -83,6 +85,7 @@ var SessionManager = class SessionManager {
|
|||
loader.close()
|
||||
container.classList.add('show')
|
||||
this.lock = false
|
||||
this.allowRemoteSave = false
|
||||
if (callback) callback()
|
||||
}, 25)
|
||||
|
||||
|
|
@ -92,13 +95,25 @@ var SessionManager = class SessionManager {
|
|||
|
||||
save() {
|
||||
|
||||
if (this.allowRemoteSave) {
|
||||
|
||||
ipc.send('sessionSave', JSON.stringify(this.session, null, ' '))
|
||||
|
||||
} else {
|
||||
|
||||
ipc.send('log', 'Could not save session file')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
saveAs() {
|
||||
|
||||
var sessionfile = JSON.stringify(this.session,null,' '),
|
||||
blob = new Blob([sessionfile],{type : 'application/json'})
|
||||
|
||||
saveAs(blob, new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16) + '.json')
|
||||
|
||||
ipc.send('savingSession')
|
||||
|
||||
}
|
||||
|
||||
list(data) {
|
||||
|
|
@ -161,8 +176,8 @@ var SessionManager = class SessionManager {
|
|||
|
||||
open(data) {
|
||||
|
||||
this.load(data,function(){
|
||||
ipc.send('sessionOpened')
|
||||
this.load(data.session,function(){
|
||||
ipc.send('sessionOpened', {path: data.path})
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,10 @@ var sidepanelData = [
|
|||
{
|
||||
title: locales('editor_save'),
|
||||
action:session.save.bind(session)
|
||||
},
|
||||
{
|
||||
title: locales('editor_save_as'),
|
||||
action:session.saveAs.bind(session)
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@ var path = require('path'),
|
|||
osc = require('./osc'),
|
||||
{ipc} = require('./server'),
|
||||
{deepCopy} = require('./utils'),
|
||||
theme = require('./theme'),
|
||||
chokidar = require('chokidar')
|
||||
theme = require('./theme')
|
||||
|
||||
var openedSessions = {},
|
||||
widgetHashTable = {},
|
||||
lastSavingClient,
|
||||
sessionBackups = {}
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -85,52 +83,7 @@ module.exports = {
|
|||
|
||||
if (!error) {
|
||||
|
||||
ipc.send('sessionOpen', session,clientId)
|
||||
|
||||
|
||||
for (var i in openedSessions) {
|
||||
if (openedSessions[i].indexOf(clientId) != -1) {
|
||||
openedSessions[i].splice(openedSessions[i].indexOf(clientId), 1)
|
||||
}
|
||||
}
|
||||
|
||||
if (data.path) {
|
||||
|
||||
if (!settings.read('readOnly')) this.sessionAddToHistory(data.path)
|
||||
|
||||
fs.lstat(data.path, (err, stats)=>{
|
||||
|
||||
if (err || !stats.isFile()) return
|
||||
|
||||
|
||||
if (!openedSessions[data.path]) {
|
||||
|
||||
openedSessions[data.path] = []
|
||||
|
||||
var watchFile = ()=>{
|
||||
var watcher = chokidar.watch(data.path)
|
||||
watcher.on('change',()=>{
|
||||
var openedSessionsClone = deepCopy(openedSessions[data.path])
|
||||
for (var k in openedSessionsClone) {
|
||||
if (openedSessionsClone[k] != lastSavingClient) {
|
||||
module.exports.sessionOpen({path:data.path}, openedSessionsClone[k])
|
||||
}
|
||||
}
|
||||
watcher.close()
|
||||
watchFile()
|
||||
})
|
||||
}
|
||||
|
||||
watchFile()
|
||||
|
||||
|
||||
}
|
||||
|
||||
openedSessions[data.path].push(clientId)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
ipc.send('sessionOpen', {path: data.path, session: session}, clientId)
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -158,11 +111,41 @@ module.exports = {
|
|||
|
||||
ipc.send('stateSend', null, null, clientId)
|
||||
|
||||
module.exports.sessionSetPath(data, clientId)
|
||||
|
||||
},
|
||||
|
||||
savingSession: function(data, clientId) {
|
||||
sessionSetPath: function(data, clientId) {
|
||||
|
||||
lastSavingClient = clientId
|
||||
ipc.clients[clientId].sessionPath = ''
|
||||
fs.lstat(data.path, (err, stats)=>{
|
||||
if (err || !stats.isFile()) return
|
||||
ipc.clients[clientId].sessionPath = data.path
|
||||
if (!settings.read('readOnly')) {
|
||||
this.sessionAddToHistory(data.path)
|
||||
ipc.send('sessionAllowRemoteSave', true, clientId)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
sessionSave: function(data, clientId) {
|
||||
|
||||
var path = ipc.clients[clientId].sessionPath
|
||||
|
||||
if (path) {
|
||||
|
||||
fs.writeFile(path, data, function(err, data) {
|
||||
if (err) throw err
|
||||
console.log('Session file saved in '+ path)
|
||||
for (var id in ipc.clients) {
|
||||
if (id !== clientId) {
|
||||
module.exports.sessionOpen({path: path}, id)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
@ -307,9 +290,10 @@ module.exports = {
|
|||
|
||||
},
|
||||
|
||||
storeBackup: function(data) {
|
||||
storeBackup: function(data, clientId) {
|
||||
|
||||
sessionBackups[data.backupId] = data
|
||||
sessionBackups[data.backupId].sessionPath = ipc.clients[clientId].sessionPath
|
||||
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ class Socket extends EventEmitter {
|
|||
this.id = id
|
||||
this.socket = null
|
||||
|
||||
this.sessionPath = ''
|
||||
|
||||
this.queue = []
|
||||
|
||||
this.hearbeat = undefined
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue