generated from coulomb/repo-seed
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:
@@ -153,22 +153,20 @@ async function loadPDFQueue() {
|
||||
console.log('[Popup] Loading PDF queue...');
|
||||
|
||||
// Get all PDFs from background script (including completed ones)
|
||||
const response = await chrome.runtime.sendMessage({ action: 'getAllPDFs' });
|
||||
let response = await chrome.runtime.sendMessage({ action: 'getAllPDFs' });
|
||||
pdfQueue = response?.entries || [];
|
||||
console.log('[Popup] Got', pdfQueue.length, 'entries from background');
|
||||
|
||||
// Also check current tab for PDF
|
||||
// Check current tab for PDF and add to persistent queue via background
|
||||
const currentTabPDF = await checkCurrentTabForPDF();
|
||||
if (currentTabPDF) {
|
||||
// Check if already in queue
|
||||
const exists = pdfQueue.some(p => p.url === currentTabPDF.url);
|
||||
if (!exists) {
|
||||
console.log('[Popup] Adding current tab PDF to queue:', currentTabPDF.filename);
|
||||
const entry: PDFQueueEntry = {
|
||||
...currentTabPDF,
|
||||
status: 'pending'
|
||||
};
|
||||
pdfQueue.unshift(entry);
|
||||
// Add via background service (will check for duplicates/dismissed)
|
||||
const addResult = await chrome.runtime.sendMessage({
|
||||
action: 'addPDF',
|
||||
pdf: currentTabPDF
|
||||
});
|
||||
if (addResult?.entry) {
|
||||
console.log('[Popup] Added current tab PDF to persistent queue:', currentTabPDF.filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,16 +175,19 @@ async function loadPDFQueue() {
|
||||
console.log('[Popup] Queue empty, checking recent downloads...');
|
||||
const recentPDFs = await checkRecentDownloads();
|
||||
for (const pdf of recentPDFs) {
|
||||
const exists = pdfQueue.some(p => p.url === pdf.url);
|
||||
if (!exists) {
|
||||
pdfQueue.push({
|
||||
...pdf,
|
||||
status: 'pending'
|
||||
});
|
||||
}
|
||||
// Add each PDF via background service (will check for duplicates/dismissed)
|
||||
await chrome.runtime.sendMessage({
|
||||
action: 'addPDF',
|
||||
pdf
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Reload queue after potential additions
|
||||
response = await chrome.runtime.sendMessage({ action: 'getAllPDFs' });
|
||||
pdfQueue = response?.entries || [];
|
||||
console.log('[Popup] Final queue count:', pdfQueue.length);
|
||||
|
||||
// Render the list
|
||||
renderPDFList();
|
||||
}
|
||||
@@ -757,7 +758,17 @@ async function handleRefreshStatus(id: string) {
|
||||
* Handle dismiss PDF
|
||||
*/
|
||||
async function handleDismissPDF(id: string) {
|
||||
await chrome.runtime.sendMessage({ action: 'removePDF', id });
|
||||
const pdf = pdfQueue.find(p => p.id === id);
|
||||
if (!pdf) return;
|
||||
|
||||
// For pending/failed/in_basket items, mark as dismissed to prevent re-showing
|
||||
// For completed items (sent/canceled), actually remove from storage
|
||||
if (pdf.status === 'sent' || pdf.status === 'canceled') {
|
||||
await chrome.runtime.sendMessage({ action: 'removePDF', id });
|
||||
} else {
|
||||
await chrome.runtime.sendMessage({ action: 'dismissPDF', id });
|
||||
}
|
||||
|
||||
pdfQueue = pdfQueue.filter(p => p.id !== id);
|
||||
renderPDFList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user