add Save backup menu action (saves a backup copy of current session with an incremented suffix appended to the file name)

This commit is contained in:
jean-emmanuel 2021-09-29 13:13:12 +02:00
parent ba08aa628e
commit 04af3e79b5
7 changed files with 39 additions and 5 deletions

View file

@ -13,6 +13,9 @@
- new textarea widget (multi line input)
- expose the computed dimensions of canvas-based widgets in `css` (as `--widget-width` and `--widget-height`) and `script` (as `locals.width` and `locals.height`)
- client
- add `Save backup` menu action (saves a backup copy of current session with an incremented suffix appended to the file name)
## 1.9.14
- bug fixes

View file

@ -8,6 +8,7 @@
- Open recent: open a recent session on the server
- Save / Save as: save session file on the server
- Fragment mode: when enabled, the session will be saved as a fragment file (only the root's first child will be saved)
- Save backup: save a copy of current session with a incremented suffix appended to the file name
- Import: import a session file from the client's filesystem
- Export: export a session file to the client's filesystem
- State

View file

@ -46,6 +46,7 @@ module.exports = {
file_open_recent_wait: 'List not loaded yet, please close and reopen the menu',
file_save: 'Save',
file_save_as: 'Save as...',
file_backup: 'Save backup',
file_import: 'Import',
file_export: 'Export',

View file

@ -46,6 +46,7 @@ module.exports = {
file_open_recent_wait: 'Liste non chargée, veuillez fermer puis ouvrir le menu à nouveau',
file_save: 'Enregistrer',
file_save_as: 'Enregistrer sous...',
file_backup: 'Enregistrer une sauvegarde',
file_import: 'Importer',
file_export: 'Exporter',

View file

@ -97,7 +97,7 @@ var SessionManager = class SessionManager extends EventEmitter {
}
save(path) {
save(path, backup=false) {
if (!this.session || READ_ONLY) return
@ -113,7 +113,8 @@ var SessionManager = class SessionManager extends EventEmitter {
ipc.send('sessionSave', {
session: this.session.toJSON(),
path: this.sessionPath
path: this.sessionPath,
backup: backup
})
} else {
@ -127,13 +128,18 @@ var SessionManager = class SessionManager extends EventEmitter {
content: data,
version: PACKAGE.version
}, 'fragment'),
path: this.sessionPath
path: this.sessionPath,
backup: backup
})
}
}
saveBackup() {
this.save('', true)
}
saveAs() {
if (!this.session || READ_ONLY) return

View file

@ -58,6 +58,15 @@ var menuEntries = [
{
separator: true
},
{
label: locales('file_backup'),
action: sessionManager.saveBackup.bind(sessionManager),
shortcut: 'mod + b',
class: ()=>{return READ_ONLY || sessionManager.session === null || !sessionManager.sessionPath ? 'disabled' :''}
},
{
separator: true
},
{
label: locales('file_import'),
action: sessionManager.import.bind(sessionManager),

View file

@ -281,11 +281,24 @@ module.exports = {
if (!path.basename(data.path).match(/.*\.json$/)) return console.error('(ERROR) Sessions must be saved as .json files')
if (data.backup) {
var newpath, i = 0
while (true) {
newpath = data.path.replace(/\.json$/, '-backup' + String(i).padStart(3, 0) + '.json')
if (fs.existsSync(newpath)) i++
else {
data.path = newpath
break
}
}
}
module.exports.fileSave(data, clientId, true, ()=>{
console.log('(INFO) Session file saved in '+ data.path)
ipc.send('sessionSaved', clientId)
if (!data.backup) ipc.send('sessionSaved', clientId)
// reload session in other clients
for (var id in ipc.clients) {
@ -294,7 +307,7 @@ module.exports = {
}
}
module.exports.sessionSetPath({path: data.path}, clientId)
if (!data.backup) module.exports.sessionSetPath({path: data.path}, clientId)
})