Skip to content

Commit

Permalink
Show tab preview panel ASAP before the preview URL is resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Dec 19, 2024
1 parent 949af2f commit 664c95a
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions webextensions/sidebar/tab-preview-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {
if (!tab)
return false;

const promisedPreviewURL = typeof message.previewURL == 'function' && message.previewURL();

let frameId;
let loadedInfo;
try {
Expand All @@ -277,9 +279,6 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {
type: 'treestyletab:ask-tab-preview-frame-loaded',
tabId,
}).catch(_error => {}),
typeof message.previewURL == 'function' && (async () => {
message.previewURL = await message.previewURL();
})(),
]);
frameId = gotFrameId;
loadedInfo = gotLoadedInfo;
Expand Down Expand Up @@ -345,17 +344,35 @@ async function sendTabPreviewMessage(tabId, message, deferredResultResolver) {

let response;
try {
const timestamp = Date.now();
response = await browser.tabs.sendMessage(tabId, {
tabId,
timestamp: Date.now(),
timestamp,
...message,
...TabPreviewFrame.getColors(),
...(promisedPreviewURL ? { previewURL: null } : {}),
animation: shouldApplyAnimation(),
logging: configs.logFor['sidebar/tab-preview-tooltip'] && configs.debug,
}, frameId ? { frameId } : {});
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}): message was sent to the frame, response=`, response);
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}): message was sent to the frame, response=`, response, ', promisedPreviewURL=', promisedPreviewURL);
if (deferredResultResolver)
deferredResultResolver(!!response);

if (response && promisedPreviewURL) {
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}, with previewURL): trying to get preview URL`);
promisedPreviewURL.then(async previewURL => {
const response = await browser.tabs.sendMessage(tabId, {
tabId,
timestamp,
...message,
previewURL,
...TabPreviewFrame.getColors(),
animation: shouldApplyAnimation(),
logging: configs.logFor['sidebar/tab-preview-tooltip'] && configs.debug,
}, frameId ? { frameId } : {});
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}, with previewURL): message was sent to the frame again, response=`, response);
});
}
}
catch (error) {
log(`sendTabPreviewMessage(${message.type}${retrying ? ', retrying' : ''}): failed to send message to the frame `, error);
Expand Down

0 comments on commit 664c95a

Please sign in to comment.