Skip to content

Commit

Permalink
Improve PDF opening time
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetsu committed Aug 30, 2020
1 parent e8db5ff commit c55d1ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
case "open_pdf": {
const id = uniqueId(32);
queue.push(id, request.payload);
chrome.runtime.sendMessage({ type: "prepare_pdf" });
chrome.runtime.openOptionsPage(() => {
sendResponse();
});
Expand Down
17 changes: 11 additions & 6 deletions src/options/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const sendMessage = async (message: any) => {
const App = () => {
const [mode, setMode] = useState<"loading" | "options" | "pdf">("loading");

const showPdfViewer = async (id: string) => {
const showPdfViewer = (id: string) => {
setMode("pdf");
location.href = `pdf/web/viewer.html?id=${id}`;
};
Expand All @@ -55,12 +55,17 @@ const App = () => {
};
init();

setInterval(async () => {
const id = (await sendMessage({ type: "shift_pdf_id" })) as string;
if (id) {
showPdfViewer(id);
chrome.runtime.onMessage.addListener(async (request) => {
switch (request?.type) {
case "prepare_pdf": {
const id = (await sendMessage({ type: "shift_pdf_id" })) as string;
if (id) {
showPdfViewer(id);
}
break;
}
}
}, 3000);
});
}, []);

switch (mode) {
Expand Down

0 comments on commit c55d1ef

Please sign in to comment.