From b4dbc5b6e7602fd0d405be5f7dbf74eb3194258c Mon Sep 17 00:00:00 2001 From: pengx17 Date: Tue, 13 May 2025 06:52:09 +0000 Subject: [PATCH] fix(electron): recorded audio is not correctly rendered after saved as attachment (#12232) fix AF-2611 ## Summary by CodeRabbit - **Refactor** - Improved the process for adding audio attachments after a recording is ready, ensuring all details (name, type, size, source, embed) are included at creation for a smoother and more reliable user experience. --- .../src/app/effects/recording.ts | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/frontend/apps/electron-renderer/src/app/effects/recording.ts b/packages/frontend/apps/electron-renderer/src/app/effects/recording.ts index 905cd3fe7..bbef4bbd2 100644 --- a/packages/frontend/apps/electron-renderer/src/app/effects/recording.ts +++ b/packages/frontend/apps/electron-renderer/src/app/effects/recording.ts @@ -51,33 +51,35 @@ export function setupRecordingEvents(frameworkProvider: FrameworkProvider) { const docProps: DocProps = { onStoreLoad: (doc, { noteId }) => { (async () => { - // name + timestamp(readable) + extension - const attachmentName = - (status.appName ?? 'System Audio') + ' ' + timestamp + '.opus'; - - // add size and sourceId to the attachment later - const attachmentId = doc.addBlock( - 'affine:attachment', - { - name: attachmentName, - type: 'audio/opus', - }, - noteId - ); - - const model = doc.getBlock(attachmentId) - ?.model as AttachmentBlockModel; - - if (model && status.filepath) { + if (status.filepath) { // it takes a while to save the blob, so we show the attachment first const { blobId, blob } = await saveRecordingBlob( doc.workspace.blobSync, status.filepath ); - model.props.size = blob.size; - model.props.sourceId = blobId; - model.props.embed = true; + // name + timestamp(readable) + extension + const attachmentName = + (status.appName ?? 'System Audio') + + ' ' + + timestamp + + '.opus'; + + // add size and sourceId to the attachment later + const attachmentId = doc.addBlock( + 'affine:attachment', + { + name: attachmentName, + type: 'audio/opus', + size: blob.size, + sourceId: blobId, + embed: true, + }, + noteId + ); + + const model = doc.getBlock(attachmentId) + ?.model as AttachmentBlockModel; if (!aiEnabled) { return;