add auto-save mechanism every 5 seconds
This commit is contained in:
@ -16,7 +16,7 @@ const handleResize = (canvas: HTMLCanvasElement) => {
|
||||
}
|
||||
};
|
||||
|
||||
const saveBeforeExit = (app: Editor): null => {
|
||||
export const saveBeforeExit = (app: Editor): null => {
|
||||
// @ts-ignore
|
||||
event.preventDefault();
|
||||
// Iterate over all local files and set the candidate to the committed
|
||||
|
||||
10
src/main.ts
10
src/main.ts
@ -24,7 +24,7 @@ import { tryEvaluate } from "./Evaluator";
|
||||
import showdown from "showdown";
|
||||
import { makeStringExtensions } from "./StringExtensions";
|
||||
import { installInterfaceLogic } from "./InterfaceLogic";
|
||||
import { installWindowBehaviors } from "./WindowBehavior";
|
||||
import { installWindowBehaviors, saveBeforeExit } from "./WindowBehavior";
|
||||
import { drawEmptyBlinkers } from "./AudioVisualisation";
|
||||
// @ts-ignore
|
||||
import { registerSW } from "virtual:pwa-register";
|
||||
@ -170,6 +170,8 @@ export class Editor {
|
||||
|
||||
// Loading universe from URL (if needed)
|
||||
loadUniverserFromUrl(this);
|
||||
|
||||
this.setPeriodicSave(5000);
|
||||
}
|
||||
|
||||
private getBuffer(type: string): any {
|
||||
@ -466,7 +468,7 @@ export class Editor {
|
||||
console.log("Hydra loaded successfully");
|
||||
this.initializeHydra();
|
||||
};
|
||||
script.onerror = function () {
|
||||
script.onerror = function() {
|
||||
console.error("Error loading Hydra script");
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
@ -496,6 +498,10 @@ export class Editor {
|
||||
ctx.scale(dpr, dpr);
|
||||
}
|
||||
}
|
||||
|
||||
private setPeriodicSave(interval: number): void {
|
||||
setInterval(saveBeforeExit(this), interval)
|
||||
}
|
||||
}
|
||||
|
||||
let app = new Editor();
|
||||
|
||||
Reference in New Issue
Block a user