Skip to content

Commit 2763cf5

Browse files
committed
fix: handle layout not yet ready when event triggers
1 parent fd07690 commit 2763cf5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ export default class PodNotes extends Plugin implements IPodNotes {
6666
}>;
6767
private transcriptionService: TranscriptionService;
6868

69+
private maxLayoutReadyAttempts = 10;
70+
private layoutReadyAttempts = 0;
71+
6972
async onload() {
7073
plugin.set(this);
7174

@@ -281,6 +284,19 @@ export default class PodNotes extends Plugin implements IPodNotes {
281284
}
282285

283286
onLayoutReady(): void {
287+
if (!this.app.workspace || !this.app.workspace.layoutReady) {
288+
// Workspace is not ready, schedule a retry
289+
this.layoutReadyAttempts++;
290+
if (this.layoutReadyAttempts < this.maxLayoutReadyAttempts) {
291+
setTimeout(() => this.onLayoutReady(), 100);
292+
} else {
293+
console.error(
294+
"Failed to initialize PodNotes layout after maximum attempts",
295+
);
296+
}
297+
return;
298+
}
299+
284300
if (this.app.workspace.getLeavesOfType(VIEW_TYPE).length) {
285301
return;
286302
}

0 commit comments

Comments
 (0)