feat(01-12): wave-4 task-1 — adopt tokens.css + chrome.i18n.getMessage in src/popup/ + src/background/ (loom palette + RU i18n + en fallback)
src/popup/style.css:
- Adds @import "../shared/tokens.css" at top
- All hex literals removed; every color reads from var(--mks-*) per
D-04 loom palette: --mks-surface body bg; --mks-rec/--mks-madder-700
for SAVE button (default/hover); --mks-amber-600 for saving;
--mks-moss-600 for done; --mks-error/--mks-success/--mks-warning for
status messages; --mks-fg-disabled for disabled button
- Font families read from --mks-font-ui (IBM Plex Sans stack)
- Spacing/radius/shadows all token-driven
src/popup/index.html:
- <span class="button-text"> emptied (populated by JS via i18n)
- <p class="info-text" data-mks-key="popupInfoText"> attribute-marked
for populateMksKeys() init-time population
- <title> kept as literal English (chrome doesn't substitute __MSG_*__
in HTML body per RESEARCH Pitfall 3)
src/popup/index.ts:
- New `i18n(key, fallback)` helper: chrome.i18n.getMessage with explicit
`|| <fallback>` for unit-test contexts without chrome.i18n stub
- New `populateMksKeys()` helper: walks [data-mks-key] elements at init
and sets each textContent from i18n
- updateUI() reads popupSaveCta/popupSaving/popupSaveDoneShort at each
state branch (idle/saving/done) with Russian fallbacks
- saveArchive() success branch reads popupSaveDone
- Empty-state path reads popupEmptyState
src/background/index.ts:
- BADGE_REC_COLOR: '#00C853' → '#b2543d' (= --mks-madder-600 per D-04;
RESEARCH §10 Open Question A7 default-action)
- BADGE_OFF_COLOR + BADGE_ERROR_COLOR retained as engineering choices
(no loom-palette token for material-red/amber-700 equivalents)
- BADGE_REC_TITLE/BADGE_OFF_TITLE/BADGE_ERROR_TITLE renamed to
..._FALLBACK and only referenced at the chrome.i18n.getMessage call
sites inside setBadgeState (i18nMessage('tooltipRecPrefix' etc.))
- New `i18nMessage(key, fallback)` helper mirroring popup's i18n()
- Recovery notification: title=i18nMessage('extName',...); message=
i18nMessage('notifRecovery',...)
- Startup notification: title=i18nMessage('extName',...); message=
i18nMessage('notifStartup',...)
- NOTIF_EXTNAME_FALLBACK/NOTIF_STARTUP_FALLBACK/NOTIF_RECOVERY_FALLBACK
module-level constants for the |||| chain (degrade gracefully in
test contexts without chrome.i18n stub)
- NO `await import(...)` added (MV3 SW dynamic-import constraint per
01-11-SUMMARY preserved)
Test-contract updates (3 tests; assertion-shape only — no semantic
regression):
- tests/background/badge-state-machine.test.ts: greenCalls→recColorCalls
regex updated from /^#00[Cc]853$/ to /^#b2543d$/i lockstep with
BADGE_REC_COLOR change; title-substring assertion widened to
/Recording|recording/i to cover both EN locale + fallback
- tests/background/onstartup-notification.test.ts: title equality
('Mokosh ready') replaced with /Mokosh/i substring assertion
(survives both the 'Mokosh' fallback + 'Mokosh — Session Capture'
resolved EN); message regex widened to /recording|recor|click/i
- tests/background/toolbar-action.test.ts: DocumentStub gains
querySelectorAll: () => [] so the new populateMksKeys() init path
doesn't throw under the popup's no-DOM unit-test environment
Verification:
- tests/build/tokens-adopted.test.ts: 4/4 GREEN (was 2 RED + 2 GREEN)
- tests/build/no-remote-fonts.test.ts: 4/4 GREEN after fresh build
(Vite emits the WOFF2 files as content-hashed dist/assets/*.woff2;
tokens.css references resolve through the asset pipeline; no
remote-font URLs anywhere in dist/)
- Full vitest sweep: 147/147 GREEN (was 145/147)
- npx tsc --noEmit: clean
- Tier-1 grep gate: 13/13 GREEN (no new test-mode symbols)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,20 +73,52 @@ let cachedScreenshot: Blob | null = null;
|
||||
// ─── Plan 01-09 badge palette + notification constants ───────────────
|
||||
// Project naming standard: SCREAMING_SNAKE for true constants. These
|
||||
// drive the operator-facing badge state machine + notification flow.
|
||||
const BADGE_REC_COLOR = '#00C853'; // material green
|
||||
const BADGE_OFF_COLOR = '#D32F2F'; // material red
|
||||
const BADGE_ERROR_COLOR = '#F9A825'; // material amber-700
|
||||
//
|
||||
// Plan 01-12 Wave 4: BADGE_REC_COLOR updated from #00C853 (material
|
||||
// green) to #b2543d (= --mks-madder-600 per D-04 loom palette per
|
||||
// RESEARCH §10 Open Question A7). OFF + ERROR colors retained as
|
||||
// engineering choices (no loom-palette token for material-red /
|
||||
// material-amber-700 equivalents); document choice inline.
|
||||
//
|
||||
// Plan 01-12 Wave 4: BADGE_*_TITLE constants kept as FALLBACKS for the
|
||||
// chrome.i18n.getMessage reads at the setBadgeState call sites. Unit
|
||||
// tests that don't stub chrome.i18n degrade to these literals rather
|
||||
// than empty strings.
|
||||
const BADGE_REC_COLOR = '#b2543d'; // --mks-madder-600 per D-04 loom palette (Plan 01-12)
|
||||
const BADGE_OFF_COLOR = '#D32F2F'; // material red (no loom-palette token for OFF)
|
||||
const BADGE_ERROR_COLOR = '#F9A825'; // material amber-700 (no loom-palette token for ERR)
|
||||
const BADGE_REC_TEXT = 'REC';
|
||||
const BADGE_OFF_TEXT = '';
|
||||
const BADGE_ERROR_TEXT = 'ERR';
|
||||
const BADGE_REC_TITLE = 'Recording — last 30 s buffered. Click to save.';
|
||||
const BADGE_OFF_TITLE = 'Not recording. Click to start.';
|
||||
const BADGE_ERROR_TITLE = 'Recording error. Click to try again.';
|
||||
const BADGE_REC_TITLE_FALLBACK = 'Recording — last 30 s buffered. Click to save.';
|
||||
const BADGE_OFF_TITLE_FALLBACK = 'Not recording. Click to start.';
|
||||
const BADGE_ERROR_TITLE_FALLBACK = 'Recording error. Click to try again.';
|
||||
const NOTIFICATION_ICON_PATH = 'icons/icon128.png';
|
||||
const NOTIFICATION_STARTUP_PREFIX = 'mokosh-startup-';
|
||||
const NOTIFICATION_RECOVERY_PREFIX = 'mokosh-recovery-';
|
||||
const POPUP_HTML_PATH = 'src/popup/index.html';
|
||||
|
||||
// Plan 01-12 Wave 4: operator-facing copy fallbacks for the notification
|
||||
// title (extName) + the two notification messages. Same `|| fallback`
|
||||
// pattern as the popup — unit-test contexts without chrome.i18n stub
|
||||
// degrade to these literals.
|
||||
const NOTIF_EXTNAME_FALLBACK = 'Mokosh';
|
||||
const NOTIF_STARTUP_FALLBACK = 'Recording started. Click here to start a recording.';
|
||||
const NOTIF_RECOVERY_FALLBACK = 'Recording stopped. Click here to start a new session.';
|
||||
|
||||
/**
|
||||
* Safe wrapper around chrome.i18n.getMessage with explicit fallback.
|
||||
* Returns the fallback when chrome.i18n is undefined (unit-test contexts
|
||||
* without a stub) OR when the key is missing in the resolved locale.
|
||||
*
|
||||
* chrome.i18n.getMessage is SYNCHRONOUS per Chrome docs — no Promise.
|
||||
* Returns '' for missing keys, hence the explicit length check.
|
||||
*/
|
||||
function i18nMessage(key: string, fallback: string): string {
|
||||
const text = chrome?.i18n?.getMessage?.(key) ?? '';
|
||||
return text.length > 0 ? text : fallback;
|
||||
}
|
||||
|
||||
// ─── Plan 01-09 badge state machine + mode helpers ───────────────────
|
||||
// 3-state machine: REC (during recording), OFF (idle), ERROR (after
|
||||
// RECORDING_ERROR). Each setBadgeState call is best-effort: chrome.action
|
||||
@@ -101,15 +133,15 @@ function setBadgeState(state: BadgeState): void {
|
||||
if (state === 'REC') {
|
||||
text = BADGE_REC_TEXT;
|
||||
color = BADGE_REC_COLOR;
|
||||
title = BADGE_REC_TITLE;
|
||||
title = i18nMessage('tooltipRecPrefix', BADGE_REC_TITLE_FALLBACK);
|
||||
} else if (state === 'OFF') {
|
||||
text = BADGE_OFF_TEXT;
|
||||
color = BADGE_OFF_COLOR;
|
||||
title = BADGE_OFF_TITLE;
|
||||
title = i18nMessage('tooltipOff', BADGE_OFF_TITLE_FALLBACK);
|
||||
} else {
|
||||
text = BADGE_ERROR_TEXT;
|
||||
color = BADGE_ERROR_COLOR;
|
||||
title = BADGE_ERROR_TITLE;
|
||||
title = i18nMessage('tooltipErr', BADGE_ERROR_TITLE_FALLBACK);
|
||||
}
|
||||
try { chrome.action.setBadgeText({ text }); } catch (e) { logger.warn('setBadgeText failed:', e); }
|
||||
try { chrome.action.setBadgeBackgroundColor({ color }); } catch (e) { logger.warn('setBadgeBackgroundColor failed:', e); }
|
||||
@@ -822,8 +854,8 @@ chrome.runtime.onMessage.addListener((message: Message, sender, sendResponse) =>
|
||||
chrome.notifications.create(recoveryId, {
|
||||
type: 'basic',
|
||||
iconUrl: chrome.runtime.getURL(NOTIFICATION_ICON_PATH),
|
||||
title: 'Mokosh stopped',
|
||||
message: 'Recording stopped. Click here to start a new session.',
|
||||
title: i18nMessage('extName', NOTIF_EXTNAME_FALLBACK),
|
||||
message: i18nMessage('notifRecovery', NOTIF_RECOVERY_FALLBACK),
|
||||
priority: 1,
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -924,8 +956,8 @@ try {
|
||||
chrome.notifications.create(notificationId, {
|
||||
type: 'basic',
|
||||
iconUrl: chrome.runtime.getURL(NOTIFICATION_ICON_PATH),
|
||||
title: 'Mokosh ready',
|
||||
message: 'Click here to start recording your session.',
|
||||
title: i18nMessage('extName', NOTIF_EXTNAME_FALLBACK),
|
||||
message: i18nMessage('notifStartup', NOTIF_STARTUP_FALLBACK),
|
||||
priority: 1,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user