diff --git a/src/components/App.tsx b/src/components/App.tsx index 92d80ecf4..8d5088f51 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -911,14 +911,10 @@ class App extends React.Component { ?.classList.toggle("theme--dark", this.state.theme === "dark"); if (this.state.autoSave && this.state.fileHandle && supported) { - try { - this.saveLocalSceneDebounced( - this.scene.getElementsIncludingDeleted(), - this.state, - ); - } catch (error) { - this.setState({ autoSave: false }); - } + this.saveLocalSceneDebounced( + this.scene.getElementsIncludingDeleted(), + this.state, + ); } if ( @@ -1054,8 +1050,19 @@ class App extends React.Component { }, SCROLL_TIMEOUT); private saveLocalSceneDebounced = debounce( - (elements: readonly ExcalidrawElement[], state: AppState) => { - saveAsJSON(elements, state); + async (elements: readonly ExcalidrawElement[], state: AppState) => { + if (this.state.autoSave && this.state.fileHandle && supported) { + try { + await saveAsJSON(elements, state); + } catch (error) { + // shouldn't (almost) ever happen, so let's log it + console.error(error); + this.setState({ + autoSave: false, + errorMessage: t("toast.autosaveFailed"), + }); + } + } }, AUTO_SAVE_TIMEOUT, ); diff --git a/src/locales/en.json b/src/locales/en.json index 03174cac0..3d257e75a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -248,6 +248,7 @@ "width": "Width" }, "toast": { + "autosaveFailed": "Autosave failed.", "copyStyles": "Copied styles.", "copyToClipboard": "Copied to clipboard.", "copyToClipboardAsPng": "Copied {{exportSelection}} to clipboard as PNG\n({{exportColorScheme}})",