Skip to content

Commit 126f030

Browse files
committed
Fix Voice Notes signing, seeking, and keyboard focus
Signed-off-by: klopez4212 <[email protected]>
1 parent f6afc06 commit 126f030

9 files changed

Lines changed: 104 additions & 13 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
osx-codesign-role: ${{ secrets.OSX_CODESIGN_ROLE }}
100100
codesign-s3-bucket: ${{ secrets.CODESIGN_S3_BUCKET }}
101101
unsigned-artifact-path: ${{ steps.unsigned.outputs.path }}
102+
entitlements-plist-path: src-tauri/entitlements.plist
102103
artifact-name: buzz-app-${{ github.run_id }}-${{ github.run_attempt }}-arm64
103104

104105
- name: Verify release DMG and bundled runtime
@@ -113,6 +114,8 @@ jobs:
113114
-R '=anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] exists and certificate leaf[field.1.2.840.113635.100.6.1.13] exists and certificate leaf[subject.OU] = EYF346PHUG' "$app"
114115
spctl --assess --type execute --verbose=4 "$app"
115116
xcrun stapler validate "$app"
117+
codesign --display --entitlements :- "$app" > "$RUNNER_TEMP/signed-entitlements.plist"
118+
test "$(/usr/libexec/PlistBuddy -c 'Print :com.apple.security.device.audio-input' "$RUNNER_TEMP/signed-entitlements.plist")" = true || { echo '::error::Signed app is missing microphone entitlement'; exit 1; }
116119
node --input-type=module - "$app/Contents/Resources/agent-runtime" <<'JS'
117120
import { readFileSync, lstatSync } from 'node:fs';
118121
import assert from 'node:assert/strict';

‎src-tauri/entitlements.plist‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.device.audio-input</key>
6+
<true/>
7+
</dict>
8+
</plist>

‎src-tauri/tauri.conf.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"bundle": {
3434
"active": true,
35+
"macOS": { "entitlements": "entitlements.plist" },
3536
"resources": { "resources/agent-runtime/": "agent-runtime/" },
3637
"icon": [
3738
"icons/32x32.png",

‎src/bundled/voice-notes/VoiceCapture.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef, useState } from "react";
1+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
22
import { IconButton } from "../../shared/design-system/ui/IconButton";
33
import { StopIcon as Square } from "../../shared/design-system/icons";
44
import type { ComposerCaptureProps } from "../../features/conversation/contracts";
@@ -13,6 +13,10 @@ export function VoiceCapture({ accept, cancel }: ComposerCaptureProps) {
1313
current.current = { accept, cancel };
1414
const finishing = useRef(false);
1515
const [failed, setFailed] = useState(false);
16+
const close = useRef<HTMLButtonElement>(null);
17+
useLayoutEffect(() => {
18+
if (recorder.error || failed) close.current?.focus();
19+
}, [recorder.error, failed]);
1620
useEffect(() => {
1721
// Strict Mode can dispose a mount immediately; do not open two permission requests.
1822
let active = true;
@@ -45,7 +49,7 @@ export function VoiceCapture({ accept, cancel }: ComposerCaptureProps) {
4549
{recorder.error ??
4650
"Could not attach this voice note. Close and try again."}
4751
</span>
48-
<button type="button" onClick={cancel}>
52+
<button ref={close} type="button" onClick={cancel}>
4953
Close
5054
</button>
5155
</div>

‎src/bundled/voice-notes/VoiceNoteCard.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function Player({
6868
const attempt = useRef(0);
6969
const [count, setCount] = useState(38);
7070
const [duration, setDuration] = useState(taggedDuration);
71+
const [metadataReady, setMetadataReady] = useState(false);
7172
const [time, setTime] = useState(0);
7273
const [playing, setPlaying] = useState(false);
7374
const [loading, setLoading] = useState(false);
@@ -221,7 +222,7 @@ function Player({
221222
max={duration || 1}
222223
step={0.01}
223224
value={Math.min(time, duration || 1)}
224-
disabled={!duration}
225+
disabled={!duration || !metadataReady}
225226
aria-valuetext={`${formatVoiceNoteDuration(time)} of ${formatVoiceNoteDuration(duration)}`}
226227
onChange={(event) => {
227228
const element = audio.current;
@@ -280,10 +281,12 @@ function Player({
280281
src={source}
281282
preload="none"
282283
onLoadedMetadata={(event) => {
284+
setMetadataReady(true);
283285
const value = event.currentTarget.duration;
284286
if (Number.isFinite(value) && value > 0) setDuration(value);
285287
applyVoiceNotePlaybackRate(event.currentTarget, rate);
286288
}}
289+
onEmptied={() => setMetadataReady(false)}
287290
onTimeUpdate={(event) => {
288291
setTime(event.currentTarget.currentTime);
289292
paintProgress(event.currentTarget.currentTime, duration);
@@ -303,6 +306,7 @@ function Player({
303306
paintProgress(0, duration);
304307
}}
305308
onError={(event) => {
309+
setMetadataReady(false);
306310
releaseAudio(event.currentTarget);
307311
attempt.current++;
308312
setError(true);

‎src/bundled/voice-notes/VoiceNoteRecorder.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export function VoiceNoteRecorder({
2323
status: "requesting" | "recording" | "processing";
2424
}) {
2525
const discardCorners = useMediaCorners();
26+
const discard = useRef<HTMLButtonElement>(null);
27+
useLayoutEffect(() => {
28+
discard.current?.focus();
29+
}, []);
2630
const waveform = useRef<HTMLDivElement>(null);
2731
const [count, setCount] = useState(38);
2832
const track = useRef<HTMLDivElement>(null);
@@ -66,6 +70,7 @@ export function VoiceNoteRecorder({
6670
<legend className="sr-only">{label ?? "Recording voice note"}</legend>
6771
<span ref={discardCorners} className={styles.discard}>
6872
<button
73+
ref={discard}
6974
className={styles.iconButton}
7075
type="button"
7176
aria-label="Discard voice note"

‎src/bundled/voice-notes/index.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@ export const apply: PluginModule["apply"] = (ctx) => {
1111
id: "recorder",
1212
title: "Voice Notes",
1313
order: 10,
14-
component: ({ session, disabled, capture }) =>
14+
component: ({ session, disabled, capture, focus }) =>
1515
session.attachments && capture ? (
1616
<button
1717
type="button"
1818
className={styles.iconButton}
1919
aria-label="Record voice note"
2020
title="Record voice note"
2121
disabled={disabled}
22-
onClick={() => capture(VoiceCapture)}
22+
onClick={() =>
23+
capture(({ accept, cancel }) => (
24+
<VoiceCapture
25+
accept={(recording) => {
26+
const accepted = accept(recording);
27+
if (accepted) focus();
28+
return accepted;
29+
}}
30+
cancel={() => {
31+
cancel();
32+
focus();
33+
}}
34+
/>
35+
))
36+
}
2337
>
2438
<MicrophoneIcon size={18} aria-hidden="true" />
2539
</button>

‎tests/browser/voice-notes.spec.mjs‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ test("record, preview, send and play the chat card with speed and seeking", {
133133
tag: "@media-recorder",
134134
}, async ({ page }) => {
135135
const errors = watchPageErrors(page);
136+
const initialCard = page
137+
.getByRole("group", { name: "Voice note", exact: true })
138+
.first();
139+
await expect(initialCard.locator("audio")).toHaveJSProperty("readyState", 0);
140+
await expect(initialCard.getByRole("slider")).toBeDisabled();
136141
await record(page);
142+
await expect(page.getByRole("textbox")).toBeFocused();
137143
const composer = page.getByRole("form", {
138144
name: "Send a message to general",
139145
});
@@ -212,6 +218,7 @@ test("record, preview, send and play the chat card with speed and seeking", {
212218
await expect(speedButton).toHaveCSS("color", "rgb(255, 255, 255)");
213219
await firstCard.hover();
214220
await expect(speedButton).toHaveCSS("color", "rgb(255, 255, 255)");
221+
await expect(firstCard.getByRole("slider")).toBeEnabled();
215222
await firstCard.getByRole("slider").fill("1");
216223
await expect
217224
.poll(() =>
@@ -240,15 +247,20 @@ test("permission cancellation, denial and plugin removal release microphones", {
240247
await page.evaluate(() => {
241248
window.voiceMic.mode = "delay";
242249
});
243-
await page
244-
.getByRole("button", { name: "Record voice note", exact: true })
245-
.click();
250+
const recordButton = page.getByRole("button", {
251+
name: "Record voice note",
252+
exact: true,
253+
});
254+
await recordButton.focus();
255+
await page.keyboard.press("Enter");
246256
await expect(
247257
page.getByRole("status").filter({ hasText: "Waiting for microphone…" }),
248258
).toBeVisible();
249-
await page
250-
.getByRole("button", { name: "Discard voice note", exact: true })
251-
.click();
259+
await expect(
260+
page.getByRole("button", { name: "Discard voice note", exact: true }),
261+
).toBeFocused();
262+
await page.keyboard.press("Enter");
263+
await expect(page.getByRole("textbox")).toBeFocused();
252264
await page.evaluate(() => window.voiceMic.release());
253265
await expect.poll(() => page.evaluate(() => window.voiceMic.stopped)).toBe(1);
254266
await page.evaluate(() => {
@@ -258,7 +270,11 @@ test("permission cancellation, denial and plugin removal release microphones", {
258270
.getByRole("button", { name: "Record voice note", exact: true })
259271
.click();
260272
await expect(page.getByRole("alert")).toContainText("Allow Buzz");
261-
await page.getByRole("button", { name: "Close", exact: true }).click();
273+
await expect(
274+
page.getByRole("button", { name: "Close", exact: true }),
275+
).toBeFocused();
276+
await page.keyboard.press("Enter");
277+
await expect(page.getByRole("textbox")).toBeFocused();
262278
await page.evaluate(() => {
263279
window.voiceMic.mode = "allow";
264280
});
@@ -270,11 +286,15 @@ test("permission cancellation, denial and plugin removal release microphones", {
270286
).toBeEnabled();
271287
await page
272288
.getByRole("button", { name: "Disable Voice Notes", exact: true })
273-
.click();
289+
.focus();
290+
await page.keyboard.press("Enter");
274291
await expect(
275292
page.getByRole("button", { name: "Finish voice note", exact: true }),
276293
).toHaveCount(0);
277294
await expect.poll(() => page.evaluate(() => window.voiceMic.stopped)).toBe(2);
295+
await expect(
296+
page.getByRole("button", { name: "Enable Voice Notes", exact: true }),
297+
).toBeFocused();
278298
expect(await page.evaluate(() => window.voiceFixture.report.published)).toBe(
279299
0,
280300
);

‎tests/integration/desktop-release.test.mjs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ const assembly = jobs.publish.steps.find((step) =>
3939
step.run?.includes("sha256sum --check"),
4040
).run;
4141

42+
test("Tauri and the release signer use microphone entitlements and verify the signed app", () => {
43+
const config = JSON.parse(
44+
readFileSync(join(root, "src-tauri/tauri.conf.json"), "utf8"),
45+
);
46+
const signing = jobs.build.steps.find((step) => step.id === "codesign");
47+
const path = `src-tauri/${config.bundle.macOS.entitlements}`;
48+
assert.equal(signing.with["entitlements-plist-path"], path);
49+
assert.match(
50+
readFileSync(join(root, path), "utf8"),
51+
/<key>com\.apple\.security\.device\.audio-input<\/key>\s*<true\s*\/>/,
52+
);
53+
const verify = jobs.build.steps.find(
54+
(step) => step.name === "Verify release DMG and bundled runtime",
55+
);
56+
assert.ok(
57+
verify.run.includes(
58+
'codesign --display --entitlements :- "$app" > "$RUNNER_TEMP/signed-entitlements.plist"',
59+
),
60+
);
61+
assert.ok(
62+
verify.run.includes(
63+
`test "$(/usr/libexec/PlistBuddy -c 'Print :com.apple.security.device.audio-input' "$RUNNER_TEMP/signed-entitlements.plist")" = true ||`,
64+
),
65+
);
66+
assert.ok(
67+
jobs.build.steps.indexOf(verify) <
68+
jobs.build.steps.findIndex(
69+
(step) => step.name === "Stage release assets and checksums",
70+
),
71+
);
72+
});
73+
4274
function temp(t) {
4375
const dir = mkdtempSync(join(tmpdir(), "desktop-release-"));
4476
t.after(() => rmSync(dir, { recursive: true, force: true }));

0 commit comments

Comments
 (0)