feat: sticky notices for sync/resolve summaries

This commit is contained in:
afiqzudinhadi 2026-08-05 12:44:30 +08:00
parent 49d7779bc1
commit f146de1b76
3 changed files with 16 additions and 12 deletions

View file

@ -43,8 +43,8 @@ export class LibraryController {
constructor(private plugin: MediaDbPlugin) {}
private notify(msg: string): void {
new Notice(msg);
private notify(msg: string, timeout?: number): void {
new Notice(msg, timeout);
}
private getKey(name: 'rawg' | 'comicvine'): string {
@ -142,7 +142,7 @@ export class LibraryController {
if (quiet) {
console.log(`[media-db-library] ${msg}`);
} else {
this.notify(msg);
this.notify(msg, 0);
}
}
@ -155,6 +155,7 @@ export class LibraryController {
this.notify(
`Library ${mode}sync (${spec.typeName}): ${report.synced} checked, ${report.written} updated, ${report.flipped.length} flipped` +
(report.errors.length ? `, ${report.errors.length} errors (see console)` : ''),
0,
);
}
return report;
@ -186,6 +187,7 @@ export class LibraryController {
this.notify(
`Library ${mode}resolve (${spec.typeName}): ${report.resolved.length} resolved, ${report.ambiguous.length} ambiguous/no match` +
(report.errors.length ? `, ${report.errors.length} errors (see console)` : ''),
0,
);
return report;
} finally {
@ -209,7 +211,7 @@ export class LibraryController {
// rest of the run -- log + surface it, then keep going with the other types
const msg = `Library sync failed for ${spec.typeName}: ${e instanceof Error ? e.message : String(e)}`;
console.log(`[media-db-library] ${msg}`);
if (!quiet) this.notify(msg);
if (!quiet) this.notify(msg, 0);
}
}
if (!full) {

View file

@ -185,45 +185,45 @@ export default class MediaDbPlugin extends Plugin {
this.addCommand({
id: 'watchlist-sync-now',
name: 'Watchlist: sync now (airing/active only)',
callback: () => void this.watchlist.syncNow(false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.watchlist.syncNow(false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
this.addCommand({
id: 'watchlist-sync-full',
name: 'Watchlist: full sync (all entries)',
callback: () => void this.watchlist.syncNow(true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.watchlist.syncNow(true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
this.addCommand({
id: 'watchlist-sync-dry-run',
name: 'Watchlist: dry-run full sync (log only, no writes)',
callback: () => void this.watchlist.syncNow(true, true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.watchlist.syncNow(true, true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
this.addCommand({
id: 'watchlist-resolve-ids',
name: 'Watchlist: resolve missing TMDB ids',
callback: () => void this.watchlist.resolveMissingIds().catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.watchlist.resolveMissingIds().catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
for (const { spec, slug } of LIBRARY_TYPES) {
this.addCommand({
id: `library-sync-${slug}`,
name: `Library: sync ${slug} now`,
callback: () => void this.library.syncType(spec, false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.library.syncType(spec, false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
this.addCommand({
id: `library-resolve-${slug}`,
name: `Library: resolve ${slug} ids`,
callback: () => void this.library.resolveType(spec).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.library.resolveType(spec).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
this.addCommand({
id: `library-dry-run-${slug}`,
name: `Library: dry-run ${slug} full sync`,
callback: () => void this.library.syncType(spec, true, true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.library.syncType(spec, true, true).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
}
this.addCommand({
id: 'library-sync-all',
name: 'Library: sync all',
callback: () => void this.library.syncAll(false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e))),
callback: () => void this.library.syncAll(false).catch((e: unknown) => new Notice(e instanceof Error ? e.message : String(e), 0)),
});
}

View file

@ -83,6 +83,7 @@ export class WatchlistController {
new Notice(
`Watchlist ${mode}sync: ${report.synced} checked, ${report.written} updated, ${report.flipped.length} flipped to Unwatched` +
(report.errors.length ? `, ${report.errors.length} errors (see console)` : ''),
0,
);
}
if (!dryRun) {
@ -147,6 +148,7 @@ export class WatchlistController {
new Notice(
`Watchlist ${mode}resolve: ${report.scanned} scanned, ${report.resolved} resolved, ${report.ambiguous} ambiguous/no match` +
(report.errors.length ? `, ${report.errors.length} errors (see console)` : ''),
0,
);
return report;
} finally {