mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* labs: delete transcript lines from a saved meeting A finished meeting's detail offers Select lines beside Copy when Labs › Delete transcript lines is on. Turns become checkable, Delete lines… asks once, and the confirmed request carries each line's source and span to one path on every OS. The final NDJSON and Markdown are replaced atomically, the rolling draft loses the same lines, and notes, provisional title, and chapters that were written from them are cleared. The user Markdown copy is rewritten only while Hex still wrote it. Refused while recording, transcribing, final-pending, or writing notes; the edit holds the notes claim. Tests cover reopening through the query library, the summary prompt after a fresh read, the hash-guarded export, rolling cleanup, the notes claim, and the pane's two-step request. Labs bookkeeping, translations, site catalog, feature maps, scenes, and goldens updated. * meetings: count selected turns and keep edits off the notes race The edit now takes the notes claim before reading the manifest, writes the cleared manifest before the transcript files, and writes them through the same publish function final publication uses. The selection bar counts turns with singular strings, drops a selection the pane no longer offers, and only warns about notes that exist. The summary regression test reads the transcript through the helper summarize_with uses. * tests: refresh labs and what is new goldens for the two new lab rows
235 lines
9.3 KiB
Rust
235 lines
9.3 KiB
Rust
//! Meetings in the Linux and Windows apps: the controller thread that
|
||
//! detects calls and records them (`meeting_watcher`), the capsules its
|
||
//! events drive, and the recording state the trays read. The macOS app runs
|
||
//! the same controller and capsules from `macos_rune`.
|
||
|
||
use std::sync::atomic::AtomicBool;
|
||
use std::sync::mpsc::{self, SyncSender};
|
||
use std::sync::{Mutex, OnceLock};
|
||
use std::thread::{self, JoinHandle};
|
||
use std::time::Instant;
|
||
|
||
use color_eyre::Result;
|
||
|
||
use crate::desktop::tray_menu::MeetingTray;
|
||
use crate::meeting::MeetingRequest;
|
||
use crate::meeting::watcher::{ControllerEvent, MeetingMenuState};
|
||
use crate::rune_ui::{Destination, Ui};
|
||
|
||
static REQUESTS: OnceLock<SyncSender<MeetingRequest>> = OnceLock::new();
|
||
/// The app, whose clipboard the tray's copy writes.
|
||
static APP: OnceLock<rune::AppHandle<Ui>> = OnceLock::new();
|
||
static STATE: Mutex<MeetingMenuState> = Mutex::new(MeetingMenuState::Idle);
|
||
|
||
/// The meeting controller and the thread that shows its events. Detection
|
||
/// stays idle until the user turns Meetings on.
|
||
pub(crate) struct Meetings {
|
||
controller: JoinHandle<()>,
|
||
events: JoinHandle<()>,
|
||
}
|
||
|
||
impl Meetings {
|
||
/// Starts the controller and installs its capsules on `app`.
|
||
pub(crate) fn install(app: &mut rune::App<Ui>, shutdown: &'static AtomicBool) -> Result<Self> {
|
||
let (event_sender, events) = mpsc::sync_channel(32);
|
||
let (commands, command_receiver) = mpsc::sync_channel(8);
|
||
let (requests, request_receiver) = mpsc::sync_channel(8);
|
||
let _ = REQUESTS.set(requests);
|
||
let controller = thread::Builder::new()
|
||
.name("hex-meetings".into())
|
||
.spawn(move || {
|
||
if let Err(error) = crate::meeting::watcher::controller_loop(
|
||
shutdown,
|
||
event_sender.clone(),
|
||
command_receiver,
|
||
request_receiver,
|
||
) {
|
||
tracing::error!(%error, "meeting controller stopped");
|
||
let _ = event_sender.send(ControllerEvent::Failed {
|
||
title: "Meeting detection stopped".into(),
|
||
error: error.to_string(),
|
||
});
|
||
}
|
||
})?;
|
||
let window = app.handle();
|
||
let _ = APP.set(window.clone());
|
||
let mut capsules = {
|
||
let chosen = window.clone();
|
||
let moved = window.clone();
|
||
crate::rune_ui::meeting_capsules::MeetingCapsules::install(
|
||
app,
|
||
commands,
|
||
move |choice| {
|
||
crate::app_settings::save_meeting_provider(choice);
|
||
chosen.update(move |ui, _| crate::rune_ui::meeting_settings_saved(ui));
|
||
},
|
||
move |corner| {
|
||
crate::app_settings::save_meeting_indicator_corner(corner);
|
||
moved.update(move |ui, _| crate::rune_ui::meeting_settings_saved(ui));
|
||
},
|
||
)
|
||
};
|
||
let events = thread::Builder::new()
|
||
.name("hex-meeting-events".into())
|
||
.spawn(move || {
|
||
for event in events {
|
||
capsules.event(&event);
|
||
#[cfg(target_os = "linux")]
|
||
if matches!(event, ControllerEvent::Offer(..)) {
|
||
let window = window.clone();
|
||
capsules.when_offer_unshown(move |reason| offer_unshown(&window, reason));
|
||
}
|
||
follow(&event, &window);
|
||
}
|
||
})?;
|
||
Ok(Self { controller, events })
|
||
}
|
||
|
||
/// Waits for the controller, which stops once `shutdown` is set: a
|
||
/// recording keeps its audio and finishes its transcript at the next
|
||
/// launch.
|
||
pub(crate) fn join(self) {
|
||
if self.controller.join().is_err() {
|
||
tracing::error!("meeting controller panicked");
|
||
}
|
||
let _ = self.events.join();
|
||
}
|
||
}
|
||
|
||
/// Asks the controller to start, stop, or summarize a meeting.
|
||
pub(crate) fn request(request: MeetingRequest) -> Result<(), String> {
|
||
if let Some(lock) = crate::labs::Feature::Meetings.managed() {
|
||
return Err(lock.refusal().into());
|
||
}
|
||
REQUESTS
|
||
.get()
|
||
.ok_or("meetings are not running")?
|
||
.try_send(request)
|
||
.map_err(|error| format!("could not reach the meeting recorder: {error}"))
|
||
}
|
||
|
||
/// The recording state the tray shows.
|
||
pub(crate) fn state() -> MeetingMenuState {
|
||
STATE
|
||
.lock()
|
||
.unwrap_or_else(|error| error.into_inner())
|
||
.clone()
|
||
}
|
||
|
||
/// The recorder as the tray shows it; `None` while Meetings is off.
|
||
pub(crate) fn tray_state() -> Option<MeetingTray> {
|
||
if !crate::app_settings::meetings_enabled() || REQUESTS.get().is_none() {
|
||
return None;
|
||
}
|
||
Some(match state() {
|
||
MeetingMenuState::Idle => MeetingTray::Idle,
|
||
MeetingMenuState::Starting => MeetingTray::Starting,
|
||
MeetingMenuState::Recording { .. } => MeetingTray::Recording,
|
||
MeetingMenuState::Transcribing => MeetingTray::Transcribing,
|
||
})
|
||
}
|
||
|
||
/// The tray's Copy last meeting transcript.
|
||
pub(crate) fn copy_last_transcript() -> Result<(), String> {
|
||
let markdown =
|
||
crate::meeting::latest_transcript_markdown().map_err(|error| format!("{error:#}"))?;
|
||
APP.get()
|
||
.ok_or("the window is not running")?
|
||
.update(move |_, tx| tx.copy(markdown));
|
||
Ok(())
|
||
}
|
||
|
||
/// The offer capsule could not open (GNOME on Wayland, #1271): the
|
||
/// Meetings pane says so and its Record starts the recording instead.
|
||
#[cfg(target_os = "linux")]
|
||
fn offer_unshown(window: &rune::AppHandle<Ui>, reason: String) {
|
||
tracing::warn!(%reason, "meeting recording offer could not show; opening the Meetings pane");
|
||
let mut message = format!(
|
||
"Hex detected a call but couldn't show its recording offer on this desktop ({reason}). Record it from here."
|
||
);
|
||
if !crate::labs::gnome_meeting_capsules() {
|
||
message.push_str(
|
||
" On GNOME, Labs › Call recording controls on GNOME can show it over your call.",
|
||
);
|
||
}
|
||
window.update(move |ui, tx| {
|
||
crate::rune_ui::meeting_failed(ui, message);
|
||
crate::rune_ui::show(ui, Destination::Meetings(None), tx);
|
||
});
|
||
window.open();
|
||
}
|
||
|
||
/// Mirrors an event into the recording state and the window.
|
||
fn follow(event: &ControllerEvent, window: &rune::AppHandle<Ui>) {
|
||
let mut state = STATE.lock().unwrap_or_else(|error| error.into_inner());
|
||
match event {
|
||
ControllerEvent::Starting(_) => *state = MeetingMenuState::Starting,
|
||
ControllerEvent::RecordingStarted { id, title, .. } => {
|
||
*state = MeetingMenuState::Recording {
|
||
started: Instant::now(),
|
||
id: id.clone(),
|
||
title: title.clone(),
|
||
chapters: Vec::new(),
|
||
warning: None,
|
||
};
|
||
}
|
||
ControllerEvent::SourceWarning { warning } => state.source_warning(*warning),
|
||
ControllerEvent::Retitled { title } => {
|
||
if let MeetingMenuState::Recording { title: shown, .. } = &mut *state {
|
||
shown.clone_from(title);
|
||
}
|
||
}
|
||
ControllerEvent::Chapters(chapters) => {
|
||
if let MeetingMenuState::Recording {
|
||
chapters: shown, ..
|
||
} = &mut *state
|
||
{
|
||
shown.clone_from(chapters);
|
||
}
|
||
}
|
||
ControllerEvent::Stopping => {}
|
||
ControllerEvent::Transcribing => *state = MeetingMenuState::Transcribing,
|
||
ControllerEvent::Finished(manifest) => {
|
||
tracing::info!(id = %manifest.id, "meeting transcript ready");
|
||
*state = MeetingMenuState::Idle;
|
||
}
|
||
ControllerEvent::Discarded(id) => {
|
||
tracing::info!(%id, "meeting had no speech; moved to the Trash");
|
||
*state = MeetingMenuState::Idle;
|
||
}
|
||
ControllerEvent::Failed { title, error } => {
|
||
tracing::error!(%title, %error, "meeting failed");
|
||
*state = MeetingMenuState::Idle;
|
||
let message = format!("{title}: {error}");
|
||
window.update(move |ui, tx| {
|
||
crate::rune_ui::meeting_failed(ui, message);
|
||
crate::rune_ui::show(ui, Destination::Meetings(None), tx);
|
||
});
|
||
window.open();
|
||
}
|
||
ControllerEvent::ImportFailed { error } => {
|
||
tracing::error!(%error, "meeting audio import failed");
|
||
let message = error.clone();
|
||
window.update(move |ui, tx| {
|
||
crate::rune_ui::meeting_import_failed(ui, message);
|
||
crate::rune_ui::show(ui, Destination::Meetings(None), tx);
|
||
});
|
||
window.open();
|
||
}
|
||
ControllerEvent::TranscriptEditFailed { error } => {
|
||
tracing::error!(%error, "could not delete meeting transcript lines");
|
||
let message = error.clone();
|
||
window.update(move |ui, _| crate::rune_ui::meeting_edit_failed(ui, message));
|
||
}
|
||
ControllerEvent::CallEnded { app, .. } => {
|
||
tracing::info!(%app, "the call ended; the recording continues until Stop");
|
||
}
|
||
ControllerEvent::Offer(..)
|
||
| ControllerEvent::OfferWithdrawn(_)
|
||
| ControllerEvent::Reminder { .. }
|
||
| ControllerEvent::ReminderWithdrawn { .. }
|
||
| ControllerEvent::CallEndedWithdrawn
|
||
| ControllerEvent::NotesProgress(_)
|
||
| ControllerEvent::NotesFinished(_) => {}
|
||
}
|
||
}
|