Skip to content

Commit

Permalink
Pop-up attached to button is no longer working in TB102
Browse files Browse the repository at this point in the history
I don't know why, but TB102 has decided not to let me open the popup
from my callback function anymore. Since it's working fine in TB115
there's no reason to waste time troubleshooting. Let's just detach the
popup in TB102.
  • Loading branch information
jikamens committed Sep 10, 2023
1 parent cf6c812 commit ef8125f
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1508,40 +1508,48 @@ const SendLater = {
return false;
}
SLStatic.info("Opening popup");
// The onClicked event on the compose action button doesn't fire if a
// pop-up is configured, so we have to set and open the popup here and
// then immediately unset the popup so that we can catch the key binding
// if the user clicks again with a modifier.
messenger.composeAction.setPopup({ popup: "ui/popup.html" });
try {
if (!(await messenger.composeAction.openPopup())) {
// openPopup doesn't return a status in TB102, so we just have to assume
// that it opened successfully. *sigh*
await SLStatic.tb115(async () => {
SLStatic.info(
"composeAction pop-up failed to open, trying standalone",
);
let tab = (await browser.tabs.query({ currentWindow: true }))[0];
let params = {
allowScriptsToClose: true,
type: "popup",
url: `ui/popup.html?tabId=${tab.id}`,
};
if (
SendLater.prefCache.detachedPopupWindowWidth &&
SendLater.prefCache.detachedPopupWindowHeight
) {
params.width = SendLater.prefCache.detachedPopupWindowWidth;
params.height = SendLater.prefCache.detachedPopupWindowHeight;
}
if (!(await messenger.windows.create(params))) {
SLStatic.error("standalone scheduling pop-up failed to open");
}
});

async function detachedPopup() {
let tab = (await browser.tabs.query({ currentWindow: true }))[0];
let params = {
allowScriptsToClose: true,
type: "popup",
url: `ui/popup.html?tabId=${tab.id}`,
};
if (
SendLater.prefCache.detachedPopupWindowWidth &&
SendLater.prefCache.detachedPopupWindowHeight
) {
params.width = SendLater.prefCache.detachedPopupWindowWidth;
params.height = SendLater.prefCache.detachedPopupWindowHeight;
}
if (!(await messenger.windows.create(params))) {
SLStatic.error("standalone scheduling pop-up failed to open");
}
} finally {
messenger.composeAction.setPopup({ popup: null });
}

await SLStatic.tb115(
async () => {
// The onClicked event on the compose action button doesn't fire if a
// pop-up is configured, so we have to set and open the popup here and
// then immediately unset the popup so that we can catch the key binding
// if the user clicks again with a modifier.
messenger.composeAction.setPopup({ popup: "ui/popup.html" });
try {
if (!(await messenger.composeAction.openPopup())) {
SLStatic.info(
"composeAction pop-up failed to open, trying standalone",
);
return await detachedPopup();
}
} finally {
messenger.composeAction.setPopup({ popup: null });
}
},
async () => {
return await detachedPopup();
},
);
},

// Custom events that are attached to user actions within
Expand Down

0 comments on commit ef8125f

Please sign in to comment.