//! The meeting capsules on Rune: the calendar meeting reminder, the //! recording offer, "left the call", the ready transcript, and the recording //! capsule. Each is an //! interactive Rune overlay, which on macOS is a non-activating `NSPanel`: //! its buttons take clicks while the call app keeps focus and Hex never //! activates. An offer that times out only closes; nothing starts or stops //! on a timeout, and the call is offered again once its app releases and //! retakes the microphone. //! //! `macos_rune` and `meeting_runtime` forward controller events; buttons //! send `ControllerCommand`s back to the controller. //! //! The recording capsule's "Copy new" and "Copy all" copy the in-call //! transcript (Parakeet, `meeting::TranscriptReader`); "Copy new" shares //! Option-Control-V's cursor and first transcribes the call up to the click //! (`meeting::entries_for_copy`), saying "Transcribing…" meanwhile. "Copy //! agent prompt" copies instructions that tell a coding agent which `hex //! meetings` commands read the meeting. The ready panel offers the same three //! under the finished meeting's title and summary. //! //! The recording capsule rests as a small pill in its corner, with a recording //! dot, the dictation HUD's listening field and a timer. It opens into Stop and its //! copies while the pointer is over it. Dragging it moves the window; on //! release it glides into a corner, which is saved. //! It is a function of the controller's current recording and the live //! Show recording indicator setting ([`PillModel`]): the call-ended prompt //! stands in for it until Keep recording, and turning the setting on or off //! mid-recording shows or hides it within a second. //! The panel capsules (offer, reminder, call ended, ready, recording //! automatically) show in that same saved corner and drag the same way. A //! throw carries a capsule toward the corner it heads for ([`throw`]). //! //! On a Linux Wayland compositor without layer-shell (GNOME) the capsules //! float on XWayland only with Labs › Call recording controls on GNOME //! (`linux::meeting_capsules`); otherwise an offer opens the Meetings pane. use std::cell::Cell; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::mpsc::SyncSender; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; #[cfg(not(target_os = "windows"))] use rune::OverlayInput; use rune::{ Align, Anim, Cursor, Cx, Drag, El, OverlayHandle, OverlaySpec, Phase, ScreenEdge, Spring, Tx, col, row, text, }; use rune_kit::{Button, ButtonVariant, ControlSize, IconButton, IconButtonVariant}; use super::controls::{Paint, PushSize, status_dot}; use crate::app_settings::{MeetingIndicatorCorner, MeetingPolicy, MeetingProviderChoice}; use crate::calendar::CalendarMeeting; use crate::desktop::i18n::{tr, tr_fill}; use crate::meeting::detection::{MeetingCandidate, OfferId}; use crate::meeting::watcher::{ControllerCommand, ControllerEvent}; use crate::meeting::{self, MeetingManifest, TranscriptEntry}; mod handoff; mod offer; #[path = "meeting_capsules/offer/surface.rs"] mod offer_surface; mod panel; mod presence; mod screen; mod stage; mod throw; mod waveform; use panel::{ agent_prompt, finalizing_window_size, hex_command, ready, ready_window_size, recording, recording_window_size, }; use screen::primary_screen_size; /// The offer, call ended, and ready capsules. const MEETING_PANEL_WIDTH: f32 = 420.0; /// The offer's "…" choices need room for three buttons beside the name. #[cfg(test)] const MEETING_MENU_WIDTH: f32 = 560.0; const MEETING_PANEL_HEIGHT: f32 = 64.0; /// Between a capsule's buttons and its right edge. const ACTIONS_INSET: f32 = 8.0; /// The reminder: the meeting's title beside up to three buttons. const REMINDER_PANEL_WIDTH: f32 = 520.0; /// "Microsoft Teams left the call" beside Keep recording and Stop & /// transcribe (#835). const CALL_ENDED_PANEL_WIDTH: f32 = 520.0; /// How often an open reminder recounts "Starts in N min". const REMINDER_TICK: Duration = Duration::from_secs(5); /// Between a capsule's window edges and what it draws. const CAPSULE_INSET: f32 = 4.0; /// Same header at rest and open so the waveform and timer stay put. const REST_HEIGHT: f32 = HEADER_HEIGHT; const REST_WIDTH: f32 = 2.0 * REST_PX + waveform::WIDTH + METER_GAP + TIMER_WIDTH; /// The header's sides, at rest and open, so the timer stays put as the pill /// opens: the inset the rows' labels, the title and the summary keep. const REST_PX: f32 = PANEL_PAD + ROW_PX; /// Between the listening field and the time. const METER_GAP: f32 = 6.0; /// "00:00" in the timer's 13 pt monospaced digits, at layout resolution. const TIMER_WIDTH: f32 = 39.0; /// The open recording pill and the ready panel. const PANEL_WIDTH: f32 = 252.0; const PANEL_RADIUS: f32 = 13.0; /// Around the open panel's rows. const PANEL_PAD: f32 = 5.0; const HEADER_HEIGHT: f32 = 36.0; const ROW_HEIGHT: f32 = 44.0; const OPEN_HEADER: f32 = REST_HEIGHT + ROW_HEIGHT; /// The three copies and the gap under the raised one. const COPIES_HEIGHT: f32 = 3.0 * ROW_HEIGHT + ROW_GAP; /// Concentric with the panel across [`PANEL_PAD`]. const ROW_RADIUS: f32 = PANEL_RADIUS - PANEL_PAD; /// A row's icon and label inset; titles and summaries share it. const ROW_PX: f32 = 9.0; /// Between two rows that can both be filled: under the raised first copy, /// and between Stop and the copies. const ROW_GAP: f32 = 2.0; /// "Microphone is silent" or "Started automatically" under the header. const NOTICE_HEIGHT: f32 = 20.0; /// The ready panel's summary: the notes writer's two sentences. const SUMMARY_LINES: usize = 3; const TITLE_LINES: usize = 3; const TITLE_INSET: f32 = (REST_HEIGHT - 20.) / 2.; const RESULT_HEADER_MAX: f32 = REST_HEIGHT + TITLE_LINES as f32 * 20. + 2. * TITLE_INSET; const SUMMARY_LINE: f32 = 19.5; /// One transparent window with room for the finished panel's longest summary. const RECORDING_WINDOW: (f32, f32) = ( PANEL_WIDTH + 2.0 * CAPSULE_INSET, RESULT_HEADER_MAX + SUMMARY_LINE * SUMMARY_LINES as f32 + ROW_PX + ROW_GAP + ROW_GAP + COPIES_HEIGHT + PANEL_PAD + 2.0 * CAPSULE_INSET, ); /// The finished meeting's title and summary grow the panel on this. const RECORDING_OPEN: Spring = Spring::new(0.42, 0.0); /// A start this quick never says "Starting…": the offer contracts straight /// into the live pill. const PENDING_LABEL_AFTER: f64 = 0.18; /// How long a copy says "Copied". const COPIED_FEEDBACK: Duration = Duration::from_millis(1_500); const OFFER_TIMEOUT: Duration = Duration::from_secs(20); const READY_TIMEOUT: Duration = Duration::from_secs(15); /// How long after an offer Linux checks that its overlay opened. #[cfg(target_os = "linux")] const OFFER_CHECK: Duration = Duration::from_secs(2); /// How long an automatic recording says so before showing its elapsed time. const AUTOMATIC_LABEL: Duration = Duration::from_secs(10); const WINDOW_MARGIN: f32 = 12.0; /// Below the menu bar. const MENU_BAR: f32 = 28.0; /// Above the Dock. const DOCK: f32 = 24.0; #[derive(Clone)] enum Kind { /// A calendar meeting is about to start; `automatic` when its call /// service is set to Always record. Reminder { meeting: CalendarMeeting, automatic: bool, }, Offer(OfferId, MeetingCandidate), /// `auto_stop` when the recording stops on its own after a grace (Labs /// › Stop when the call ends); Keep recording then cancels that. CallEnded { app: String, auto_stop: bool, }, Ready(Box), Finalizing { duration_ms: u64, }, /// An automatic recording while the recording indicator is off. AutoStarted { title: String, }, Recording(Recording), } /// The recording the controller reported, as its capsule draws it. #[derive(Clone)] struct Recording { id: String, title: String, started: Instant, automatic: bool, /// The microphone is digitally silent (#1518). warning: Option, } /// What the recording capsule is a function of, besides the live Show /// recording indicator setting: the controller's current recording, and /// whether the call-ended prompt stands in for it. #[derive(Default)] struct PillModel { recording: Option, /// The call-ended prompt shows instead of the pill until Keep recording, /// or until another panel capsule replaces it. call_ended: bool, /// The recording the pill shows now. shown: Option, /// Where this recording was last shown, kept through transcription for its summary. last_anchor: Option<(String, MeetingIndicatorCorner)>, } impl PillModel { fn apply(&mut self, event: &ControllerEvent, now: Instant) { match event { ControllerEvent::RecordingStarted { id, title, automatic, } => { self.recording = Some(Recording { id: id.clone(), title: title.clone(), started: now, automatic: *automatic, warning: None, }); self.call_ended = false; } ControllerEvent::Retitled { title } => { if let Some(recording) = &mut self.recording { recording.title = title.clone(); } } ControllerEvent::SourceWarning { warning } => { if let Some(recording) = &mut self.recording { recording.warning = *warning; } } ControllerEvent::CallEnded { .. } => self.call_ended = true, // The call came back before its grace: the notice goes and the // recording capsule returns, as Keep recording does. ControllerEvent::CallEndedWithdrawn => self.call_ended = false, ControllerEvent::Offer(..) | ControllerEvent::Reminder { .. } => { self.call_ended = false; } ControllerEvent::Starting(_) | ControllerEvent::Transcribing | ControllerEvent::Finished(_) | ControllerEvent::Failed { .. } => { self.recording = None; self.call_ended = false; } ControllerEvent::OfferWithdrawn(_) | ControllerEvent::ReminderWithdrawn { .. } | ControllerEvent::Stopping | ControllerEvent::Chapters(_) | ControllerEvent::ImportFailed { .. } | ControllerEvent::NotesProgress(_) | ControllerEvent::NotesFinished(_) => {} } } fn keep_recording(&mut self) { self.call_ended = false; } /// The recording the pill shows with the indicator setting `indicator`. fn pill(&self, indicator: bool) -> Option<&Recording> { self.recording .as_ref() .filter(|_| indicator && !self.call_ended) } } #[derive(Clone, Copy, Debug, PartialEq)] enum LiveCopy { New, All, Prompt, } /// The shown meeting's transcript as last read: the recording's in-call /// transcript by the ticker, or the ready meeting's when it shows. #[derive(Default)] struct Live { /// A swipe within a wide action row is not a click, even on release inside it. row_swiped: bool, entries: Vec, /// What Copy new would copy now. pending: meeting::PendingDelta, copied: Option<(LiveCopy, Instant)>, /// Copy new is transcribing up to the click. copying: bool, } impl Live { fn copied(&self, kind: LiveCopy) -> bool { self.copied .is_some_and(|(copied, at)| copied == kind && at.elapsed() < COPIED_FEEDBACK) } } struct Capsule { kind: Option, /// The offer shows its Never offer / Always record choices in place of /// its actions. more_open: bool, /// Arms another 20 s if Cancel returns to an offer whose timer already fired. rearm_offer: Option, presentation: offer_surface::Presentation, /// The recording host's outline and layers in motion. stage: stage::Stage, /// The whole surface arriving and leaving, and its lines changing. surface: presence::Surface, live: Live, waveform: Option>, commands: SyncSender, hide: Option>, show: Option>, /// The call-ended prompt's Keep recording brings the recording capsule /// back. keep_recording: Option>, resize: Option, choose: Choose, /// The pointer is over the recording pill (or holding it), or over the /// ready panel. hovered: bool, /// The command was accepted, but the worker has not reported capture stopped. stopping: bool, /// A timeout arrived while the ready panel was hovered or the offer's /// choices were open. Leaving closes the former; Cancel rearms the latter. expired: bool, /// Where the capsule rests. corner: MeetingIndicatorCorner, /// Moves the capsule's window by a drag's travel from `corner`. shift: Option, /// The drag in progress and the glide into a corner after it. throw: throw::Throw, /// Reduce Motion, as the view last read it: a release jumps to its /// corner. reduced: Cell, /// The window's scale, as the view last read it: device pixels per point. scale: Cell, /// The primary screen in points, for a release's corner; a type that /// tests can replace with no screen at all. screen: ScreenFn, save_corner: SaveCorner, /// Reads a recording's transcript through now off the main thread, then /// calls [`Capsule::finish_copy_new`]. Without it, Copy new copies what /// the ticker last read. copy_new: Option, } type Choose = Arc; type CopyNew = Arc; /// Sets the capsule window's size in points. type Resize = Arc; type Shift = Arc; type SaveCorner = Arc; /// The primary screen in points, given the window's pixels-per-point scale. type ScreenFn = fn(f32) -> Option<(f32, f32)>; impl Capsule { fn send(&self, command: ControllerCommand) -> bool { self.commands.try_send(command).is_ok() } /// The meeting whose transcript the capsule copies: the recording, or /// the ready meeting. fn meeting_id(&self) -> Option<&str> { match &self.kind { Some(Kind::Recording(Recording { id, .. })) => Some(id), Some(Kind::Ready(manifest)) => Some(&manifest.id), _ => None, } } /// Windows sizes the recording capsule's window to the pill it draws. /// Elsewhere the window stays at its largest and only the `.hit()` pill /// takes the pointer. #[cfg_attr(not(target_os = "windows"), allow(dead_code))] fn fit_recording_window(&self) { if self.presentation.inherits_offer_window() { return; } if let (Some(resize), Some(Kind::Recording(shown))) = (&self.resize, &self.kind) { resize(recording_window_size(self.open(), Some(shown))); } } /// The recording's pill is held open: by the pointer, or by Stop. fn open(&self) -> bool { self.hovered || self.stopping } fn set_hovered(&mut self, inside: bool) { if self.presentation.blocks_hover(inside) { return; } self.hovered = inside; #[cfg(target_os = "windows")] self.fit_recording_window(); if !inside && self.expired && matches!(self.kind, Some(Kind::Ready(_))) { self.close(); } } /// Saves the offered provider's choice; returns whether there was one. fn choose(&self, policy: MeetingPolicy) -> bool { let Some(Kind::Offer(_, candidate)) = &self.kind else { return false; }; let Some(provider) = candidate.provider() else { return false; }; tracing::info!(key = %provider.key, ?policy, "meeting provider choice made from an offer"); (self.choose)(provider.choose(policy)); true } /// Closed from this moment; the window hides once the surface has gone. fn close(&mut self) { let kind = self.kind.take(); self.surface.leave(kind); } /// Notes update an existing summary; they never present one. fn refresh_ready(&mut self, manifest: Box) { if let Some(Kind::Ready(ready)) = &mut self.kind && ready.id == manifest.id { *ready = manifest; #[cfg(target_os = "windows")] if let Some(resize) = &self.resize { resize(ready_window_size(ready)); } } } /// The pending stop the notice named was withdrawn: the automatic stop's /// notice goes. The "still recording" notice names no stop, and a newer /// panel of another kind stays, as [`ControllerEvent::ReminderWithdrawn`] /// leaves another reminder alone. fn withdraw_call_ended(&mut self) -> bool { if !matches!( self.kind, Some(Kind::CallEnded { auto_stop: true, .. }) ) { return false; } self.close(); true } fn press_copy_new(&mut self, tx: &mut Tx) { let Some(id) = self.meeting_id().map(str::to_owned) else { return; }; if self.live.copying { return; } match self.copy_new.clone() { Some(copy_new) => { self.live.copying = true; copy_new(id); } None => { let entries = self.live.entries.clone(); self.copy_new_from(&id, &entries, tx); } } } /// Copies the new turns of `entries`, read through the click for the /// meeting `id`, if it still shows. fn finish_copy_new( &mut self, id: &str, entries: color_eyre::Result>, tx: &mut Tx, ) { // A reply for an earlier meeting leaves the shown one's copy alone. if self.meeting_id() != Some(id) { return; } self.live.copying = false; match entries { Ok(entries) => self.copy_new_from(id, &entries, tx), Err(error) => tracing::warn!(%error, "could not read new meeting transcript turns"), } } fn copy_new_from(&mut self, id: &str, entries: &[TranscriptEntry], tx: &mut Tx) { // Rune's clipboard write has no acknowledgment, so the cursor commits // once it is queued (as GPUI's Copy new did). match meeting::try_consume_delta_from(id, entries, |text| { tx.copy(text.to_owned()); Ok(()) }) { Ok(_) => { if entries.len() > self.live.entries.len() { self.live.entries = entries.to_vec(); } self.live.pending = meeting::PendingDelta::default(); self.live.copied = Some((LiveCopy::New, Instant::now())); } Err(error) => tracing::warn!(%error, "could not copy new meeting transcript turns"), } } fn copy_all(&mut self, tx: &mut Tx) { let markdown = match &self.kind { Some(Kind::Recording(_)) if self.live.entries.is_empty() => return, Some(Kind::Recording(_)) => meeting::transcript_markdown(&self.live.entries), Some(Kind::Ready(manifest)) => { match meeting::transcript_markdown_for_manifest(manifest) { Ok(markdown) => markdown, Err(error) => { tracing::warn!(%error, "could not copy meeting transcript"); return; } } } _ => return, }; tx.copy(markdown); self.live.copied = Some((LiveCopy::All, Instant::now())); } fn copy_prompt(&mut self, tx: &mut Tx) { let prompt = match &self.kind { Some(Kind::Recording(Recording { id, title, .. })) => { let reached = self.live.entries.last().map_or(0, |entry| entry.end_ms); agent_prompt(&hex_command(), id, title, Some(reached)) } Some(Kind::Ready(manifest)) => agent_prompt( &hex_command(), &manifest.id, &meeting::display_title(manifest), None, ), _ => return, }; tx.copy(prompt); self.live.copied = Some((LiveCopy::Prompt, Instant::now())); } /// The capsule's window size, for snapping a drag. fn window_size(&self) -> (f32, f32) { if self.presentation.inherits_offer_window() { return self.presentation.window(); } match &self.kind { Some(Kind::Finalizing { .. }) => finalizing_window_size(), Some(Kind::Recording(shown)) => recording_window_size(self.open(), Some(shown)), Some(Kind::Ready(manifest)) => ready_window_size(manifest), Some(Kind::Offer(..)) => self.presentation.window(), Some(kind) => (panel_width(kind), MEETING_PANEL_HEIGHT), None => (MEETING_PANEL_WIDTH, MEETING_PANEL_HEIGHT), } } /// The capsule follows the pointer one to one. On release it glides /// from where it was let go, at the throw's speed, into the corner the /// throw heads for (under Reduce Motion it jumps there). A cancelled /// drag (Escape, window blur) returns to the corner it started from and /// saves nothing. fn drag(&mut self, drag: &Drag, tx: &mut Tx) { let Some(shift) = self.shift.clone() else { return; }; let now = tx.clock(); match drag.phase { Phase::Down => self.throw.press(now), Phase::Move => { let (x, y) = self.throw.track(now, drag.dx, drag.dy); shift(self.corner, x, y); } Phase::Up if drag.cancelled() => { self.throw.stop(); shift(self.corner, 0.0, 0.0); } Phase::Up => { let offset = self.throw.track(now, drag.dx, drag.dy); let velocity = self.throw.velocity(now); let Some(screen) = (self.screen)(self.scale.get()) else { self.throw.stop(); shift(self.corner, 0.0, 0.0); return; }; let landing = throw::land(self.corner, offset, velocity, screen, self.window_size()); let corner = landing.corner; let glide = if self.reduced.get() { self.throw.stop(); None } else { self.throw.glide(landing, now) }; match glide { Some((x, y)) => { shift(corner, x, y); tx.wake_after(Duration::ZERO); } None => shift(corner, 0.0, 0.0), } if corner != self.corner { tracing::info!(?corner, "meeting capsule moved"); self.corner = corner; (self.save_corner)(corner); // The pill changes sides with the window; it must not // slide across it. tx.instant(); } } } } } /// Where a corner's capsule window sits: its edge and margin, and its /// alignment and inset along that edge, after a drag of (dx, dy) points. fn corner_placement( corner: MeetingIndicatorCorner, dx: f32, dy: f32, ) -> (ScreenEdge, f32, Align, f32) { let (edge, margin) = if corner.is_top() { (ScreenEdge::Top, WINDOW_MARGIN + MENU_BAR + dy) } else { (ScreenEdge::Bottom, WINDOW_MARGIN + DOCK - dy) }; let (align, inset) = if corner.is_right() { (Align::End, WINDOW_MARGIN - dx) } else { (Align::Start, WINDOW_MARGIN + dx) }; (edge, margin, align, inset) } fn place_capsule( handle: &OverlayHandle, corner: MeetingIndicatorCorner, dx: f32, dy: f32, ) { let (edge, margin, align, inset) = corner_placement(corner, dx, dy); handle.place(edge, margin); handle.set_align(align, inset); } /// Linux: lets the capsule's next show float on XWayland where Wayland has /// no layer-shell, only by Labs › Call recording controls on GNOME (#1274). /// Off, Rune can't open it there and the Meetings pane stands in (#1271). fn float_on_xwayland(capsule: &OverlayHandle) { #[cfg(target_os = "linux")] capsule.set_xwayland_input(crate::linux::meeting_capsules::on_xwayland()); #[cfg(not(target_os = "linux"))] let _ = capsule; } /// The two capsules: the timed panel (offer, call ended, ready) and the /// recording capsule in the configured corner. pub(crate) struct MeetingCapsules { panel: OverlayHandle, /// While a real offer is visible it already occupies the recording host. handoff: offer::Host, pill: Pill, /// Bumped whenever the panel shows something new, so a stale timeout /// doesn't close it. generation: Arc, /// Which finished/finalizing meeting still occupies the recording window. finishing: Option, } /// The recording capsule, rebuilt from its [`PillModel`] and the live Show /// recording indicator setting whenever either may have changed: on each /// controller event, on Keep recording, and each second while recording. #[derive(Clone)] struct Pill { handle: OverlayHandle, model: Arc>, } impl Pill { fn keep_recording(&self) { self.lock().keep_recording(); self.reconcile(); } fn lock(&self) -> std::sync::MutexGuard<'_, PillModel> { self.model.lock().unwrap_or_else(|error| error.into_inner()) } /// Shows, refreshes, or hides the pill to match the model; returns the /// recording it shows. fn reconcile(&self) -> Option { self.reconcile_locked(&mut self.lock(), false) } fn reconcile_locked(&self, model: &mut PillModel, inherit: bool) -> Option { let Some(recording) = model .pill(crate::app_settings::meeting_indicator_enabled()) .cloned() else { if model.shown.take().is_some() || inherit { self.handle.update(|capsule, tx| capsule.dismiss(tx)); } return None; }; let id = recording.id.clone(); if model.shown.as_ref() == Some(&id) { self.handle.update(move |capsule, _| { capsule.kind = Some(Kind::Recording(recording)); // A notice coming or going changes the resting pill's width. #[cfg(target_os = "windows")] capsule.fit_recording_window(); }); return Some(id); } model.shown = Some(id.clone()); let corner = crate::app_settings::meeting_indicator_corner(); model.last_anchor = Some((id.clone(), corner)); if inherit { self.handle .update(move |c, tx| c.start_recording(recording, tx)); return Some(id); } place_capsule(&self.handle, corner, 0.0, 0.0); // Windows: a shown pill starts at rest. self.handle .resize(recording_window_size(false, Some(&recording))); #[cfg(target_os = "windows")] self.handle.set_input(rune::OverlayInput::All); self.handle.update(move |capsule, tx| { capsule.presentation = Default::default(); capsule.stage = Default::default(); capsule.corner = corner; capsule.start_recording(recording, tx); }); float_on_xwayland(&self.handle); self.handle.show(); Some(id) } /// Whether the controller still records `id`. fn records(&self, id: &str) -> bool { self.lock() .recording .as_ref() .is_some_and(|recording| recording.id == id) } /// While recording `id`: each second, reconciles the pill (the elapsed /// time, the indicator setting) and, while it shows, reads the in-call /// transcript here rather than on the main thread. fn tick(&self, id: String) { let pill = self.clone(); std::thread::spawn(move || { let mut reader = meeting::TranscriptReader::default(); while pill.records(&id) { std::thread::sleep(Duration::from_secs(1)); if pill.reconcile().as_ref() != Some(&id) { continue; } let entries = match reader.read(&id) { Ok(entries) => entries, Err(error) => { tracing::debug!(%error, "could not read the in-call transcript"); continue; } }; let pending = meeting::pending_delta(&id, &entries); let id = id.clone(); pill.handle.update(move |capsule, _| { if matches!(&capsule.kind, Some(Kind::Recording(Recording { id: shown, .. })) if *shown == id) { capsule.live.entries = entries; capsule.live.pending = pending; } }); } }); } } impl MeetingCapsules { /// `choose` saves a "Never offer" or "Always record" choice (the window /// keeps the settings it saves). pub(crate) fn install( app: &mut rune::App, commands: SyncSender, choose: impl Fn(MeetingProviderChoice) + Send + Sync + 'static, save_corner: impl Fn(MeetingIndicatorCorner) + Send + Sync + 'static, ) -> Self { let choose: Choose = Arc::new(choose); let save_corner: SaveCorner = Arc::new(save_corner); let overlay = |app: &mut rune::App, name, size: (f32, f32), recording: bool| { let spec = OverlaySpec { name, size, edge: ScreenEdge::Top, margin: WINDOW_MARGIN + MENU_BAR, align: Align::End, inset: WINDOW_MARGIN, interactive: true, view, } .options(Default::default()); let spec = if recording { spec.compositor(waveform::Ink::default()) } else { spec }; let handle = app.overlay( spec.poll(poll), Capsule { kind: None, more_open: false, rearm_offer: None, presentation: Default::default(), stage: Default::default(), surface: Default::default(), live: Live::default(), waveform: None, commands: commands.clone(), hide: None, show: None, keep_recording: None, resize: None, choose: choose.clone(), hovered: false, stopping: false, expired: false, corner: MeetingIndicatorCorner::default(), shift: None, throw: throw::Throw::default(), reduced: Cell::new(false), scale: Cell::new(1.0), screen: primary_screen_size, save_corner: save_corner.clone(), copy_new: None, }, ); // Only the drawn capsule (its `.hit()` body) takes clicks; the // window's transparent rest passes them to the app beneath. // Windows instead sizes each window to what it draws, so the // whole window may take the pointer there (`recording_window_size` // and `show_recording`); Regions' sampled pointer positions can // leave the transparent rest of a wide window hit-testable. #[cfg(not(target_os = "windows"))] handle.set_input(OverlayInput::Regions); let (hide, resize, shift) = (handle.clone(), handle.clone(), handle.clone()); let show = handle.clone(); let copied = handle.clone(); let copy_new: CopyNew = Arc::new(move |id: String| { let copied = copied.clone(); // The wait for the transcript through the click stays off // the main thread. std::thread::spawn(move || { let entries = meeting::entries_for_copy(&id); copied.update(move |capsule, tx| capsule.finish_copy_new(&id, entries, tx)); }); }); handle.update(move |capsule, _| { capsule.copy_new = Some(copy_new); capsule.hide = Some(Arc::new(move || hide.hide())); capsule.show = Some(Arc::new(move || show.show())); capsule.resize = Some(Arc::new(move |size| resize.resize(size))); capsule.shift = Some(Arc::new(move |corner, dx, dy| { place_capsule(&shift, corner, dx, dy); })); }); handle }; let panel = overlay( app, "Hex meeting", (MEETING_PANEL_WIDTH, MEETING_PANEL_HEIGHT), false, ); let pill = Pill { handle: overlay( app, "Hex meeting recording", recording_window_size(false, None), true, ), model: Arc::default(), }; let kept = pill.clone(); let anchors = pill.model.clone(); pill.handle.update(move |capsule, _| { capsule.save_corner = Arc::new(move |corner| { if let Some((_, at)) = &mut anchors .lock() .unwrap_or_else(|e| e.into_inner()) .last_anchor { *at = corner; } save_corner(corner); }); }); panel.update(move |capsule, _| { capsule.keep_recording = Some(Arc::new(move || kept.keep_recording())); }); Self { panel, handoff: Default::default(), pill, generation: Arc::default(), finishing: None, } } /// Shows, updates, or closes a capsule for each controller event. pub(crate) fn event(&mut self, event: &ControllerEvent) { let route = self.handoff.route(event); let inherit = route == offer::Route::Inherit; if inherit { self.handoff = Default::default(); } else if route == offer::Route::Close { self.close_panel(); } self.advance_handoff(event, inherit); match event { ControllerEvent::Reminder { meeting, automatic } => { // Unanswered, it closes without recording or snoozing // anything, when the scheduler lets the next one show. let now_ms = crate::calendar::wall_clock_ms(); let until_ms = crate::calendar::reminder_until_ms(meeting.start_ms, now_ms); let timeout = Duration::from_millis((until_ms - now_ms).max(0) as u64); self.show_panel( Kind::Reminder { meeting: meeting.clone(), automatic: *automatic, }, Some(timeout), ); } ControllerEvent::ReminderWithdrawn { occurrence } => { let (occurrence, generation) = (occurrence.clone(), self.generation.clone()); self.panel.update(move |capsule, tx| { if matches!(&capsule.kind, Some(Kind::Reminder { meeting, .. }) if meeting.occurrence() == occurrence) { generation.fetch_add(1, Ordering::SeqCst); capsule.dismiss(tx); } }); } ControllerEvent::Offer(id, candidate) => { tracing::info!( source = candidate.source.label(), title = %candidate.title, application = ?candidate.application, "meeting recording offer shown" ); self.show_panel(Kind::Offer(*id, candidate.clone()), None); } ControllerEvent::OfferWithdrawn(_) => { // The shown offer's own route closes it. } ControllerEvent::Starting(_) | ControllerEvent::Transcribing if route != offer::Route::Ordinary => {} ControllerEvent::Starting(_) | ControllerEvent::Transcribing => self.close_panel(), ControllerEvent::Stopping => self.pill.handle.update(|c, tx| { c.mark_stopping(); c.stir(tx); }), ControllerEvent::RecordingStarted { title, automatic, .. } => { if *automatic && !crate::app_settings::meeting_indicator_enabled() { // Nothing else on screen would say a recording began. self.show_panel( Kind::AutoStarted { title: title.clone(), }, Some(AUTOMATIC_LABEL), ); } } ControllerEvent::CallEnded { app, auto_stop } => { self.show_panel( Kind::CallEnded { app: app.clone(), auto_stop: *auto_stop, }, None, ); } ControllerEvent::CallEndedWithdrawn => { let generation = self.generation.clone(); self.panel.update(move |capsule, tx| { if capsule.withdraw_call_ended() { generation.fetch_add(1, Ordering::SeqCst); tx.wake_after(Duration::ZERO); } }); } ControllerEvent::Finished(manifest) => { let panel = self.finish_meeting(manifest); // Copy new's hint reads the final transcript, off the main // thread. let id = manifest.id.clone(); std::thread::spawn(move || { let entries = match meeting::TranscriptReader::default().read(&id) { Ok(entries) => entries, Err(error) => { tracing::debug!(%error, "could not read the finished transcript"); return; } }; let pending = meeting::pending_delta(&id, &entries); panel.update(move |capsule, _| { if capsule.meeting_id() == Some(id.as_str()) { capsule.live.entries = entries; capsule.live.pending = pending; } }); }); } ControllerEvent::NotesFinished(manifest) => { let manifest = manifest.clone(); let panel = self.handle_for(&manifest.id); panel.update(move |capsule, _| capsule.refresh_ready(manifest)); } ControllerEvent::NotesProgress(id) => self.notes_progress(id), ControllerEvent::Retitled { .. } | ControllerEvent::SourceWarning { .. } | ControllerEvent::Failed { .. } | ControllerEvent::ImportFailed { .. } | ControllerEvent::Chapters(_) => {} } } fn show_panel(&mut self, kind: Kind, timeout: Option) { let host = match &kind { Kind::Offer(id, _) => offer::Host::Offered(*id), _ => offer::Host::Panel, }; if host.on_pill() != self.handoff.on_pill() { self.close_panel(); } self.handoff = host; let panel = self.panel_handle().clone(); let generation = self.generation.fetch_add(1, Ordering::SeqCst) + 1; let reminder = matches!(kind, Kind::Reminder { .. }); // The saved corner, and a finished meeting its recording's corner. let corner = panel::show_corner( &kind, true, self.pill.lock().last_anchor.as_ref(), crate::app_settings::meeting_indicator_corner, ); place_capsule(&panel, corner, 0.0, 0.0); let presentation = offer_surface::Presentation::for_kind(&kind, false); // Only the detected offer reserves space for its wider page. The // other Windows panels retain their original, window-sized input. #[cfg(target_os = "windows")] panel.set_input(if matches!(kind, Kind::Offer(..)) { rune::OverlayInput::Regions } else { rune::OverlayInput::All }); panel.resize(match &kind { Kind::Offer(..) => presentation.window(), Kind::Ready(manifest) => ready_window_size(manifest), kind => (panel_width(kind), MEETING_PANEL_HEIGHT), }); let offer_id = match kind { Kind::Offer(id, _) => Some(id), _ => None, }; let rearm = offer_id .is_some() .then(|| offer::timer(panel.clone(), self.generation.clone(), generation)); panel.update(move |capsule, tx| capsule.show(kind, presentation, corner, rearm, tx)); float_on_xwayland(&panel); panel.show(); if let Some(id) = offer_id { offer_surface::load_icon(panel, id); } if reminder && let Some(timeout) = timeout { // Recount "Starts in N min" while this reminder may show. let (panel, current) = (self.panel.clone(), self.generation.clone()); let until = Instant::now() + timeout; std::thread::spawn(move || { while current.load(Ordering::SeqCst) == generation && Instant::now() < until { std::thread::sleep(REMINDER_TICK); panel.update(|_, _| {}); } }); } if let Some(timeout) = timeout { self.timeout(self.panel.clone(), generation, timeout); } } /// Closes the capsule shown for `generation` after `timeout`, unless a /// newer one replaced it or the pointer holds a ready panel open. fn timeout(&self, panel: OverlayHandle, generation: u64, timeout: Duration) { let current = self.generation.clone(); std::thread::spawn(move || { std::thread::sleep(timeout); if current.load(Ordering::SeqCst) == generation { panel.update(move |capsule, _| { // Checked again when applied: a newer capsule may // have been shown since. if current.load(Ordering::SeqCst) != generation { return; } // A ready panel waits for the pointer to leave it. if capsule.hovered && matches!(capsule.kind, Some(Kind::Ready(_))) { capsule.expired = true; return; } capsule.close(); }); } }); } /// Linux: calls `unshown` with Rune's reason when the offer just shown /// could not open its overlay (GNOME on Wayland has no layer-shell for /// interactive overlays, #1271), unless a newer capsule replaced it. #[cfg(target_os = "linux")] pub(crate) fn when_offer_unshown(&self, unshown: impl FnOnce(String) + Send + 'static) { let (panel, current) = (self.panel_handle().clone(), self.generation.clone()); let generation = current.load(Ordering::SeqCst); std::thread::spawn(move || { std::thread::sleep(OFFER_CHECK); if current.load(Ordering::SeqCst) != generation || panel.availability() != rune::Availability::Unavailable { return; } unshown( panel .failure() .unwrap_or_else(|| "no reason given".to_owned()), ); }); } // The capsule hides its own window once its surface has gone, and only // while it still shows nothing, so closing then showing stays shown. fn close_panel(&mut self) { self.generation.fetch_add(1, Ordering::SeqCst); self.panel_handle() .update(|capsule, tx| capsule.dismiss(tx)); self.handoff = Default::default(); } fn panel_handle(&self) -> &OverlayHandle { if self.handoff.on_pill() { &self.pill.handle } else { &self.panel } } } fn button( p: Paint, key: &str, label: &str, primary: bool, press: impl Fn(&mut Capsule) + 'static, ) -> El { Button::new(label) .variant(if primary { ButtonVariant::Contrast } else { ButtonVariant::Neutral }) .build_push(p.k) .key(key) // The capsule's body drags; its buttons are buttons. .cursor(Cursor::Pointer) // The surface answers in the frame of the press. .on_press_tx(move |c: &mut Capsule, tx| { press(c); c.stir(tx); }) } static CLOSE: &rune::Icon = &rune_theme_opencode::icons::CLOSE; /// The ✕ that closes a capsule whose actions have no way to. It only hides /// the capsule: nothing is sent to the controller (#996). fn dismiss_button(p: Paint) -> El { IconButton::new(CLOSE) .variant(IconButtonVariant::Ghost) .control_size(ControlSize::Large) .label(tr("Close")) .build(p.k) .key("dismiss") .cursor(Cursor::Pointer) .on_press_tx(|c: &mut Capsule, tx| { c.close(); c.stir(tx); }) } /// The overlay's frame hook: steps the surface, and a glide into its corner, /// a frame at a time until they rest, and keeps a recording's waveform fed. fn poll(capsule: &mut Capsule, now: f64, tx: &mut Tx) -> bool { // The surface first: the field is drawn once a frame, at the width the // wall has just reached. let mut changed = capsule.step_stage(now, tx); changed |= waveform::poll(capsule, now, tx); if !capsule.throw.gliding() { return changed; } let offset = capsule.throw.step(now); if let Some(shift) = &capsule.shift { let (x, y) = offset.unwrap_or_default(); shift(capsule.corner, x, y); } if offset.is_some() { tx.wake_after(Duration::ZERO); } changed } fn view(capsule: &Capsule, cx: &mut Cx) -> El { capsule.reduced.set(cx.is_reduced_motion()); capsule.scale.set(cx.env().scale); presence::present(capsule, view_body(capsule, cx)) .hover_motion_within(Anim::INSTANT, Anim::INSTANT) } fn view_body(capsule: &Capsule, cx: &mut Cx) -> El { // Recording and its summary stay dark; offers and reminders follow the host. let dark = matches!( capsule.drawn(), Some(Kind::Recording(_) | Kind::Finalizing { .. } | Kind::Ready(_)) ) || cx.system_dark(); let p = Paint::new(dark, cx.env().scale); if let Some(el) = offer_surface::transition( capsule, Paint::new(cx.system_dark(), cx.env().scale), Paint::new(true, cx.env().scale), ) { return el; } let Some(kind) = capsule.drawn() else { return row().key("empty"); }; let parts = match kind { Kind::Recording(shown) => return recording(p, capsule, shown), Kind::Finalizing { duration_ms } => return panel::finalizing(p, capsule, *duration_ms), Kind::AutoStarted { title } => ( p.danger(), tr("Recording automatically").to_owned(), title.clone(), // Dismissing leaves the recording going; the menu bar still // shows it. vec![ button(p, "stop", tr("Stop"), true, |c| { if c.send(ControllerCommand::Stop) { c.close(); } }), dismiss_button(p), ], ), Kind::Reminder { meeting, automatic } => { reminder(p, meeting, *automatic, crate::calendar::wall_clock_ms()) } Kind::Offer(id, candidate) => return offer_surface::view(p, capsule, *id, candidate), Kind::CallEnded { app, auto_stop } => ( p.danger(), tr_fill("{} left the call", app), if *auto_stop { tr("Hex stops recording in 30 s unless you keep recording.") } else { tr("Hex is still recording.") } .to_owned(), vec![ button(p, "keep-recording", tr("Keep recording"), false, |c| { if matches!( c.kind, Some(Kind::CallEnded { auto_stop: true, .. }) ) { c.send(ControllerCommand::KeepRecording); } if let Some(keep_recording) = &c.keep_recording { keep_recording(); } c.close(); }), button(p, "stop-meeting", tr("Stop & transcribe"), true, |c| { if c.send(ControllerCommand::Stop) { c.close(); } }), ], ), Kind::Ready(manifest) => return ready(p, capsule, manifest), }; pill(p, capsule, parts) } /// The panel capsule's width for `kind`, room for its title beside its /// buttons. fn panel_width(kind: &Kind) -> f32 { match kind { Kind::Reminder { .. } => REMINDER_PANEL_WIDTH, Kind::CallEnded { .. } => CALL_ENDED_PANEL_WIDTH, _ => MEETING_PANEL_WIDTH, } } /// "Starts in 1 min", "Starting now", or "Started 2 min ago". fn starts_label(start_ms: i64, now_ms: i64) -> String { let minutes = crate::calendar::minutes_until(start_ms, now_ms); if minutes > 0 { tr_fill("Starts in {} min", &minutes.to_string()) } else { let ago = (now_ms - start_ms) / 60_000; if ago < 1 { tr("Starting now").to_owned() } else { tr_fill("Started {} min ago", &ago.to_string()) } } } /// The calendar reminder: Record, or Join & record when the invitation has /// a call link. With Always record set for its service, it says so and /// offers Join and Don't record instead. fn reminder( p: Paint, meeting: &CalendarMeeting, automatic: bool, now_ms: i64, ) -> (rune::Color, String, String, Vec) { let when = starts_label(meeting.start_ms, now_ms); let has_link = meeting.link.is_some(); let send_meeting = |command: fn(CalendarMeeting) -> ControllerCommand| { move |c: &mut Capsule| { let Some(Kind::Reminder { meeting, .. }) = &c.kind else { return; }; let command = command(meeting.clone()); c.send(command); c.close(); } }; if automatic { let mut actions = vec![button( p, "dont-record", tr("Don't record"), false, send_meeting(ControllerCommand::DismissReminder), )]; if has_link { actions.push(button( p, "join", tr("Join"), true, send_meeting(ControllerCommand::JoinMeeting), )); } return ( p.accent(), meeting.display_title(), tr_fill("{} · Hex records automatically", &when), actions, ); } let mut actions = vec![button( p, "not-now", tr("Not now"), false, send_meeting(ControllerCommand::DismissReminder), )]; if has_link { actions.push(button( p, "join-record", tr("Join & record"), false, send_meeting(|meeting| ControllerCommand::RecordMeeting { meeting, join: true, }), )); } actions.push(button( p, "record", tr("Record"), true, send_meeting(|meeting| ControllerCommand::RecordMeeting { meeting, join: false, }), )); let subtitle = match &meeting.link { Some(link) => format!("{when} · {}", link.provider.label()), None => when, }; (p.accent(), meeting.display_title(), subtitle, actions) } /// The panel capsule (reminder, offer, call ended): status dot, two /// truncated lines, and its actions, in a rounded rectangle. It drags to /// another corner like the recording capsule. fn pill( p: Paint, capsule: &Capsule, (dot, title, subtitle, actions): (rune::Color, String, String, Vec), ) -> El { // Only the body takes the pointer, not the window's margin around it. let body = pill_body(p, status_dot(dot), &title, &subtitle) .w_full() .child(row().key("actions").gap(8.0).children(actions)) .hit() .cursor(Cursor::Grab) .on_drag(|c: &mut Capsule, drag, tx| c.drag(drag, tx)); row() .key("capsule") .w_full() .h_full() .px(4.0) .py(4.0) .child(presence::anchored(capsule, body)) } /// The panel capsule's corners, concentric with its buttons' (`radius.md`) /// across the [`ACTIONS_INSET`] between them and the edge. fn panel_radius(p: Paint) -> f32 { p.k.radius.md + ACTIONS_INSET } /// The panel capsule's body: its dot and two truncated lines in a rounded /// rectangle. fn pill_body(p: Paint, dot: El, title: &str, subtitle: &str) -> El { let c = &p.k.c; // A status named by its title, announced when the capsule's title // changes; the subtitle stays readable inside it. row() .key("pill") .role("status") .label(title) .h_full() .gap(12.0) .pl(16.0) .pr(ACTIONS_INSET) .center_y() .radius(panel_radius(p)) .fill(c.bg_base) .border(p.hair, c.border_base) .child(dot) .child( col() .key("lines") .grow(1.0) .min_w(0.0) .child( text(title.to_owned()) .key("title") .truncate() .font(p.k.ty.ui_medium) .color(p.text()) .a11y_hidden(), ) .children((!subtitle.is_empty()).then(|| { text(subtitle.to_owned()) .key("subtitle") .truncate() .font(p.k.ty.small) .color(p.faint()) })), ) } #[cfg(test)] mod tests { use std::sync::mpsc::{self, Receiver}; use rune::text::TextSystem; use rune::{Env, Runtime}; use super::panel::shell_word; use super::throw::nearest_corner; use super::*; use crate::meeting::detection::MeetingSource; type Chosen = Arc>>; const PANEL: (f32, f32) = (MEETING_PANEL_WIDTH, MEETING_PANEL_HEIGHT); const MENU: (f32, f32) = (MEETING_MENU_WIDTH, MEETING_PANEL_HEIGHT); const RECORDING: (f32, f32) = RECORDING_WINDOW; const REMINDER: (f32, f32) = (REMINDER_PANEL_WIDTH, MEETING_PANEL_HEIGHT); const CALL_ENDED: (f32, f32) = (CALL_ENDED_PANEL_WIDTH, MEETING_PANEL_HEIGHT); /// "Design sync" a minute from now, with a Zoom link or none. fn design_sync(link: bool) -> CalendarMeeting { let start_ms = crate::calendar::wall_clock_ms() + 59_000; CalendarMeeting { id: "design-sync".into(), title: "Design sync".into(), start_ms, end_ms: start_ms + 30 * 60_000, attendees: vec!["Dax".into(), "Adam".into()], link: link.then(|| crate::calendar::CallLink { provider: crate::calendar::CallProvider::Zoom, url: "https://anomaly.zoom.us/j/123456789".into(), }), } } fn reminder(link: bool, automatic: bool) -> Kind { Kind::Reminder { meeting: design_sync(link), automatic, } } fn slack_huddle() -> MeetingCandidate { MeetingCandidate { key: "meeting-slack".into(), title: "Slack huddle".into(), source: MeetingSource::SlackHuddle, application: Some("com.tinyspeck.slackmacgap".into()), named: false, site: None, application_name: Some("Slack".into()), call: None, } } fn offer(candidate: MeetingCandidate) -> Kind { Kind::Offer(OfferId::at(Instant::now()), candidate) } fn bare_browser() -> MeetingCandidate { MeetingCandidate { key: "meeting-brave".into(), title: "Browser call".into(), source: MeetingSource::BrowserCall, application: Some("com.brave.Browser".into()), named: false, site: None, application_name: Some("Brave Browser".into()), call: None, } } fn runtime( kind: Kind, more_open: bool, dark: bool, size: (f32, f32), ) -> (Runtime, Receiver, Chosen) { let (commands, received) = mpsc::sync_channel(4); let chosen = Chosen::default(); let saved = chosen.clone(); let text = TextSystem::new(rune_theme_opencode::FONTS, rune_theme_opencode::FAMILIES); let presentation = offer_surface::Presentation::for_kind(&kind, more_open); let size = if matches!(kind, Kind::Offer(..)) { presentation.window() } else { size }; let capsule = Capsule { kind: Some(kind), more_open, rearm_offer: None, presentation, stage: Default::default(), surface: presence::Surface::shown(), live: Live::default(), waveform: None, commands, hide: None, show: None, keep_recording: None, resize: None, choose: Arc::new(move |choice| saved.lock().unwrap().push(choice)), hovered: false, stopping: false, expired: false, corner: MeetingIndicatorCorner::TopRight, shift: None, throw: throw::Throw::default(), reduced: Cell::new(false), scale: Cell::new(1.0), // No screen: a release lands back in the corner it started in. screen: |_| None, save_corner: Arc::new(|_| {}), copy_new: None, }; let env = Env { system_dark: dark, scale: 2.0, }; let mut rt = crate::rune_ui::offscreen::runtime(capsule, view, size, env, text); // The native overlay polls each frame; here only the surface steps, // so no test reads the wall clock or the capture meter. rt.poll = Some(|c: &mut Capsule, now, tx: &mut Tx| c.step_stage(now, tx)); rt.frame(0.0); (rt, received, chosen) } fn tap(rt: &mut Runtime, key: &str) { let (x, y) = rt.find(key).unwrap_or_else(|| panic!("no element {key}")); rt.pointer_down(x, y); rt.pointer_up(x, y); rt.frame(1.0 / 60.0); } fn texts(rt: &Runtime) -> Vec { rt.elements().into_iter().filter_map(|e| e.text).collect() } #[test] fn an_offer_names_the_call_without_asking_about_consent() { let (rt, _, _) = runtime(offer(slack_huddle()), false, true, PANEL); assert_eq!(texts(&rt)[0], "Slack huddle detected"); assert!(rt.find("subtitle").is_none()); assert!(rt.find("offer-more").is_some()); } /// The offscreen runtime has no host poll. Step the same presentation /// clock the native overlay polls, on the original surface. fn navigate_offer(rt: &mut Runtime, key: &str) { tap(rt, key); for _ in 0..60 { advance_offer(rt); } } fn advance_offer(rt: &mut Runtime) { rt.frame(1.0 / 60.0); } /// Lands everything in flight, as `settle_all` lands Rune's tracks. fn settle_stage(rt: &mut Runtime) { rt.update(|c, tx| { let now = tx.clock(); c.settle_stage(now); }); } /// The runtime's surface, stage and Rune's tracks all at rest. fn landed(rt: &mut Runtime) { settle_stage(rt); rt.settle_all(); rt.frame(0.); } #[test] fn the_offer_menu_stays_usable_past_the_unanswered_deadline() { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), false, true, PANEL); let (arm, armed) = mpsc::channel(); rt.state.set_offer_timer(Some(Box::new(move |delay, fire| { arm.send((delay, fire)).unwrap() }))); let (delay, fire) = armed.try_recv().unwrap(); assert_eq!(delay, Duration::from_secs(20)); rt.frame(19.0); navigate_offer(&mut rt, "offer-more"); assert!(rt.find("always-record").is_some()); assert!(commands.try_recv().is_err()); assert!(chosen.lock().unwrap().is_empty()); // Deliver the original 20 s timer on this same widened capsule. rt.frame(delay.as_secs_f64() - 19.0); rt.update(|c, _| fire(c)); rt.frame(0.0); assert!(rt.find("always-record").is_some(), "menu closed at expiry"); assert!(commands.try_recv().is_err()); assert!(chosen.lock().unwrap().is_empty()); tap(&mut rt, "never-offer"); assert_eq!(chosen.lock().unwrap()[0].policy, MeetingPolicy::NeverOffer); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::Dismiss) )); } #[test] fn always_record_saves_the_choice_and_records_this_call() { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), false, true, PANEL); navigate_offer(&mut rt, "offer-more"); rt.update(|c, _| c.expire_offer()); assert_eq!(texts(&rt)[0], "Slack huddles"); tap(&mut rt, "always-record"); let chosen = chosen.lock().unwrap(); assert_eq!(chosen.len(), 1); assert_eq!(chosen[0].key, "com.tinyspeck.slackmacgap"); assert_eq!(chosen[0].policy, MeetingPolicy::AlwaysRecord); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::Record(candidate, Some(_))) if candidate.key == "meeting-slack" )); assert!(rt.state.presentation.inherits_offer_window()); } #[test] fn an_old_offer_timeout_cannot_close_a_replacement() { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), false, true, PANEL); let current = Arc::new(AtomicU64::new(1)); let queued = offer::delivery(current.clone(), 1, Capsule::expire_offer); navigate_offer(&mut rt, "offer-more"); // A new offer of the very same call replaces the open choices // before Rune gets to the first offer's timeout update. current.fetch_add(1, Ordering::SeqCst); rt.update(|c, _| { c.kind = Some(offer(slack_huddle())); c.more_open = false; c.presentation = offer_surface::Presentation::for_kind(c.kind.as_ref().unwrap(), false); }); rt.set_viewport(PANEL, 2.0); rt.update(queued); rt.frame(0.0); assert!(rt.find("offer-more").is_some()); assert!(rt.find("always-record").is_none()); assert!(commands.try_recv().is_err()); assert!(chosen.lock().unwrap().is_empty()); } #[test] fn an_untouched_offer_times_out_without_a_choice() { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), false, true, PANEL); rt.update(|c, _| c.expire_offer()); rt.frame(0.0); // Closed at once; what it showed leaves over the next frames. assert!(rt.state.kind.is_none()); for _ in 0..40 { rt.frame(1.0 / 60.0); } assert!(rt.find("offer-more").is_none()); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::OfferTimedOut(_)) )); assert!(commands.try_recv().is_err()); assert!(chosen.lock().unwrap().is_empty()); } #[test] fn cancel_returns_to_a_timed_clickable_offer() { for deadline_passed in [false, true] { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), false, true, PANEL); let (arm, armed) = mpsc::channel(); rt.state.set_offer_timer(Some(Box::new(move |delay, fire| { arm.send((delay, fire)).unwrap() }))); let (delay, first_timeout) = armed.try_recv().unwrap(); assert_eq!(delay, Duration::from_secs(20)); navigate_offer(&mut rt, "offer-more"); if deadline_passed { rt.update(|c, _| first_timeout(c)); } navigate_offer(&mut rt, "offer-cancel"); assert!(rt.find("record").is_some()); assert!(commands.try_recv().is_err()); assert!(chosen.lock().unwrap().is_empty()); if deadline_passed { let (delay, new_timeout) = armed.try_recv().expect("Cancel rearms the expired timer"); assert_eq!(delay, Duration::from_secs(20)); rt.update(|c, _| new_timeout(c)); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::OfferTimedOut(_)) )); } else { assert!(armed.try_recv().is_err(), "original timer is still pending"); tap(&mut rt, "not-now"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::Dismiss) )); rt.update(|c, _| first_timeout(c)); } assert!(rt.state.kind.is_none()); assert!(commands.try_recv().is_err()); } } #[test] fn never_offer_saves_the_choice_and_dismisses() { let (mut rt, commands, chosen) = runtime(offer(slack_huddle()), true, true, MENU); tap(&mut rt, "never-offer"); assert_eq!(chosen.lock().unwrap()[0].policy, MeetingPolicy::NeverOffer); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::Dismiss) )); } #[test] fn a_browser_on_an_unknown_page_cannot_be_set_to_always_record() { let (rt, _, _) = runtime(offer(bare_browser()), true, true, MENU); assert!(rt.find("never-offer").is_some()); assert!(rt.find("always-record").is_none()); } #[test] fn an_automatic_recording_says_so_at_first() { let recording = |started| { Kind::Recording(Recording { id: "m".into(), title: "Slack Huddle call — 2:30 PM".into(), started, automatic: true, warning: None, }) }; let (mut rt, _, _) = runtime(recording(Instant::now()), false, true, RECORDING); assert!(texts(&rt).contains(&"Started automatically".to_string())); // Open, it says so under the header. open_recording(&mut rt); assert!(rt.find("notice-line").is_some()); let earlier = Instant::now() - AUTOMATIC_LABEL - Duration::from_secs(1); let (rt, _, _) = runtime(recording(earlier), false, true, RECORDING); assert!(!texts(&rt).iter().any(|text| text.contains("automatically"))); } #[test] fn a_recording_says_when_its_microphone_is_silent() { let mut kind = live_recording("m"); let Kind::Recording(Recording { warning, .. }) = &mut kind else { panic!("a recording"); }; *warning = Some(crate::meeting::TrackWarning::DigitalSilence); let (rt, _, _) = runtime(kind, false, true, RECORDING); assert!( texts(&rt).contains(&"Microphone is silent".to_string()), "{:?}", texts(&rt) ); } #[test] fn a_reminder_with_a_link_joins_and_records_on_one_click() { let (mut rt, commands, _) = runtime(reminder(true, false), false, true, REMINDER); let shown = texts(&rt); assert!(shown.contains(&"Design sync".to_string()), "{shown:?}"); assert!( shown.contains(&"Starts in 1 min · Zoom".to_string()), "{shown:?}" ); assert!(rt.find("record").is_some()); tap(&mut rt, "join-record"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::RecordMeeting { meeting, join: true }) if meeting.id == "design-sync" )); assert!(rt.state.kind.is_none()); } #[test] fn a_reminder_without_a_link_only_records() { let (mut rt, commands, _) = runtime(reminder(false, false), false, false, REMINDER); assert!(texts(&rt).contains(&"Starts in 1 min".to_string())); assert!(rt.find("join-record").is_none()); tap(&mut rt, "record"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::RecordMeeting { join: false, .. }) )); } #[test] fn dismissing_a_reminder_tells_the_controller() { let (mut rt, commands, _) = runtime(reminder(true, false), false, true, REMINDER); tap(&mut rt, "not-now"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::DismissReminder(meeting)) if meeting.id == "design-sync" )); assert!(rt.state.kind.is_none()); } #[test] fn an_always_record_reminder_says_so_and_never_offers_record() { let (mut rt, commands, _) = runtime(reminder(true, true), false, true, REMINDER); assert!(texts(&rt).contains(&"Starts in 1 min · Hex records automatically".to_string())); assert!(rt.find("record").is_none()); assert!(rt.find("join-record").is_none()); tap(&mut rt, "join"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::JoinMeeting(_)) )); let (mut rt, commands, _) = runtime(reminder(false, true), false, true, REMINDER); assert!(rt.find("join").is_none()); tap(&mut rt, "dont-record"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::DismissReminder(_)) )); } #[test] fn a_reminders_buttons_take_the_pointer_while_its_body_grabs() { let (mut rt, _, _) = runtime(reminder(true, false), false, true, REMINDER); landed(&mut rt); for key in ["not-now", "join-record", "record"] { let (x, y) = rt.find(key).unwrap(); rt.pointer_move(x, y); rt.frame(1. / 60.); assert_eq!(rt.cursor(), Cursor::Pointer, "{key}"); } // The name and the time between the dot and the buttons drag it. let (x, y) = rt.find("title").unwrap(); rt.pointer_move(x, y); rt.frame(1. / 60.); assert_eq!(rt.cursor(), Cursor::Grab); } #[test] fn the_reminder_counts_down_to_the_start() { let now = 1_000_000; assert_eq!(starts_label(now + 4 * 60_000 + 1, now), "Starts in 5 min"); assert_eq!(starts_label(now + 60_000, now), "Starts in 1 min"); assert_eq!(starts_label(now, now), "Starting now"); assert_eq!(starts_label(now - 59_000, now), "Starting now"); assert_eq!(starts_label(now - 2 * 60_000, now), "Started 2 min ago"); } fn live_recording(id: &str) -> Kind { Kind::Recording(Recording { id: id.into(), title: "Q4 launch sync".into(), started: Instant::now() - Duration::from_secs(258), automatic: false, warning: None, }) } fn call() -> Vec { let entry = |source, start_ms, text: &str| TranscriptEntry { source, start_ms, end_ms: start_ms + 2_000, text: text.into(), }; vec![ entry( meeting::MeetingSource::System, 0, "Kickoff is at two thirty.", ), entry( meeting::MeetingSource::Microphone, 3_000, "Two thirty works.", ), entry(meeting::MeetingSource::System, 6_000, "Then let's ship it."), ] } /// The meeting paste cursor follows one meeting at a time, so the tests /// that copy take turns with it. static PASTE_CURSOR: Mutex<()> = Mutex::new(()); #[test] fn the_recording_capsule_copies_the_in_call_transcript() { let _cursor = PASTE_CURSOR .lock() .unwrap_or_else(|error| error.into_inner()); let id = "capsule-copy-test"; let (mut rt, _, _) = runtime(live_recording(id), false, true, RECORDING); open_recording(&mut rt); // Nothing transcribed yet: both copies are unavailable. assert!(texts(&rt).contains(&"Copy new".to_string())); assert!(texts(&rt).contains(&"No speech yet".to_string())); tap(&mut rt, "copy-new"); tap(&mut rt, "copy-all"); assert!(rt.copy_request.is_none()); rt.update(|capsule, _| { capsule.live.entries = call(); capsule.live.pending = meeting::pending_delta(id, &call()); }); rt.frame(1.0 / 60.0); assert!(texts(&rt).contains(&"8 sec new".to_string())); tap(&mut rt, "copy-new"); assert_eq!( rt.copy_request.take().as_deref(), Some( "Them: Kickoff is at two thirty.\n\nYou: Two thirty works.\n\nThem: Then let's ship it." ) ); assert!(texts(&rt).contains(&"Copied".to_string())); // What was copied is not new again, here or for Option-Control-V. assert_eq!(meeting::pending_delta(id, &call()).turns, 0); rt.update(|capsule, _| capsule.live.copied = None); rt.frame(1.0 / 60.0); assert!(texts(&rt).contains(&"Up to date".to_string())); tap(&mut rt, "copy-all"); let all = rt.copy_request.take().unwrap(); assert!( all.starts_with("**Them** · 00:00\nKickoff is at two thirty."), "{}", &*all ); } #[test] fn copy_new_copies_the_transcript_read_through_the_click() { let _cursor = PASTE_CURSOR .lock() .unwrap_or_else(|error| error.into_inner()); let id = "capsule-copy-through-click"; let (mut rt, _, _) = runtime(live_recording(id), false, true, RECORDING); let asked: Arc>> = Arc::default(); let record = asked.clone(); open_recording(&mut rt); rt.update(move |capsule, _| { capsule.copy_new = Some(Arc::new(move |id| record.lock().unwrap().push(id))); }); rt.frame(1.0 / 60.0); // The ticker has shown nothing yet, but the call may hold speech. tap(&mut rt, "copy-new"); assert_eq!(*asked.lock().unwrap(), [id]); assert!(texts(&rt).contains(&"Transcribing…".to_string())); assert!(rt.copy_request.is_none()); tap(&mut rt, "copy-new"); assert_eq!(asked.lock().unwrap().len(), 1, "one copy at a time"); rt.update(move |capsule, tx| capsule.finish_copy_new(id, Ok(call()), tx)); rt.frame(1.0 / 60.0); assert_eq!( rt.copy_request.take().as_deref(), Some( "Them: Kickoff is at two thirty.\n\nYou: Two thirty works.\n\nThem: Then let's ship it." ) ); assert!(texts(&rt).contains(&"Copied".to_string())); assert_eq!(meeting::pending_delta(id, &call()).turns, 0); // A copy still running when the next recording shows: its late reply // neither copies nor ends the new recording's copy. let next = "capsule-copy-through-click-next"; tap(&mut rt, "copy-new"); rt.update(move |capsule, _| { capsule.kind = Some(live_recording(next)); capsule.live = Live::default(); }); rt.frame(1.0 / 60.0); tap(&mut rt, "copy-new"); assert_eq!(*asked.lock().unwrap(), [id, id, next]); rt.update(move |capsule, tx| capsule.finish_copy_new(id, Ok(call()), tx)); rt.frame(1.0 / 60.0); assert!(rt.copy_request.is_none()); assert!(rt.state.live.copying); assert!(texts(&rt).contains(&"Transcribing…".to_string())); rt.update(move |capsule, tx| capsule.finish_copy_new(next, Ok(call()), tx)); rt.frame(1.0 / 60.0); assert!(rt.copy_request.take().is_some()); assert!(!rt.state.live.copying); } fn open_recording(rt: &mut Runtime) { let (x, y) = rt.find("pill").unwrap(); rt.pointer_move(x, y); rt.frame(0.0); settle_stage(rt); rt.settle_all(); rt.frame(0.0); } /// A stopped capture snaps by the window it was resized to, not the /// largest one: `capture_stopped` and the drag's `window_size` read /// one size. #[test] fn a_stopped_capture_snaps_by_the_window_it_was_resized_to() { let (mut rt, _, _) = runtime(live_recording("finalizing-size"), false, true, RECORDING); rt.update(|capsule, _| capsule.capture_stopped()); rt.update(|capsule, _| { assert!(matches!(capsule.kind, Some(Kind::Finalizing { .. }))); assert_eq!(capsule.window_size(), finalizing_window_size()); }); } #[test] fn the_recording_capsule_rests_compact_and_opens_under_the_pointer() { let (mut rt, _, _) = runtime(live_recording("capsule-hover"), false, true, RECORDING); rt.update(|capsule, _| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 2, span_ms: 4 * 60_000 + 59_000, }; }); landed(&mut rt); // At rest, the meter and time, no actions. assert!(rt.find("copy-new").is_none()); assert!(rt.find("stop").is_none()); assert_eq!(texts(&rt), ["04:18"]); let (x, _) = rt.find("pill").unwrap(); assert!( x > RECORDING.0 / 2.0, "a right corner's pill rests on the right" ); open_recording(&mut rt); assert!(rt.state.hovered); assert!(rt.find("copy-new").is_some()); assert!(texts(&rt).contains(&"4 min new".to_string())); // Moving onto a button inside the pill keeps it open. let (x, y) = rt.find("stop").unwrap(); rt.pointer_move(x, y); rt.frame(0.0); assert!(rt.state.hovered); rt.pointer_leave(); rt.frame(0.0); assert!(!rt.state.hovered); } #[test] fn dragging_the_recording_capsule_moves_it_and_snaps_to_a_corner() { type Moves = Arc>>; let (mut rt, _, _) = runtime(live_recording("capsule-drag"), false, true, RECORDING); let (moves, saved): (Moves, Arc>>) = Default::default(); let (record, save) = (moves.clone(), saved.clone()); rt.update(move |capsule, _| { capsule.shift = Some(Arc::new(move |corner, dx, dy| { record.lock().unwrap().push((corner, dx, dy)); })); capsule.save_corner = Arc::new(move |corner| save.lock().unwrap().push(corner)); }); rt.frame(0.0); let (x, y) = rt.find("pill").unwrap(); rt.pointer_move(x, y); rt.pointer_down(x, y); rt.pointer_move(x - 20.0, y + 30.0); rt.frame(0.0); assert_eq!( moves.lock().unwrap().last(), Some(&(MeetingIndicatorCorner::TopRight, -20.0, 30.0)) ); rt.pointer_up(x - 20.0, y + 30.0); rt.frame(0.0); // Off the main thread there is no screen to snap against, so it // returns to its corner. assert_eq!( moves.lock().unwrap().last(), Some(&(MeetingIndicatorCorner::TopRight, 0.0, 0.0)) ); assert!(saved.lock().unwrap().is_empty()); } #[test] fn a_cancelled_capsule_drag_returns_to_its_corner_without_saving() { type Moves = Arc>>; let (mut rt, _, _) = runtime(live_recording("capsule-cancel"), false, true, RECORDING); let (moves, saved): (Moves, Arc>>) = Default::default(); let (record, save) = (moves.clone(), saved.clone()); rt.update(move |capsule, _| { capsule.shift = Some(Arc::new(move |corner, dx, dy| { record.lock().unwrap().push((corner, dx, dy)); })); capsule.save_corner = Arc::new(move |corner| save.lock().unwrap().push(corner)); }); rt.frame(0.0); let (x, y) = rt.find("pill").unwrap(); rt.pointer_move(x, y); rt.pointer_down(x, y); rt.pointer_move(x - 400.0, y + 300.0); rt.frame(0.0); rt.key(rune::KeyEvent { key: rune::Key::Escape, mods: rune::Mods::default(), }); rt.frame(0.0); assert_eq!( moves.lock().unwrap().last(), Some(&(MeetingIndicatorCorner::TopRight, 0.0, 0.0)) ); assert!(saved.lock().unwrap().is_empty()); } #[test] fn a_released_capsule_snaps_to_the_corner_nearest_its_centre() { use MeetingIndicatorCorner::*; let screen = (1512.0, 982.0); let nearest = |from, dx, dy| nearest_corner(from, dx, dy, screen, RECORDING); assert_eq!(nearest(TopRight, -100.0, 40.0), TopRight); assert_eq!(nearest(TopRight, -700.0, 0.0), TopLeft); assert_eq!(nearest(TopRight, 0.0, 700.0), BottomRight); assert_eq!(nearest(BottomLeft, 700.0, -600.0), TopRight); assert_eq!(nearest(BottomLeft, 10.0, -10.0), BottomLeft); let (edge, margin, align, inset) = corner_placement(BottomLeft, 10.0, -10.0); assert!(matches!((edge, align), (ScreenEdge::Bottom, Align::Start))); assert_eq!( (margin, inset), (WINDOW_MARGIN + DOCK + 10.0, WINDOW_MARGIN + 10.0) ); } #[test] fn a_released_panel_snaps_by_its_own_size() { use MeetingIndicatorCorner::*; let screen = (1512.0, 982.0); // The panel's centre sits 222 pt in from the right edge, the // recording capsule's 142 pt: the same drag crosses the middle // only for the wider window. assert_eq!( nearest_corner(TopRight, -560.0, 0.0, screen, PANEL), TopLeft ); assert_eq!( nearest_corner(TopRight, -560.0, 0.0, screen, RECORDING), TopRight ); assert_eq!( nearest_corner(TopRight, -600.0, 0.0, screen, PANEL), TopLeft ); assert_eq!( nearest_corner(TopLeft, 0.0, 500.0, screen, PANEL), BottomLeft ); assert_eq!( nearest_corner(BottomRight, 0.0, -400.0, screen, PANEL), BottomRight ); assert_eq!( nearest_corner(BottomRight, 0.0, -500.0, screen, PANEL), TopRight ); } #[test] fn each_corner_places_the_panel_at_its_edges() { use MeetingIndicatorCorner::*; let top = WINDOW_MARGIN + MENU_BAR; let bottom = WINDOW_MARGIN + DOCK; for (corner, margin) in [ (TopRight, top), (TopLeft, top), (BottomRight, bottom), (BottomLeft, bottom), ] { let (edge, placed_margin, align, inset) = corner_placement(corner, 0.0, 0.0); assert_eq!( matches!(edge, ScreenEdge::Top), corner.is_top(), "{corner:?}" ); assert_eq!(matches!(align, Align::End), corner.is_right(), "{corner:?}"); assert_eq!( (placed_margin, inset), (margin, WINDOW_MARGIN), "{corner:?}" ); } } #[test] fn a_panel_drags_like_the_recording_capsule() { type Moves = Arc>>; let (mut rt, _, _) = runtime(ready_transcript(), false, true, ready_size()); let moves: Moves = Moves::default(); let record = moves.clone(); rt.update(move |capsule, _| { capsule.shift = Some(Arc::new(move |corner, dx, dy| { record.lock().unwrap().push((corner, dx, dy)); })); }); rt.frame(0.0); let (x, y) = rt.find("meta").unwrap(); rt.pointer_move(x, y); rt.pointer_down(x, y); rt.pointer_move(x - 20.0, y + 30.0); rt.frame(0.0); rt.pointer_up(x - 20.0, y + 30.0); rt.frame(0.0); let moves = moves.lock().unwrap(); assert!( moves.contains(&(MeetingIndicatorCorner::TopRight, -20.0, 30.0)), "{moves:?}" ); assert_eq!( moves.last(), Some(&(MeetingIndicatorCorner::TopRight, 0.0, 0.0)) ); // The drag pressed nothing. assert!(rt.state.kind.is_some()); } fn call_ended() -> Kind { Kind::CallEnded { app: MeetingSource::Teams.label().into(), auto_stop: false, } } fn ready_transcript() -> Kind { ready_with(serde_json::Value::Null) } /// "Lantern design sync", with Apple Intelligence's summary. fn ready_summarized() -> Kind { ready_with(serde_json::json!({ "title": "Lantern design sync", "summary": "March 26 depends on passing the soak test by March 5. Friday's playtest decides the festival demo.", })) } fn ready_size_of(kind: &Kind) -> (f32, f32) { let Kind::Ready(manifest) = kind else { panic!("a ready meeting"); }; ready_window_size(manifest) } fn ready_size() -> (f32, f32) { ready_size_of(&ready_transcript()) } fn ready_with(notes: serde_json::Value) -> Kind { Kind::Ready(Box::new( serde_json::from_value(serde_json::json!({ "schema_version": 1, "id": "ready-snap", "title": "Design sync", "status": "complete", "created_at_ms": 1_760_000_000_000_u64, "ended_at_ms": null, "duration_ms": 536_000, "notes": notes, "title_source": if notes.is_null() { "user" } else { "default" }, "system": {"file": "system.wav", "samples": 0, "dropped_packets": 0}, "microphone": {"file": "microphone.wav", "samples": 0, "dropped_packets": 0}, "error": null, "export_path": "/Users/alex/Documents/Hex Meetings/Design sync.md" })) .unwrap(), )) } fn auto_started() -> Kind { Kind::AutoStarted { title: "Slack Huddle call — 2:30 PM".into(), } } #[test] fn the_ready_panel_copies_the_finished_meeting() { let _cursor = PASTE_CURSOR .lock() .unwrap_or_else(|error| error.into_inner()); let kind = ready_summarized(); let size = ready_size_of(&kind); let (mut rt, commands, _) = runtime(kind, false, true, size); let shown = texts(&rt); for expected in [ "Lantern design sync", "08:56", "Copy all", "Copy agent prompt", ] { assert!(shown.contains(&expected.to_string()), "{shown:?}"); } assert!(shown.iter().any(|text| text.starts_with("March 26"))); // The transcript reads after the panel shows; until then Copy new // has nothing to say. tap(&mut rt, "copy-new"); assert!(rt.copy_request.is_none()); rt.update(|capsule, _| { capsule.live.entries = call(); capsule.live.pending = meeting::pending_delta("ready-snap", &call()); }); rt.frame(1.0 / 60.0); assert!(texts(&rt).contains(&"8 sec new".to_string())); tap(&mut rt, "copy-new"); assert!(rt.copy_request.take().unwrap().starts_with("Them: Kickoff")); assert_eq!(meeting::pending_delta("ready-snap", &call()).turns, 0); tap(&mut rt, "copy-prompt"); let prompt = rt.copy_request.take().unwrap(); assert!( prompt.contains("meetings show ready-snap --md"), "{}", &*prompt ); assert!(commands.try_recv().is_err()); assert!(rt.state.kind.is_some()); } #[test] fn summary_inherits_the_recordings_outer_anchor_without_the_drag_lab() { use MeetingIndicatorCorner::{BottomLeft, TopRight}; let anchor = ("ready-snap".to_owned(), BottomLeft); let kind = ready_summarized(); let corner = panel::show_corner(&kind, false, Some(&anchor), || TopRight); assert_eq!(corner, BottomLeft); assert_eq!( panel::show_corner(&call_ended(), false, Some(&anchor), || BottomLeft), TopRight ); let (mut live, _, _) = runtime(live_recording("ready-snap"), false, false, RECORDING); live.update(|c, tx| { if let Some(Kind::Recording(shown)) = &mut c.kind { shown.started = Instant::now() - Duration::from_secs(536); } c.live.entries = call(); c.corner = BottomLeft; c.hovered = true; fixture_scope(c); tx.instant(); }); let size = ready_size_of(&kind); let (mut ready, commands, _) = runtime(kind, false, false, size); ready.update(move |c, tx| { c.corner = corner; c.live.entries = call(); tx.instant(); }); let outer = |rt: &mut Runtime, window: (f32, f32)| { settle_stage(rt); rt.settle_all(); rt.frame(0.0); let [x, y, _, h] = rt .elements() .into_iter() .find(|e| e.key.as_deref() == Some("pill")) .unwrap() .rect; // Both windows target the primary screen. Convert their local // bottom-left point to screen-edge distances, including the dock margin. let (edge, margin, align, inset) = corner_placement(rt.state.corner, 0.0, 0.0); assert!(matches!((edge, align), (ScreenEdge::Bottom, Align::Start))); (x + inset, window.1 - (y + h) + margin) }; assert_eq!(outer(&mut live, RECORDING), outer(&mut ready, size)); let (x, y) = ready.find("dismiss").unwrap(); ready.pointer_move(x, y); ready.frame(0.0); assert!(ready.state.hovered); if let Some(dir) = std::env::var_os("HEX_SUMMARY_SNAPS") { let dir = std::path::PathBuf::from(dir); std::fs::create_dir_all(&dir).unwrap(); let gpu = rune::render::Gpu::try_new(rune::render::Gpu::instance(), None).unwrap(); for (name, rt, size) in [ ("recording", &mut live, RECORDING), ("summary", &mut ready, size), ] { rt.transparent = true; let (w, h, pixels) = render(&gpu, rt, size); rune::render::write_png(&dir.join(format!("{name}.png")), w, h, &pixels).unwrap(); } } tap(&mut ready, "dismiss"); assert!(ready.state.kind.is_none()); assert!(ready.copy_request.is_none() && commands.try_recv().is_err()); let Kind::Ready(notes) = ready_summarized() else { unreachable!() }; ready.update(move |c, _| c.refresh_ready(notes)); assert!(ready.state.kind.is_none()); } #[test] fn a_ready_panel_whose_time_ran_out_closes_when_the_pointer_leaves() { let (mut rt, _, _) = runtime(ready_transcript(), false, true, ready_size()); rt.update(|capsule, _| { capsule.set_hovered(true); capsule.expired = true; }); assert!(rt.state.kind.is_some()); rt.update(|capsule, _| capsule.set_hovered(false)); assert!(rt.state.kind.is_none()); } #[test] fn the_agent_prompt_names_real_commands() { assert_eq!( agent_prompt("hex", "2026-11-10-1430", "Q4 launch sync", Some(258_000)), "Use my Hex meeting \"Q4 launch sync\" as context. It is still recording.\n\n\ Read the transcript so far:\n hex meetings show 2026-11-10-1430 --md\n\n\ Catch up on what was said since this prompt (the first turn may repeat):\n \ hex meetings show 2026-11-10-1430 --from 04:18 --md\n\n\ Find a topic, then read around the time it came up:\n \ hex meetings search \"\"\n \ hex meetings show 2026-11-10-1430 --from --to --md\n" ); let finished = agent_prompt("hex", "m", "Design sync", None); assert!(finished.starts_with("Use my Hex meeting \"Design sync\" as context.\n\n")); assert!(finished.contains(" hex meetings show m --md\n")); assert!(!finished.contains("--from 0")); } #[test] fn hex_commands_quote_paths_with_spaces() { assert_eq!( shell_word("/Applications/Hex.app/Contents/MacOS/hex"), "/Applications/Hex.app/Contents/MacOS/hex" ); assert_eq!( shell_word("/Users/alex/Hex Builds/hex"), "'/Users/alex/Hex Builds/hex'" ); assert_eq!(shell_word("it's"), r"'it'\''s'"); } #[test] fn copy_new_says_how_much_is_new() { let (mut rt, _, _) = runtime(live_recording("hint"), false, true, RECORDING); open_recording(&mut rt); for (span_ms, expected) in [ (400, "1 sec new"), (1_000, "1 sec new"), (59_999, "59 sec new"), (60_000, "1 min new"), (61 * 60_000, "61 min new"), ] { rt.update(move |capsule, _| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 1, span_ms }; }); rt.frame(1.0 / 60.0); assert!( texts(&rt).contains(&expected.to_string()), "{span_ms}: {:?}", texts(&rt) ); } } #[test] fn a_bottom_corner_opens_upward() { let (mut rt, _, _) = runtime(live_recording("bottom"), false, true, RECORDING); rt.update(|capsule, _| capsule.corner = MeetingIndicatorCorner::BottomRight); open_recording(&mut rt); let (_, header) = rt.find("header").unwrap(); let (_, copy_new) = rt.find("copy-new").unwrap(); assert!(header > copy_new, "the header sits nearest the screen edge"); } #[test] fn dismissing_an_automatic_recording_never_stops_it() { let (mut rt, commands, _) = runtime(auto_started(), false, true, PANEL); tap(&mut rt, "dismiss"); assert!(commands.try_recv().is_err()); assert!(rt.state.kind.is_none()); } #[test] fn an_automatic_stop_says_so_and_keep_recording_cancels_it() { let auto = Kind::CallEnded { app: MeetingSource::WhatsApp.label().into(), auto_stop: true, }; let (mut rt, commands, _) = runtime(auto, false, true, CALL_ENDED); assert!( texts(&rt) .contains(&"Hex stops recording in 30 s unless you keep recording.".to_string()) ); tap(&mut rt, "keep-recording"); assert!(matches!( commands.try_recv(), Ok(ControllerCommand::KeepRecording) )); assert!(rt.state.kind.is_none()); // Without the lab, Keep recording sends nothing. let (mut rt, commands, _) = runtime(call_ended(), false, true, CALL_ENDED); assert!(texts(&rt).contains(&"Hex is still recording.".to_string())); let kept = Arc::new(AtomicU64::new(0)); let counted = kept.clone(); rt.state.keep_recording = Some(Arc::new(move || { counted.fetch_add(1, Ordering::SeqCst); })); tap(&mut rt, "keep-recording"); assert!(commands.try_recv().is_err()); assert_eq!( kept.load(Ordering::SeqCst), 1, "the recording capsule returns" ); assert!(rt.state.kind.is_none()); } fn started(id: &str) -> ControllerEvent { ControllerEvent::RecordingStarted { id: id.into(), title: "Design sync".into(), automatic: false, } } fn shown(model: &PillModel, indicator: bool) -> Option<(String, String, Instant)> { model .pill(indicator) .map(|shown| (shown.id.clone(), shown.title.clone(), shown.started)) } #[test] fn keep_recording_brings_back_the_recording_capsule_as_it_was() { let mut model = PillModel::default(); let start = Instant::now(); model.apply(&started("m"), start); model.apply( &ControllerEvent::CallEnded { app: "Zoom".into(), auto_stop: false, }, start, ); assert!(model.pill(true).is_none(), "the prompt stands in for it"); model.apply( &ControllerEvent::Retitled { title: "Q4 launch sync".into(), }, start, ); model.keep_recording(); assert_eq!( shown(&model, true), Some(("m".into(), "Q4 launch sync".into(), start)) ); // Another panel replacing the prompt brings it back too. model.apply( &ControllerEvent::CallEnded { app: "Zoom".into(), auto_stop: false, }, start, ); model.apply( &ControllerEvent::Offer(OfferId::at(start), slack_huddle()), start, ); assert!(model.pill(true).is_some()); // Stop & transcribe leaves it closed until the recording ends. model.apply( &ControllerEvent::CallEnded { app: "Zoom".into(), auto_stop: false, }, start, ); model.apply(&ControllerEvent::Transcribing, start); assert!(model.pill(true).is_none()); model.keep_recording(); assert!(model.pill(true).is_none()); } #[test] fn a_withdrawn_stop_brings_back_the_recording_capsule_and_closes_its_notice() { let mut model = PillModel::default(); let start = Instant::now(); model.apply(&started("m"), start); model.apply( &ControllerEvent::CallEnded { app: "Zoom".into(), auto_stop: true, }, start, ); assert!(model.pill(true).is_none(), "the notice stands in for it"); model.apply(&ControllerEvent::CallEndedWithdrawn, start); assert_eq!( shown(&model, true), Some(("m".into(), "Design sync".into(), start)) ); // The notice itself closes with it. let (mut rt, _, _) = runtime( Kind::CallEnded { app: MeetingSource::WhatsApp.label().into(), auto_stop: true, }, false, true, CALL_ENDED, ); rt.update(|capsule, _| assert!(capsule.withdraw_call_ended())); assert!(rt.state.kind.is_none()); // The "still recording" notice names no stop, so it stays. let (mut rt, _, _) = runtime(call_ended(), false, true, CALL_ENDED); rt.update(|capsule, _| assert!(!capsule.withdraw_call_ended())); assert!(matches!( rt.state.kind.as_ref(), Some(Kind::CallEnded { auto_stop: false, .. }) )); // A newer panel of another kind stays. let (mut rt, _, _) = runtime(live_recording("kept"), false, true, RECORDING); rt.update(|capsule, _| assert!(!capsule.withdraw_call_ended())); assert!(matches!(rt.state.kind.as_ref(), Some(Kind::Recording(_)))); } #[test] fn the_recording_capsule_follows_the_indicator_setting_mid_recording() { let mut model = PillModel::default(); let start = Instant::now(); model.apply(&started("m"), start); assert!(model.pill(false).is_none()); assert_eq!( shown(&model, true), Some(("m".into(), "Design sync".into(), start)) ); model.apply( &ControllerEvent::Failed { title: "Meeting recording failed".into(), error: "the microphone went away".into(), }, start, ); assert!(model.pill(true).is_none()); } #[test] fn the_call_ended_title_fits_beside_its_buttons() { let kind = call_ended(); assert_eq!(panel_width(&kind), CALL_ENDED.0); let (mut rt, _, _) = runtime(kind, false, false, CALL_ENDED); landed(&mut rt); let title = rt .elements() .into_iter() .find(|e| e.key.as_deref() == Some("title")) .unwrap(); assert_eq!(title.text.as_deref(), Some("Microsoft Teams left the call")); let style = rune_theme_opencode::kit(false).ty.ui_medium; let (width, _) = rt.text.measure("Microsoft Teams left the call", style, 2.0); assert!( width <= title.rect[2] + 0.5, "title needs {width} pt, has {}", title.rect[2] ); } include!("meeting_capsules/motion_fixture.rs"); include!("meeting_capsules/offer/proof.rs"); include!("meeting_capsules/replay_fixture.rs"); include!("meeting_capsules/exits_tests.rs"); include!("meeting_capsules/pill_tests.rs"); /// No `--snap` scene draws an overlay, so this renders the capsules to /// PNGs in `HEX_CAPSULE_SNAPS` for review; without it, or a GPU, it skips. #[test] fn capsule_snapshots() { use rune::render::Gpu; let Some(folder) = std::env::var_os("HEX_CAPSULE_SNAPS") else { return; }; let Ok(gpu) = Gpu::try_new(Gpu::instance(), None) else { eprintln!("skipping capsule snapshots: no GPU adapter"); return; }; let folder = std::path::PathBuf::from(folder); std::fs::create_dir_all(&folder).unwrap(); let mut google_meet = slack_huddle(); google_meet.source = MeetingSource::GoogleMeet; google_meet.site = Some("meet.google.com".into()); google_meet.title = "Design sync".into(); google_meet.named = true; let states = [ ("offer", offer(slack_huddle()), false, PANEL), ("offer-choices", offer(slack_huddle()), true, MENU), ("offer-choices-site", offer(google_meet), true, MENU), ("reminder", reminder(true, false), false, REMINDER), ("reminder-no-link", reminder(false, false), false, REMINDER), ("reminder-automatic", reminder(true, true), false, REMINDER), ("call-ended", call_ended(), false, CALL_ENDED), ( "recording-automatic", Kind::Recording(Recording { id: "m".into(), title: "Slack Huddle call — 2:30 PM".into(), started: Instant::now() - Duration::from_secs(4), automatic: true, warning: None, }), false, RECORDING, ), ("auto-started", auto_started(), false, PANEL), ("ready", ready_transcript(), false, ready_size()), ( "ready-summary", ready_summarized(), false, ready_size_of(&ready_summarized()), ), ]; type Setup = fn(&mut Capsule); let nothing: Setup = |_| {}; let states = states .into_iter() .map(|(name, kind, more_open, size)| (name, kind, more_open, size, nothing)) .chain::<[(&str, Kind, bool, (f32, f32), Setup); 9]>([ ( "recording-rest", live_recording("snap"), false, RECORDING, fixture_scope, ), ( "recording-silent", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { if let Some(Kind::Recording(shown)) = &mut capsule.kind { shown.warning = Some(crate::meeting::TrackWarning::DigitalSilence); } }, ), ( "recording-hover", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 3, span_ms: 4 * 60_000 + 12_000, }; fixture_scope(capsule); capsule.hovered = true; }, ), ( "recording-hover-bottom-left", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 3, span_ms: 4 * 60_000 + 12_000, }; capsule.corner = MeetingIndicatorCorner::BottomLeft; capsule.hovered = true; }, ), ( "recording-hover-silent", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { if let Some(Kind::Recording(shown)) = &mut capsule.kind { shown.warning = Some(crate::meeting::TrackWarning::DigitalSilence); } capsule.hovered = true; }, ), ( "recording-empty", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| capsule.hovered = true, ), ( "recording-transcribing", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 3, span_ms: 8_000, }; capsule.live.copying = true; capsule.hovered = true; }, ), ( "recording-copied", live_recording("snap"), false, RECORDING, |capsule: &mut Capsule| { capsule.live.entries = call(); capsule.live.copied = Some((LiveCopy::New, Instant::now())); capsule.hovered = true; }, ), ( "ready-finished", ready_summarized(), false, ready_size_of(&ready_summarized()), |capsule: &mut Capsule| { capsule.live.entries = call(); capsule.live.pending = meeting::PendingDelta { turns: 3, span_ms: 3 * 60_000 + 5_000, }; }, ), ]); for (name, kind, more_open, size, setup) in states { for dark in [false, true] { let (mut rt, _, _) = runtime(kind.clone(), more_open, dark, size); let size = if matches!(kind, Kind::Offer(..)) { rt.state.presentation.window() } else { size }; rt.update(move |capsule, _| setup(capsule)); let (w, h, pixels) = render(&gpu, &mut rt, size); let theme = if dark { "dark" } else { "light" }; let path = folder.join(format!("capsule-{name}-{theme}.png")); rune::render::write_png(&path, w, h, &pixels).unwrap(); } } } fn render( gpu: &rune::render::Gpu, rt: &mut Runtime, size: (f32, f32), ) -> (u32, u32, Vec) { settle_stage(rt); rt.settle_all(); rt.frame(0.0); let (w, h) = ((size.0 * 2.0) as u32, (size.1 * 2.0) as u32); let mut renderer = crate::rune_ui::offscreen::renderer(&gpu.device); let target = crate::rune_ui::offscreen::target(&gpu.device, w, h); if matches!(rt.state.kind, Some(Kind::Recording(_))) { if rt.state.waveform.is_none() { let now = Instant::now(); let mut wave = waveform::Listening::new(now); wave.sample(now, [0.0; 2]); rt.state.waveform = Some(Box::new(wave)); } return ( w, h, paint_recording( gpu, &mut renderer, &target, rt, &mut waveform::Ink::default(), ), ); } renderer.prepare( &gpu.device, &gpu.queue, &mut rt.text.atlas, &rt.instances, (w, h), ); let mut encoder = gpu.device.create_command_encoder(&Default::default()); renderer.draw(&mut encoder, &target.view, rt.clear_color()); target.copy(&mut encoder); gpu.queue.submit([encoder.finish()]); (w, h, target.read(&gpu.device)) } /// The call-ended, ready, and automatic-recording capsules against /// `tests/golden/meeting-capsule-*.png`; `HEX_UPDATE_GOLDENS=1` rewrites /// them. Without a GPU adapter it skips. Like every golden it is checked /// on Linux only: glyph coverage on Metal differs past the tolerance. #[test] #[cfg_attr(not(target_os = "linux"), ignore = "goldens are checked on Linux")] fn panel_goldens() { let Ok(gpu) = rune::render::Gpu::try_new(rune::render::Gpu::instance(), None) else { eprintln!("skipping meeting capsule golden: no GPU adapter"); return; }; let folder = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/golden"); let states = [ ("call-ended", call_ended(), CALL_ENDED), ("ready", ready_transcript(), ready_size()), ("auto-started", auto_started(), PANEL), ("recording-rest", live_recording("fixture"), RECORDING), ("recording-open", live_recording("fixture"), RECORDING), ]; let mut misses = Vec::new(); for ((name, kind, size), dark) in states .into_iter() .flat_map(|state| [false, true].map(|dark| (state.clone(), dark))) { let theme = if dark { "dark" } else { "light" }; let file = format!("meeting-capsule-{name}-{theme}"); let path = folder.join(format!("{file}.png")); let (mut rt, _, _) = runtime(kind, false, dark, size); if name.starts_with("recording-") { rt.update(move |c, _| { if let Some(Kind::Recording(shown)) = &mut c.kind { shown.started = Instant::now() - Duration::from_secs(258); } fixture_scope(c); c.hovered = name == "recording-open"; c.live.entries = call(); c.live.pending = meeting::PendingDelta { turns: 2, span_ms: 64_000, }; }); } let (w, h, pixels) = render(&gpu, &mut rt, size); if std::env::var_os("HEX_UPDATE_GOLDENS").is_some() { rune::render::write_png(&path, w, h, &pixels).unwrap(); continue; } // Where CI's golden-actual artifact picks it up. let actual = std::env::temp_dir().join(format!("rune-settings-{file}-actual.png")); if !path.exists() { rune::render::write_png(&actual, w, h, &pixels).unwrap(); misses.push(format!("{file} is missing; actual at {}", actual.display())); continue; } let decoder = png::Decoder::new(std::io::BufReader::new(std::fs::File::open(&path).unwrap())); let mut reader = decoder.read_info().unwrap(); let mut golden = vec![0; reader.output_buffer_size().unwrap()]; let info = reader.next_frame(&mut golden).unwrap(); if (info.width, info.height) != (w, h) { rune::render::write_png(&actual, w, h, &pixels).unwrap(); misses.push(format!( "{name}-{theme}: size changed; actual at {}", actual.display() )); continue; } // GPUs differ in the last bit of blending and glyph coverage. let differing = pixels .chunks(4) .zip(golden.chunks(4)) .filter(|(a, b)| a.iter().zip(b.iter()).any(|(x, y)| x.abs_diff(*y) > 12)) .count(); if differing > (w * h) as usize / 500 { rune::render::write_png(&actual, w, h, &pixels).unwrap(); misses.push(format!( "{name}-{theme}: {differing} pixels differ; actual at {}", actual.display() )); } } assert!(misses.is_empty(), "{}", misses.join("\n")); } }