mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-30 15:42:42 +08:00
Improve localstorage auto backups
This commit is contained in:
parent
8105a562ac
commit
4448019d77
@ -670,6 +670,9 @@
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
}
|
||||
#start_screen button {
|
||||
margin-right: 4px;
|
||||
}
|
||||
#start_screen .recent_project {
|
||||
margin: 2px 0;
|
||||
display: flex;
|
||||
|
@ -20,7 +20,6 @@ const Blockbench = {
|
||||
Undo.finishEdit()
|
||||
},
|
||||
reload() {
|
||||
localStorage.removeItem('backup_model')
|
||||
if (isApp) {
|
||||
Blockbench.setProgress(0)
|
||||
Blockbench.addFlag('allow_closing')
|
||||
|
@ -246,11 +246,13 @@ function unselectAll() {
|
||||
TickUpdates.selection = true;
|
||||
}
|
||||
//Backup
|
||||
const AutoBackupModels = {};
|
||||
setInterval(function() {
|
||||
if (Project && (Outliner.root.length || Project.textures.length)) {
|
||||
try {
|
||||
var model = Codecs.project.compile({compressed: false, minify: true, backup: true});
|
||||
localStorage.setItem('backup_model', model)
|
||||
var model = Codecs.project.compile({compressed: false, backup: true, raw: true});
|
||||
AutoBackupModels[Project.uuid] = model;
|
||||
localStorage.setItem('backup_model', JSON.stringify(AutoBackupModels));
|
||||
} catch (err) {
|
||||
console.error('Unable to create backup. ', err)
|
||||
}
|
||||
|
@ -337,7 +337,6 @@ function createBackup(init) {
|
||||
if (init || elements.length === 0) return;
|
||||
|
||||
var model = Codecs.project.compile({compressed: true, backup: true})
|
||||
localStorage.setItem('backup_model', model)
|
||||
var file_name = 'backup_'+d.getDate()+'.'+(d.getMonth()+1)+'.'+(d.getYear()-100)+'_'+d.getHours()+'.'+d.getMinutes()
|
||||
var file_path = folder_path+osfs+file_name+'.bbmodel'
|
||||
|
||||
@ -385,7 +384,6 @@ function closeBlockbenchWindow() {
|
||||
window.onbeforeunload = null;
|
||||
Blockbench.addFlag('allow_closing');
|
||||
Blockbench.dispatchEvent('before_closing')
|
||||
localStorage.removeItem('backup_model')
|
||||
if (Project.EditSession) Project.EditSession.quit()
|
||||
return currentwindow.close();
|
||||
};
|
||||
|
@ -257,18 +257,24 @@ onVueSetup(function() {
|
||||
Blockbench.startup_count = parseInt(localStorage.getItem('startups')||0)
|
||||
|
||||
//Backup Model
|
||||
if (localStorage.getItem('backup_model') && (!isApp || !currentwindow.webContents.second_instance)) {
|
||||
var backup_model = localStorage.getItem('backup_model')
|
||||
localStorage.removeItem('backup_model')
|
||||
if (localStorage.getItem('backup_model') && (!isApp || !currentwindow.webContents.second_instance) && localStorage.getItem('backup_model').length > 40) {
|
||||
var backup_models = localStorage.getItem('backup_model')
|
||||
|
||||
addStartScreenSection({
|
||||
let section = addStartScreenSection({
|
||||
color: 'var(--color-back)',
|
||||
graphic: {type: 'icon', icon: 'fa-archive'},
|
||||
text: [
|
||||
{type: 'h2', text: tl('message.recover_backup.title')},
|
||||
{text: tl('message.recover_backup.message')},
|
||||
{type: 'button', text: tl('dialog.ok'), click: (e) => {
|
||||
loadModelFile({content: backup_model, path: 'backup.bbmodel', no_file: true})
|
||||
{type: 'button', text: tl('message.recover_backup.recover'), click: (e) => {
|
||||
for (let uuid in backup_models) {
|
||||
loadModelFile({content: backup_models[uuid], path: 'backup.bbmodel', no_file: true})
|
||||
}
|
||||
section.delete();
|
||||
}},
|
||||
{type: 'button', text: tl('dialog.discard'), click: (e) => {
|
||||
localStorage.removeItem('backup_model');
|
||||
section.delete();
|
||||
}}
|
||||
]
|
||||
})
|
||||
|
@ -330,6 +330,9 @@ class ModelProject {
|
||||
ModelProject.all.remove(this);
|
||||
delete ProjectData[this.uuid];
|
||||
Project = 0;
|
||||
|
||||
delete AutoBackupModels[this.uuid];
|
||||
localStorage.setItem('backup_model', JSON.stringify(AutoBackupModels));
|
||||
|
||||
if (last_selected && last_selected !== this) {
|
||||
last_selected.select();
|
||||
|
@ -174,8 +174,9 @@
|
||||
"message.rotation_limit.message": "Rotations are limited by Minecraft to one axis and 22.5 degree increments. Rotating on a different axis will clear all rotations on the other axes. Convert the model to \"Generic Model\" if you are modeling for other purposes and need free rotations.",
|
||||
"message.file_not_found.title": "File Not Found",
|
||||
"message.file_not_found.message": "Blockbench could not find the requested file. Make sure it is saved locally and not in a cloud.",
|
||||
"message.recover_backup.title": "Recover Model",
|
||||
"message.recover_backup.message": "Blockbench was closed without saving. Do you want to recover the model?",
|
||||
"message.recover_backup.title": "Recover Models",
|
||||
"message.recover_backup.message": "Blockbench was closed without saving. Do you want to recover the models?",
|
||||
"message.recover_backup.recover": "Recover",
|
||||
"message.screenshot.title": "Screenshot",
|
||||
"message.screenshot.clipboard": "Clipboard",
|
||||
"message.screenshot.right_click": "Right click or long press the screenshot to copy",
|
||||
|
Loading…
Reference in New Issue
Block a user