hex/src/rune_ui/meetings_host.rs
Dax 6118eb828f
meetings: labs toggle to mute the microphone while recording (#2659)
* meetings: labs toggle to mute the microphone while recording

* meetings: clear the microphone mute when its lab goes off

Labs › Mute the microphone while recording ANDed the controller's switch
with the gate, so turning the lab off restored audio but left the switch
set; turning the lab back on in the same recording silently re-muted it.
The controller now reconciles the switch once per pass and clears it
while the lab is off.

The request and reset live in capture.rs as small policies so their tests
give the recording and lab explicitly instead of reading saved settings,
which also covers the accepted path. The docs say the capsule only shows
a "Microphone muted" notice; its buttons are in the pane and menu bar.
2026-11-24 05:42:54 -05:00

410 lines
16 KiB
Rust

//! The Meetings pane's listing, read from the meetings store on every OS,
//! and the meeting requests the Linux and Windows windows perform in their
//! own process (macOS's go through `macos_host`), and what the meeting
//! capsules and controller tell the window.
#[cfg(not(target_os = "macos"))]
use std::path::PathBuf;
use std::time::{Duration, Instant};
use super::Ui;
use super::meetings::{Chapter, Meeting, Status, Transcript, Turn};
#[cfg(not(target_os = "macos"))]
use super::platform::MeetingRequest;
#[cfg(not(target_os = "macos"))]
use crate::desktop::i18n::tr;
const RESCAN: Duration = Duration::from_secs(1);
/// Linux and Windows: the window and the meeting controller share one
/// process, so the window performs meeting requests itself.
#[cfg(not(target_os = "macos"))]
#[derive(Default)]
pub(super) struct LocalMeetings {
feed: MeetingFeed,
/// The transcript folder panel, while it is open.
folder_choice: Option<crate::desktop::file_dialog::Pending>,
}
#[cfg(not(target_os = "macos"))]
impl LocalMeetings {
/// `wake` redraws the window once the folder panel answers.
pub(super) fn send(
&mut self,
request: MeetingRequest,
wake: impl Fn() + Send + 'static,
) -> Result<(), String> {
use crate::meeting::MeetingRequest as Controller;
let failed = |error: color_eyre::Report| format!("{error:#}");
match request {
MeetingRequest::Start => {
crate::meeting::runtime::request(Controller::Start { title: None })
}
MeetingRequest::Stop => crate::meeting::runtime::request(Controller::Stop),
MeetingRequest::Import(_) => Err("Importing audio is only available on macOS.".into()),
MeetingRequest::DeleteTranscript { id, entries } => {
crate::meeting::runtime::request(Controller::DeleteTranscript { id, entries })
}
// The control and its visible states are macOS's; elsewhere the
// request is taken and the controller leaves it alone.
MeetingRequest::SetMicrophoneMuted(muted) => {
crate::meeting::runtime::request(Controller::SetMicrophoneMuted(muted))
}
MeetingRequest::Summarize(id) => {
crate::meeting::runtime::request(Controller::Summarize(id))
}
MeetingRequest::Rename { id, title } => crate::meeting::rename(&id, &title)
.map(|_| ())
.map_err(failed),
MeetingRequest::Trash(id) => crate::meeting::trash(&id).map_err(failed),
MeetingRequest::Reveal(target) => {
// A file is selected in its folder; a recording folder opens
// itself.
if target.is_markdown() {
crate::meeting::reveal(target.path());
} else {
crate::meeting::open_folder(target.path());
}
Ok(())
}
MeetingRequest::RevealFolder => {
let folder = crate::app_settings::meeting_output_folder();
std::fs::create_dir_all(&folder).map_err(|error| error.to_string())?;
crate::meeting::open_folder(&folder);
Ok(())
}
MeetingRequest::ChooseFolder => {
use crate::desktop::file_dialog::{Dialog, Target};
if self.folder_choice.is_none() {
self.folder_choice = Some(crate::desktop::file_dialog::open(
Dialog {
title: tr("Transcript folder").into(),
target: Target::Folder,
directory: Some(crate::app_settings::meeting_output_folder()),
},
wake,
));
}
Ok(())
}
}
}
/// The folder the panel answered with since the last call.
pub(super) fn chosen_folder(&mut self) -> Option<Result<PathBuf, String>> {
let choice = self.folder_choice.as_ref()?.poll()?;
self.folder_choice = None;
choice.transpose()
}
pub(super) fn meetings(&mut self) -> Option<Result<Vec<Meeting>, String>> {
self.feed.poll()
}
}
/// The Meetings pane's listing from the read-only store query, rescanned at
/// most once a second; unchanged meeting folders come from its cache.
#[derive(Default)]
pub(super) struct MeetingFeed {
library: Option<crate::meeting::query::Library>,
scan_at: Option<Instant>,
shown: Option<Result<Vec<Meeting>, String>>,
}
impl MeetingFeed {
pub(super) fn poll(&mut self) -> Option<Result<Vec<Meeting>, String>> {
let now = Instant::now();
if self.scan_at.is_some_and(|at| now < at) {
return None;
}
self.scan_at = Some(now + RESCAN);
let listed = self.scan();
if self.shown.as_ref() == Some(&listed) {
return None;
}
self.shown = Some(listed.clone());
Some(listed)
}
fn scan(&mut self) -> Result<Vec<Meeting>, String> {
let library = match &self.library {
Some(library) => library,
None => {
let root = crate::meeting::root().map_err(|error| format!("{error:#}"))?;
self.library
.insert(crate::meeting::query::Library::new(root))
}
};
let scan = library.scan().map_err(|error| format!("{error:#}"))?;
let now_ms = crate::desktop::events::now_ms();
let root = library.root();
Ok(scan
.meetings
.iter()
.map(|meeting| pane_meeting(meeting, root, now_ms))
.collect())
}
}
/// A stored meeting as the pane shows it.
fn pane_meeting(
meeting: &crate::meeting::query::Meeting,
root: &std::path::Path,
now_ms: u64,
) -> Meeting {
use crate::meeting::MeetingStatus;
let manifest = &meeting.manifest;
let transcript = if meeting.entries.is_empty() && !meeting.warnings.is_empty() {
Transcript::Unavailable(meeting.warnings.join("\n"))
} else {
Transcript::Loaded(turns(&meeting.entries))
};
let folder = root.join(&meeting.id);
Meeting {
id: meeting.id.clone(),
title: meeting.title(),
status: match meeting.status {
MeetingStatus::Starting => Status::Starting,
MeetingStatus::Recording => Status::Recording,
MeetingStatus::Transcribing => Status::Transcribing,
MeetingStatus::Complete => Status::Complete,
MeetingStatus::Interrupted => Status::Interrupted,
MeetingStatus::Failed => Status::Failed,
},
day: crate::meeting::day_label(meeting.start_ms(), now_ms),
clock: crate::meeting::clock(meeting.start_ms()),
duration_ms: meeting.duration_ms(now_ms),
app: manifest.app.clone(),
summary: manifest
.notes
.as_ref()
.map(|notes| notes.summary.clone())
.filter(|summary| !summary.is_empty()),
notes_running: crate::meeting::notes_in_progress(&meeting.id),
reveal: crate::meeting::RevealTarget::for_meeting(manifest, &folder),
folder,
error: manifest.error.clone(),
export_error: manifest.export_error.clone(),
notes_error: manifest.notes_error.clone(),
live_error: manifest.live_transcription_error.clone(),
microphone_warning: manifest.microphone.warning,
transcript,
imported: manifest.imported,
// Sections come from the transcript lines, not the merged turns, as
// the menu bar and `hex meetings show --chapter` read them.
kept_for: (!meeting.status.is_active())
.then(|| {
crate::meeting::retention_for(manifest, crate::app_settings::meeting_retention())
})
.filter(|retention| retention.max_age_ms().is_some())
.map(crate::app_settings::MeetingRetention::label),
chapters: meeting
.chapter_views(now_ms)
.iter()
.map(|view| Chapter {
title: view.chapter.title.clone(),
summary: view.chapter.summary.clone(),
start_ms: view.chapter.start_ms,
markdown: view.markdown(),
})
.collect(),
}
}
/// Speaker turns, marking silences of 30 s or more. Each turn carries the
/// published lines it covers so the pane can delete exactly those.
fn turns(entries: &[crate::meeting::TranscriptEntry]) -> Vec<Turn> {
let mut previous_end: Option<u64> = None;
let mut cursor = 0;
crate::meeting::coalesce_transcript(entries.iter().cloned())
.into_iter()
.map(|turn| {
let pause_before_ms = previous_end
.map(|end| turn.start_ms.saturating_sub(end))
.filter(|pause| *pause >= 30_000);
previous_end = Some(previous_end.map_or(turn.end_ms, |end| end.max(turn.end_ms)));
// The entries are sorted and coalescing keeps their order, so a
// turn covers the next contiguous lines inside its own span.
let mut covered = Vec::new();
while let Some(entry) = entries.get(cursor) {
if entry.source != turn.source
|| entry.start_ms < turn.start_ms
|| entry.end_ms > turn.end_ms
{
break;
}
covered.push(crate::meeting::TranscriptEntryKey::of(entry));
cursor += 1;
}
Turn {
mine: turn.source == crate::meeting::MeetingSource::Microphone,
start_ms: turn.start_ms,
text: turn.text,
pause_before_ms,
entries: covered,
}
})
.collect()
}
/// The capsule committed a choice; adopt the owner's next revision.
pub(crate) fn meeting_settings_saved(ui: &mut Ui) {
ui.send(super::host::Request::ReloadSettings);
}
/// A meeting recording could not start or finish; the Meetings pane says why.
pub(crate) fn meeting_failed(ui: &mut Ui, error: String) {
ui.meetings.start_pending = false;
ui.meetings.stop_pending = false;
ui.meetings.runtime_error = Some(error);
}
/// Transcript lines could not be deleted; the Meetings pane says why.
pub(crate) fn meeting_edit_failed(ui: &mut Ui, error: String) {
ui.meetings.edit_error = Some(error);
}
#[cfg(test)]
mod tests {
use super::*;
use crate::meeting::{MeetingSource, TranscriptEntry, TranscriptEntryKey};
/// Each displayed turn carries exactly the published lines under it, in
/// transcript order, however the speakers interleave.
#[test]
fn turns_carry_exactly_their_own_published_lines() {
let line = |source, start_ms: u64, end_ms: u64, text: &str| TranscriptEntry {
source,
start_ms,
end_ms,
text: text.into(),
};
let entries = vec![
line(MeetingSource::Microphone, 0, 4_000, "First."),
line(MeetingSource::Microphone, 4_000, 8_000, "Second."),
line(MeetingSource::System, 8_000, 12_000, "In between."),
line(
MeetingSource::Microphone,
12_000,
16_000,
"After the reply.",
),
line(MeetingSource::Microphone, 20_000, 23_000, "A pause later."),
];
let keys = |turn: &Turn| turn.entries.clone();
let of = TranscriptEntryKey::of;
let turns = turns(&entries);
assert_eq!(
turns.iter().map(|turn| turn.start_ms).collect::<Vec<_>>(),
[0, 8_000, 12_000, 20_000],
"adjacent same-speaker lines join, the other speaker splits them, \
and more than three seconds apart stays apart"
);
assert_eq!(keys(&turns[0]), [of(&entries[0]), of(&entries[1])]);
assert_eq!(keys(&turns[1]), [of(&entries[2])]);
assert_eq!(keys(&turns[2]), [of(&entries[3])]);
assert_eq!(keys(&turns[3]), [of(&entries[4])]);
}
#[test]
fn the_meeting_feed_lists_stored_meetings_once_until_they_change() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/meetings");
let mut feed = MeetingFeed {
library: Some(crate::meeting::query::Library::new(root)),
..MeetingFeed::default()
};
let meetings = feed.poll().expect("the first poll lists").unwrap();
let ids: Vec<_> = meetings.iter().map(|meeting| meeting.id.as_str()).collect();
assert_eq!(
ids,
[
"1790001000000-1003",
"1790000500000-1002",
"1790000000000-1001"
],
"newest first, without the unreadable folder"
);
let standup = &meetings[0];
assert_eq!(standup.status, Status::Interrupted, "an unlocked recording");
let review = &meetings[1];
assert_eq!(review.title, "Roadmap review");
let Transcript::Loaded(turns) = &review.transcript else {
panic!("the roadmap review has a transcript");
};
assert!(!turns[0].mine && turns[1].mine);
assert_eq!(turns.last().unwrap().pause_before_ms, Some(42_000));
feed.scan_at = None;
assert!(
feed.poll().is_none(),
"an unchanged listing is not sent again"
);
}
#[test]
fn copy_section_matches_the_menu_bar_and_the_cli() {
let root = std::env::temp_dir().join(format!(
"hex-copy-section-{}-{}",
std::process::id(),
crate::desktop::events::now_ms()
));
let id = "1790003000000-1005";
let fixture = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/meetings-chapters")
.join(id);
let directory = root.join(id);
std::fs::create_dir_all(&directory).unwrap();
std::fs::copy(
fixture.join("manifest.json"),
directory.join("manifest.json"),
)
.unwrap();
// One speaker's two lines join into one turn across the boundary
// at 06:30; the second line belongs to the chapter after.
let line = |start_ms: u64, end_ms: u64, text: &str| crate::meeting::TranscriptEntry {
source: crate::meeting::MeetingSource::Microphone,
start_ms,
end_ms,
text: text.into(),
};
let entries = [
line(181_000, 188_000, "Next, the motion lint."),
line(386_000, 389_000, "That settles the lint."),
line(390_500, 397_000, "Last thing: a name for the chat app."),
];
let ndjson = entries
.iter()
.map(|entry| serde_json::to_string(entry).unwrap() + "\n")
.collect::<String>();
std::fs::write(directory.join("transcript.ndjson"), ndjson).unwrap();
// A final publication includes both files, even though chapter
// queries render their own Markdown from the structured entries.
std::fs::write(
directory.join("transcript.md"),
"# Team sync\n\n**You** · 03:01\nNext, the motion lint.\n\n\
**You** · 06:26\nThat settles the lint.\n\n\
**You** · 06:30\nLast thing: a name for the chat app.\n",
)
.unwrap();
let library = crate::meeting::query::Library::new(&root);
let meeting = library.meeting(id).unwrap();
let now_ms = crate::desktop::events::now_ms();
let pane = pane_meeting(&meeting, &root, now_ms);
let chapters = &meeting.manifest.chapters;
for (index, chapter) in pane.chapters.iter().enumerate() {
// The menu bar's Copy Section (`meeting::section_for_id`).
let menu = crate::meeting::section_markdown(
&chapters[index],
&crate::meeting::chapter_entries(&entries, chapters, index),
meeting.manifest.imported,
);
assert_eq!(chapter.markdown, menu);
let cli = library.chapter_markdown(id, index + 1, now_ms).unwrap();
assert!(cli.ends_with(&format!("\n{menu}\n")), "{cli}");
}
assert!(pane.chapters[1].markdown.contains("That settles the lint."));
assert!(!pane.chapters[1].markdown.contains("Last thing"));
assert!(pane.chapters[2].markdown.contains("Last thing"));
std::fs::remove_dir_all(root).unwrap();
}
}