Skip to content

Commit

Permalink
Fix metadataCache event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaoumov committed Jul 17, 2024
1 parent 7fa7b93 commit e6be6ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ async function runWithTimeout<R>(timeoutInMilliseconds: number, asyncFn: () => P
throw new Error(`Timed out in ${timeoutInMilliseconds} milliseconds`);
}
}

export function convertToSync(promise: Promise<unknown>): void {
promise.catch(console.error);
}
5 changes: 3 additions & 2 deletions src/BetterMarkdownLinksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getAllLinks,
getCacheSafe
} from "./MetadataCache.ts";
import { convertToSync } from "./Async.ts";

type GenerateMarkdownLinkFn = (file: TFile, sourcePath: string, subpath?: string, alias?: string) => string;

Expand Down Expand Up @@ -49,7 +50,7 @@ export default class BetterMarkdownLinksPlugin extends Plugin {
callback: this.convertLinksInEntireVault.bind(this)
});

this.registerEvent(this.app.metadataCache.on("changed", () => void this.handleMetadataCacheChanged));
this.registerEvent(this.app.metadataCache.on("changed", (file) => convertToSync(this.handleMetadataCacheChanged(file))));
}

public async saveSettings(newSettings: BetterMarkdownLinksPluginSettings): Promise<void> {
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class BetterMarkdownLinksPlugin extends Plugin {
}

if (!checking) {
this.convertLinksInFile(activeFile).catch(console.error);
convertToSync(this.convertLinksInFile(activeFile));
}

return true;
Expand Down

0 comments on commit e6be6ec

Please sign in to comment.