Skip to content

The desktop app's times keep up while it sits idle and follow the 12/24-hour setting - #241

Merged
pitis merged 2 commits into
mainfrom
feat/desktop-live-times
Nov 28, 2026
Merged

pitis merged 2 commits into
mainfrom
feat/desktop-live-times

Conversation

@pitis

@pitis pitis commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • Times keep up in an idle window. The desktop app works out its times while drawing the window: the chat list's "Now"/"5m", search results, stories, and the timeline's day separators and event lines. It now draws the window again as each minute starts (Hush::observe). The time comes from GPUI's clock: the system's in the app, the test's in tests. So "Today" turns into "Yesterday" at midnight, and "14:05" into "Mon", without anything else redrawing. This matches the Mac app's TimelineView(.everyMinute) and its midnight refreshDays.
  • Bubble times follow the system's 12/24-hour choice: "9:05 AM" or "09:05", as the Mac app's short time style (Formatting.bubbleTime) does. The choice comes from the OS (src/clock.rs):
    • macOS: the current locale's short time pattern (NSDateFormatter, short time style). The formatter is made the way the Mac app makes its own, so System Settings' 24-hour switch applies to both apps alike.
    • Windows: the user's short time format (GetLocaleInfoEx, LOCALE_SSHORTTIME).
    • Linux: on GNOME, gsettings get org.gnome.desktop.interface clock-format, because GNOME's switch sets that and not the locale. Elsewhere, or if that can't be read, the locale's T_FMT (newlocale + nl_langinfo_l).
    • Deciding 12 or 24 hours from a pattern is pure code with unit tests. Quoted text counts as text, not as an hour: Canadian French's HH 'h' mm is 24-hour.
    • The setting is read once, at launch, off the window's thread (on GNOME it runs gsettings). A change shows from the next launch, as the Mac app also makes its formatter once (Formatting.cached).
    • A failed read falls back to 24 hours, as before this PR. It logs why: the OS error, gsettings' exit status, or a value it doesn't know.
  • No new crates. The change only turns on features of crates the app already uses (objc2-foundation's NSDateFormatter, windows-sys's Win32_Globalization). It also adds libc, already in the tree, as a Linux dependency. Cargo.lock is unchanged.

Kept as the Mac app has it

  • The chat list's time for today stays "14:05" on both clocks. The Mac app formats it as fixed HH:mm (Formatting.listTime). Only bubble times follow the system clock, on the Mac and now here.
  • The window redraws on the minute, as .everyMinute does. Clock times and the midnight change are on time. "Now" turns into "1m" at the first minute start after the message is 60 seconds old, as on the Mac.

Shortcuts (// shortcut: in src/clock.rs)

  • Only the 12/24-hour choice is followed. Times are written in English ("9:05 AM"), not in the locale's whole style (Canadian French's "09 h 05", Korean's "오후 9:05").
  • On Linux, only GNOME's switch or the locale is followed. Cinnamon's, XFCE's and MATE's clocks have a 12/24-hour switch of their own. KDE sets LC_TIME, so it is covered.

How it was tested

Each new test failed before the change (checked against stubs and without the minute redraw):

  • an_idle_window_draws_its_times_again_as_each_minute_starts (window test). It moves the test clock to 1 ms before the next minute starts (0 redraws), then to the minute start (1), then to 1 ms before the following one (still 1), then to that start (2). Without the minute loop it drew 0 times; with a loop going by the real clock it drew 3 times in one minute.
  • the_times_are_drawn_again_as_each_minute_starts: the wait until the next minute starts.
  • bubble_times_read_on_the_clock_chosen: "9:05 AM", "2:30 PM", "12:00 AM", "12:15 PM" / "09:05", "14:30".
  • a_time_pattern_says_which_clock, a_locales_time_format_says_which_clock: macOS and Windows patterns, and glibc time formats. A mutation check confirms the quoted-text cases fail without the quote handling.

Gate, from core/ with CARGO_INCREMENTAL=0 (all pass):

  • cargo fmt --check
  • cargo clippy --all-targets -q -- -D warnings
  • cargo clippy --all-targets --features hush-desktop/snapshot -q -- -D warnings
  • cargo test --features hush-desktop/snapshot -q (295 + 537 passed)

The gate was run last on the branch head after make update; main had not moved.

Also:

  • macOS read on this Mac: it gives HH:mm, the same pattern a Swift DateFormatter(timeStyle: .short) gives here. With -AppleLocale en_US, Swift gives h:mm a, which the parser reads as 12-hour.
  • Windows and Linux reads: they type-check and pass clippy -D warnings for x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu. That was a scratch crate holding only clock.rs, because the whole app needs C cross-compilers for SQLCipher. They have not been run on Windows or Linux.
  • Snapshots (--snapshot): looked at on this Mac's 24-hour clock (unchanged). I also rendered them once with the 12-hour clock forced, as a temporary local edit that isn't committed. "6:20 PM" fits the bubbles and the times laid over pictures; the chat list keeps "18:05".

The Swift leg of make check (xcodebuild) was skipped: nothing in app/ changes.

Closes #227

…24-hour setting

An idle window draws itself again as each minute starts, so the chat
list's relative times and the day separators move on (Today becomes
Yesterday at midnight). Bubble times follow the system's 12/24-hour
choice: the locale's short time on macOS, the short time format on
Windows, GNOME's clock format or the locale's on Linux.
…why it failed

The redraw reads the time from GPUI's scheduler clock (the system's,
or in tests the test's), so the window test checks one redraw per
minute start, exactly. The quoted-text tests reach the quote branch.
The setting is read off the window's thread at launch; failed reads
log their cause; %OI counts as a 12-hour hour; comments corrected.
@pitis

pitis commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Review (/pr-review-toolkit:review-pr: code, tests, comments, silent failures)

The review found no Critical issues and three Important ones, all fixed in d9fa9e7. The gate passes on d9fa9e7, the branch head after make update (main had not moved): fmt, both clippy runs, and tests (295 + 537 passed). The Windows and Linux reads type-check and pass clippy again, for x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu.

Important: fixed

  1. The window test couldn't catch the window redrawing too often (tests). The loop worked out its wait from the real clock, but in tests it slept on the fake one. So a minute of test time could hold several redraws, and the test only asserted >=.
    • Fix: the loop now reads the time from GPUI's scheduler clock (now_ms). In the app that is Utc::now(); in tests it is the test clock, which advance_clock moves.
    • The test now checks exact counts: 0 redraws 1 ms before the minute starts, 1 at the start, still 1 a millisecond before the next start, 2 at that start.
    • It fails against the old loop (3 redraws in one minute).
  2. The quoted-text tests never reached the quote branch (tests). "HH 'h' mm" hits the H first, and "'o''clock' HH:mm" gave the right answer through the k in "clock".
    • Fix: added "'h' HH:mm" (24-hour) and "'o''clock' h:mm a" (12-hour).
    • A mutation check with the quote handling removed now fails the test.
  3. The to_next_minute doc claimed "Now" turns into "1m" on time (comments). It doesn't. Relative times are counted from the message's own send time, so they change up to 59 s after that point, as with the Mac app's .everyMinute.
    • Fix: reworded. Relative times move on within a minute of their change; clock times and day names change as it happens.

Suggestions: applied

  • Reading off the window's thread. The 12/24-hour setting is now read at launch on GPUI's background pool (Hush::new), not during the first bubble's render. On GNOME, that read runs gsettings. (Raised by the code and silent-failure reviewers.)
  • Warnings say why a read failed:
    • the Windows error code (last_os_error);
    • for gsettings, the spawn error, the exit status, or the value it didn't know;
    • a failed newlocale (its errno), which was silent before.
  • %OI (the locale's own digits) now counts as a 12-hour hour. A test covers it.
  • Comments:
    • TWELVE_HOUR says it is about bubble times only, and that the chat list keeps "14:05", as the Mac app's does.
    • The first shortcut names locales where the style differs today (Canadian French "09 h 05").
    • A new shortcut names the Linux desktops whose own switch isn't read (Cinnamon, XFCE, MATE).
    • The "read once" line is no longer marked a shortcut, because the Mac app also makes its formatter once (Formatting.cached).
    • "as before" in a test became "every read's fallback".

Suggestions: declined, with reasons

  • Test that the text on screen changes ("Now" to "1m"), not only that a redraw happens. Every view takes chrono::Local::now() while it draws. Moving all of them onto the executor clock would reach beyond this issue. list_time and day are already unit-tested with an explicit now. GPUI's list re-renders visible rows each frame (layout_items), and the code reviewer confirmed nothing caches a formatted time.
  • Test the macOS read with a fixed locale. That would mean changing the read only for the test. The read was checked by hand on this Mac: HH:mm, the same pattern Swift's DateFormatter(timeStyle: .short) gives.
  • Pull the GNOME branch out into a pure function with its own test. It is two string comparisons, and the cross-check type-checks it. Not worth a separate function.
  • Test that the minute loop stops when the window goes. It holds a WeakEntity and ends on its first failed update, the same pattern as the playback and typing loops. Closing the window also quits the app.
  • A test of bubble_time reading TWELVE_HOUR. It would be a tautology.
  • Read GNOME's setting through the xdg-desktop-portal, to work inside Flatpak. The app isn't packaged as a Flatpak; revisit if it ever is.

Known limits (no change)

  • GPUI's timers on macOS and Linux don't count time asleep, and libdispatch may fire one a little late. So after a wake past midnight, an untouched window can show "Today" for up to a minute. Any activation or hover redraws it at once.

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's times keep up while it sits idle and follow the 12/24-hour setting

1 participant