Try new saving technique for PWA
This commit is contained in:
@ -16,14 +16,23 @@ const handleResize = (canvas: HTMLCanvasElement) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const saveBeforeExit = (app: Editor): void => {
|
||||||
|
// @ts-ignore
|
||||||
|
event.preventDefault();
|
||||||
|
// Iterate over all local files and set the candidate to the committed
|
||||||
|
app.currentFile().candidate = app.view.state.doc.toString();
|
||||||
|
app.currentFile().committed = app.view.state.doc.toString();
|
||||||
|
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
|
||||||
|
app.clock.stop();
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
export const installWindowBehaviors = (
|
export const installWindowBehaviors = (
|
||||||
app: Editor,
|
app: Editor,
|
||||||
window: Window,
|
window: Window,
|
||||||
preventMultipleTabs: boolean = false
|
preventMultipleTabs: boolean = false
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener("resize", () =>
|
window.addEventListener("resize", () =>
|
||||||
handleResize(app.interface.scope as HTMLCanvasElement)
|
handleResize(app.interface.scope as HTMLCanvasElement)
|
||||||
);
|
);
|
||||||
@ -31,14 +40,10 @@ export const installWindowBehaviors = (
|
|||||||
handleResize(app.interface.feedback as HTMLCanvasElement)
|
handleResize(app.interface.feedback as HTMLCanvasElement)
|
||||||
);
|
);
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
// @ts-ignore
|
saveBeforeExit(app)
|
||||||
event.preventDefault();
|
});
|
||||||
// Iterate over all local files and set the candidate to the committed
|
window.addEventListener("visibilitychange", () => {
|
||||||
app.currentFile().candidate = app.view.state.doc.toString();
|
saveBeforeExit(app)
|
||||||
app.currentFile().committed = app.view.state.doc.toString();
|
|
||||||
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
|
|
||||||
app.clock.stop();
|
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (preventMultipleTabs) {
|
if (preventMultipleTabs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user