Skip to content

Commit 3791218

Browse files
committed
making plugin work upon restart.
1 parent ad01930 commit 3791218

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/main.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,14 @@ export default class HackerNewsPlugin extends Plugin {
2929
return new HackerNewsView(leaf, this);
3030
});
3131

32-
if (this.app.workspace.getLeavesOfType(VIEW_TYPE).length == 0) {
33-
await this.app.workspace.getRightLeaf(false).setViewState({
34-
type: VIEW_TYPE,
35-
});
36-
}
37-
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(VIEW_TYPE).first());
38-
3932
this.addCommand({
4033
id: 'hackernews-open-view',
4134
name: t('Open HackerNews'),
42-
callback: async () => {
43-
if (this.app.workspace.getLeavesOfType(VIEW_TYPE).length == 0) {
44-
await this.app.workspace.getRightLeaf(false).setViewState({
45-
type: VIEW_TYPE,
46-
});
47-
}
48-
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(VIEW_TYPE).first());
49-
},
35+
callback: this.openWindowLeaf.bind(this),
5036
});
5137

38+
this.app.workspace.onLayoutReady(this.openWindowLeaf.bind(this))
39+
5240
let refreshInterval = parseInt(this.settings.defaultRefreshInterval)
5341
if (Number.isNaN(refreshInterval) || refreshInterval <= 0) { refreshInterval = 60 }
5442

@@ -74,4 +62,14 @@ export default class HackerNewsPlugin extends Plugin {
7462
async saveSettings(): Promise<void> {
7563
await this.saveData(this.settings);
7664
}
65+
66+
async openWindowLeaf() {
67+
if (this.app.workspace.getLeavesOfType(VIEW_TYPE).length == 0) {
68+
await this.app.workspace.getRightLeaf(false).setViewState({
69+
type: VIEW_TYPE,
70+
});
71+
}
72+
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(VIEW_TYPE).first());
73+
dispatchEvent(new Event('obsidian-hackernews-fetchTopHN'))
74+
}
7775
}

0 commit comments

Comments
 (0)