From 0464c15367da31bc477178e296e9874875a62c16 Mon Sep 17 00:00:00 2001 From: Prateek Sharma Date: Sat, 21 Nov 2026 11:10:11 +0530 Subject: [PATCH] fix(extension): announce a ready summary instead of showing it in the notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS shows only about four lines of a notification, so the shortened summary ended in macOS's own "…" and the hint to open the extension was lost. The "Summary Ready!" notification now just says the summary is ready and to open the extension, in Chrome and Firefox. Removes truncateForNotification and summaryNotification, now unused. Bumps the extension to 0.3.5. Co-Authored-By: Claude Opus 5.5 --- extension/background.js | 7 ++++-- extension/js/utils.js | 29 ---------------------- extension/manifest.json | 2 +- extension/package.json | 2 +- extension/tests/background.test.mjs | 6 ++--- extension/tests/utils.test.mjs | 38 +---------------------------- 6 files changed, 11 insertions(+), 73 deletions(-) diff --git a/extension/background.js b/extension/background.js index b95c815..951bfc6 100644 --- a/extension/background.js +++ b/extension/background.js @@ -7,10 +7,13 @@ import { TtsEngine } from './js/tts-engine.js'; import { pickTts } from './js/tts-webspeech.js'; import { promptLogin } from './js/login-prompt.js'; import { injectIntoOpenTabs, readSelection, selectionErrorMessage } from './js/site-access.js'; -import { summaryNotification } from './js/utils.js'; const apiClient = new ApiClient(); +// Only a pointer, not the summary: macOS and others cut long notification text +// off, and the full summary is in the popup. +const SUMMARY_READY_MESSAGE = 'Your summary is ready. Open the extension to read it.'; + const engine = new TtsEngine({ // chrome.tts in Chrome; Firefox has no chrome.tts, so the Web Speech API. tts: pickTts({ @@ -348,7 +351,7 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => { message: 'Text may be too short or incomplete for summarization.' }); } else { - notify('Summary Ready!', summaryNotification(summary.summary)); + notify('Summary Ready!', SUMMARY_READY_MESSAGE); } } catch (error) { console.error('Failed to summarize:', error); diff --git a/extension/js/utils.js b/extension/js/utils.js index d90a19b..c03acd4 100644 --- a/extension/js/utils.js +++ b/extension/js/utils.js @@ -45,35 +45,6 @@ export function truncate(text, max) { return chars.length <= max ? text : chars.slice(0, max).join('') + '…'; } -/** Longest notification message we send; Firefox cuts longer ones off. */ -export const NOTIFICATION_MAX = 200; - -/** - * Text shortened for a notification: whitespace collapsed, at most `max` - * characters including the "…", cut at a word boundary when one is near. - * Counts graphemes, so emoji and accented letters are never split. - */ -export function truncateForNotification(text, max = NOTIFICATION_MAX) { - const clean = String(text ?? '').replace(/\s+/g, ' ').trim(); - const graphemes = [...new Intl.Segmenter(undefined, { granularity: 'grapheme' }).segment(clean)].map((s) => s.segment); - if (graphemes.length <= max) return clean; - const cut = graphemes.slice(0, max - 1).join(''); - const space = cut.lastIndexOf(' '); - // Back up to the last word only if that keeps most of the text. - const head = space >= cut.length * 0.7 ? cut.slice(0, space) : cut; - return `${head.replace(/[\s.,;:!?-]+$/, '')}…`; -} - -const FULL_SUMMARY_HINT = ' Open the extension for the full summary.'; - -/** A summary short enough for a notification (Firefox cuts long ones off). */ -export function summaryNotification(summary) { - if (!summary) return 'Summary generated successfully.'; - const short = truncateForNotification(summary); - if (short === summary.replace(/\s+/g, ' ').trim()) return short; - return truncateForNotification(summary, NOTIFICATION_MAX - FULL_SUMMARY_HINT.length) + FULL_SUMMARY_HINT; -} - export function relativeDate(iso, now = Date.now()) { const date = new Date(iso); const mins = Math.floor((now - date.getTime()) / 60000); diff --git a/extension/manifest.json b/extension/manifest.json index a7ac53a..bdb3a04 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "TTS Study Assistant", - "version": "0.3.4", + "version": "0.3.5", "description": "Save and listen to text from any webpage", "minimum_chrome_version": "121", "permissions": [ diff --git a/extension/package.json b/extension/package.json index 442a175..38550e8 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1,6 +1,6 @@ { "name": "tts-study-assistant", - "version": "0.3.4", + "version": "0.3.5", "description": "Instant text-to-speech browser extension for Chrome and Firefox, with study features", "scripts": { "test": "node --test tests/*.test.mjs" diff --git a/extension/tests/background.test.mjs b/extension/tests/background.test.mjs index 48b595b..1d01824 100644 --- a/extension/tests/background.test.mjs +++ b/extension/tests/background.test.mjs @@ -161,7 +161,7 @@ for (const [browser, withTts] of [['chrome', true], ['firefox', false]]) { } }); - test(`${browser}: a long summary from the context menu is shortened for the notification`, async () => { + test(`${browser}: a summary from the context menu is announced, not shown, in the notification`, async () => { const { chrome, calls } = await loadBackground(`${browser}-long-summary`, { withTts }); chrome.storage.local.get = async () => ({ access_token: 'token' }); // logged in const summary = 'This summary is far longer than a notification can show. '.repeat(20); @@ -180,8 +180,8 @@ for (const [browser, withTts] of [['chrome', true], ['firefox', false]]) { } const last = calls.notifications.at(-1); assert.equal(last.title, 'Summary Ready!'); - assert.ok([...last.message].length <= 200, `${[...last.message].length} characters`); - assert.match(last.message, /Open the extension for the full summary\.$/); + assert.equal(last.message, 'Your summary is ready. Open the extension to read it.'); + assert.ok(!last.message.includes('This summary'), 'the summary text is not in the notification'); }); test(`${browser}: no tab update listener and no openPopup message`, async () => { diff --git a/extension/tests/utils.test.mjs b/extension/tests/utils.test.mjs index d7de9ee..c20475c 100644 --- a/extension/tests/utils.test.mjs +++ b/extension/tests/utils.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; -import { formatTime, NOTIFICATION_MAX, RATES, siteDomainFor, snapRate, summaryNotification, truncate, truncateForNotification } from '../js/utils.js'; +import { formatTime, RATES, siteDomainFor, snapRate, truncate } from '../js/utils.js'; test('snapRate maps any stored speed to one of the four steps', () => { assert.deepEqual(RATES, [0.5, 1, 1.5, 2]); @@ -40,39 +40,3 @@ test('truncate by code points', () => { assert.equal(truncate('hello', 10), 'hello'); assert.equal(truncate('πŸ˜€πŸ˜€πŸ˜€', 2), 'πŸ˜€πŸ˜€β€¦'); }); - -test('truncateForNotification leaves short text alone, collapsing whitespace', () => { - assert.equal(truncateForNotification('Short summary.'), 'Short summary.'); - assert.equal(truncateForNotification(' two\n\nlines '), 'two lines'); - assert.equal(truncateForNotification('x'.repeat(NOTIFICATION_MAX)), 'x'.repeat(NOTIFICATION_MAX)); - assert.equal(truncateForNotification(undefined), ''); -}); - -test('truncateForNotification cuts at a word boundary within the limit', () => { - const text = 'The quick brown fox jumps over the lazy dog. '.repeat(10); - const short = truncateForNotification(text, 50); - assert.ok([...short].length <= 50, short); - assert.ok(short.endsWith('…')); - assert.ok(text.startsWith(short.slice(0, -1)), 'a prefix of the text'); - assert.match(short, /\w…$/, 'no trailing space or punctuation before the ellipsis'); - assert.equal(short, 'The quick brown fox jumps over the lazy dog. The…'); -}); - -test('truncateForNotification hard-cuts one long word', () => { - assert.equal(truncateForNotification('a'.repeat(30), 10), 'aaaaaaaaa…'); -}); - -test('truncateForNotification never splits emoji or accented letters', () => { - const family = 'πŸ‘¨β€πŸ‘©β€πŸ‘§'; // one grapheme, five code points - const short = truncateForNotification(family.repeat(20), 5); - assert.equal(short, family.repeat(4) + '…'); - assert.equal(truncateForNotification('e\u0301'.repeat(20), 4), 'e\u0301'.repeat(3) + '…'); -}); - -test('summaryNotification keeps short summaries and points long ones to the popup', () => { - assert.equal(summaryNotification('A short summary.'), 'A short summary.'); - assert.equal(summaryNotification(''), 'Summary generated successfully.'); - const long = summaryNotification('word '.repeat(200)); - assert.ok([...long].length <= NOTIFICATION_MAX, `${[...long].length} characters`); - assert.match(long, /… Open the extension for the full summary\.$/); -});