Skip to content

The desktop app shows pictures, plays voice messages, and opens or saves files in chats - #181

Merged
pitis merged 4 commits into
mainfrom
feat/desktop-files-shown
Nov 14, 2026
Merged

pitis merged 4 commits into
mainfrom
feat/desktop-files-shown

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

A chat in the desktop app now shows its messages' files the way the Mac app's AttachmentViews.swift does. Before, every file showed as "📎 Attachment".

  • Pictures show inline. Each fits a 320 box and is never enlarged, with 240×180 when the size is unknown and 12-point rounded corners. A picture is decoded off the main thread to at most 640 px on a side, like the Mac app's Thumbnails, and EXIF rotation is applied. Clicking a picture opens it. A picture that won't decode shows as a file row, so it can still be opened.
  • Voice and audio messages have play/pause (a 28-point filled circle), a 140×4 track and the time (m:ss, tabular digits). The length is read from the recording's bytes in memory before it plays, for recordings up to 20 MB, as on the Mac. A recording that can't be decoded says "This recording can't be played", and it can still be opened from its menu.
  • Other files, videos included, show as 260-wide rows: an icon for the type, the name (or "File") and the size, worded like ByteCountFormatter: "1.2 MB", "340 KB". Clicking a row opens the file in the system's app for it.
  • Download states, the same for every kind: a download button (a filled circle with an arrow), a spinner while downloading, and an orange "Retry" when the download failed. Clicking a file that isn't downloaded yet downloads it (download_attachment). AttachmentChanged reloads the open chat's files.
  • Captions show under their file. A file without a caption has no text, and its time sits under it on the right. A message with neither text nor files says "Attachment", as on the Mac. Deleted, view-once and sticker messages show no files here, as on the Mac (stickers are The desktop app shows and sends stickers #151, view-once is The desktop app shows polls and view-once media #152).
  • Open and Save As… are on every downloaded file's right-click menu. Programs and scripts (Signal Desktop's isFileDangerous list, plus macOS and Linux ones such as .app, .command, .sh, .desktop, .deb) offer Save As… only, and clicking them saves. Save As… uses the system's save dialog (prompt_for_new_path). The copy is written beside the chosen file first, then renamed over it, so an existing file is only replaced by a complete copy.

Files stay encrypted on disk

  • Files are never read from disk directly: pictures and recordings come from Client::file_bytes (decrypted in memory), and opened or saved copies from Client::copy_file. A recording plays from memory, so unlike the Mac app it never needs a decrypted copy.
  • An opened file is a decrypted copy under its own name, in a folder of its own: <data folder>/open/<random>/. There is one copy per file, reused on later clicks, and it is deleted when its message expires or is deleted, or its chat is deleted. The data folder is the core's own (0700 on Unix), not the shared /tmp, and not the Mac app's Hush-open. All copies are also deleted at quit and at launch, once the core holds the data folder, like Files.clearLeftovers. Each copy's folder is removed on its own, so one that a program still holds open (Windows locks it) doesn't keep the others; a failure is logged and the next launch tries again.
  • A copy is marked as coming from someone else, so the system checks it before it runs:
    • macOS: the com.apple.quarantine mark, as Files.quarantine writes it.
    • Windows: the Mark of the Web (Zone.Identifier, Internet zone), which SmartScreen checks.
    • Linux: no such mark exists. Copies are never executable.
  • The file name the sender chose is cleaned before use. Only its last part is kept, characters Windows can't hold and invisible direction and format characters become _, trailing dots and spaces are dropped (".." with them), Windows device names get a leading _, and long names are cut to 200 bytes keeping the extension. A file without a name gets "file" and its type's extension, unless that extension is a program's.

New dependencies

  • rodio 0.23 (playback only, with Symphonia's AAC/M4A, MP3, Vorbis, FLAC and WAV decoders). GPUI and gpui-component have no audio playback, and this is the smallest cross-platform option. It plays through cpal: CoreAudio on macOS, WASAPI on Windows, ALSA on Linux. Linux already needs libasound2-dev (it's in the README list), so no new system package is needed.
  • image 0.25: already in the tree through GPUI, with the same features. It is used directly to decode pictures small, because GPUI's own Image decoding keeps every pixel of a photo in its cache (about 48 MB for a 12 MP photo).
  • libc, on macOS only, for the quarantine mark (already in the tree).
  • tracing, already in the tree, sends warnings (file ids and errors only) to the core's log. rodio's tracing feature sends sound-output errors there too.

Where the code is

Everything lives in core/desktop/src/app/files.rs (state and logic) and core/desktop/src/app/files/view.rs (drawing). app/mod.rs and app/view.rs change only to hook it in:

  • one field on Hush;
  • the files come from the same client.details call as the reactions (actions::load_reactions), read again on AttachmentChanged;
  • clearing them on select and delete_chat, and deleting a message's opened copies on MessageChanged/MessageExpired once it is gone;
  • deleting opened copies at launch and at quit;
  • the bubble draws the files above its text line, and render_row takes the window's handle for clicks.

Different from the Mac app (say if you want it otherwise)

  • Videos: the Mac app shows a video as a file row that plays in Quick Look. GPUI can't play video in the window, so here the same row opens the decrypted copy in the system's video player. There is no poster frame, because that would need a video decoder; the Mac app doesn't show one either.
  • Open uses the system's app instead of Quick Look. There is no in-window viewer.
  • One recording plays at a time: starting another stops the first, as in Signal Desktop. The Mac app can play several at once.
  • GIFs show their first frame, as the Mac app's thumbnails do. They don't animate.
  • Opus recordings (audio/ogg; codecs=opus) can't be decoded, because Symphonia has no Opus decoder. They say "This recording can't be played" and can still be opened or saved.
  • Picture memory: decoded pictures are kept for the open chat only and decoded again when it is reopened. The Mac app keeps 32 MB of them across chats. This is marked shortcut:.

How it was tested

  • cargo test -p hush-desktop: 37 pass. The new tests were written first and failed against todo!() stubs. They cover:
    • which kind each file shows as, in each state;
    • that deleted, view-once and sticker messages show no files;
    • picture box sizes;
    • the size wording;
    • the recording clock;
    • cleaning sender-chosen names (../, ..\, .., :, ?, trailing dots, con.txt);
    • decoding small, in BGRA order, never enlarging, and refusing still-encrypted bytes;
    • reading a recording's length from WAV bytes;
    • the quarantine mark (macOS);
    • that clearing the opened copies leaves the rest of the data folder;
    • the caption/"Attachment" text.
  • cargo fmt --check, plus cargo clippy -p hush-desktop --all-targets -- -D warnings with and without --features snapshot: clean. The pre-commit hook's workspace clippy also passed.
  • Decoding was also checked by hand against real files made with afconvert/ffmpeg/lame:
    • plays: ffmpeg's ADTS AAC (3.07 s), M4A/AAC (3.07 s), MP3 (3 s);
    • fails: Ogg Opus (not supported), and an afconvert ADTS file that starts with an 11-byte frame (Symphonia stops on it).
  • A new --snapshot screen, files, renders Bogdan's chat. It has a voice message (0:42), Menu.pdf (1.2 MB), a photo still to download, Beach.mp4 downloading, Tickets.zip failed with Retry, a captioned photo and an outgoing photo, in light and dark. The pictures are inside the bubble with 12-point rounded corners. Uncaptioned files have their time under them on the right. The rows, download button, spinner and orange Retry look right in both modes. The existing chat screen is unchanged.
  • make check wasn't run: it needs the signing certificate, which this Mac doesn't have.

Not tested

  • Against a linked phone: no real downloads, AttachmentChanged events, opening or saving with the real core, or sound output. Playing would make sound on this Mac, so it was checked only up to the decoded source.
  • The right-click menu and the save dialog: popups don't render offscreen.
  • Windows and Linux builds: only macOS is installed here. The OS-specific code (the mark) is behind cfg, and rodio/cpal support all three systems.

Closes #136
Part of #157

@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes (commit 5c4d25c, then the merge of main with #180 in ec24ba5).

1. Opened copies pile up and outlive their message: fixed.

  • There is now one decrypted copy per file (Files.copies, by file id, with its chat and message), reused on later clicks. A click while the copy is still being made waits for it.
  • A copy is deleted when:
    • its message expires (MessageExpired);
    • it is deleted (on MessageChanged, client.message(key) reads None or deleted);
    • its chat is deleted (delete_chat).
  • All copies are also deleted at quit and at launch.
  • If a message goes while its copy is being made, the copy is discarded.

2. Programs and scripts are never opened: fixed.

  • The final name (after cleaning) is checked against Signal Desktop's isFileDangerous list, plus macOS's and Linux's own: app command tool terminal workflow pkg mpkg fileloc inetloc sh bash zsh csh ksh desktop deb rpm appimage run bin py pyw pl rb, and url.
  • Such a file's menu has Save As… only. Any click on it (row, picture, Open) saves it instead.
  • A nameless file never gets a program's extension from its content type (application/exe → file).
  • Tests: programs_and_scripts_are_never_opened_only_saved.

3. Direction and format characters in names: fixed. Control characters and Cf characters become _: U+00AD, U+061C, U+180E, U+200B–200F, U+202A–202E, U+2060–2064, U+2066–206F, U+FEFF, U+FFF9–FFFB. Tests include invoice\u{202E}fdp.exe → invoice_fdp.exe, which is then only saved.

4. The media loader kept working on the old chat: fixed. Before each file it checks that the chat is the same (generation, else it stops) and that the file is still wanted: its picture still Loading, or its length still unknown.

5. Opening went through GPUI's silent opener, which logs on Windows: fixed. The app now runs the opener itself, off the main thread:

  • macOS: /usr/bin/open -- <file>;
  • Linux: xdg-open <file>;
  • Windows: explorer.exe <file>, whose exit code is ignored.

The opener's own output is discarded, because it names the file. A failure shows "Couldn't open … : no app here opens this kind of file". Test (macOS): a_file_no_app_opens_is_said.

6. Sound output gone mid-play: fixed.

  • A Clock follows each play. If the position stops moving for 30 ticks (3 s) while playing and not ended, playback stops and the banner says "The recording stopped: the sound output went away".
  • 3 s rather than ~1 s, because Bluetooth outputs can take a second or two to start.
  • rodio's tracing feature is on, so sound-output errors reach the core's log.
  • Test: a_recording_that_stops_moving_while_playing_has_lost_its_output.

7. Leftover copies when one is locked: fixed. Each copy's folder is removed on its own, and failures are logged (the error only).

  • At launch and at quit, every copy folder inside open/ is removed separately.
  • A half-made copy, or a .part file left by a failed save, is also logged if it can't be removed.

8. Decode limits: done.

  • Decoding now has limits: max_alloc of 64 MP × 4 bytes, and pictures over 64 MP are refused and shown as a file.
  • EXIF orientation is applied after shrinking.
  • A broken EXIF falls back to no rotation instead of failing the picture.
  • Test: a_photo_is_turned_as_it_says_after_it_is_made_small (EXIF orientation 6 on 40×20 → 20×40, and on 1280×640 → 320×640).

9. Picture memory is uncapped: stated, not capped. A real LRU needs pictures to load per drawn row, which is a rework (GPUI's image_cache element would do it). The shortcut: comment now gives the figure: up to 1.6 MB a picture, about 160 MB for a page of 100 photos, kept until another chat opens. The PR body says the same. A follow-up issue is worth filing if photo-heavy chats need it.

10. Playback: done.

  • The clock redraws only when the shown second or track pixel changes.
  • Recordings over 50 MB show as a file row that opens in the system's player.
  • The sound output closes after 2 minutes paused (the next play starts over) and on chat change.
  • The output device is opened off the main thread, along with decoding (start).

11. One client.details call: done, reusing #180's. #180 merged first, so files now come from its load_reactions details call. That is one shared call per page, folded and checked against the chat (files_loaded, three lines added in actions/mod.rs). AttachmentChanged reads the page's details again. A message the core couldn't read keeps the files it showed. Test: a_message_the_core_couldnt_read_keeps_its_files.

12. Names: done.

  • Names are cut to 200 bytes, keeping the extension and whole characters.
  • COM0–9, COM¹²³, LPT0–9, LPT¹²³, CONIN$ and CONOUT$ are now reserved too.
  • Test: names_lose_direction_marks_and_windows_devices_and_stay_short.

13. Sticky failures: done.

  • clear_files also clears unplayable and the lengths.
  • Read and decode failures are logged separately, with the file id and the error.
  • A picture that didn't read or decode shows as a file row, so Open says why, instead of a grey box read again on every reload.

14. Save As: done. The .part file is fsynced before the rename. A failed .part removal is logged. The error text now says "the file's path".

15. Retry for files without a pointer or too large: left to your core issue, as asked.

16. Ids keyed by row index: nothing to change. Every file element and its right-click menu is keyed by the attachment id (("file", id), ("play", id), ("retry", id), ("download", id), and the menu derives from them), never by the row index.

Owner's voice notes (one-off, uncommitted test, read-only, nothing copied or kept): all 9 decode, 4 ADTS AAC and 5 M4A. Durations: 5.7, 12.8, 15.3, 15.3 s (ADTS); 7.2, 3.3, 4.9, 8.1, 17.2 s (M4A).

Checks:

  • cargo fmt --check: clean.
  • cargo clippy -p hush-desktop --all-targets -- -D warnings, with and without --features snapshot: clean.
  • cargo test -p hush-desktop: 54 pass. The 7 new tests failed against todo!() stubs first; the orientation test passed from the start, because it guards the reordering rather than a bug.
  • Snapshots: files and reply (light and dark) show files, quotes, reactions and the action bar together after the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The desktop app shows pictures, videos, voice messages and files in chats

1 participant