Fix state persistence when popup is closed

- Add 'dismissed' status to prevent dismissed PDFs from reappearing
- Persist PDFs discovered from current tab and recent downloads via background
- Add dismissPDF function that marks PDFs as dismissed instead of removing
- Dismissed PDFs are kept for 7 days for duplicate detection, then cleaned up
- Completed items (sent/canceled) can still be fully removed
- Add addPDF message handler to service worker for popup-discovered PDFs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-16 10:20:28 +01:00
parent 3a48d4f497
commit 468473f03b
3 changed files with 89 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ import {
getAllPDFs,
getPendingPDFs,
updatePDFStatus,
dismissPDF,
removePDF,
cleanupOldEntries,
PDFStatus,
@@ -129,6 +130,19 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true;
}
// Add a PDF to the queue (from popup discovery)
if (request.action === 'addPDF') {
addPDF(request.pdf).then(entry => {
if (entry) {
console.log('[Service Worker] PDF added via message:', entry.filename);
}
return updateBadge().then(() => entry);
}).then(entry => {
sendResponse({ entry });
});
return true;
}
// Legacy: Get only actionable PDFs
if (request.action === 'getPDFQueue') {
getPendingPDFs().then(entries => {
@@ -148,6 +162,15 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true;
}
if (request.action === 'dismissPDF') {
dismissPDF(request.id).then(() => {
return updateBadge();
}).then(() => {
sendResponse({ success: true });
});
return true;
}
if (request.action === 'removePDF') {
removePDF(request.id).then(() => {
return updateBadge();