Changelog: - forward download progress from background/offscreen workers to content frames - add progress UI and button state management in Safari Books page script - emit structured progress callbacks and faster image fetching in SafariBooksDownloader - sync Firefox bundle with progress plumbing and concurrency improvements - ignore packaged extension archives Description: Expose progress events through the downloader so the content script can present real-time status, including chapter and asset fetching milestones. Added concurrency controls, page detection, and packaging telemetry, while keeping Firefox build behavior in sync and ignoring generated .xpi bundles.
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
import { SafariBooksDownloader } from "./safaribooks/downloader.js";
|
|
import { collectSessionCookies } from "./safaribooks/cookies.js";
|
|
|
|
const downloader = new SafariBooksDownloader((message) => {
|
|
console.info(`[SafariBooksDownloader] ${message}`);
|
|
}, (payload) => {
|
|
try {
|
|
chrome.runtime.sendMessage({
|
|
type: "offscreen-download-progress",
|
|
requestId: currentRequestId,
|
|
payload
|
|
});
|
|
} catch (_) {
|
|
// ignore communication errors
|
|
}
|
|
});
|
|
|
|
let currentRequestId = null;
|
|
|
|
async function handleOffscreenDownload(message) {
|
|
const { requestId, bookId, options = {} } = message;
|
|
if (!bookId) {
|
|
chrome.runtime.sendMessage({
|
|
type: "offscreen-download-complete",
|
|
requestId,
|
|
ok: false,
|
|
error: "Missing book ID."
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
currentRequestId = requestId;
|
|
await collectSessionCookies();
|
|
await downloader.download(bookId, {
|
|
theme: options.theme ?? "none",
|
|
kindle: Boolean(options.kindle)
|
|
});
|
|
chrome.runtime.sendMessage({
|
|
type: "offscreen-download-complete",
|
|
requestId,
|
|
ok: true
|
|
});
|
|
} catch (error) {
|
|
chrome.runtime.sendMessage({
|
|
type: "offscreen-download-complete",
|
|
requestId,
|
|
ok: false,
|
|
error: error.message
|
|
});
|
|
}
|
|
currentRequestId = null;
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener((message) => {
|
|
if (message?.type === "offscreen-download") {
|
|
handleOffscreenDownload(message);
|
|
}
|
|
});
|
|
|
|
chrome.runtime
|
|
.sendMessage({ type: "offscreen-ready" })
|
|
.catch(() => {
|
|
// ignore errors if background not ready yet
|
|
});
|