Skip to content

Commit bb8599e

Browse files
authored
Feat/improvements (#155)
* feat: Add transcription queue for episodes (#132) * feat: Add volume control to player (#133) * fix: mount views with svelte api (#134) * fix: Reserve image space and use native lazy load (#138) * Reserve image space and use native lazy load * Fix image loading attribute type * fix: fix Obsidian listener accumulation (#141) * feaet: Optimize latest episodes aggregation (#142) * fix: Add keys to podcast lists (#136) * fix: Stabilize episode list layout (#139) * style: move inline podcast styles into CSS (#145) * fix: persist hide-played toggle (#144) * feat: Optimize latest episodes updates (#143) * refactor: Remove redundant currentTime sync (#147) * fix: Replace moment date formatting in episode list (#148) * feat: Stream feed loading in PodcastView (#140) * Improve podcast feed initial loading * Guard feed search before cache ready * fix: Optimize Fuse reuse in search (#149) * feat: Improve topbar focus contrast (#150) * feat: Add live input handling for episode search (#135) * fix: Use Intl formatter for episode dates (#153) * feat: Improve nav cues and native lazy images (#152) * feat: Improve podcast loading feedback (#151) * fix: guard obsidian inputs from feedback loops (#154) * fix: settings corruption
1 parent 2d8b5c5 commit bb8599e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/main.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export default class PodNotes extends Plugin implements IPodNotes {
7474

7575
private maxLayoutReadyAttempts = 10;
7676
private layoutReadyAttempts = 0;
77+
private isReady = false;
78+
private pendingSave: IPodNotesSettings | null = null;
79+
private saveScheduled = false;
80+
private saveChain: Promise<void> = Promise.resolve();
7781

7882
override async onload() {
7983
plugin.set(this);
@@ -320,6 +324,8 @@ export default class PodNotes extends Plugin implements IPodNotes {
320324
);
321325

322326
this.registerEvent(getContextMenuHandler(this.app));
327+
328+
this.isReady = true;
323329
}
324330

325331
onLayoutReady(): void {
@@ -381,6 +387,45 @@ export default class PodNotes extends Plugin implements IPodNotes {
381387
}
382388

383389
async saveSettings() {
384-
await this.saveData(this.settings);
390+
if (!this.isReady) return;
391+
392+
this.pendingSave = this.cloneSettings();
393+
394+
if (this.saveScheduled) {
395+
return this.saveChain;
396+
}
397+
398+
this.saveScheduled = true;
399+
400+
this.saveChain = this.saveChain
401+
.then(async () => {
402+
while (this.pendingSave) {
403+
const snapshot = this.pendingSave;
404+
this.pendingSave = null;
405+
await this.saveData(snapshot);
406+
}
407+
})
408+
.catch((error) => {
409+
console.error("PodNotes: failed to save settings", error);
410+
})
411+
.finally(() => {
412+
this.saveScheduled = false;
413+
414+
// If a save was requested while we were saving, run again.
415+
if (this.pendingSave) {
416+
void this.saveSettings();
417+
}
418+
});
419+
420+
return this.saveChain;
421+
}
422+
423+
private cloneSettings(): IPodNotesSettings {
424+
// structuredClone is available in Obsidian's Electron runtime; fallback for safety.
425+
if (typeof structuredClone === "function") {
426+
return structuredClone(this.settings);
427+
}
428+
429+
return JSON.parse(JSON.stringify(this.settings)) as IPodNotesSettings;
385430
}
386431
}

0 commit comments

Comments
 (0)