add auto-save mechanism every 5 seconds

This commit is contained in:
2023-11-10 20:18:22 +01:00
parent 293ae8bb7d
commit 142f4ae653
2 changed files with 9 additions and 3 deletions

View File

@ -16,7 +16,7 @@ const handleResize = (canvas: HTMLCanvasElement) => {
} }
}; };
const saveBeforeExit = (app: Editor): null => { export const saveBeforeExit = (app: Editor): null => {
// @ts-ignore // @ts-ignore
event.preventDefault(); event.preventDefault();
// Iterate over all local files and set the candidate to the committed // Iterate over all local files and set the candidate to the committed

View File

@ -24,7 +24,7 @@ import { tryEvaluate } from "./Evaluator";
import showdown from "showdown"; import showdown from "showdown";
import { makeStringExtensions } from "./StringExtensions"; import { makeStringExtensions } from "./StringExtensions";
import { installInterfaceLogic } from "./InterfaceLogic"; import { installInterfaceLogic } from "./InterfaceLogic";
import { installWindowBehaviors } from "./WindowBehavior"; import { installWindowBehaviors, saveBeforeExit } from "./WindowBehavior";
import { drawEmptyBlinkers } from "./AudioVisualisation"; import { drawEmptyBlinkers } from "./AudioVisualisation";
// @ts-ignore // @ts-ignore
import { registerSW } from "virtual:pwa-register"; import { registerSW } from "virtual:pwa-register";
@ -170,6 +170,8 @@ export class Editor {
// Loading universe from URL (if needed) // Loading universe from URL (if needed)
loadUniverserFromUrl(this); loadUniverserFromUrl(this);
this.setPeriodicSave(5000);
} }
private getBuffer(type: string): any { private getBuffer(type: string): any {
@ -466,7 +468,7 @@ export class Editor {
console.log("Hydra loaded successfully"); console.log("Hydra loaded successfully");
this.initializeHydra(); this.initializeHydra();
}; };
script.onerror = function () { script.onerror = function() {
console.error("Error loading Hydra script"); console.error("Error loading Hydra script");
}; };
document.head.appendChild(script); document.head.appendChild(script);
@ -496,6 +498,10 @@ export class Editor {
ctx.scale(dpr, dpr); ctx.scale(dpr, dpr);
} }
} }
private setPeriodicSave(interval: number): void {
setInterval(saveBeforeExit(this), interval)
}
} }
let app = new Editor(); let app = new Editor();