mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* Graduate six meeting labs, move four into Meetings settings, and throw capsules into corners (t1532) * Regenerate goldens and count call rows from the provider list (t1532) * Trace a recording pill hover and reversal offscreen (t1571) * Keep the recording meter anchored and show each audio track (t1571) * Keep light and dark recording snapshots from Linux (t1571) * Draw dictation’s listening field inside the meeting pill (t1571) * Refresh meeting pill goldens with the listening field (t1571) * Paint just the listening dots on the meeting surface (t1571) * Keep dots-only recording goldens in light and dark (t1571) * Keep recording controls and the dictation HUD dark on light desktops (t1571) * Refresh the dark overlays on light-host goldens (t1571) * Keep the finished meeting in its corner and let Close dismiss it (t1571) * Refresh finished summary goldens with the close control (t1571) * Open shipped features from What’s new (t1574) * Keep release-specific links distinct from feature navigation (t1574) * Document and translate the feature feed (t1574) * Verify dark and light navigation to both controls (t1574) * Show feature icons and calendar-day headings in What’s new (t1574) * Verify local-day boundaries and refresh both feed goldens (t1574) * Separate What's new navigation from build details (t1574) * Check What’s new selection through accessibility (t1574) * Refresh only the lower sidebar in the Linux goldens (t1574) * Drop the graduated labs from the Labs card and catalog (t1532) * Keep the merged meeting files inside the source cap (t1532) * Regenerate the Labs and Meetings goldens for the cleanup (t1532) * Drop the graduated labs from the website catalog (t1532) * Keep the throw's frame hook on every capsule (t1532)
133 lines
3.8 KiB
Rust
133 lines
3.8 KiB
Rust
//! Meeting finished events: tells one local API subscriber
|
|
//! (`GET /meetings/events`) a meeting's id once its final transcript and
|
|
//! Markdown are written. Only the id leaves this module: no title, path,
|
|
//! transcript text, or audio. With nobody subscribed, nothing is queued
|
|
//! or kept.
|
|
|
|
use std::sync::Mutex;
|
|
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, SyncSender, TrySendError};
|
|
use std::time::Duration;
|
|
|
|
/// Events waiting for a slow subscriber; more are dropped and logged.
|
|
const BACKLOG: usize = 16;
|
|
|
|
/// The one subscriber slot.
|
|
pub(crate) struct Hub {
|
|
subscriber: Mutex<Option<SyncSender<String>>>,
|
|
}
|
|
|
|
static HUB: Hub = Hub::new();
|
|
|
|
/// The process's hub, which the meeting recorder publishes to.
|
|
pub(crate) fn global() -> &'static Hub {
|
|
&HUB
|
|
}
|
|
|
|
/// Publishes a finished meeting.
|
|
pub(crate) fn publish(id: &str) {
|
|
HUB.publish(id);
|
|
}
|
|
|
|
impl Hub {
|
|
pub(crate) const fn new() -> Self {
|
|
Self {
|
|
subscriber: Mutex::new(None),
|
|
}
|
|
}
|
|
|
|
/// Takes the one subscriber slot; `None` while another subscriber holds it.
|
|
pub(crate) fn subscribe(&'static self) -> Option<Subscription> {
|
|
let mut slot = self
|
|
.subscriber
|
|
.lock()
|
|
.unwrap_or_else(|error| error.into_inner());
|
|
if slot.is_some() {
|
|
return None;
|
|
}
|
|
let (sender, receiver) = mpsc::sync_channel(BACKLOG);
|
|
*slot = Some(sender);
|
|
Some(Subscription {
|
|
hub: self,
|
|
receiver,
|
|
})
|
|
}
|
|
|
|
/// Hands `id` to the subscriber, if someone listens.
|
|
pub(crate) fn publish(&self, id: &str) {
|
|
let mut slot = self
|
|
.subscriber
|
|
.lock()
|
|
.unwrap_or_else(|error| error.into_inner());
|
|
let Some(sender) = slot.as_ref() else {
|
|
return;
|
|
};
|
|
match sender.try_send(id.to_owned()) {
|
|
Ok(()) => tracing::info!(meeting = id, "sent meeting finished event"),
|
|
Err(TrySendError::Full(_)) => {
|
|
tracing::warn!(
|
|
meeting = id,
|
|
"meeting finished event dropped: subscriber is behind"
|
|
);
|
|
}
|
|
Err(TrySendError::Disconnected(_)) => *slot = None,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The subscriber's end; dropping it frees the slot.
|
|
pub(crate) struct Subscription {
|
|
hub: &'static Hub,
|
|
receiver: Receiver<String>,
|
|
}
|
|
|
|
impl Subscription {
|
|
/// The next finished meeting's id, waiting at most `timeout`.
|
|
pub(crate) fn next(&self, timeout: Duration) -> Result<String, RecvTimeoutError> {
|
|
self.receiver.recv_timeout(timeout)
|
|
}
|
|
}
|
|
|
|
impl Drop for Subscription {
|
|
fn drop(&mut self) {
|
|
*self
|
|
.hub
|
|
.subscriber
|
|
.lock()
|
|
.unwrap_or_else(|error| error.into_inner()) = None;
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn a_finished_meeting_reaches_the_one_subscriber_as_its_id() {
|
|
static TEST_HUB: Hub = Hub::new();
|
|
let subscription = TEST_HUB.subscribe().unwrap();
|
|
assert!(TEST_HUB.subscribe().is_none(), "one subscriber at a time");
|
|
TEST_HUB.publish("1700000000000-42");
|
|
assert_eq!(
|
|
subscription.next(Duration::from_secs(1)).unwrap(),
|
|
"1700000000000-42"
|
|
);
|
|
assert_eq!(
|
|
subscription.next(Duration::from_millis(10)),
|
|
Err(RecvTimeoutError::Timeout),
|
|
"published once"
|
|
);
|
|
drop(subscription);
|
|
assert!(TEST_HUB.subscribe().is_some(), "dropping frees the slot");
|
|
}
|
|
|
|
#[test]
|
|
fn nothing_is_kept_before_anyone_subscribes() {
|
|
static TEST_HUB: Hub = Hub::new();
|
|
TEST_HUB.publish("before-anyone-listened");
|
|
let subscription = TEST_HUB.subscribe().unwrap();
|
|
assert_eq!(
|
|
subscription.next(Duration::from_millis(10)),
|
|
Err(RecvTimeoutError::Timeout)
|
|
);
|
|
}
|
|
}
|