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:
parent
ba08aa628e
commit
04af3e79b5
7 changed files with 39 additions and 5 deletions
|
|
@ -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',
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue