Skip to content

feat: add three-way theme toggle to popup#129

Merged
zhongnansu merged 8 commits intomainfrom
feat/theme-toggle
Apr 1, 2026
Merged

feat: add three-way theme toggle to popup#129
zhongnansu merged 8 commits intomainfrom
feat/theme-toggle

Conversation

@zhongnansu
Copy link
Copy Markdown
Member

Summary

  • Adds a three-way theme toggle (Auto / Light / Dark) to the extension popup
  • Stores preference in chrome.storage.local — defaults to Auto (OS preference)
  • detectTheme() is now async: checks storage first, falls back to OS preference
  • Open bubbles live-update when theme preference changes via chrome.storage.onChanged
  • All callers updated to await the async functions

Files Changed

  • popup.html — segmented control UI with dark mode support
  • src/popup.js — read/write theme preference
  • src/content/bubble/core.js — async detectTheme(), live theme listener + cleanup
  • src/content/trigger/button.js — async createToolbar/showTrigger/launchAction
  • src/content/index.jsawait on showBubble/showBubbleWithPresets calls
  • src/content/trigger/screenshot.jsawait on showBubbleWithPresets
  • tests/ — 6 new tests, all existing tests updated for async (577 total, 0 failures)

Test plan

  • Build succeeds (npm run build)
  • All 577 tests pass (npx vitest run)
  • Toggle in popup persists across sessions
  • Auto mode follows OS preference
  • Light/Dark override OS preference
  • Open bubble live-updates when toggle changes
  • Accessible: aria-pressed on toggle buttons

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 30, 2026

📦 PR Preview — Ask AI Extension

Version: 1.1.0
Zip size: 20.6 KB

⬇️ Download artifact


Permissions

No permission changes detected. ✅


Preview Checklist

Before merging, manually test with the artifact above:

  • Load unpacked extension in chrome://extensions (developer mode)
  • Select text on any webpage and verify the trigger button appears
  • Click the trigger button and confirm the popup renders correctly
  • Right-click selected text and verify context menu items are present
  • Open a CSP-restricted page (e.g. chrome://extensions) and verify fallback works
  • Check the DevTools console for errors

Updated by PR Preview Bot — workflow run

@github-actions github-actions Bot added docs Documentation changes tests Changes to test files labels Mar 30, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 30, 2026

📊 Code Coverage Report

File Coverage Status
proxy/src/index.js 97.9% 🟢
proxy/src/openai.js 100.0% 🟢
proxy/src/rate-limit.js 100.0% 🟢
proxy/src/validate.js 95.3% 🟢
src/options.js 100.0% 🟢
src/popup.js 97.3% 🟢
src/background/index.js 81.7% 🟢
src/content/api.js 88.2% 🟢
src/content/detection.js 99.3% 🟢
src/content/history.js 86.1% 🟢
src/content/image-capture.js 93.4% 🟢
src/content/presets.js 100.0% 🟢
src/content/prompt.js 100.0% 🟢
src/content/autosuggest/context.js 100.0% 🟢
src/content/autosuggest/debounce.js 100.0% 🟢
src/content/autosuggest/ghost-text.js 100.0% 🟢
src/content/autosuggest/index.js 75.6% 🔴
src/content/autosuggest/styles.js 100.0% 🟢
src/content/bubble/core.js 76.6% 🔴
src/content/bubble/history.js 85.3% 🟢
src/content/bubble/markdown.js 96.0% 🟢
src/content/bubble/stream.js 97.0% 🟢
src/content/bubble/styles.js 100.0% 🟢
src/content/shared/constants.js 100.0% 🟢
src/content/shared/dom-utils.js 100.0% 🟢
src/content/shared/preset-usage.js 91.8% 🟢
src/content/shared/state.js 100.0% 🟢
src/content/trigger/button.js 91.5% 🟢
src/content/trigger/progress-ring.js 100.0% 🟢
src/content/trigger/screenshot.js 98.6% 🟢
src/content/trigger/selection.js 72.8% 🔴
src/content/trigger/styles.js 100.0% 🟢
Overall 93.1% 🟢 PASS

Threshold: 80%

✅ Coverage meets the minimum threshold.


Updated by Code Coverage workflow

zhongnansu and others added 7 commits March 31, 2026 22:06
Add segmented control between autosuggest toggle and settings link.
Reads theme from chrome.storage.local on load (default: Auto),
persists selection on click, and updates active button styling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
detectTheme() now checks chrome.storage.local for an explicit
'light'/'dark' preference before falling back to OS matchMedia.
initBubble/showBubble/showBubbleWithPresets and createToolbar/
showTrigger/createTriggerButton updated to await detectTheme.
Adds chrome.storage.onChanged listener in createBubbleHost for
live theme updates, cleaned up in hideBubble.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- helpers.js: add chrome.storage.onChanged mock
- bubble.test.js: await showBubble/detectTheme, make callbacks async
- popup.test.js: add theme segment DOM, add 6 theme toggle tests
- toolbar.test.js: mock detectTheme as Promise, await showTrigger
- trigger.test.js: mock detectTheme as Promise, await async calls,
  flush microtasks after fake timer advance

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…r, add aria-pressed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Log errors instead of silently swallowing in showBubble .catch()
- Add live theme update listener to toolbar via storage.onChanged
- Clean up toolbar storage listener in hideTrigger()
- Fix showBubble mock to return Promise for .catch() chain

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add .catch() to fire-and-forget showTrigger calls in selection.js
- Fix dark mode border color for .theme-row in popup
- Sync package-lock.json version to 1.1.0

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the infra Changes to infrastructure files label Apr 1, 2026
Add a creation lock to showTrigger() to prevent concurrent
createToolbar() calls when multiple selection events fire before
the first async toolbar creation resolves.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zhongnansu zhongnansu merged commit 9163b1a into main Apr 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation changes infra Changes to infrastructure files tests Changes to test files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant