Skip to content

Commit

Permalink
fix: register event listener after initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Jul 25, 2022
1 parent f4f0573 commit d32d0f4
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,7 @@ export default class ObsidianGit extends Plugin {
console.log('loading ' + this.manifest.name + " plugin");
await this.loadSettings();
this.migrateSettings();
this.modifyEvent = this.app.vault.on("modify", () => {
this.debRefresh();
});
this.deleteEvent = this.app.vault.on("delete", () => {
this.debRefresh();
});
this.createEvent = this.app.vault.on("create", () => {
this.debRefresh();
});
this.renameEvent = this.app.vault.on("rename", () => {
this.debRefresh();
});

this.registerEvent(this.modifyEvent);
this.registerEvent(this.deleteEvent);
this.registerEvent(this.createEvent);
this.registerEvent(this.renameEvent);
addEventListener("git-refresh", this.refresh.bind(this));

this.registerView(GIT_VIEW_CONFIG.type, (leaf) => {
Expand Down Expand Up @@ -298,6 +282,25 @@ export default class ObsidianGit extends Plugin {
case "valid":
this.gitReady = true;
this.setState(PluginState.idle);

this.modifyEvent = this.app.vault.on("modify", () => {
this.debRefresh();
});
this.deleteEvent = this.app.vault.on("delete", () => {
this.debRefresh();
});
this.createEvent = this.app.vault.on("create", () => {
this.debRefresh();
});
this.renameEvent = this.app.vault.on("rename", () => {
this.debRefresh();
});

this.registerEvent(this.modifyEvent);
this.registerEvent(this.deleteEvent);
this.registerEvent(this.createEvent);
this.registerEvent(this.renameEvent);

dispatchEvent(new CustomEvent('git-refresh'));

if (this.settings.autoPullOnBoot) {
Expand Down

0 comments on commit d32d0f4

Please sign in to comment.