Refactor duplicated capture logic, fix format bug, race condition, and dead code#16
Draft
Refactor duplicated capture logic, fix format bug, race condition, and dead code#16
Conversation
Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
- Extract getCaptureDependencies, createAndStoreAsset, handlePostCapture helpers from duplicated code in handleSelectionComplete and handleScreenshotCapture - Delete dead code src/services/ScreenshotService.ts (never imported anywhere) - Fix offscreen.ts to use user format preference in canvas.toDataURL() - Fix race condition in NumbersApiManager.getNumbersApi() with promise-based singleton - Fix type mismatch: use Date.now() instead of new Date().toISOString() for createdAt Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicated capture logic and remove dead code
Refactor duplicated capture logic, fix format bug, race condition, and dead code
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five code quality and correctness issues: ~350 lines of duplicated capture logic, a dead service file, watermark always outputting PNG regardless of user format setting, a singleton race condition, and
createdAttype mismatches.Changes
Extract shared capture helpers (
service-worker.ts)Pulled duplicated logic from
handleSelectionCompleteandhandleScreenshotCaptureinto three shared helpers:getCaptureDependencies(tab, settings)— geolocation + source website metadatacreateAndStoreAsset(...)— asset construction and IndexedDB writehandlePostCapture(asset, settings, fromPopup)— notification, badge, auto-upload queueDelete
ScreenshotService.ts278-line file from an earlier architecture, never imported anywhere. Removed entirely.
Fix watermark format (
offscreen.ts)canvas.toDataURL()was hardcoded to'image/png'. Addedformat?: 'png' | 'jpeg'toWatermarkPayloadand bothADD_WATERMARKcall sites now passsettings.screenshotFormat, so JPEG captures are no longer silently re-encoded as PNG.Fix
getNumbersApi()race condition (NumbersApiManager.ts)Concurrent calls before initialization completed could trigger duplicate
initialize()calls. Replaced theinstancevariable with a cached promise:Fix
createdAttype mismatch (popup.tsx)Two
createdAtassignments usednew Date().toISOString()(string) behindas anycasts. Replaced withDate.now()to matchAsset.createdAt: number.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.