generated from coulomb/repo-seed
Fix: Restore fallback to check recent downloads
When the persistent queue is empty (e.g., after extension reload), fall back to checking recent downloads from Chrome downloads API. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -164,7 +164,6 @@ async function loadPDFQueue() {
|
|||||||
const exists = pdfQueue.some(p => p.url === currentTabPDF.url);
|
const exists = pdfQueue.some(p => p.url === currentTabPDF.url);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
console.log('[Popup] Adding current tab PDF to queue:', currentTabPDF.filename);
|
console.log('[Popup] Adding current tab PDF to queue:', currentTabPDF.filename);
|
||||||
// Add to queue (will be added to persistent queue when user interacts)
|
|
||||||
const entry: PDFQueueEntry = {
|
const entry: PDFQueueEntry = {
|
||||||
...currentTabPDF,
|
...currentTabPDF,
|
||||||
status: 'pending'
|
status: 'pending'
|
||||||
@@ -173,10 +172,71 @@ async function loadPDFQueue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback: check recent downloads if queue is still empty
|
||||||
|
if (pdfQueue.length === 0) {
|
||||||
|
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'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Render the list
|
// Render the list
|
||||||
renderPDFList();
|
renderPDFList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check recent downloads for PDFs (fallback mechanism)
|
||||||
|
*/
|
||||||
|
async function checkRecentDownloads(): Promise<DetectedPDF[]> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
chrome.downloads.search(
|
||||||
|
{
|
||||||
|
limit: 20,
|
||||||
|
orderBy: ['-startTime']
|
||||||
|
},
|
||||||
|
(items) => {
|
||||||
|
console.log('[Popup] Checked recent downloads:', items.length, 'items');
|
||||||
|
|
||||||
|
const pdfs: DetectedPDF[] = [];
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (
|
||||||
|
item.state === 'complete' &&
|
||||||
|
(item.filename.toLowerCase().endsWith('.pdf') || item.mime === 'application/pdf')
|
||||||
|
) {
|
||||||
|
let domain = 'unknown';
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(item.url);
|
||||||
|
domain = urlObj.hostname;
|
||||||
|
} catch (e) {
|
||||||
|
// Keep default
|
||||||
|
}
|
||||||
|
|
||||||
|
pdfs.push({
|
||||||
|
id: `download-${item.id}`,
|
||||||
|
filename: item.filename.split('/').pop() || item.filename,
|
||||||
|
url: item.url,
|
||||||
|
size: item.fileSize,
|
||||||
|
timestamp: new Date(item.startTime).getTime(),
|
||||||
|
sourceDomain: domain
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[Popup] Found', pdfs.length, 'PDF downloads');
|
||||||
|
resolve(pdfs);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the PDF list
|
* Render the PDF list
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user