Merge pull request #73 from wagesj45/codex/implement-sortana--message-in-background.js

Add displayed message retrieval and update details page
This commit is contained in:
Jordan Wages 2025-07-07 00:15:37 -05:00 committed by GitHub
commit 46c101f101
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 10 deletions

View file

@ -501,6 +501,15 @@ async function clearCacheForMessages(idsInput) {
logger.aiLog("failed to collect details", { level: 'error' }, e);
return { subject: '', results: [] };
}
} else if (msg?.type === "sortana:getDisplayedMessages") {
try {
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
const messages = await browser.messageDisplay.getDisplayedMessages(tab?.id);
return { messages };
} catch (e) {
logger.aiLog("failed to get displayed messages", { level: 'error' }, e);
return { messages: [] };
}
} else if (msg?.type === "sortana:clearCacheForMessage") {
try {
await clearCacheForMessages([msg.id]);

View file

@ -15,6 +15,6 @@
</div>
</div>
</section>
<script src="details.js"></script>
<script type="module" src="details.js"></script>
</body>
</html>

View file

@ -1,12 +1,9 @@
document.addEventListener("DOMContentLoaded", async () => {
const aiLog = (await import(browser.runtime.getURL("logger.js"))).aiLog;
const qMid = parseInt(new URLSearchParams(location.search).get("mid"), 10);
if (!isNaN(qMid)) {
loadMessage(qMid);
return;
}
const aiLog = (await import(browser.runtime.getURL("logger.js"))).aiLog;
const qMid = parseInt(new URLSearchParams(location.search).get("mid"), 10);
if (!isNaN(qMid)) {
loadMessage(qMid);
} else {
const thisTab = await browser.tabs.getCurrent();
//const baseTabId = thisTab.openerTabId ?? thisTab.id;
//const [header] = await browser.messageDisplay.getDisplayedMessages(baseTabId);
@ -16,7 +13,7 @@ document.addEventListener("DOMContentLoaded", async () => {
//} else {
// aiLog("Details popup: no displayed message found");
//}
});
}
async function loadMessage(id) {
const storage = (globalThis.messenger ?? browser).storage;