# HG changeset patch # User Ludovic Chabant # Date 1696266609 25200 # Node ID 06504ceb32838c285ef9af0f6d945cf557fa8cff # Parent f2e066bbe343b5b7ccfae4a14c44239c9fce59e4 Make all shutdown logic synchronous. It looks like there's a bug in Obsidian where adding asynchronous operations on shutdown (via `tasks.addPromise`) crashes the app when the user runs the `Reload App Without Saving` command. So we have to do it all synchronously instead. diff -r f2e066bbe343 -r 06504ceb3283 src/main.ts --- a/src/main.ts Mon Oct 02 10:07:26 2023 -0700 +++ b/src/main.ts Mon Oct 02 10:10:09 2023 -0700 @@ -461,14 +461,15 @@ delete this.data.rememberedFiles[file.path]; }; - private readonly onAppQuit = async (tasks: Tasks): Promise => { - const _this = this; - tasks.addPromise( - _this.rememberAllOpenedFileStates() - .then(() => _this.writeStateDatabase(STATE_DB_PATH))); + private readonly onAppQuit = function(tasks: Tasks) { + this.unregisterAllViews(); + this.rememberAllOpenedFileStates(); + this.writeStateDatabase(STATE_DB_PATH); + console.log("RememberFileState: done with app-quit cleanup."); } - private readonly rememberAllOpenedFileStates = async(): Promise => { + private readonly rememberAllOpenedFileStates = function() { + console.log("RememberFileState: remembering all opened file states..."); this.app.workspace.getLeavesOfType("markdown").forEach( (leaf: WorkspaceLeaf) => { const view = leaf.view as MarkdownView; @@ -477,13 +478,15 @@ ); } - private readonly writeStateDatabase = async(path: string): Promise => { + private readonly writeStateDatabase = function(path: string) { const fs = this.app.vault.adapter; const jsonDb = JSON.stringify(this.data); - await fs.write(path, jsonDb); + console.log("RememberFileState: writing state database..."); + fs.write(path, jsonDb) + .then(() => { console.log("RememberFileState: wrote state database."); }); } - private readonly readStateDatabase = async(path: string): Promise => { + private readonly readStateDatabase = async function(path: string): Promise { const fs = this.app.vault.adapter; if (await fs.exists(path)) { const jsonDb = await fs.read(path);