Skip to content

Commit 58261fb

Browse files
authored
Merge pull request #24 from codebridger/CU-86exkh0z3_Step-3-First-run-dashboard-fix-name-avatar-timezone-install-extension-nudge_Navid-Shad
feat: announce extension presence on dashboard origins for install nudge #86exkh0z3
2 parents b96ad90 + 69dcf1b commit 58261fb

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/plugins/modular-rest.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,38 @@ if (typeof Storage !== "undefined" && isDashboardOrigin()) {
3838
};
3939
}
4040

41+
// Announce extension presence to the dashboard so it can hide the "install
42+
// the extension" nudge. window.postMessage crosses the content-script /
43+
// page-world boundary; the message is scoped to the page's own origin.
44+
if (typeof window !== "undefined" && isDashboardOrigin()) {
45+
const announcePresence = () => {
46+
try {
47+
window.postMessage(
48+
{
49+
source: "subturtle-extension",
50+
type: "presence",
51+
version: chrome.runtime.getManifest().version,
52+
},
53+
window.location.origin
54+
);
55+
} catch (_e) {
56+
// postMessage can fail in odd sandboxed iframes — non-fatal.
57+
}
58+
};
59+
60+
// Announce immediately in case the dashboard listener is already attached.
61+
announcePresence();
62+
63+
// Respond to dashboard pings in case the dashboard mounts after us.
64+
window.addEventListener("message", (event) => {
65+
if (event.source !== window) return;
66+
const data = event.data;
67+
if (data?.source === "subturtle-dashboard" && data?.type === "ping") {
68+
announcePresence();
69+
}
70+
});
71+
}
72+
4173
import { GlobalOptions, authentication } from "@modular-rest/client";
4274

4375
import { sendMessage, sendMessageToTabs } from "../common/helper/massage";

0 commit comments

Comments
 (0)