diff --git a/docs/sound-effects.md b/docs/sound-effects.md index 8db2466..f70c081 100644 --- a/docs/sound-effects.md +++ b/docs/sound-effects.md @@ -15,7 +15,7 @@ The app and Storybook share the same control implementations. Motion supports re | Disable sounds | Silent; cancels active and pending cues | | Tabs, hover, accordions, tooltips, continuous sliders, telemetry | Silent | -Both libraries use 35% global volume. A grouped switch produces one cue, even when it changes several sensors. Hydration and programmatic updates remain silent. Sound preferences persist across restarts; asynchronous actions cannot replay a cue cancelled by muting. +Both libraries use 70% global volume. A grouped switch produces one cue, even when it changes several sensors. Hydration and programmatic updates remain silent. Sound preferences persist across restarts; asynchronous actions cannot replay a cue cancelled by muting. ## Audio implementation diff --git a/tauri-app/scripts/test-feedback-email.mjs b/tauri-app/scripts/test-feedback-email.mjs new file mode 100644 index 0000000..5cd9207 --- /dev/null +++ b/tauri-app/scripts/test-feedback-email.mjs @@ -0,0 +1,116 @@ +import { chromium } from 'playwright'; +import assert from 'node:assert/strict'; +import { mkdir } from 'node:fs/promises'; + +const browser = await chromium.launch(); +const sent = []; +const failures = []; +let rejectNext = false; +try { + const page = await browser.newPage({ viewport: { width: 651, height: 900 } }); + page.on('pageerror', error => failures.push(error.message)); + await page.exposeFunction('__feedbackSend', async input => { + sent.push(input); + if (rejectNext) { rejectNext = false; throw new Error('Temporary submission failure'); } + if (process.env.FEEDBACK_PORTAL_URL) { + const fields = { name: input.name, message: input.message, app_version: '2.2.18', os: 'windows' }; + if (input.email) fields.email = input.email; + if (input.includeDiagnostics) { + fields.diagnostics_summary = 'Local email integration check'; + fields.diagnostics = { name: 'cleanmeter-diagnostics.txt', mimeType: 'text/plain', buffer: Buffer.from('Local integration diagnostics\n') }; + } + const response = await page.request.post(`${process.env.FEEDBACK_PORTAL_URL}/api/feedback`, { + headers: { 'x-feedback-key': process.env.FEEDBACK_TEST_KEY ?? 'local-email-test-key' }, + multipart: fields, + }); + assert.equal(response.status(), 201, await response.text()); + } + }); + await page.route('**/src/lib/tauri.ts*', async route => { + const response = await route.fetch(); + const source = await response.text(); + const marker = 'export const submitFeedback = (input) => {'; + assert.ok(source.includes(marker), 'Intercept only the desktop transport boundary'); + await route.fulfill({ response, body: source.replace(marker, `${marker} return window.__feedbackSend(input);`) }); + }); + await page.goto(process.env.APP_URL ?? 'http://127.0.0.1:1433/'); + const open = async () => { + await page.getByRole('tab', { name: 'Help', exact: true }).click(); + await page.getByRole('button', { name: 'Give feedback', exact: true }).click(); + }; + await open(); + const email = page.getByRole('textbox', { name: 'Email (optional)', exact: true }); + const message = page.getByRole('textbox', { name: 'Message', exact: true }); + const submit = page.getByRole('button', { name: 'Submit', exact: true }); + await email.waitFor({ timeout: 5000 }); + await message.fill('Anonymous email test'); + await submit.click(); + await page.getByRole('dialog').waitFor({ state: 'hidden' }); + assert.equal(sent.at(-1).email, undefined, 'Blank email stays optional'); + await open(); + await email.fill('invalid'); + await email.blur(); + await message.fill('Contact email integration test'); + assert.equal(await email.getAttribute('aria-invalid'), 'true'); + assert.equal(await submit.isDisabled(), true); + const count = sent.length; + await email.fill('reply@example.com'); + rejectNext = true; + await submit.click(); + await page.getByRole('alert').filter({ hasText: 'Temporary submission failure' }).waitFor(); + assert.equal(await email.inputValue(), 'reply@example.com'); + assert.equal(await message.inputValue(), 'Contact email integration test'); + assert.equal(sent.length, count + 1); + await page.getByRole('checkbox', { name: 'Include system specs and app logs' }).check(); + await submit.click(); + await page.getByRole('dialog').waitFor({ state: 'hidden' }); + assert.equal(sent.at(-1).email, 'reply@example.com'); + assert.equal(sent.at(-1).includeDiagnostics, true); + await open(); + assert.equal(await email.inputValue(), ''); + assert.equal(await message.inputValue(), ''); + for (const colorScheme of ['light', 'dark']) { + await page.emulateMedia({ colorScheme }); + for (const height of [900, 500]) { + await page.setViewportSize({ width: 651, height }); + const fieldGeometry = await page.locator('#fb-name, #fb-email').evaluateAll(inputs => inputs.map(input => { + const style = getComputedStyle(input); + return { + id: input.id, + height: input.parentElement.getBoundingClientRect().height, + textSpace: input.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom), + lineHeight: parseFloat(style.lineHeight), + }; + })); + assert.ok(Math.abs(fieldGeometry[0].height - fieldGeometry[1].height) < 0.5, 'Name and email fields have equal heights'); + for (const field of fieldGeometry) assert.ok(field.textSpace >= field.lineHeight, `${field.id}: its text line fits inside the field without vertical clipping`); + await email.fill('invalid'); + await email.blur(); + await email.scrollIntoViewIfNeeded(); + assert.equal(await email.getAttribute('aria-invalid'), 'true'); + const errorContrast = await page.locator('#fb-email-error').evaluate(element => { + const luminance = color => { + const channels = color.match(/[\d.]+/g).slice(0, 3).map(Number).map(value => { + const s = value / 255; + return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; + }); + return channels[0] * 0.2126 + channels[1] * 0.7152 + channels[2] * 0.0722; + }; + const foreground = luminance(getComputedStyle(element).color); + const background = luminance(getComputedStyle(element.closest('[role="dialog"]')).backgroundColor); + return (Math.max(foreground, background) + 0.05) / (Math.min(foreground, background) + 0.05); + }); + assert.ok(errorContrast >= 4.5, `Readable email error in ${colorScheme}: ${errorContrast.toFixed(2)}:1`); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); + await mkdir('test-results', { recursive: true }); + if (colorScheme === 'dark' && height === 900) await page.screenshot({ path: 'test-results/feedback-email-dark.png' }); + await submit.scrollIntoViewIfNeeded(); + const box = await submit.boundingBox(); + assert.ok(box.y >= 0 && box.y + box.height <= height, 'Submit remains reachable at short heights'); + } + } + assert.deepEqual(failures, []); + console.log('PASS optional email, validation, retry preservation, diagnostics, draft reset, both themes, short window, and submission transport'); +} finally { + await browser.close(); +} diff --git a/tauri-app/sound-lab/index.html b/tauri-app/sound-lab/index.html index 720cd8d..74111c3 100644 --- a/tauri-app/sound-lab/index.html +++ b/tauri-app/sound-lab/index.html @@ -3,7 +3,7 @@ :root{font:16px system-ui,sans-serif;color:#eef2f8;background:#10141c;color-scheme:dark}*{box-sizing:border-box}body{margin:0}main{max-width:1050px;margin:auto;padding:40px 24px}h1{font-size:34px;margin:0 0 10px}h2{font-size:22px;margin-top:32px}p{color:#aebbd0;line-height:1.6}label{display:flex;flex-direction:column;gap:9px}button,select{font:inherit;border:1px solid #46546b;border-radius:10px;background:#252f40;color:inherit;padding:12px;cursor:pointer}button:hover{background:#364863}button:focus-visible,select:focus-visible,input:focus-visible{outline:3px solid #83e7c1;outline-offset:3px}.controls{display:flex;flex-wrap:wrap;gap:20px;background:#1a2230;padding:20px;border-radius:14px;align-items:center}.controls label{min-width:130px;flex:1}.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px}.cue{text-align:left;min-height:85px}.cue strong{display:block;margin-bottom:8px}.cue small{color:#b1c4dc}.inline{flex-direction:row;align-items:center!important}#status{position:sticky;bottom:12px;background:#193d32;border:1px solid #337660;padding:14px;border-radius:10px;margin-top:28px}a{color:#83e7c1}button:disabled{opacity:.45;cursor:default}input[type=range]{width:100%}

Sound lab

Listen, compare, and choose your favourites. These controls only affect this playground.

-
+

Audio readiness uses the same quiet output helper as Cleanmeter. It stops when this page loses focus or is muted. No sounds play automatically.

Compare Cleanmeter cues

These use the app's default sound theme. Volume follows the slider above.

Explore the library

diff --git a/tauri-app/src-tauri/src/commands.rs b/tauri-app/src-tauri/src/commands.rs index 5c01108..304bbc9 100644 --- a/tauri-app/src-tauri/src/commands.rs +++ b/tauri-app/src-tauri/src/commands.rs @@ -571,6 +571,8 @@ pub fn grant_admin_consent(settings_mgr: State<'_, SettingsManager>) { #[derive(serde::Deserialize)] pub struct FeedbackInput { pub name: String, + #[serde(default)] + pub email: Option, pub message: String, #[serde(rename = "attachmentPath")] pub attachment_path: Option, @@ -578,6 +580,29 @@ pub struct FeedbackInput { pub include_diagnostics: bool, } +#[cfg(test)] +mod feedback_email_tests { + use super::FeedbackInput; + + #[test] + fn feedback_rejects_a_non_string_contact_email() { + let input = serde_json::json!({ "name": "Test", "message": "Issue", "email": 17 }); + assert!(serde_json::from_value::(input).is_err()); + } + + #[test] + fn feedback_accepts_old_payloads_without_email() { + let input: FeedbackInput = serde_json::from_value(serde_json::json!({ "name": "Test", "message": "Issue" })).unwrap(); + assert!(input.email.is_none()); + } + + #[test] + fn feedback_keeps_the_supplied_contact_email() { + let input: FeedbackInput = serde_json::from_value(serde_json::json!({ "name": "Test", "message": "Issue", "email": "reply@example.com" })).unwrap(); + assert_eq!(input.email.as_deref(), Some("reply@example.com")); + } +} + // POSTs feedback to the portal. URL + write key are injected at build time via // option_env!; if either is missing (e.g. a plain local dev build) the command // returns an error instead of attempting a request. Touches no app state. @@ -604,6 +629,10 @@ pub async fn submit_feedback(input: FeedbackInput, app: AppHandle) -> Result<(), .text("app_version", env!("CARGO_PKG_VERSION")) .text("os", std::env::consts::OS); + if let Some(email) = input.email.as_deref().map(str::trim).filter(|email| !email.is_empty()) { + form = form.text("email", email.to_owned()); + } + if let Some(path) = input.attachment_path.as_deref() { let file_path = std::path::Path::new(path); let (bytes, mime) = crate::feedback_attachment::read(file_path).await?; diff --git a/tauri-app/src/app/components/stories/FeedbackDialog.stories.tsx b/tauri-app/src/app/components/stories/FeedbackDialog.stories.tsx index 4224d6a..e27492d 100644 --- a/tauri-app/src/app/components/stories/FeedbackDialog.stories.tsx +++ b/tauri-app/src/app/components/stories/FeedbackDialog.stories.tsx @@ -1,5 +1,6 @@ import { useState } from "react"; import type { Meta, StoryObj } from "@storybook/react-vite"; +import { expect, userEvent, within } from "storybook/test"; import { FeedbackDialog } from "../../../components/settings/settings/FeedbackDialog"; const meta: Meta = { @@ -21,6 +22,20 @@ export const Default: Story = { }, }; +export const OptionalEmail: Story = { + ...Default, + play: async () => { + const dialog = within(document.body).getByRole("dialog"); + const email = within(dialog).getByRole("textbox", { name: "Email (optional)" }); + await userEvent.type(email, "invalid"); + await userEvent.tab(); + await expect(email).toHaveAttribute("aria-invalid", "true"); + await userEvent.clear(email); + await userEvent.type(email, "reply@example.com"); + await expect(email).toHaveAttribute("aria-invalid", "false"); + }, +}; + // Click "Add attachment" to see the picker error state. const failingPicker = async (): Promise => { throw "The file is open in another program."; diff --git a/tauri-app/src/components/settings/settings/FeedbackDialog.tsx b/tauri-app/src/components/settings/settings/FeedbackDialog.tsx index a320006..36177ca 100644 --- a/tauri-app/src/components/settings/settings/FeedbackDialog.tsx +++ b/tauri-app/src/components/settings/settings/FeedbackDialog.tsx @@ -73,6 +73,8 @@ export function FeedbackDialog({ pickAttachment = pickFeedbackAttachment, }: FeedbackDialogProps) { const [name, setName] = React.useState(""); + const [email, setEmail] = React.useState(""); + const [emailTouched, setEmailTouched] = React.useState(false); const [message, setMessage] = React.useState(""); const [attachment, setAttachment] = React.useState(null); const [includeDiagnostics, setIncludeDiagnostics] = React.useState(false); @@ -90,6 +92,8 @@ export function FeedbackDialog({ React.useEffect(() => { if (!open) { setName(""); + setEmail(""); + setEmailTouched(false); setMessage(""); setAttachment(null); setIncludeDiagnostics(false); @@ -104,7 +108,10 @@ export function FeedbackDialog({ (attachment ? removeRef : addRef).current?.focus(); }, [attachment]); - const canSubmit = message.trim() !== "" && !submitting; + const trimmedEmail = email.trim(); + const emailValid = trimmedEmail === "" || (trimmedEmail.length <= 254 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedEmail)); + const emailError = emailTouched && !emailValid; + const canSubmit = message.trim() !== "" && emailValid && !submitting; // Editing the report retires the previous failure message. const edit = (set: (value: string) => void) => (e: React.ChangeEvent) => { @@ -137,6 +144,7 @@ export function FeedbackDialog({ try { await submitFeedback({ name: name.trim(), + email: trimmedEmail || undefined, message: message.trim(), attachmentPath: attachment?.path, includeDiagnostics, @@ -197,7 +205,7 @@ export function FeedbackDialog({ +
+ + setEmailTouched(true)} + error={emailError} + aria-invalid={emailError} + aria-describedby={emailError ? "fb-email-error" : undefined} + /> + {emailError && ( + + )} +
+