hex/src/rune_ui/meetings.rs
Dax 49de3e1675
meetings: import audio files (labs) (#1462)
* meetings: import audio files behind a Labs switch

Adds Labs › Import audio (macOS, off by default): Meetings offers Import audio… beside Start recording, decodes a WAV, M4A, MP3, AIFF, or CAF file to 16 kHz mono float through a new AVFoundation Swift bridge in bounded blocks, writes it as an ordinary meeting with an empty microphone track, and runs the same final transcript, Markdown export, and notes path a recording does. Imported turns are labelled Speaker in the pane and its Markdown export; a manifest flag keeps older files reading as recorded meetings. Refuses while a recording or another import runs, and a final.pending meeting finishes on the next launch if Hex quits mid-import.

* meetings: harden audio import decoding and cleanup

Fixes review findings on #1462: the staging WAV is named for AVAudioFile, declares kAudioFileWAVEType, closes before Rust reads it, and the converter loop separates input exhaustion from termination, writes every non-empty buffer, downmixes stereo, and reports a zero-frame read as EOF. Every failure before final.pending removes the meeting folder; quitting during the final pass leaves it Interrupted with final.pending for the next launch; shutdown logs import errors and still joins pending finals. The import button and watcher share the managed Labs gate, and the watcher refuses an off-lab import before spawning a worker. Adds macOS decode tests for 44.1 kHz stereo float and 16-bit PCM.

* meetings: cancel abandoned audio imports and sweep their folders

A quit now cancels the AVFoundation decode between blocks, so the existing cleanup removes the meeting folder within the drain. A crash or a quit past the deadline can still leave a staging file and lock; a launch sweep removes those folders only when they have no manifest, contain system.importing.wav, and their lock is free. Also drops read error code 0 as EOF, autopools each converter iteration, and makes the macOS stereo tests silent on the left so a lost downmix fails.

* meetings: keep compressed imports whole and close the import crash window

A short AVAudioFile read no longer ends input; only a zero-frame read, kAudioFileEndOfFileError, or an error at/after the recorded end does. The import now fsyncs its staging WAV, creates and syncs the empty microphone track, and computes its samples before the rename; the manifest write immediately follows the rename. The launch sweep also removes a folder with both finished tracks and no manifest, covering the rename-to-manifest window.

* meetings: mark imports explicitly for the launch sweep

An import writes import.pending under its lock before decoding and removes it only after final.pending is synced; the sweep now requires that marker, no manifest, and a free lock, so it never guesses from the files a folder contains. A tail read error after a short read counts as EOF for MP3s whose estimated length is too high, while a mid-file error after a full read still fails.
2026-11-06 15:25:22 -05:00

1491 lines
52 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The Meetings pane (macOS beta): recorded calls by day with their status,
//! search, a detail with notes, the live or final transcript as turns,
//! Copy transcript, Rename, an overflow menu (copy summary, reveal,
//! summarize, delete), and the two-step trash confirmation. Recording is
//! started and stopped from the header, whose `Recordings | Settings` switch
//! also shows the feature's settings (Call recording, Calendar, Detected
//! calls). With Meetings off, the pane is the opt-in card alone.
//!
//! The meetings store and controller are macOS-only, so the pane reads
//! [`Meeting`] values the host loads (formatted with `meeting::day_label`,
//! `meeting::clock`, and the coalesced transcript) and sends
//! [`MeetingRequest`]s back. Scenes feed [`MeetingsPane::fixture`].
use rune::{El, TextEdit, Tx, col, row, text};
use rune_kit::{IconButton, IconButtonVariant, Menu as KitMenu, MenuItem, Placement, TextInput};
use super::controls::{
ButtonKind, DESCRIPTION, Paint, button, card, page, pulsing_dot, segmented_tx,
};
use super::list_detail::{self as ld, Item};
use super::lists::{Tone, dismissible_error_panel, error_panel, section_label, tone_tag};
use super::platform::MeetingRequest;
use super::{Menu, Ui};
use crate::desktop::file_dialog::{Dialog, Filter, Pending, Target};
use crate::desktop::i18n::{tr, tr_fill, tr_named};
static MORE_ICON: rune::Icon = rune::Icon {
name: "hex-more",
view: 16.0,
body: r#"<circle cx="3.5" cy="8" r="1.25" fill="currentColor"/><circle cx="8" cy="8" r="1.25" fill="currentColor"/><circle cx="12.5" cy="8" r="1.25" fill="currentColor"/>"#,
};
// Only the macOS host reports the states fixtures do not show.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Status {
Starting,
Recording,
Transcribing,
Complete,
Interrupted,
Failed,
}
impl Status {
pub(super) fn is_active(self) -> bool {
matches!(self, Self::Starting | Self::Recording | Self::Transcribing)
}
}
/// One speaker turn. `mine` is the microphone side ("You").
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct Turn {
pub(super) mine: bool,
pub(super) start_ms: u64,
pub(super) text: String,
/// A silence of 30 s or more before this turn.
pub(super) pause_before_ms: Option<u64>,
}
/// One topic of a meeting (Labs), from `start_ms` to
/// the next chapter's start.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct Chapter {
pub(super) title: String,
pub(super) summary: String,
pub(super) start_ms: u64,
/// What Copy section copies, from the same transcript lines as the menu
/// bar and `hex meetings show --chapter`.
pub(super) markdown: String,
}
// Only the macOS host reports the states fixtures do not show.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) enum Transcript {
Loaded(Vec<Turn>),
Unavailable(String),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct Meeting {
pub(super) id: String,
pub(super) title: String,
pub(super) status: Status,
/// `Today`, `Yesterday`, or a date, from `meeting::day_label`.
pub(super) day: String,
/// The start time, from `meeting::clock`.
pub(super) clock: String,
pub(super) duration_ms: u64,
pub(super) app: Option<String>,
pub(super) summary: Option<String>,
pub(super) notes_running: bool,
/// What the overflow menu reveals: the exported Markdown while it still
/// exists, else the recording folder. Trash takes the Markdown too.
pub(super) reveal: crate::meeting::RevealTarget,
pub(super) error: Option<String>,
pub(super) export_error: Option<String>,
pub(super) notes_error: Option<String>,
pub(super) live_error: Option<String>,
pub(super) transcript: Transcript,
pub(super) chapters: Vec<Chapter>,
/// Imported from an audio file (Labs › Import audio): its one track is
/// labelled Speaker.
pub(super) imported: bool,
/// How long it is kept once finished, as `MeetingRetention::label`;
/// `None` when it is kept for good.
pub(super) kept_for: Option<&'static str>,
}
impl Meeting {
fn turns(&self) -> &[Turn] {
match &self.transcript {
Transcript::Loaded(turns) => turns,
Transcript::Unavailable(_) => &[],
}
}
fn searchable(&self) -> String {
let mut text = format!(
"{} {} {}",
self.title,
self.app.as_deref().unwrap_or_default(),
self.summary.as_deref().unwrap_or_default()
);
for turn in self.turns() {
text.push(' ');
text.push_str(&turn.text);
}
text.to_lowercase()
}
}
/// What the pane shows, picked in its header.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(super) enum View {
#[default]
Recordings,
Settings,
}
/// Meetings is on, so the pane lists recordings and settings instead of the
/// opt-in card (`MeetingSettings::available`; scenes leave `developer` off).
pub(super) fn available(ui: &Ui) -> bool {
crate::labs::Feature::Meetings.managed().is_none()
&& (ui.settings.meetings.enabled || ui.platform.developer)
}
/// Whether something can write a meeting's notes when asked: OpenCode once
/// Summaries chooses it, otherwise Apple Intelligence on a Mac that has it.
fn notes_available(ui: &Ui) -> bool {
ui.settings.meetings.summaries == crate::app_settings::MeetingSummaries::OpenCode
|| apple_intelligence_writes(ui)
}
/// Whether Apple Intelligence writes notes asked for now: Summaries isn't
/// OpenCode and this Mac has it.
fn apple_intelligence_writes(ui: &Ui) -> bool {
ui.settings.meetings.summaries != crate::app_settings::MeetingSummaries::OpenCode
&& ui.platform.caps.os == super::platform::Os::Macos
&& ui.platform.notes.is_available()
}
/// What writes the notes now, as the generator picks it.
fn notes_running_label(ui: &Ui) -> &'static str {
if apple_intelligence_writes(ui) {
tr("Writing a title and summary with Apple Intelligence…")
} else {
tr("Writing a title and summary with OpenCode…")
}
}
#[derive(Default)]
pub(super) struct MeetingsPane {
pub(super) view: View,
/// Newest first, as the store lists them.
pub(super) meetings: Vec<Meeting>,
error: Option<String>,
/// The last recording that could not start or finish.
pub(super) runtime_error: Option<String>,
/// The last audio file that could not be imported (Labs › Import audio).
pub(super) import_error: Option<String>,
/// The audio file dialog while it is open.
import_chooser: Option<Pending>,
pub(super) search: TextEdit,
pub(super) selected: Option<String>,
pub(super) renaming: Option<String>,
pub(super) rename: TextEdit,
pub(super) delete_armed: Option<String>,
action_error: Option<String>,
/// What was last copied, for the button's "Copied".
copied: Option<(String, String)>,
pub(super) start_pending: bool,
pub(super) stop_pending: bool,
/// Where Linux and Windows perform meeting requests.
#[cfg(not(target_os = "macos"))]
pub(super) local: super::meetings_host::LocalMeetings,
}
/// `42 min`, `1 h 05 min`, or `< 1 min`.
fn length(milliseconds: u64) -> String {
let minutes = milliseconds / 60_000;
match minutes {
0 => tr("< 1 min").into(),
1..=59 => tr_fill("{} min", &minutes.to_string()),
_ => tr_named(
"{hours} h {minutes} min",
&[
("hours", &(minutes / 60).to_string()),
("minutes", &format!("{:02}", minutes % 60)),
],
),
}
}
/// `mm:ss`, as `meeting::format_duration`.
fn clock_offset(milliseconds: u64) -> String {
let seconds = milliseconds / 1_000;
format!("{:02}:{:02}", seconds / 60, seconds % 60)
}
/// Speaker turns as Markdown, as `meeting::transcript_markdown`; an imported
/// meeting's one track is Speaker.
fn transcript_markdown(turns: &[Turn], imported: bool) -> String {
turns
.iter()
.map(|turn| {
format!(
"**{}** · {}\n{}",
if imported {
"Speaker"
} else if turn.mine {
"You"
} else {
"Them"
},
clock_offset(turn.start_ms),
turn.text.trim()
)
})
.collect::<Vec<_>>()
.join("\n\n")
}
impl MeetingsPane {
fn meeting(&self, id: &str) -> Option<&Meeting> {
self.meetings.iter().find(|meeting| meeting.id == id)
}
fn active(&self) -> Option<&Meeting> {
self.meetings
.iter()
.find(|meeting| meeting.status.is_active())
}
fn visible(&self) -> Vec<&Meeting> {
let query = self.search.text.trim().to_lowercase();
self.meetings
.iter()
.filter(|meeting| query.is_empty() || meeting.searchable().contains(&query))
.collect()
}
/// Adopts a fresh listing: follows a recording that just started,
/// settles the Start/Stop buttons, and drops a selection that is gone.
pub(super) fn adopt(&mut self, listed: Result<Vec<Meeting>, String>) {
let meetings = match listed {
Ok(meetings) => meetings,
Err(error) => {
self.error = Some(error);
return;
}
};
let active = meetings.iter().find(|meeting| meeting.status.is_active());
let previous = self.active().map(|meeting| meeting.id.clone());
if let Some(active) = active {
self.start_pending = false;
if previous.as_deref() != Some(active.id.as_str()) {
self.select(active.id.clone());
}
}
if active.is_none_or(|meeting| meeting.status == Status::Transcribing) {
self.stop_pending = false;
}
if let Some(selected) = &self.selected
&& !meetings.iter().any(|meeting| &meeting.id == selected)
{
self.selected = None;
}
self.meetings = meetings;
self.error = None;
}
pub(super) fn select(&mut self, id: String) {
if self.selected.as_deref() != Some(id.as_str()) {
self.renaming = None;
self.delete_armed = None;
self.action_error = None;
}
self.selected = Some(id);
}
/// One recording, one with notes, one without, and one that failed.
pub(super) fn fixture() -> Self {
let turn = |mine, seconds: u64, text: &str| Turn {
mine,
start_ms: seconds * 1_000,
text: text.into(),
pause_before_ms: None,
};
let mut conversation = vec![
turn(
false,
1,
"Basically, I want Anomaly Arcade to be one login where you add friends and jump into any game.",
),
turn(false, 4, "I need to finish my StarCraft game, too."),
turn(true, 9, "Oh nice. How far along is it?"),
turn(
false,
13,
"Close. I feel like over a couple of months we could make twenty to thirty games.",
),
turn(true, 20, "That's basically a new version of Steam."),
turn(
false,
24,
"If we're seeing Roblox, the idea should be to become Roblox.",
),
turn(
true,
31,
"Apple has a new thing where you hold two phones together and there's this pulse and gravity well. Could be a nice mini gravity well for the transitions.",
),
turn(false, 40, "Prototype it in WebGPU, whatever's faster."),
turn(
true,
95,
"The build screen looks rough, by the way. We need a proposal for it.",
),
turn(
false,
101,
"Agreed. Write it up and I'll review it tomorrow.",
),
];
conversation[8].pause_before_ms = Some(55_000);
let meeting =
|id: &str, title: &str, status, day: &str, clock: &str, minutes: u64| Meeting {
id: id.into(),
title: title.into(),
status,
day: day.into(),
clock: clock.into(),
duration_ms: minutes * 60_000 + 20_000,
app: None,
summary: None,
notes_running: false,
reveal: crate::meeting::RevealTarget::Folder(
format!("/Users/kit/Library/Application Support/hex/meetings/{id}").into(),
),
error: None,
export_error: None,
notes_error: None,
live_error: None,
transcript: Transcript::Loaded(Vec::new()),
chapters: Vec::new(),
imported: false,
kept_for: Some("24 hours"),
};
let mut live = meeting(
"preview-live",
"Zoom call — 14:05",
Status::Recording,
"Today",
"14:05",
7,
);
live.app = Some("Zoom".into());
live.transcript = Transcript::Loaded(conversation[..6].to_vec());
let mut notes = meeting(
"preview-notes",
"Arcade launch plan",
Status::Complete,
"Today",
"11:12",
38,
);
notes.app = Some("Zoom".into());
notes.reveal = crate::meeting::RevealTarget::Markdown(
"/Users/kit/Documents/Hex Meetings/Arcade launch plan.md".into(),
);
notes.summary = Some(
"One login for every Anomaly Arcade game, aiming for twenty to thirty games over the next couple of months. The build screen needs a proposal before more polish."
.into(),
);
notes.transcript = Transcript::Loaded(conversation.clone());
let mut design = meeting(
"preview-design",
"Design review",
Status::Complete,
"Yesterday",
"16:30",
24,
);
design.app = Some("FaceTime".into());
design.transcript = Transcript::Loaded(conversation[2..6].to_vec());
let mut failed = meeting(
"preview-failed",
"Meeting — 09:58",
Status::Failed,
"Yesterday",
"09:58",
2,
);
failed.error = Some("ScreenCaptureKit stopped the capture.".into());
Self {
meetings: vec![live, notes, design, failed],
selected: Some("preview-notes".into()),
..Self::default()
}
}
/// The fixture with recordings from more call services: a Zoom call, a
/// Google Meet tab, a Teams website call, a Slack huddle, FaceTime, and
/// one started by hand.
#[cfg(all(test, not(target_os = "macos")))]
pub(super) fn platforms_fixture() -> Self {
let mut pane = Self::fixture();
let mut more = Vec::new();
for (id, title, app) in [
("preview-meet", "Weekly sync", "Google Meet"),
("preview-teams", "Vendor check-in", "teams.microsoft.com"),
("preview-huddle", "Release huddle", "Slack Huddle"),
] {
let mut meeting = pane.meetings[2].clone();
meeting.id = id.into();
meeting.title = title.into();
meeting.app = Some(app.into());
more.push(meeting);
}
pane.meetings.splice(2..2, more);
pane
}
/// The fixture with live chapters (Labs) on the
/// meeting with notes, its title extended by them.
pub(super) fn chapters_fixture() -> Self {
let mut pane = Self::fixture();
let chapters = [
(
"One login",
"One login for every Arcade game, twenty to thirty games in a couple of months.",
0,
),
(
"Gravity well",
"A pulse and gravity well for transitions, prototyped in WebGPU.",
31_000,
),
(
"Build screen",
"The build screen needs a written proposal.",
95_000,
),
];
if let Some(notes) = pane.meetings.iter_mut().find(|m| m.id == "preview-notes") {
notes.title = "Arcade launch plan: One login, Gravity well, Build screen".into();
let turns = notes.turns().to_vec();
let imported = notes.imported;
notes.chapters = chapters
.iter()
.enumerate()
.map(|(index, &(title, summary, start_ms))| {
let end_ms = chapters.get(index + 1).map(|next| next.2);
let inside = turns
.iter()
.filter(|turn| {
turn.start_ms >= start_ms
&& end_ms.is_none_or(|end| turn.start_ms < end)
})
.cloned()
.collect::<Vec<_>>();
Chapter {
title: title.into(),
summary: summary.into(),
start_ms,
markdown: format!(
"## {title}\n\n{summary}\n\n{}",
transcript_markdown(&inside, imported)
)
.trim_end()
.into(),
}
})
.collect();
}
pane
}
}
/// Sends `request` where it is carried out (on Linux and Windows, the
/// window's own meetings, not the OS host, which ignores meeting requests).
fn ask(ui: &mut Ui, request: MeetingRequest) -> bool {
match ui.send_meeting(request) {
Ok(()) => true,
Err(error) => {
ui.meetings.action_error = Some(error);
false
}
}
}
fn start(ui: &mut Ui) {
ui.meetings.start_pending = ask(ui, MeetingRequest::Start);
}
fn stop(ui: &mut Ui) {
ui.meetings.stop_pending = ask(ui, MeetingRequest::Stop);
}
fn start_rename(ui: &mut Ui, id: String) {
let Some(meeting) = ui.meetings.meeting(&id) else {
return;
};
ui.meetings.rename = TextEdit::new(meeting.title.clone());
ui.meetings.renaming = Some(id);
ui.open = None;
}
fn finish_rename(ui: &mut Ui) {
let Some(id) = ui.meetings.renaming.take() else {
return;
};
let title = ui.meetings.rename.text.trim().to_string();
if title.is_empty() {
return;
}
if ask(
ui,
MeetingRequest::Rename {
id: id.clone(),
title: title.clone(),
},
) && ui.host.is_fixture()
&& let Some(meeting) = ui.meetings.meetings.iter_mut().find(|m| m.id == id)
{
meeting.title = title;
}
}
/// The first press arms the confirmation; the confirmation trashes.
fn trash(ui: &mut Ui, id: String) {
ui.open = None;
if ui.meetings.delete_armed.as_deref() != Some(id.as_str()) {
ui.meetings.delete_armed = Some(id);
return;
}
ui.meetings.delete_armed = None;
if ask(ui, MeetingRequest::Trash(id.clone())) && ui.host.is_fixture() {
ui.meetings.meetings.retain(|meeting| meeting.id != id);
ui.meetings.selected = None;
}
}
fn copy(ui: &mut Ui, tx: &mut Tx, id: String, what: impl Into<String>, text: String) {
tx.copy(text);
ui.meetings.copied = Some((id, what.into()));
}
/// The status tag; `Ready` only in the detail header, so the list stays
/// quiet for finished meetings.
/// The detail's status, while it is one worth a tag.
pub(super) fn status_tag(p: Paint, status: Status, stop_pending: bool) -> Option<El> {
let (label, tone) = match status {
Status::Recording if stop_pending => (tr("Transcribing"), Tone::Accent),
Status::Starting | Status::Recording => (tr("Recording"), Tone::Danger),
Status::Transcribing => (tr("Transcribing"), Tone::Accent),
Status::Complete => return None,
Status::Interrupted => (tr("Interrupted"), Tone::Neutral),
Status::Failed => (tr("Failed"), Tone::Danger),
};
Some(tone_tag(p, "status", label, tone))
}
/// The opt-in card while Meetings is off; otherwise the header's view
/// switch and Start/Stop, then the recordings or the settings.
pub(super) fn pane(ui: &Ui, p: Paint, layer: &mut Vec<El>) -> (Vec<El>, El) {
if !available(ui) {
let content = page("content").child(card(
p,
"enable",
vec![super::platform_settings::meetings_toggle(ui, p)],
));
return (Vec::new(), super::scroll_body(p.k, "scroll", content));
}
let action = recording_action(ui, p);
if ui.meetings.view == View::Settings {
let content =
page("content").children(super::platform_settings::meetings_settings(ui, p, layer));
return (
vec![action],
super::scroll_body(p.k, "settings-scroll", content),
);
}
recordings(ui, p, layer, action)
}
/// The header's `Recordings | Settings` switch, beside the title so it stays
/// put whichever view shows; none while the opt-in card does.
pub(super) fn view_switch(ui: &Ui, p: Paint) -> Option<El> {
if !available(ui) {
return None;
}
let views = [tr("Recordings"), tr("Settings")];
let selected = match ui.meetings.view {
View::Recordings => 0,
View::Settings => 1,
};
Some(segmented_tx(
p,
"meetings-view",
&views,
selected,
|ui: &mut Ui, index: usize, tx: &mut Tx| {
let view = if index == 0 {
View::Recordings
} else {
View::Settings
};
if ui.meetings.view != view {
tx.settle();
ui.flush_drafts();
ui.open = None;
ui.meetings.view = view;
ui.meetings.renaming = None;
ui.meetings.delete_armed = None;
}
},
))
}
fn search(ui: &Ui, p: Paint) -> El {
TextInput::new(&ui.meetings.search)
.placeholder(tr("Search meetings"))
.width(None)
.leading_icon(p.k.glyph.search)
.on_edit(|ui: &mut Ui| &mut ui.meetings.search)
.build(p.k)
.key("meetings-search")
}
/// Start recording, or the active recording's elapsed time and Stop.
fn recording_action(ui: &Ui, p: Paint) -> El {
let pane = &ui.meetings;
let busy = |label: &str| {
text(label)
.key("meeting-busy")
.font(DESCRIPTION)
.color(p.muted())
};
let active = pane.active();
let action = match active.map(|meeting| meeting.status) {
_ if pane.stop_pending => busy(tr("Finalizing…")),
Some(Status::Transcribing) => busy(tr("Finalizing…")),
Some(Status::Starting) => busy(tr("Starting…")),
// Recording is a state, not the screen's main action.
Some(Status::Recording) => row()
.key("stop-meeting-control")
.gap(12.0)
.center_y()
.child(
row()
.key("elapsed-group")
.gap(6.0)
.center_y()
.child(pulsing_dot(p.danger()))
.children(active.map(|meeting| {
text(clock_offset(meeting.duration_ms))
.key("elapsed")
.font(p.k.ty.mono)
.color(p.muted())
})),
)
.child(button(
p,
"stop-meeting",
tr("Stop & transcribe"),
ButtonKind::Secondary,
|ui: &mut Ui, _| stop(ui),
)),
_ if pane.start_pending => busy(tr("Starting…")),
_ => button(
p,
"start-meeting",
tr("Start recording"),
ButtonKind::Primary,
|ui: &mut Ui, _| start(ui),
),
};
// Importing is a second way in, never a competing main action.
if crate::labs::meeting_import() && active.is_none() && !pane.start_pending {
return row()
.key("meeting-actions")
.gap(8.0)
.center_y()
.child(button(
p,
"import-meeting",
tr("Import audio…"),
ButtonKind::Secondary,
|ui: &mut Ui, _| choose_import(ui),
))
.child(action);
}
action
}
/// The Labs › Import audio file dialog: one supported audio file.
fn choose_import(ui: &mut Ui) {
if ui.meetings.import_chooser.is_some() {
return;
}
ui.meetings.action_error = None;
let waker = ui.modes.waker.clone();
let wake = move || {
if let Some(waker) = &waker {
waker();
}
};
ui.meetings.import_chooser = Some(crate::desktop::file_dialog::open(
Dialog {
title: tr("Import audio").into(),
target: Target::File(vec![Filter {
label: tr("Audio files").into(),
extensions: &["wav", "m4a", "mp3", "aiff", "aif", "caf"],
}]),
directory: dirs::audio_dir(),
},
wake,
));
}
/// The audio file dialog's answer: a chosen file is imported where meetings
/// are carried out. True when the answer changed what the pane shows.
pub(super) fn poll_import(ui: &mut Ui) -> bool {
let Some(choice) = ui.meetings.import_chooser.as_ref().and_then(Pending::poll) else {
return false;
};
ui.meetings.import_chooser = None;
match choice {
Ok(Some(path)) => {
ask(ui, MeetingRequest::Import(path));
}
Ok(None) => {}
Err(error) => ui.meetings.action_error = Some(error),
}
true
}
/// An audio file could not be imported; the Meetings pane says why.
pub(crate) fn meeting_import_failed(ui: &mut Ui, error: String) {
ui.meetings.import_error = Some(error);
}
/// A row's state line: what went wrong or is happening, else the app and
/// length.
fn row_meta(pane: &MeetingsPane, meeting: &Meeting, p: Paint) -> (String, Option<rune::Color>) {
let (state, ink) = match meeting.status {
Status::Recording if pane.stop_pending => (Some(tr("Transcribing")), None),
Status::Starting | Status::Recording => (Some(tr("Recording")), Some(p.danger())),
Status::Transcribing => (Some(tr("Transcribing")), None),
Status::Failed => (Some(tr("Failed")), Some(p.danger())),
Status::Interrupted => (Some(tr("Interrupted")), None),
Status::Complete => (None, None),
};
let mut parts: Vec<String> = state.map(String::from).into_iter().collect();
parts.extend(meeting.app.clone());
if !meeting.status.is_active() {
parts.push(length(meeting.duration_ms));
}
(parts.join(" · "), ink)
}
/// The icon before a row's title: the call service's when its app names
/// one and a neutral one otherwise (another app, or a meeting started by
/// hand).
fn platform_icon(meeting: &Meeting) -> &'static rune::Icon {
match meeting
.app
.as_deref()
.and_then(crate::calendar::CallProvider::from_meeting_app)
{
Some(provider) => super::platform_settings::provider_icon(provider),
None => &super::icons::CALL,
}
}
/// Copy transcript as an icon: a completed row's hover action, or the
/// card's.
fn copy_action(p: Paint, pane: &MeetingsPane, meeting: &Meeting, what: &'static str) -> El {
let copied = pane
.copied
.as_ref()
.is_some_and(|(id, copied)| id == &meeting.id && copied == what);
let glyph = if copied {
p.k.glyph.check_small
} else {
ld::COPY_ICON
};
let id = meeting.id.clone();
let press = move |ui: &mut Ui, tx: &mut Tx| {
if let Some(meeting) = ui.meetings.meeting(&id) {
let markdown = transcript_markdown(meeting.turns(), meeting.imported);
copy(ui, tx, id.clone(), what, markdown);
}
};
if what == "row" {
ld::row_action(p, "row-copy", glyph, tr("Copy transcript"), press)
} else {
ld::ghost_icon(
p,
"meeting-copy-transcript",
glyph,
tr("Copy transcript"),
press,
)
}
}
/// The day-grouped list and the selected meeting's card.
fn recordings(ui: &Ui, p: Paint, layer: &mut Vec<El>, action: El) -> (Vec<El>, El) {
let pane = &ui.meetings;
let mut notices = Vec::new();
if let Some(error) = &pane.error {
notices.push(error_panel(
p,
"meetings-error",
tr("Meetings could not be loaded."),
error,
));
}
if let Some(error) = &pane.runtime_error {
notices.push(dismissible_error_panel(
p,
"meeting-runtime-error",
tr("Meeting could not be recorded."),
error,
|ui: &mut Ui| ui.meetings.runtime_error = None,
));
}
if let Some(error) = &pane.import_error {
notices.push(dismissible_error_panel(
p,
"meeting-import-error",
tr("Audio could not be imported."),
error,
|ui: &mut Ui| ui.meetings.import_error = None,
));
}
let body = if pane.meetings.is_empty() {
ld::empty_state(
p,
"meetings-empty",
ld::HISTORY_ICON,
tr("No meetings yet."),
Some(tr("Record a call to see its notes and transcript here.")),
)
} else {
let mut list = col().key("meetings-list").label(tr("Meetings"));
let mut day: Option<&str> = None;
let visible = pane.visible();
let count = visible.len();
for (index, meeting) in visible.into_iter().enumerate() {
if day != Some(meeting.day.as_str()) {
list = list.child(ld::group(
p,
&format!("day{index}"),
day_label(&meeting.day),
day.is_none(),
));
day = Some(&meeting.day);
}
let (meta, meta_ink) = row_meta(pane, meeting, p);
let completed = meeting.status == Status::Complete && !meeting.turns().is_empty();
let id = meeting.id.clone();
list = list.child(
ld::item_with_icon(
p,
Item {
key: format!("meeting-{}", meeting.id),
title: meeting.title.clone(),
meta,
meta_ink,
time: meeting.clock.clone(),
hover: completed
.then(|| copy_action(p, pane, meeting, "row"))
.into_iter()
.collect(),
selected: pane.selected.as_deref() == Some(meeting.id.as_str()),
},
Some(platform_icon(meeting)),
move |ui: &mut Ui| ui.meetings.select(id.clone()),
)
.position_in_set(index + 1, count),
);
}
let detail = match pane.selected.as_deref().and_then(|id| pane.meeting(id)) {
Some(meeting) => detail(ui, p, meeting, layer),
None if pane.visible().is_empty() => ld::empty_state(
p,
"meetings-empty",
ld::SEARCH_ICON,
tr("No meetings match."),
None,
),
None => ld::empty_state(
p,
"meeting-detail",
ld::HISTORY_ICON,
tr("Select a meeting."),
None,
),
};
let column = ld::list_column(p, search(ui, p), "meetings-scroll", list);
ld::body(p, "meetings-body", column, detail)
};
(
vec![action],
col()
.key("meetings-pane")
.grow(1.0)
.shrink()
.children((!notices.is_empty()).then(|| ld::notices(notices)))
.child(body),
)
}
fn day_label(day: &str) -> &str {
match day {
"Today" => tr("Today"),
"Yesterday" => tr("Yesterday"),
other => other,
}
}
fn detail(ui: &Ui, p: Paint, meeting: &Meeting, layer: &mut Vec<El>) -> El {
let pane = &ui.meetings;
let active = meeting.status.is_active();
let copied = |what: &str| {
pane.copied
.as_ref()
.is_some_and(|(id, copied)| id == &meeting.id && copied == what)
};
let armed = pane.delete_armed.as_deref() == Some(meeting.id.as_str());
let renaming = pane.renaming.as_deref() == Some(meeting.id.as_str());
let mut actions = Vec::new();
let mut confirm = None;
if armed && !active && !meeting.notes_running {
// The confirmation sits under the title until it is answered.
let id = meeting.id.clone();
confirm = Some(
row()
.key("delete-confirm")
.gap(8.0)
.pt(14.0)
.child(
button(
p,
"meeting-confirm-delete",
if meeting.reveal.is_markdown() {
tr("Trash recording & Markdown")
} else {
tr("Trash recording")
},
ButtonKind::Danger,
move |ui: &mut Ui, _| trash(ui, id.clone()),
)
.default_button(),
)
.child(button(
p,
"meeting-cancel-delete",
tr("Cancel"),
ButtonKind::Secondary,
|ui: &mut Ui, _| ui.meetings.delete_armed = None,
)),
);
} else if !renaming {
// The title field brings its own Save and Cancel.
if !meeting.turns().is_empty() {
actions.push(copy_action(p, pane, meeting, "transcript"));
}
if !active {
let id = meeting.id.clone();
actions.push(ld::ghost_icon(
p,
"meeting-rename",
ld::EDIT_ICON,
tr("Rename"),
move |ui: &mut Ui, _| start_rename(ui, id.clone()),
));
}
actions.extend(overflow(ui, p, meeting, layer));
}
let title = if renaming {
row()
.key("rename")
.w_full()
.gap(8.0)
.center_y()
.child(
TextInput::new(&pane.rename)
.label(tr("Name"))
.width(Some(220.0))
.on_edit(|ui: &mut Ui| &mut ui.meetings.rename)
.on_submit(|ui: &mut Ui, _| finish_rename(ui))
.build(p.k)
.key("rename-field"),
)
.child(button(
p,
"meeting-save-title",
tr("Save"),
ButtonKind::Secondary,
|ui: &mut Ui, _| finish_rename(ui),
))
.child(button(
p,
"meeting-cancel-title",
tr("Cancel"),
ButtonKind::Secondary,
|ui: &mut Ui, _| ui.meetings.renaming = None,
))
} else {
ld::card_title(p, &meeting.title)
};
let mut meta_line = vec![
day_label(&meeting.day).to_string(),
meeting.clock.clone(),
clock_offset(meeting.duration_ms),
];
meta_line.extend(meeting.app.clone());
if !meeting.status.is_active()
&& let Some(kept_for) = meeting.kept_for
{
meta_line.push(tr_fill("Deleted after {}", tr(kept_for)));
}
let mut meta: Vec<El> = status_tag(p, meeting.status, pane.stop_pending)
.into_iter()
.collect();
meta.push(ld::meta_text(p, &meta_line.join(" · ")));
let errors = [
pane.action_error
.as_deref()
.map(|error| ("action-error", tr("Meeting could not be updated."), error)),
meeting
.error
.as_deref()
.map(|error| ("recording-error", tr("Recording failed."), error)),
meeting
.export_error
.as_deref()
.map(|error| ("export-error", tr("Markdown not saved."), error)),
meeting
.notes_error
.as_deref()
.filter(|_| !meeting.notes_running)
.map(|error| ("notes-error", tr("Notes could not be written."), error)),
meeting
.live_error
.as_deref()
.filter(|_| active)
.map(|error| ("live-error", tr("Live transcript unavailable."), error)),
];
let mut body = col().key("detail-body").gap(24.0).pb(8.0);
for (key, title, error) in errors.into_iter().flatten() {
body = body.child(error_panel(p, key, title, error));
}
if let Some(summary) = &meeting.summary {
let summary = summary.trim();
body = body.child(
col()
.key("notes")
.gap(6.0)
.child(section_label(p, "summary-label", tr("Summary")))
.child(
text(if summary.is_empty() {
tr("Nothing to summarize.")
} else {
summary
})
.key("summary")
.font(p.k.ty.body)
.color(if summary.is_empty() {
p.faint()
} else {
p.text()
})
.wrap(),
),
);
} else if meeting.notes_running {
body = body.child(
text(notes_running_label(ui))
.key("notes-running")
.font(DESCRIPTION)
.color(p.faint()),
);
}
if !meeting.chapters.is_empty() {
body = body.child(chapters(p, meeting, &copied));
}
let transcript_label = match meeting.status {
Status::Starting | Status::Recording if !pane.stop_pending => tr("Live transcript"),
Status::Starting | Status::Recording | Status::Transcribing => tr("Draft transcript"),
Status::Complete => tr("Transcript"),
Status::Interrupted | Status::Failed => tr("Recovered draft"),
};
body = body.child(
col()
.key("transcript-block")
.gap(10.0)
.child(section_label(p, "transcript-label", transcript_label))
.child(transcript(p, meeting, pane.stop_pending)),
);
col()
.key("meeting-detail")
.grow(1.0)
.shrink()
.child(ld::card_header(title, meta, actions))
.children(confirm)
.child(ld::card_scroll_sticky(
p,
"meeting-transcript",
body,
follows_live_transcript(ui, meeting),
))
}
/// Labs › Follow live transcript: a recording meeting's transcript keeps
/// its newest line in view while scrolled to the bottom. Off, and for any
/// meeting not recording, the card scrolls only by hand, as before.
fn follows_live_transcript(ui: &Ui, meeting: &Meeting) -> bool {
ui.settings.labs.follow_live_transcript
&& crate::labs::Feature::FollowLiveTranscript.shipped()
&& matches!(meeting.status, Status::Starting | Status::Recording)
&& !ui.meetings.stop_pending
}
/// The meeting's chapters, each with its start, name, line, and Copy
/// section.
fn chapters(p: Paint, meeting: &Meeting, copied: &dyn Fn(&str) -> bool) -> El {
let mut list = col()
.key("chapters")
.gap(10.0)
.pb(16.0)
.child(section_label(p, "chapters-label", tr("Chapters")));
for (index, chapter) in meeting.chapters.iter().enumerate() {
let what = format!("chapter{index}");
let id = meeting.id.clone();
let mut words = col().key("words").gap(2.0).grow(1.0).shrink().child(
text(chapter.title.clone())
.key("title")
.font(p.k.ty.body_medium)
.color(p.text())
.wrap(),
);
if !chapter.summary.trim().is_empty() {
words = words.child(
text(chapter.summary.trim())
.key("summary")
.font(DESCRIPTION)
.color(p.muted())
.wrap(),
);
}
list = list.child(
row()
.key(format!("chapter{index}"))
.gap(12.0)
.child(
text(clock_offset(chapter.start_ms))
.key("clock")
.font(p.k.ty.mono)
.color(p.faint())
.pt(1.0),
)
.child(words)
.child(
ld::ghost_icon(
p,
"copy-section",
if copied(&what) {
p.k.glyph.check_small
} else {
ld::COPY_ICON
},
tr("Copy section"),
move |ui: &mut Ui, tx: &mut Tx| {
if let Some(markdown) = ui
.meetings
.meeting(&id)
.and_then(|meeting| meeting.chapters.get(index))
.map(|chapter| chapter.markdown.clone())
{
copy(ui, tx, id.clone(), what.clone(), markdown);
}
},
)
.mt(-4.0),
),
);
}
list
}
/// Less common actions behind the ellipsis, Delete last.
fn overflow(ui: &Ui, p: Paint, meeting: &Meeting, layer: &mut Vec<El>) -> Option<El> {
let active = meeting.status.is_active();
let mut menu = KitMenu::new("meeting-actions")
.placement(Placement::BottomEnd)
.gutter(4.0)
.min_width(200.0)
.open(ui.open == Some(Menu::MeetingActions))
.on_close(|ui: &mut Ui| ui.open = None);
let mut items = 0;
if let Some(summary) = meeting.summary.clone() {
let id = meeting.id.clone();
let copied = ui
.meetings
.copied
.as_ref()
.is_some_and(|(copied, what)| copied == &meeting.id && what == "notes");
// Stays open so "Copied" confirms the copy.
menu = menu.item(
MenuItem::new(if copied {
tr("Copied")
} else {
tr("Copy summary")
})
.on_select_tx(move |ui: &mut Ui, tx: &mut Tx| {
copy(ui, tx, id.clone(), "notes", summary.trim().to_string());
ui.open = Some(Menu::MeetingActions);
}),
);
items += 1;
}
if !active {
// The label and the file it reveals are one value, so they can't
// disagree.
let reveal = meeting.reveal.clone();
menu = menu.item(
MenuItem::new(if reveal.is_markdown() {
tr("Reveal Markdown")
} else {
tr("Reveal files")
})
.on_select(move |ui: &mut Ui| {
ui.open = None;
ask(ui, MeetingRequest::Reveal(reveal.clone()));
}),
);
items += 1;
}
if meeting.status == Status::Complete && notes_available(ui) {
if meeting.notes_running {
menu = menu.item(MenuItem::new(tr("Summarizing…")).disabled(true));
} else {
let id = meeting.id.clone();
menu = menu.item(
MenuItem::new(if meeting.summary.is_some() {
tr("Regenerate summary")
} else {
tr("Summarize")
})
.on_select(move |ui: &mut Ui| {
ui.open = None;
ask(ui, MeetingRequest::Summarize(id.clone()));
}),
);
}
items += 1;
}
if !active && !meeting.notes_running {
if items > 0 {
menu = menu.separator();
}
let id = meeting.id.clone();
menu = menu
.item(MenuItem::new(tr("Delete…")).on_select(move |ui: &mut Ui| trash(ui, id.clone())));
items += 1;
}
if items == 0 {
return None;
}
let trigger = IconButton::new(&MORE_ICON)
.variant(IconButtonVariant::Ghost)
.control_size(rune_kit::ControlSize::Small)
.label(tr("More"))
.on_press(|ui: &mut Ui| {
ui.open = (ui.open != Some(Menu::MeetingActions)).then_some(Menu::MeetingActions);
})
.build(p.k)
.key("meeting-more");
Some(menu.trigger(trigger).build(p.k, layer))
}
fn transcript(p: Paint, meeting: &Meeting, stop_pending: bool) -> El {
let empty = |copy: &str| {
text(copy)
.key("transcript-empty")
.font(DESCRIPTION)
.color(p.faint())
.wrap()
};
let turns = match &meeting.transcript {
Transcript::Unavailable(error) => {
return error_panel(p, "transcript-error", tr("Transcript unavailable."), error);
}
Transcript::Loaded(turns) => turns,
};
if turns.is_empty() {
return empty(match meeting.status {
Status::Starting => tr("Preparing local audio capture…"),
Status::Recording if meeting.live_error.is_some() => {
tr("Live transcription is unavailable. Audio is still recording safely.")
}
Status::Recording if stop_pending => tr("Building the final transcript…"),
Status::Recording => tr("Listening for speech…"),
Status::Transcribing => tr("Building the final transcript…"),
Status::Complete => tr("No speech was transcribed."),
Status::Interrupted | Status::Failed => tr("No recoverable transcript is available."),
});
}
let mut lines = col().key("turns").gap(14.0);
for (index, turn) in turns.iter().enumerate() {
lines = lines.children(turn_line(p, index, turn, meeting.imported));
}
if meeting.status == Status::Recording && !stop_pending {
lines = lines.child(
text(tr("Listening…"))
.key("listening")
.font(p.k.ty.small)
.color(p.faint()),
);
}
lines
}
/// One turn of a transcript: the pause before it, if any, then the speaker,
/// the time, and the words. An imported meeting has one track: Speaker.
pub(super) fn turn_line(p: Paint, index: usize, turn: &Turn, imported: bool) -> Vec<El> {
let mut els = Vec::new();
if let Some(pause) = turn.pause_before_ms {
els.push(
text(tr_fill("{} pause", &length(pause)))
.key(format!("pause{index}"))
.font(p.k.ty.small)
.color(p.faint()),
);
}
els.push(
col()
.key(format!("turn{index}"))
.gap(2.0)
.child(
row()
.key("speaker")
.gap(8.0)
.child(
text(if imported {
tr("Speaker")
} else if turn.mine {
tr("You")
} else {
tr("Them")
})
.key("name")
.font(p.k.ty.small_medium)
.color(if turn.mine && !imported {
p.text()
} else {
p.faint()
}),
)
.child(
text(clock_offset(turn.start_ms))
.key("clock")
.font(p.k.ty.small)
.color(p.faint()),
),
)
.child(
text(turn.text.clone())
.key("text")
.font(p.k.ty.body)
.color(p.text())
.wrap(),
),
);
els
}
#[cfg(all(test, not(target_os = "macos")))]
mod tests {
use super::*;
use crate::rune_ui::Service;
use crate::rune_ui::platform::PlatformHost;
/// An imported meeting has one track: every turn is Speaker, not Them.
#[test]
fn an_imported_meeting_labels_its_one_track_speaker() {
let turn = |mine| Turn {
mine,
start_ms: 1_000,
text: "Hi.".into(),
pause_before_ms: None,
};
assert!(transcript_markdown(&[turn(false)], true).contains("**Speaker** · 00:01"));
assert!(transcript_markdown(&[turn(true)], true).contains("**Speaker**"));
assert!(transcript_markdown(&[turn(true)], false).contains("**You**"));
assert!(transcript_markdown(&[turn(false)], false).contains("**Them**"));
}
/// Linux and Windows carry meeting requests out in the window's own
/// process; the OS host ignored them, so Stop, Rename, and Trash from
/// the pane did nothing and reported nothing (#566).
#[test]
fn pane_requests_reach_the_window_s_own_meetings() {
let mut ui = Ui::with(
crate::app_settings::AppSettings::default(),
Service::Fixture(Vec::new()),
);
assert!(matches!(ui.host, PlatformHost::Local(_)));
ui.meetings = MeetingsPane::fixture();
// No meeting controller runs in tests, so the request is refused
// rather than silently accepted.
stop(&mut ui);
assert!(!ui.meetings.stop_pending);
assert!(ui.meetings.action_error.is_some());
}
/// A known call service's icon, and the neutral one for any other or
/// no app (#1290).
#[test]
fn platform_icons_fall_back_to_a_neutral_one() {
let pane = MeetingsPane::platforms_fixture();
let name = |id: &str| platform_icon(pane.meeting(id).unwrap()).name;
assert_eq!(name("preview-live"), "hex-provider-zoom");
assert_eq!(name("preview-meet"), "hex-provider-meet");
assert_eq!(name("preview-teams"), "hex-provider-teams");
assert_eq!(name("preview-huddle"), "hex-provider-slack");
assert_eq!(name("preview-design"), "hex-row-call");
assert_eq!(name("preview-failed"), "hex-row-call");
}
/// Labs › Follow live transcript: only a recording meeting's transcript
/// follows its newest line, and only with the lab on (#1332).
#[test]
fn only_a_recording_transcript_follows_and_only_with_its_lab() {
let mut settings = crate::app_settings::AppSettings::default();
let pane = MeetingsPane::fixture();
let live = pane.meeting("preview-live").unwrap();
let finished = pane.meeting("preview-notes").unwrap();
let ui = Ui::with(settings.clone(), Service::Fixture(Vec::new()));
assert!(!follows_live_transcript(&ui, live));
assert!(!follows_live_transcript(&ui, finished));
settings.labs.follow_live_transcript = true;
let mut ui = Ui::with(settings, Service::Fixture(Vec::new()));
assert!(follows_live_transcript(&ui, live));
assert!(!follows_live_transcript(&ui, finished));
ui.meetings.stop_pending = true;
assert!(!follows_live_transcript(&ui, live));
}
/// Off a Mac the notes are written by OpenCode, so the progress line
/// names it, never Apple Intelligence (#1151).
#[test]
fn notes_progress_names_opencode_off_a_mac() {
let ui = Ui::with(
crate::app_settings::AppSettings::default(),
Service::Fixture(Vec::new()),
);
let label = notes_running_label(&ui);
assert!(label.contains("OpenCode"), "{label}");
assert!(!label.contains("Apple Intelligence"), "{label}");
}
}