Skip to content

Commit

Permalink
Add setting for auto backup interval
Browse files Browse the repository at this point in the history
Closes #2460
  • Loading branch information
JannisX11 committed Aug 27, 2024
1 parent 7e928b6 commit 897dc77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions js/interface/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
24 changes: 18 additions & 6 deletions js/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ const AutoBackup = {
]
})
}

AutoBackup.backupProjectLoop(false);
}
},
async backupOpenProject() {
Expand Down Expand Up @@ -369,20 +371,30 @@ 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);
}
}
}


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() {
Expand Down
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 897dc77

Please sign in to comment.