Skip to content

The desktop app sends pictures and files - #187

Merged
pitis merged 2 commits into
mainfrom
feat/desktop-send-files
Nov 14, 2026
Merged

pitis merged 2 commits into
mainfrom
feat/desktop-send-files

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

The desktop app can send pictures and files, as the Mac app does (ComposerView.swift's FileTray, AppStore.addFiles and send, Composer.pastedFiles):

  • Attach: a round "+" beside the message field opens the system's file picker (several files, no folders). Chats ▸ Attach Files… does the same, with ⇧⌘A (Ctrl+Shift+A on Windows and Linux).
  • Drag and drop onto the chat. A frame shows while files are over it. A chat without a composer (requests, blocked) doesn't take them.
  • Paste (⌘V/Ctrl+V in the composer) uses the Mac's rule. Copied files are attached. Text is pasted as text, even when it comes with a picture of itself (as from a word processor). A picture alone, like a screenshot, is saved as Pasted image xxxxxxxx.png and attached. GPUI's clipboard gives files on macOS and Windows, and pictures on all three systems. On Linux, files copied in a file manager paste as their paths' text, because GPUI doesn't read them there (a shortcut: comment in paste); dropping them or using "+" works.
  • Tray above the field. Each file shows its thumbnail (pictures) or a file icon, its name and ✕ ("Remove …"). Each file is added only once. The send button shows while files wait, even with no text.
  • Sending uses send_attachments with the text and its styles as the caption (none if it's empty), and the reply's quote goes with it. Pressing ↩ while a dropped or pasted file is still being read waits for it, so a caption never goes without its picture. If the send fails, the files and the words go back. The error is the core's text, as on the Mac: "Menu.pdf is larger than 100 MB". If another chat was opened meanwhile, the error also says that the files weren't sent. A failed upload is an ordinary failed message, so the existing Retry handles it.
  • While editing, no files can be added: an edit changes only the text. Files already in the tray wait for the next message, and the send button shows only for words. When the picker answers after a dialog was opened, the dialog keeps the keyboard.
  • Leaving the chat (another chat opens, or it's deleted) empties the tray, as on the Mac.
  • Pasted pictures are written to the desktop app's own data folder (Hush Desktop/paste, which only we can read; never the Mac app's). They're deleted once the core has its encrypted copy, when they leave the tray, and at launch and quit. The user's own files are never touched.
  • Each file sent carries its type, worked out from its extension. Pictures also carry their pixel size as shown: a photo whose EXIF turns it a quarter has width and height swapped, as the Mac does.

The code is in its own module, core/desktop/src/app/attach.rs. It hooks into send, select/delete_chat, the composer row, the chat view and the menu. It reuses files::thumbnail for the tray's pictures.

New direct dependency: mime_guess (default features off), to get a file's type from its extension. It's already built in this tree through reqwest with the same features, so nothing new is compiled, and it is pure Rust on all three systems.

Why

Closes #137. Part of #157.

How it was tested

  • Unit tests in attach.rs:

    • the paste rule (files first, then text, then a picture)
    • describing a file: its type by extension in any case, the size of a turned photo, a broken picture still sent as a file, folders and missing files skipped
    • writing a pasted picture as a PNG (BMP converted, unreadable data refused with the Mac's wording)
    • a file is added to the tray only once
    • only pasted pictures are deleted, including a paste/../x path that only looks like one
    • clearing the paste folder at launch and quit
  • Window tests (headless GPUI, --features snapshot) using real keys and real drop events:

    • ⌘V of a copied file, of text with a picture, and of a screenshot
    • dropping files and a folder, including a duplicate
    • ⇧⌘A opening the picker and its answer filling the tray; no picker and no paste while editing
    • leaving the chat empties the tray and deletes the pasted PNG
    • a failed send refills the tray first; a sent one deletes the pasted PNG

    I broke each hook in turn (no drop handler, no paste capture, no clearing on select, edits allowed) and confirmed its test fails.

  • Window tests from the review:

    • the picker's answer leaves a dialog's field focused;
    • the send button shows for files, but not for an edit without words;
    • a failed send of a file the core refuses (a sparse 100 MB+ file, through an unlinked core) brings back the files, the words, the reply and the core's wording;
    • ↩ right after ⌘V waits for the file and sends the words with it.
  • Unit tests for what ↩ sends (text, files with or without a caption, an edit only, waiting) and for the error after a chat switch.

  • cargo fmt --check, cargo clippy -p hush-desktop --all-targets -- -D warnings (with and without --features snapshot), cargo test -p hush-desktop (90) and --features snapshot (106) all pass.

  • I checked the snapshots (light and dark). The "files" screen now has a pasted screenshot and a PDF waiting in the tray, the "+" button and the send button. The "chat" and "reply" screens show the "+" beside the field, with the reply bar spanning the full width above.

Not tested

  • The live window: the native file picker on each system, the frame while dragging (offscreen rendering has no drag state), and pasting from the real clipboards of Windows and Linux. The paste rule is built on what GPUI's clipboard code reads on each system.
  • A real send: the app isn't linked to a phone here. The send_attachments call is the Mac app's.
  • Building on Windows and Linux: nothing in this change is system-specific.
  • make check needs a signing certificate this Mac doesn't have. The core is unchanged.

Files chosen with the + button or Attach Files (Shift-Cmd-A, Ctrl elsewhere), dropped on the
chat or pasted wait in a tray above the composer and go with the next message, its text as
their caption. A pasted picture is written as a PNG into the data folder and removed once the
core has its copy, once it leaves the tray, and at launch and quit. A failed send puts the files
back in the tray.
…files

The send keeps formatted text's words, styles and drafts, and passes the styles as the files'
caption's. The picker's answer leaves a dialog opened meanwhile its keys. The send button hides
while editing without words. A return pressed while files are being added waits for them. A
failed send says the core's words, and that its files weren't sent once another chat is open.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes, in 7c16f9b (merged with main after #186, test-first: each new test failed before its fix).

Merge with #186. send is #186's (typed, compose::message, set_typed, drafts keep the words) with the files branch added. The caption's styles go to send_attachments. The composer is with_compose(with_composer_bar(with_attach(…))), and attach::keys() is in key_bindings(), so every_shortcut_parses covers ⇧⌘A.

Rulings applied

  • "+" stays a button until stickers (The desktop app shows and sends stickers #151).
  • Send failures show the core's words, as the Mac does (describe(&e)): "Menu.pdf is larger than 100 MB", without the "Couldn't send the message:" prefix. This applies to text sends too.
  • Linux: files copied in a file manager paste as path text because GPUI doesn't read them. This is now a shortcut: comment in paste and a note in the PR body.

1 (Important), the picker's answer took the keys from a dialog opened meanwhile. Fixed. The composer gets the focus back only if can_attach() (no dialog, chat writable). The files chosen still join the chat's tray: a dialog no longer blocks adding, only the picker and the refocus. Test: the_pickers_answer_leaves_a_dialog_opened_meanwhile_its_keys opens Username during ⇧⌘A and then answers the picker.

2, "Save edit" showed and did nothing while editing with files and no words. Fixed. shows_send() is true for words, or for files when not editing. Test: the_send_button_shows_for_files_but_not_for_an_edit_without_words.

3, a caption could go without a file still being added. Fixed. adding counts the adds in progress (reading a file, writing a pasted picture). ↩ during an add sets send_waiting and keeps the words in the composer. The last add to finish sends, unless an edit started meanwhile. Leaving the chat cancels the wait. Test: return_while_a_file_is_being_added_sends_the_words_with_it does ⌘V then ↩ in the same tick; the words wait, then go with the file.

4, a failed send after a chat switch dropped its files silently. Fixed. unsent() says what didn't come back, for example "…. Its text is back in its chat, without the quote, and its files weren't sent." or "…. Its files weren't sent." Unit test: a_send_whose_words_went_to_a_draft_says_what_wasnt_sent.

5, send() with files had no tests. Fixed. The decision is now a pure attach::plan(words, editing, adding, files) returning Nothing, Edit, Wait, Text or Files { caption }. send() acts on it. Unit test return_sends_files_with_their_caption_and_an_edit_only_its_words covers:

  • files are sent instead of text;
  • the caption is None without words;
  • an edit with files waiting does only the edit;
  • a send waits while files are being added.

The window test a_failed_send_brings_back_its_words_files_and_reply_in_the_mac_apps_words goes end to end. It uses an unlinked core and a sparse file over 100 MB, which only send_attachments refuses. It checks:

  • the error is "big.pdf is larger than 100 MB";
  • the file goes back to the tray, and the words go back into the composer;
  • the reply comes back;
  • composer_empty is false with words and true for files alone, and the send button still shows for the files.

Observation (#186's code, not changed here). In the headless tests, a simulated Enter puts "\n" into the field before PressEnter fires. #186's failure path restores typed as it was when sent, so the restored words had a trailing newline. My tests call send directly. Whether a real platform does the same is unchecked.

Checks: cargo fmt --check; clippy -D warnings with and without --features snapshot; cargo test -p hush-desktop (90) and --features snapshot (106). I re-rendered the snapshots after the merge: the "files" screen shows the tray, "+" and send button; the "compose" screen shows the mention picker and preview over the field, with "+" beside it.

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 sends pictures and files

1 participant