From 1aec222b7fc08f3d89b5fe9f0896b3449d3828b2 Mon Sep 17 00:00:00 2001 From: Svit-personal Date: Wed, 11 Nov 2026 08:54:53 +0100 Subject: [PATCH 1/4] feat: restyle the review and sponsor cards after Prolific's prompt cards Adds a visible "Not now" button and the extension's real name to the review card, a heart badge to the sponsor card, and hides the footer while the sponsor card shows so the popup stays within 600px. --- wxt/entrypoints/components/HeartIcon.tsx | 13 ++ wxt/entrypoints/components/PhoneAppTile.tsx | 2 +- wxt/entrypoints/components/PromptCard.tsx | 35 ++-- .../components/PromptCards.test.ts | 122 ++++++++++++++ .../components/ReviewPromptCard.tsx | 15 +- .../components/SponsorMilestoneCard.tsx | 17 +- wxt/entrypoints/popup/App.css | 151 +++++++++++++----- wxt/entrypoints/popup/App.tsx | 19 +-- wxt/entrypoints/utils/popupSlots.test.ts | 33 +++- wxt/entrypoints/utils/popupSlots.ts | 11 +- 10 files changed, 330 insertions(+), 88 deletions(-) create mode 100644 wxt/entrypoints/components/HeartIcon.tsx create mode 100644 wxt/entrypoints/components/PromptCards.test.ts diff --git a/wxt/entrypoints/components/HeartIcon.tsx b/wxt/entrypoints/components/HeartIcon.tsx new file mode 100644 index 0000000..c13ff86 --- /dev/null +++ b/wxt/entrypoints/components/HeartIcon.tsx @@ -0,0 +1,13 @@ +interface HeartIconProps { + className?: string; + size: number; +} + +// GitHub Sponsors' heart. Decorative: every use sits beside text that says "Sponsor". +export default function HeartIcon({ className, size }: HeartIconProps) { + return ( + + ); +} diff --git a/wxt/entrypoints/components/PhoneAppTile.tsx b/wxt/entrypoints/components/PhoneAppTile.tsx index 456ab45..65c9cc5 100644 --- a/wxt/entrypoints/components/PhoneAppTile.tsx +++ b/wxt/entrypoints/components/PhoneAppTile.tsx @@ -62,7 +62,7 @@ export default function PhoneAppTile() {

Get the Android app

Scan with your phone, or

- + Open Google Play
diff --git a/wxt/entrypoints/components/PromptCard.tsx b/wxt/entrypoints/components/PromptCard.tsx index 868efd2..ee6e763 100644 --- a/wxt/entrypoints/components/PromptCard.tsx +++ b/wxt/entrypoints/components/PromptCard.tsx @@ -1,4 +1,5 @@ import type { ReactNode } from 'react'; +import HeartIcon from './HeartIcon'; interface PromptCardProps { // Names the region for screen readers' landmark lists. @@ -6,24 +7,32 @@ interface PromptCardProps { title: ReactNode; body: ReactNode; onDismiss: () => void; - // The card's actions, primary first. - children: ReactNode; + // The ask itself, rendered before "Not now". + action: ReactNode; + // An optional quiet link after "Not now". + link?: ReactNode; + // The sponsor ask gets the header Sponsor button's pink, as a thank-you rather + // than another settings box. + isSponsor?: boolean; } -// Shared shell for the popup's one-time asks: title, one line of text, actions. -// The dismiss button sits top-right but comes last in the DOM, so screen readers -// and Tab reach the ask and its actions before "Not now". -export default function PromptCard({ label, title, body, onDismiss, children }: PromptCardProps) { +// Shared shell for the popup's one-time asks, matching Prolific Studies Notifier's: +// title, one line of text, then the ask and a "Not now" of equal weight side by side. +export default function PromptCard({ label, title, body, onDismiss, action, link, isSponsor = false }: PromptCardProps) { return ( -
+
+ {isSponsor && ( + + )}

{title}

{body}

-
{children}
- +
+ {action} + + {link} +
); } diff --git a/wxt/entrypoints/components/PromptCards.test.ts b/wxt/entrypoints/components/PromptCards.test.ts new file mode 100644 index 0000000..585347a --- /dev/null +++ b/wxt/entrypoints/components/PromptCards.test.ts @@ -0,0 +1,122 @@ +import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; +import { act, createElement, type ReactElement } from 'react'; +import { createRoot, type Root } from 'react-dom/client'; +import ReviewPromptCard from './ReviewPromptCard'; +import SponsorMilestoneCard from './SponsorMilestoneCard'; +import { ISSUES_URL } from '@/entrypoints/utils/reviewPrompt'; + +// Tells React these renders run inside act(), so state updates flush synchronously. +(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; + +let host: HTMLDivElement; +let root: Root; + +function render(element: ReactElement): void { + act(() => root.render(element)); +} + +function buttonNamed(name: string): HTMLButtonElement { + const match = [...host.querySelectorAll('button')].find((b) => b.textContent?.trim() === name); + if (!match) throw new Error(`No button named "${name}"`); + return match; +} + +function card(): HTMLElement { + return host.querySelector('[role="region"]')!; +} + +beforeEach(() => { + host = document.createElement('div'); + document.body.appendChild(host); + root = createRoot(host); +}); + +afterEach(() => { + act(() => root.unmount()); + host.remove(); +}); + +describe('ReviewPromptCard', () => { + it('asks about the extension by the name shown in the popup header', () => { + render(createElement(ReviewPromptCard, { onRate: vi.fn(), onDismiss: vi.fn() })); + + expect(card().getAttribute('aria-label')).toBe('Rate this extension'); + expect(card().querySelector('h2')?.textContent).toBe('Enjoying Search automatic rewards?'); + }); + + it('rates from the primary button', () => { + const onRate = vi.fn(); + render(createElement(ReviewPromptCard, { onRate, onDismiss: vi.fn() })); + + act(() => buttonNamed('Rate it').click()); + + expect(onRate).toHaveBeenCalledOnce(); + }); + + it('dismisses from a visible "Not now" button beside the rate button', () => { + const onDismiss = vi.fn(); + render(createElement(ReviewPromptCard, { onRate: vi.fn(), onDismiss })); + + const buttons = [...host.querySelectorAll('button')].map((b) => b.textContent?.trim()); + expect(buttons).toEqual(['Rate it', 'Not now']); + + act(() => buttonNamed('Not now').click()); + + expect(onDismiss).toHaveBeenCalledOnce(); + }); + + it('links problem reports to GitHub issues in a new tab', () => { + render(createElement(ReviewPromptCard, { onRate: vi.fn(), onDismiss: vi.fn() })); + + const link = host.querySelector('a')!; + expect(link.textContent).toBe('Not working? Report it'); + expect(link.getAttribute('href')).toBe(ISSUES_URL); + expect(link.getAttribute('target')).toBe('_blank'); + expect(link.getAttribute('rel')).toContain('noopener'); + }); +}); + +describe('SponsorMilestoneCard', () => { + it('thanks the user with their run count, highlighted', () => { + render(createElement(SponsorMilestoneCard, { completedRuns: 30, onSponsor: vi.fn(), onDismiss: vi.fn() })); + + expect(card().getAttribute('aria-label')).toBe('Support this extension'); + const title = card().querySelector('h2')!; + expect(title.textContent).toBe('30 search runs done for you'); + expect(title.querySelector('strong')?.textContent).toBe('30'); + }); + + it('says why sponsoring matters', () => { + render(createElement(SponsorMilestoneCard, { completedRuns: 30, onSponsor: vi.fn(), onDismiss: vi.fn() })); + + expect(card().querySelector('p')?.textContent).toBe('Free and built in my spare time. Sponsoring keeps it working when Bing changes.'); + }); + + it('shows a decorative heart badge hidden from screen readers', () => { + render(createElement(SponsorMilestoneCard, { completedRuns: 30, onSponsor: vi.fn(), onDismiss: vi.fn() })); + + const badge = card().querySelector('.prompt-card-badge')!; + expect(badge.getAttribute('aria-hidden')).toBe('true'); + }); + + it('sponsors from the primary button', () => { + const onSponsor = vi.fn(); + render(createElement(SponsorMilestoneCard, { completedRuns: 30, onSponsor, onDismiss: vi.fn() })); + + act(() => buttonNamed('Sponsor from $2').click()); + + expect(onSponsor).toHaveBeenCalledOnce(); + }); + + it('dismisses from a visible "Not now" button after the sponsor button', () => { + const onDismiss = vi.fn(); + render(createElement(SponsorMilestoneCard, { completedRuns: 30, onSponsor: vi.fn(), onDismiss })); + + const buttons = [...host.querySelectorAll('button')].map((b) => b.textContent?.trim()); + expect(buttons).toEqual(['Sponsor from $2', 'Not now']); + + act(() => buttonNamed('Not now').click()); + + expect(onDismiss).toHaveBeenCalledOnce(); + }); +}); diff --git a/wxt/entrypoints/components/ReviewPromptCard.tsx b/wxt/entrypoints/components/ReviewPromptCard.tsx index 2bd507e..c1548d9 100644 --- a/wxt/entrypoints/components/ReviewPromptCard.tsx +++ b/wxt/entrypoints/components/ReviewPromptCard.tsx @@ -11,14 +11,15 @@ export default function ReviewPromptCard({ onRate, onDismiss }: ReviewPromptCard return ( - - - Something not working? Report it - - + action={} + link={ + + Not working? Report it + + } + /> ); } diff --git a/wxt/entrypoints/components/SponsorMilestoneCard.tsx b/wxt/entrypoints/components/SponsorMilestoneCard.tsx index ab4a6f9..3f12c98 100644 --- a/wxt/entrypoints/components/SponsorMilestoneCard.tsx +++ b/wxt/entrypoints/components/SponsorMilestoneCard.tsx @@ -1,3 +1,4 @@ +import HeartIcon from './HeartIcon'; import PromptCard from './PromptCard'; interface SponsorMilestoneCardProps { @@ -10,11 +11,17 @@ export default function SponsorMilestoneCard({ completedRuns, onSponsor, onDismi return ( {completedRuns} search runs done for you} + body="Free and built in my spare time. Sponsoring keeps it working when Bing changes." onDismiss={onDismiss} - > - - + isSponsor + action={ + + } + /> ); } diff --git a/wxt/entrypoints/popup/App.css b/wxt/entrypoints/popup/App.css index c7c569c..66b77e5 100644 --- a/wxt/entrypoints/popup/App.css +++ b/wxt/entrypoints/popup/App.css @@ -24,6 +24,11 @@ --sponsor-border: #d0d7de; --sponsor-text: #24292f; --sponsor-heart: #bf3989; + /* The sponsor prompt card: a soft pink tint and a pink fill with white text. */ + --sponsor-soft: #fdf2f8; + --sponsor-line: #f2cde1; + --sponsor-fill: #bf3989; + --sponsor-fill-hover: #9c2e6f; --radius: 8px; } @@ -50,6 +55,9 @@ --sponsor-border: #3d444d; --sponsor-text: #e6edf3; --sponsor-heart: #db61a2; + --sponsor-soft: #36212e; + --sponsor-line: #5a3350; + --sponsor-fill-hover: #a8327a; } } @@ -150,6 +158,11 @@ a { padding: 0 12px; } +/* No footer below (see choosePopupSlots): keep the bottom edge it would have given. */ +.content:last-child { + padding-bottom: 12px; +} + .primary-action { width: 100%; padding: 9px 12px; @@ -514,28 +527,42 @@ a { align-items: flex-start; } +/* A compact .primary-action: same fill and hover, sized like the header pill. */ .phone-app-link { display: inline-block; + min-height: 24px; margin-top: 7px; - text-decoration: none; + padding: 3px 12px; + font-size: 12.5px; + font-weight: 600; + line-height: 18px; white-space: nowrap; + color: var(--color-on-primary); + text-decoration: none; + background-color: var(--color-primary); + border-radius: 6px; + transition: background-color 0.15s ease; +} + +.phone-app-link:hover { + background-color: var(--color-primary-hover); } /* ---- One-time asks: review and sponsor milestone (PromptCard) ---- + Same look as Prolific Studies Notifier's: the ask and "Not now" side by side. A due card takes the promo tiles' place, so it is sized to fit where they were without pushing the popup past 600px. */ .prompt-card { display: grid; - grid-template-columns: minmax(0, 1fr) auto; + grid-template-columns: minmax(0, 1fr); grid-template-areas: - 'title dismiss' - 'body body' - 'actions actions'; + 'title' + 'body' + 'actions'; padding: 8px 12px 9px; background-color: var(--color-surface); - /* Tinted border sets the ask apart from the settings cards without shouting. */ - border: 1px solid rgba(var(--color-primary-rgb), 0.45); + border: 1px solid var(--color-border); border-radius: var(--radius); } @@ -547,6 +574,12 @@ a { line-height: 1.3; } +/* Scoped: the phone app panel reuses the title class and keeps its plain text colour. + The higher-contrast brand blue: darker in light mode, lighter in dark. */ +.prompt-card .prompt-card-title { + color: var(--color-primary-hover); +} + .prompt-card-body { grid-area: body; margin: 1px 0 0; @@ -558,70 +591,106 @@ a { .prompt-card-actions { grid-area: actions; display: flex; - flex-wrap: wrap; align-items: center; - gap: 6px 12px; + gap: 8px; margin-top: 7px; } -/* A compact .primary-action: same fill and hover, sized like the header pill. */ -.prompt-card-primary { - min-height: 24px; - padding: 3px 12px; +.prompt-card-button { + flex: 1; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 5px; + height: 26px; + padding: 0 10px; font: inherit; - font-size: 12.5px; + font-size: 13px; font-weight: 600; - line-height: 18px; + white-space: nowrap; color: var(--color-on-primary); background-color: var(--color-primary); - border: 0; + border: 1px solid transparent; border-radius: 6px; cursor: pointer; transition: background-color 0.15s ease; } -.prompt-card-primary:hover { +.prompt-card-button:hover { background-color: var(--color-primary-hover); } +.prompt-card-button--quiet { + color: var(--color-primary-hover); + background-color: var(--color-surface); + border-color: var(--color-border); +} + +.prompt-card-button--quiet:hover { + background-color: var(--color-bg); +} + +/* Beside the buttons rather than under them: a line less in a popup with no height to spare. */ .prompt-card-link { + flex: none; font-size: 12px; + white-space: nowrap; color: var(--color-text-muted); text-underline-offset: 2px; } .prompt-card-link:hover { - color: var(--color-primary); + color: var(--color-primary-hover); } -/* 24px hit area, pulled into the padding so it doesn't make the title row taller. */ -.prompt-card-dismiss { - grid-area: dismiss; - align-self: start; - display: inline-flex; - align-items: center; - justify-content: center; - width: 24px; - height: 24px; - margin: -4px -7px -4px 6px; - padding: 0; - color: var(--color-text-muted); - background: none; - border: 0; - border-radius: 6px; - cursor: pointer; +/* The header Sponsor button's pink, as a soft tint, a heart badge beside the copy and a + pink button, so the milestone reads as a thank-you rather than another settings box. */ +.prompt-card--sponsor { + grid-template-columns: auto minmax(0, 1fr); + grid-template-areas: + 'badge title' + 'badge body' + 'actions actions'; + column-gap: 10px; + background: linear-gradient(135deg, var(--sponsor-soft) 0%, var(--color-surface) 75%); + border-color: var(--sponsor-line); } -.prompt-card-dismiss:hover { +.prompt-card--sponsor .prompt-card-title { color: var(--color-text); - background-color: var(--color-track); } -.prompt-card-dismiss svg { - fill: none; - stroke: currentColor; - stroke-width: 1.75; - stroke-linecap: round; +.prompt-card-badge { + grid-area: badge; + align-self: center; + display: grid; + place-items: center; + width: 34px; + height: 34px; + border-radius: 50%; + background: linear-gradient(135deg, #e0619f, var(--sponsor-fill)); + box-shadow: 0 2px 6px rgba(191, 57, 137, 0.3); + animation: heart-beat 0.9s ease-in-out 0.4s 2; +} + +.prompt-card-badge svg, +.prompt-card-button--sponsor svg { + fill: #fff; +} + +.prompt-card-count { + color: var(--sponsor-heart); + font-weight: 700; +} + +.prompt-card-button--sponsor { + flex: 1.5; + color: #fff; + background-color: var(--sponsor-fill); +} + +.prompt-card-button--sponsor:hover { + background-color: var(--sponsor-fill-hover); } .footer { diff --git a/wxt/entrypoints/popup/App.tsx b/wxt/entrypoints/popup/App.tsx index 5a123c4..96c46aa 100644 --- a/wxt/entrypoints/popup/App.tsx +++ b/wxt/entrypoints/popup/App.tsx @@ -14,6 +14,7 @@ import ToggleRow from '@/entrypoints/components/ToggleRow'; import ReviewPromptCard from '@/entrypoints/components/ReviewPromptCard'; import SponsorMilestoneCard from '@/entrypoints/components/SponsorMilestoneCard'; import PhoneAppTile from '@/entrypoints/components/PhoneAppTile'; +import HeartIcon from '@/entrypoints/components/HeartIcon'; import { usePromptCard } from '@/entrypoints/hooks/usePromptCard'; import { getCrossPromoLink } from '@/entrypoints/utils/crossPromo'; import { choosePopupSlots } from '@/entrypoints/utils/popupSlots'; @@ -82,9 +83,7 @@ function App() { rel="noopener noreferrer" title="Enjoying the extension? Sponsor from $5/month and get your name featured in the README." > - + Sponsor @@ -143,12 +142,14 @@ function App() { )} - + {slots.showFooter && ( + + )} ); } diff --git a/wxt/entrypoints/utils/popupSlots.test.ts b/wxt/entrypoints/utils/popupSlots.test.ts index 475655d..25f7b61 100644 --- a/wxt/entrypoints/utils/popupSlots.test.ts +++ b/wxt/entrypoints/utils/popupSlots.test.ts @@ -14,39 +14,56 @@ const LOADED: PopupSlotInputs = { describe('choosePopupSlots', () => { it('shows nothing in either slot until the run state has loaded', () => { expect(choosePopupSlots({ ...LOADED, isRunStateLoaded: false, dueCard: 'review' })) - .toEqual({ showRunPanel: false, lower: 'loading' }); + .toEqual({ showRunPanel: false, lower: 'loading', showFooter: false }); }); it('shows nothing in either slot until the prompt state has loaded', () => { expect(choosePopupSlots({ ...LOADED, isPromptLoaded: false, completedSearches: 5 })) - .toEqual({ showRunPanel: false, lower: 'loading' }); + .toEqual({ showRunPanel: false, lower: 'loading', showFooter: false }); }); it('shows the promo tiles and no panel when nothing has run and no card is due', () => { - expect(choosePopupSlots(LOADED)).toEqual({ showRunPanel: false, lower: 'tiles' }); + expect(choosePopupSlots(LOADED)).toEqual({ showRunPanel: false, lower: 'tiles', showFooter: true }); }); it('shows a finished run\'s panel with the promo tiles when no card is due', () => { expect(choosePopupSlots({ ...LOADED, completedSearches: 5 })) - .toEqual({ showRunPanel: true, lower: 'tiles' }); + .toEqual({ showRunPanel: true, lower: 'tiles', showFooter: true }); }); // Together they overflow Chrome's 600px popup. it('shows a due card instead of a finished run\'s panel', () => { expect(choosePopupSlots({ ...LOADED, completedSearches: 5, dueCard: 'review' })) - .toEqual({ showRunPanel: false, lower: 'review' }); + .toEqual({ showRunPanel: false, lower: 'review', showFooter: true }); expect(choosePopupSlots({ ...LOADED, completedSearches: 5, dueCard: 'sponsor' })) - .toEqual({ showRunPanel: false, lower: 'sponsor' }); + .toEqual({ showRunPanel: false, lower: 'sponsor', showFooter: false }); }); it('keeps a running run\'s panel and holds a due card back for a later popup', () => { expect(choosePopupSlots({ ...LOADED, isSearching: true, dueCard: 'review' })) - .toEqual({ showRunPanel: true, lower: 'tiles' }); + .toEqual({ showRunPanel: true, lower: 'tiles', showFooter: true }); }); // Otherwise its result would vanish under the card the moment it finished. it('keeps the panel of a run that finished while the popup was open, and the card waits', () => { expect(choosePopupSlots({ ...LOADED, wasSearchingThisPopup: true, completedSearches: 5, dueCard: 'review' })) - .toEqual({ showRunPanel: true, lower: 'tiles' }); + .toEqual({ showRunPanel: true, lower: 'tiles', showFooter: true }); + }); + + // The sponsor card is two lines taller than the review card; with the short-gap + // warning as well it would push the popup to 616px. It is the donate ask itself, + // so the footer's Donate link adds nothing while it shows. + it('hides the footer while the sponsor card shows, and keeps it for the review card', () => { + expect(choosePopupSlots({ ...LOADED, dueCard: 'sponsor' }).showFooter).toBe(false); + expect(choosePopupSlots({ ...LOADED, dueCard: 'review' }).showFooter).toBe(true); + }); + + // Otherwise it would show while storage loads, then vanish if the sponsor card is due. + it('holds the footer back until the prompt state has loaded', () => { + expect(choosePopupSlots({ ...LOADED, isPromptLoaded: false }).showFooter).toBe(false); + }); + + it('keeps the footer when a run holds the sponsor card back', () => { + expect(choosePopupSlots({ ...LOADED, isSearching: true, dueCard: 'sponsor' }).showFooter).toBe(true); }); }); diff --git a/wxt/entrypoints/utils/popupSlots.ts b/wxt/entrypoints/utils/popupSlots.ts index dfe69c3..8dece73 100644 --- a/wxt/entrypoints/utils/popupSlots.ts +++ b/wxt/entrypoints/utils/popupSlots.ts @@ -16,6 +16,9 @@ export interface PopupSlots { // What goes below the settings: a prompt card, the promo tiles, or nothing // yet ('loading'). lower: PromptCard | 'tiles' | 'loading'; + // The Help/Contact/GitHub/Donate links. The sponsor card is the donate ask + // itself and, with the short-gap warning, would overflow 600px beside them. + showFooter: boolean; } // Decides the popup's two optional areas. The run panel and a prompt card @@ -32,9 +35,9 @@ export function choosePopupSlots({ isPromptLoaded, dueCard, }: PopupSlotInputs): PopupSlots { - if (!isRunStateLoaded || !isPromptLoaded) return { showRunPanel: false, lower: 'loading' }; - if (isSearching || wasSearchingThisPopup) return { showRunPanel: true, lower: 'tiles' }; - if (dueCard) return { showRunPanel: false, lower: dueCard }; + if (!isRunStateLoaded || !isPromptLoaded) return { showRunPanel: false, lower: 'loading', showFooter: false }; + if (isSearching || wasSearchingThisPopup) return { showRunPanel: true, lower: 'tiles', showFooter: true }; + if (dueCard) return { showRunPanel: false, lower: dueCard, showFooter: dueCard !== 'sponsor' }; // A zero count means nothing has run, and showing 0/5 would read as stalled. - return { showRunPanel: completedSearches > 0, lower: 'tiles' }; + return { showRunPanel: completedSearches > 0, lower: 'tiles', showFooter: true }; } From 814858c05ab5053513dc31a00488eb1602fbbd9a Mon Sep 17 00:00:00 2001 From: Svit-personal Date: Wed, 11 Nov 2026 08:56:08 +0100 Subject: [PATCH 2/4] fix: run the daily tasks once when startup and the daily-check alarm coincide On a morning start Chrome can deliver onStartup together with the 6-hourly daily-check alarm that came due while the browser was closed. Both read yesterday's date before either recorded today, so the dashboard and searches opened twice; and if the alarm won outright, the startup cleanup stopped its run after the first search. The two checks now take turns, and the cleanup leaves a run started in this session alone. --- .../background/dailySchedule.test.ts | 41 +++++++++++++ wxt/entrypoints/background/dailySchedule.ts | 61 +++++++++++++++---- 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/wxt/entrypoints/background/dailySchedule.test.ts b/wxt/entrypoints/background/dailySchedule.test.ts index 4fa25ea..749fa82 100644 --- a/wxt/entrypoints/background/dailySchedule.test.ts +++ b/wxt/entrypoints/background/dailySchedule.test.ts @@ -310,6 +310,47 @@ describe('handleDailyCheckAlarm', () => { expect(await getStorageItem('lastOpened', StorageValues.SYNC)).toBe(new Date().toLocaleDateString()); }); + // On a morning start Chrome can deliver onStartup and the daily-check alarm + // that came due overnight together. Both used to read yesterday's date before + // either recorded today, so the dashboard and the searches opened twice. + it('starts today\'s run once when startup and the alarm arrive together', async () => { + const urls = trackCreatedTabs(); + await seed({ lastOpened: new Date(0).toLocaleDateString() }); + + await Promise.all([handleStartup(), handleDailyCheckAlarm({ name: 'dailyCheck' })]); + await flushPendingWork(); + + expect(urls.filter((url) => url === DASHBOARD_URL)).toHaveLength(1); + expect(urls.filter((url) => url.startsWith('https://www.bing.com/search?q='))).toHaveLength(1); + }); + + // The alarm can win the race outright: its run is already going when the + // startup handler's "leftover run" cleanup comes along, which used to stop it + // after the first search. + it('keeps a run the alarm started just before the startup handler ran', async () => { + trackCreatedTabs(); + await seed({ lastOpened: new Date(0).toLocaleDateString() }); + + await handleDailyCheckAlarm({ name: 'dailyCheck' }); + await handleStartup(); + await flushPendingWork(); + + expect(await getStorageItem('isSearching', StorageValues.SYNC)).toBe(true); + expect(await fakeBrowser.alarms.get('openTabAlarm')).toBeDefined(); + }); + + it('still stops a run left over from before the browser restarted', async () => { + trackCreatedTabs(); + await seed({ active: false, autoDaily: false, isSearching: true, currentSearch: 3 }); + await setStorageItems({ runStartedAt: 0 }, StorageValues.LOCAL); + await fakeBrowser.alarms.create('openTabAlarm', { delayInMinutes: 1 }); + + await handleStartup(); + + expect(await getStorageItem('isSearching', StorageValues.SYNC)).toBe(false); + expect(await fakeBrowser.alarms.get('openTabAlarm')).toBeUndefined(); + }); + it('does nothing when today has already run', async () => { const urls = trackCreatedTabs(); await seed({ lastOpened: new Date().toLocaleDateString() }); diff --git a/wxt/entrypoints/background/dailySchedule.ts b/wxt/entrypoints/background/dailySchedule.ts index 5778597..346eb79 100644 --- a/wxt/entrypoints/background/dailySchedule.ts +++ b/wxt/entrypoints/background/dailySchedule.ts @@ -1,6 +1,6 @@ import { storage } from '#imports'; import { browser } from 'wxt/browser'; -import { getStorageItems, setStorageItem, setStorageItems } from '@/entrypoints/hooks/useStorage'; +import { getStorageItem, getStorageItems, setStorageItem, setStorageItems } from '@/entrypoints/hooks/useStorage'; import { StorageValues } from '@/entrypoints/enums/storageValues'; import { toInt } from '@/entrypoints/utils/search'; import { DEFAULTS } from '@/entrypoints/utils/settings'; @@ -18,6 +18,24 @@ const DAILY_CHECK_ALARM = 'dailyCheck'; // gate periodically so the day rollover is caught without needing a restart. const DAILY_CHECK_PERIOD_MINUTES = 360; +// When runRewards last started something (local area). Compared with when this +// worker started, it tells a run begun in this session from one left over from +// before a browser restart. +const RUN_STARTED_AT_KEY = 'runStartedAt'; +const WORKER_STARTED_AT = Date.now(); + +// The startup handler and the daily-check alarm both run the once-a-day check, +// and on a morning start Chrome can deliver both together: the alarm came due +// while the browser was closed. Each waits for the one before it to finish, so +// the second sees today's date and the run happens once. +let dailyQueue: Promise = Promise.resolve(); + +function oneAtATime(task: () => Promise): Promise { + const result = dailyQueue.then(task, task); + dailyQueue = result.catch(() => {}); + return result; +} + // Runs whatever the user has enabled: the dashboard visit if "Daily set" or // "Claim points" is on, and the Bing searches if "Daily searches" is on. Both // the automatic daily trigger and the popup's "Get rewards" button call this, so @@ -41,6 +59,8 @@ export async function runRewards(): Promise { // meant not a single search ran that day. One tab covers both dashboard // jobs — two would fight over the foreground, and the SPA only renders while // it is visible. + const isStartingAnything = isDailySetEnabled || isClaimEnabled || (isSearchesEnabled && searches > 0); + if (isStartingAnything) await setStorageItem(RUN_STARTED_AT_KEY, Date.now()); if (isDailySetEnabled || isClaimEnabled) { void openDailyRewards({ doDailySet: isDailySetEnabled, @@ -52,7 +72,11 @@ export async function runRewards(): Promise { } } -export async function checkLastOpened(): Promise { +export function checkLastOpened(): Promise { + return oneAtATime(runIfNewDay); +} + +async function runIfNewDay(): Promise { const today = new Date().toLocaleDateString(); const s = await getStorageItems(['lastOpened'], StorageValues.SYNC); if (s.lastOpened !== today) { @@ -120,16 +144,27 @@ export async function handleInstallOrUpdate(details: { reason: string }): Promis } export async function handleStartup(): Promise { - // A search run never survives a browser restart, so clear its state *before* - // today's run is considered: alarms outlive the session and would resume - // opening Bing tabs on their own, and resetting the flag afterwards used to - // clobber the `isSearching` that a fresh run had just set. - await stopSearches(); - await setStorageItems({ currentSearch: 0 }, StorageValues.SYNC); - // Tab ids do not survive a browser restart, so anything still registered for - // cleanup points at tabs that no longer exist. - await clearTrackedTabs(); - const s = await getStorageItems(['active', 'autoDaily', 'claimPoints'], StorageValues.SYNC); - if (s.active || s.autoDaily || s.claimPoints) await checkLastOpened(); + await oneAtATime(async () => { + // A search run never survives a browser restart, so clear its state *before* + // today's run is considered: alarms outlive the session and would resume + // opening Bing tabs on their own, and resetting the flag afterwards used to + // clobber the `isSearching` that a fresh run had just set. The daily-check + // alarm can start today's run just before this gets its turn, though, and + // that run belongs to this session, so it is left alone. + if (!(await hasRunStartedInThisWorker())) { + await stopSearches(); + await setStorageItems({ currentSearch: 0 }, StorageValues.SYNC); + // Tab ids do not survive a browser restart, so anything still registered + // for cleanup points at tabs that no longer exist. + await clearTrackedTabs(); + } + const s = await getStorageItems(['active', 'autoDaily', 'claimPoints'], StorageValues.SYNC); + if (s.active || s.autoDaily || s.claimPoints) await runIfNewDay(); + }); await scheduleDailyCheckAlarm(); } + +async function hasRunStartedInThisWorker(): Promise { + const startedAt = await getStorageItem(RUN_STARTED_AT_KEY); + return Number.isFinite(startedAt) && (startedAt as number) >= WORKER_STARTED_AT; +} From 2114d3491c1290f20a484a27baa1f9274fb82ab0 Mon Sep 17 00:00:00 2001 From: Svit-personal Date: Wed, 11 Nov 2026 08:56:43 +0100 Subject: [PATCH 3/4] fix: clarify the popup's search settings and bring back the Rewards link - Rename "Search automatically" back to "Daily searches" (the 3.1.0 and website name) and say it also gates Get rewards' searches. - Its info text now covers the 6-hourly day check, not only browser start. - Restore a Rewards dashboard link in the footer; 3.1.0 had one. - The short-gap warning no longer claims Microsoft stops crediting: testing credited 10-20s gaps. It warns that very short gaps may look automated. - The Sponsor tooltip's minimum matches the $2 tier the sponsor card quotes. --- wxt/entrypoints/popup/App.tsx | 15 ++++++++------- wxt/entrypoints/utils/search.ts | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/wxt/entrypoints/popup/App.tsx b/wxt/entrypoints/popup/App.tsx index 96c46aa..a6cae29 100644 --- a/wxt/entrypoints/popup/App.tsx +++ b/wxt/entrypoints/popup/App.tsx @@ -60,8 +60,9 @@ function App() { dueCard: prompt.card, }); - // Gaps this short are honoured, but they are below what Microsoft reliably - // credits — so the field warns rather than silently overriding the choice. + // Gaps this short are honoured. Testing found them credited, but a steady + // burst of searches reads as automated, so the field warns rather than + // silently overriding the choice. const isTimeoutRisky = Number.isFinite(timeout) && timeout < RECOMMENDED_MIN_TIMEOUT_SECONDS; // Picking a level sets a sensible search count; the number field stays @@ -81,7 +82,7 @@ function App() { className="sponsor-button" target="_blank" rel="noopener noreferrer" - title="Enjoying the extension? Sponsor from $5/month and get your name featured in the README." + title="Enjoying the extension? Sponsor from $2 a month, or from $5 a month to get your name in the README." > Sponsor @@ -96,8 +97,8 @@ function App() {

Daily tasks

- + {isTimeoutRisky && (

- Under {RECOMMENDED_MIN_TIMEOUT_SECONDS}s Microsoft often stops crediting searches. - {' '}{DEFAULTS.timeout}s or more is recommended. + Very short gaps may look automated. {DEFAULTS.timeout}s is the default.

)} @@ -144,6 +144,7 @@ function App() { {slots.showFooter && (