Add setting for auto backup interval

Closes #2460
This commit is contained in:
JannisX11 2024-08-27 22:00:50 +02:00
parent 7e928b6a35
commit 897dc77615
3 changed files with 26 additions and 6 deletions

View File

@ -363,6 +363,10 @@ const Settings = {
updateStreamerModeNotification();
}});
new Setting('cdn_mirror', {value: false});
new Setting('recovery_save_interval', {value: 30, type: 'number', min: 0, onChange() {
clearTimeout(AutoBackup.loop_timeout);
AutoBackup.backupProjectLoop(false);
}});
//Interface
new Setting('interface_mode', {category: 'interface', value: 'auto', type: 'select', options: {

View File

@ -283,6 +283,8 @@ const AutoBackup = {
]
})
}
AutoBackup.backupProjectLoop(false);
}
},
async backupOpenProject() {
@ -369,6 +371,21 @@ const AutoBackup = {
reject();
}
});
},
loop_timeout: null,
backupProjectLoop(run_save = true) {
if (run_save && Project && (Outliner.root.length || Project.textures.length)) {
try {
AutoBackup.backupOpenProject();
} catch (err) {
console.error('Unable to create backup. ', err)
}
}
let interval = settings.recovery_save_interval.value;
if (interval != 0) {
interval = Math.max(interval, 5);
AutoBackup.loop_timeout = setTimeout(() => AutoBackup.backupProjectLoop(true), interval * 1000);
}
}
}
@ -376,13 +393,8 @@ const AutoBackup = {
setInterval(function() {
if (Project && (Outliner.root.length || Project.textures.length)) {
Validator.validate();
try {
AutoBackup.backupOpenProject();
} catch (err) {
console.error('Unable to create backup. ', err)
}
}
}, 1e3*30)
}, 1e3*30);
//Misc
const TickUpdates = {
Run() {

View File

@ -876,6 +876,8 @@
"settings.streamer_mode.desc": "Hides sensitive information like recent models",
"settings.cdn_mirror": "Use CDN Mirror",
"settings.cdn_mirror.desc": "Use the mirror CDN to download plugins. The mirror receives updates faster and works in some regions where the default does not work.",
"settings.recovery_save_interval": "Recovery Point Save Interval",
"settings.recovery_save_interval.desc": "Blockbench regularly saves the open project in the background to recover in case of a computer crash. Set the interval in seconds. Set to 0 to disable saving.",
"settings.interface_scale": "Interface Scale",
"settings.interface_scale.desc": "Scale of the entire Blockbench interface",
@ -1691,6 +1693,8 @@
"action.import_texture.desc": "Import one or more textures from your file system",
"action.create_texture": "Create Texture",
"action.create_texture.desc": "Create a blank texture or template texture",
"action.create_texture_group": "Create Texture Group",
"action.create_texture_group.desc": "Create a group for your textures",
"action.append_to_template": "Append Elements to Template...",
"action.append_to_template.desc": "Add the currently selected elements to the texture template",
"action.save_textures": "Save Textures",