feat: load remote config on page load

This commit is contained in:
AdenMGB committed 2026-10-30 20:01:54 +10:30
1 parent 1bd88ec81c
commit 6e2251159e
6 files changed
+64 -31

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ import {
registerGoogleCalendarMessageHandlers,
registerOutlookCalendarMessageHandlers,
} from "./background/calendarBackground";
import { createCustomThemesHandlers } from "./background/customThemesHandlers";
import {
createRemoteConfigHandlers,
initRemoteConfigBackground,
+18
View File
@@ -4101,6 +4101,24 @@ div.day-empty {
.bsplus-founder-badge-hero__stage .bsplus-founder-badge {
pointer-events: auto;
}
.bsplus-remote-page-banner {
width: 90%;
margin: 0 auto 0.75rem;
padding: 0.65rem 0.85rem;
border-radius: 12px;
border: 1px solid color-mix(in srgb, var(--text-primary) 14%, transparent);
background: color-mix(in srgb, var(--text-primary) 5%, var(--background-primary));
font-size: 0.95rem;
line-height: 1.5;
color: var(--text-primary);
}
.bsplus-remote-page-banner__title {
font-weight: 600;
margin: 0 0 0.35rem;
}
.whatsnewTextContainer.bsplus-founder-badge-body p {
margin: 0 0 1rem;
font-size: 1.2rem;
@@ -6,20 +6,6 @@ import type { RemoteCampaign } from "@/seqta/utils/remoteConfig/types";
import { requestSettingsDestination } from "@/seqta/utils/settingsNavigation";
import { openSettingsPopup } from "@/seqta/utils/setupSettingsButton";
function campaignHero(campaign: RemoteCampaign): HTMLElement | null {
const hero = campaign.hero;
if (!hero?.url) return null;
if (hero.type === "video") {
return createPopupHeroVideo(hero.url, hero.alt ?? "");
}
const img = document.createElement("img");
img.src = hero.url;
img.alt = hero.alt ?? "";
img.className = "whatsnewHeroImage";
img.loading = "lazy";
return img;
}
export function openRemoteCampaignPopup(
campaign: RemoteCampaign,
onDismissed?: () => void,
@@ -31,27 +17,45 @@ export function openRemoteCampaignPopup(
/* html */ `<div class="whatsnewHeader"><h1>${title}</h1>${subtitle ? `<p>${subtitle}</p>` : ""}</div>`,
).firstChild as HTMLElement;
const body = stringToHTML(/* html */ `<div class="whatsnewTextContainer"></div>`)
.firstChild as HTMLElement;
if (campaign.bodyHtml) body.innerHTML = campaign.bodyHtml;
const buttons = campaign.buttons?.length
? campaign.buttons
: [{ id: "dismiss", label: "Dismiss", action: "dismiss" as const }];
const footer = stringToHTML(
/* html */ `<div class="bsplus-campaign-actions flex flex-wrap gap-2 justify-end p-4">${buttons
.map(
(btn) =>
`<button type="button" id="bsplus-campaign-${campaign.id}-${btn.id}" class="bsplus-tos-btn bsplus-tos-btn--primary">${btn.label}</button>`,
)
.join("")}</div>`,
).firstChild as HTMLElement;
const actionsHtml = buttons
.map(
(btn, i) =>
`<button type="button" id="bsplus-campaign-${campaign.id}-${btn.id}" class="bsplus-cal-btn ${i === 0 ? "bsplus-cal-btn--primary" : "bsplus-cal-btn--ghost"}">${btn.label}</button>`,
)
.join("");
const text = stringToHTML(/* html */ `
<div class="whatsnewTextContainer bsplus-founder-badge-body" style="overflow-y: auto;">
<div class="bsplus-campaign-body"></div>
<div class="bsplus-founder-badge-actions">${actionsHtml}</div>
</div>
`).firstChild as HTMLElement;
const bodySlot = text.querySelector(".bsplus-campaign-body");
if (bodySlot && campaign.bodyHtml) bodySlot.innerHTML = campaign.bodyHtml;
const content: HTMLElement[] = [];
const hero = campaignHero(campaign);
if (hero) content.push(hero);
content.push(body, footer);
const hero = campaign.hero;
if (hero?.url) {
if (hero.type === "video") {
content.push(createPopupHeroVideo(hero.url, hero.alt ?? ""));
} else {
const wrap = stringToHTML(/* html */ `<div class="whatsnewImgContainer"></div>`)
.firstChild as HTMLElement;
const img = document.createElement("img");
img.src = hero.url;
img.alt = hero.alt ?? "";
img.className = "whatsnewImg";
img.loading = "lazy";
wrap.append(img);
content.push(wrap);
}
}
content.push(text);
const actions = buttons.map((btn) => ({
id: `bsplus-campaign-${campaign.id}-${btn.id}`,
@@ -70,6 +74,7 @@ export function openRemoteCampaignPopup(
openPopup({
header,
content,
animateSelector: ".whatsnewImgContainer, .whatsnewTextContainer *",
actions,
afterClose: () => {
void markCampaignSeen(campaign.id);
+3
View File
@@ -7,7 +7,10 @@ import {
BSPLUS_INSTALL_REGISTERED_AT_KEY,
BSPLUS_LOCAL_OVERRIDE_ONOFF_KEY,
BSPLUS_REMOTE_CONFIG_ETAG_KEY,
BSPLUS_REMOTE_CONFIG_FETCHED_AT_KEY,
BSPLUS_REMOTE_CONFIG_LAST_HOSTNAME_KEY,
BSPLUS_REMOTE_CONFIG_SNAPSHOT_KEY,
BSPLUS_REMOTE_LAST_PRIMARY_OK_KEY,
} from "@/seqta/utils/remoteConfig/storageKeys";
/** Matches the contract in docs/CLOUD_SETTINGS_SYNC_SERVER.md */
+3 -1
View File
@@ -121,13 +121,15 @@ describe("hydrateRemoteConfigFromStorage", () => {
jest.doMock("@/seqta/utils/listeners/SettingsState", () => ({
settingsState: { onoff: true },
}));
const { hydrateRemoteConfigFromStorage } = await import("./runtime");
const { hydrateRemoteConfigFromStorage, notifyRemoteConfigPageContext } = await import("./runtime");
await hydrateRemoteConfigFromStorage();
notifyRemoteConfigPageContext("learn.example.edu.au");
const browser = jest.requireMock("webextension-polyfill");
const types = browser.runtime.sendMessage.mock.calls.map(
(c: [{ type?: string }]) => c[0]?.type,
);
expect(types).toContain("getRemoteConfigSnapshot");
expect(types).toContain("setRemoteConfigPageContext");
expect(types).toContain("refreshRemoteConfig");
expect(types.indexOf("getRemoteConfigSnapshot")).toBeLessThan(
types.indexOf("refreshRemoteConfig"),
+5 -1
View File
@@ -111,7 +111,6 @@ export async function hydrateRemoteConfigFromStorage(): Promise<RemoteConfigSnap
} catch {
// SW unavailable
}
void browser.runtime.sendMessage({ type: "refreshRemoteConfig" }).catch(() => {});
}
applyRemoteRuntime(
@@ -123,11 +122,16 @@ export async function hydrateRemoteConfigFromStorage(): Promise<RemoteConfigSnap
return snapshot;
}
export function syncRemoteConfigFromBackend(): void {
void browser.runtime.sendMessage({ type: "refreshRemoteConfig" }).catch(() => {});
}
export function notifyRemoteConfigPageContext(hostname: string): void {
void browser.storage.local.set({ [BSPLUS_REMOTE_CONFIG_LAST_HOSTNAME_KEY]: hostname });
void browser.runtime
.sendMessage({ type: "setRemoteConfigPageContext", hostname })
.catch(() => {});
syncRemoteConfigFromBackend();
}
export async function markCampaignSeen(campaignId: string, ack?: boolean): Promise<void> {