Remove unnecessary event handler; wait up to 1 second for File Explorer pane to load on initialization

This commit is contained in:
Isaac Lyman 2022-03-09 22:00:49 -07:00
parent 5a51033da8
commit cea1cc5760
1 changed files with 10 additions and 9 deletions

17
main.ts
View File

@ -86,7 +86,15 @@ export default class NovelWordCountPlugin extends Plugin {
public async initialize() {
await this.refreshAllCounts();
await this.updateDisplayedCounts();
try {
await this.updateDisplayedCounts();
} catch (err) {
// File Explorer pane may not be loaded yet
setTimeout(() => {
this.updateDisplayedCounts();
}, 1000);
}
}
public async updateDisplayedCounts() {
@ -151,13 +159,6 @@ export default class NovelWordCountPlugin extends Plugin {
}
private handleEvents(): void {
this.registerEvent(
this.app.workspace.on("file-open", async () => {
await this.loadSettings();
await this.updateDisplayedCounts();
})
);
this.registerEvent(
this.app.vault.on("modify", async (file) => {
await this.fileHelper.updateFileCounts(