Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gsoc'24 Simulator Crash Proof of Work Draft PR #296

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/simulator/src/data/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ import { confirmOption } from '#/components/helpers/confirmComponent/ConfirmComp
* Helper function to recover unsaved data
* @category data
*/
export async function recoverProject() {
if (localStorage.getItem('recover')) {
var data = JSON.parse(localStorage.getItem('recover'))
if (await confirmOption(`Would you like to recover: ${data.name}`)) {
load(data)
}
localStorage.removeItem('recover')
function recoverDataFlow(data) {
const confirmationMessage = `Would you like to recover: ${data.name}`;
if (confirm(confirmationMessage)) {
load(data);
}
localStorage.removeItem('recover');
localStorage.removeItem('autosave');
}

export function recoverProject() {
const recoverData = localStorage.getItem('recover');
const autosaveData = localStorage.getItem('autosave');

if (recoverData) {
const data = JSON.parse(recoverData);
recoverDataFlow(data);
} else if (autosaveData) {
const data = JSON.parse(autosaveData);
recoverDataFlow(data);
} else {
showError('No recover project found')
showError('No recover project found');
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/simulator/src/data/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,24 @@ export default async function save() {
// Restore everything
resetup()
}

/**
* Function to autosave the data of circuit
* @category data
* @exports save
*/
var checkForAutosave = 1;

export async function autosave() {
var circuitData = await generateSaveData('Untitled');
localStorage.setItem('autosave', circuitData);
}

export function checkBackups() {
if (checkForAutosave < globalScope.backups.length) {
autosave();
checkForAutosave = globalScope.backups.length;
}
}

setInterval(checkBackups, 3000);
3 changes: 3 additions & 0 deletions src/simulator/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ async function loadProjectData() {
showMessage(
"We have detected that you did not save your last work. Don't worry we have recovered them. Access them using Project->Recover"
)
} else if (localStorage.getItem('autosave')) {
// Restore unsaved data which didn't get saved due to unexpected simulator crash.
showMessage("We have detected an unexpected simulator crash. Don't worry we have recovered your project. Access them using Project->Recover");
}
}

Expand Down
Loading