hex/src/app_settings/meetings.rs
Kit Langton 5f01839ea8
feat(meetings): graduate meeting labs into normal behaviour and Meetings settings (#1821)
* 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)
2026-11-16 00:51:48 -08:00

600 lines
21 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.

//! Meeting settings: recording, retention, call providers, the calendar,
//! the recording indicator, and their live values for the running app.
use super::*;
/// Screen corner where the floating meeting recording indicator snaps.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
#[repr(u8)]
pub enum MeetingIndicatorCorner {
#[default]
TopRight = 0,
TopLeft = 1,
BottomRight = 2,
BottomLeft = 3,
}
impl MeetingIndicatorCorner {
pub const fn is_right(self) -> bool {
matches!(self, Self::TopRight | Self::BottomRight)
}
pub const fn is_top(self) -> bool {
matches!(self, Self::TopRight | Self::TopLeft)
}
const fn decode(value: u8) -> Self {
match value {
1 => Self::TopLeft,
2 => Self::BottomRight,
3 => Self::BottomLeft,
_ => Self::TopRight,
}
}
}
/// Opt-in meeting recording. Detection, the Meetings pane, and the meeting
/// paste shortcut stay off in release builds until `enabled` is set.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(default)]
pub struct MeetingSettings {
pub enabled: bool,
/// Folder for finished Markdown transcripts; `None` uses the default.
pub output_folder: Option<PathBuf>,
/// Who titles finished meetings and writes their two-sentence summary.
pub summaries: MeetingSummaries,
/// Retired: read once by the summaries migration, never written.
#[serde(default, skip_serializing)]
pub summarize_with_apple_intelligence: Option<bool>,
/// Retired: read once by the summaries migration, never written.
#[serde(default, skip_serializing)]
pub summarize_with_opencode: Option<bool>,
/// Show the floating recording indicator while a meeting is recording.
pub show_recording_indicator: bool,
/// Screen corner the floating recording indicator snaps to after dragging.
pub recording_indicator_corner: MeetingIndicatorCorner,
/// What to do when a call from each website or app is detected. Older
/// files only had a `never_offer` list, whose entries carry no `policy`
/// and so read as Never offer.
#[serde(alias = "never_offer")]
pub providers: Vec<MeetingProviderChoice>,
/// Reminders before calendar meetings (macOS). Off until the user
/// connects a calendar.
pub calendar: CalendarSettings,
/// How long finished meetings are kept before they move to the Trash.
/// `None` until the user chooses: meetings recorded since the default
/// began are kept 24 hours, and older ones stay. Left out of the file
/// while unchosen: a build from before it can't read `null` (#744).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub retention: Option<MeetingRetention>,
/// How long finished meetings keep their WAV tracks, apart from their
/// text (Meetings › Settings › Keep audio). `None` follows `retention`
/// (Same as meetings), and is left out of the file.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub audio_retention: Option<MeetingRetention>,
/// A recording Hex started on its own stops once its call app has left
/// the microphone and gone quiet for 30 s (macOS).
pub stop_when_call_ends: bool,
/// How finished meetings are written to `output_folder`.
pub export: MeetingExportSettings,
/// The OpenCode `provider/model` that writes meeting notes when
/// `summaries` is OpenCode; left out of the file while unset, when
/// OpenCode's own default model writes them.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub opencode_model: Option<String>,
}
/// How finished meetings are written to the meetings folder.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(default)]
pub struct MeetingExportSettings {
/// Notes or a rename rename the exported Markdown to the meeting's
/// title, keeping its date and time.
pub descriptive_filenames: bool,
/// The transcript exports as `<stem>.transcript.md` and the notes go to
/// `<stem>.notes.md` beside it, linking back to the transcript.
pub notes_file: bool,
}
/// Who writes meeting titles and summaries. There is no fallback: Mac never
/// sends the transcript to OpenCode, and OpenCode never runs on this Mac.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
#[repr(u8)]
pub enum MeetingSummaries {
Off = 0,
/// Apple Intelligence on this Mac (macOS only).
Mac = 1,
/// The OpenCode model, which the transcript is sent to.
#[serde(rename = "opencode")]
OpenCode = 2,
}
impl MeetingSummaries {
/// On this Mac on macOS, otherwise off.
pub const fn platform_default() -> Self {
if cfg!(target_os = "macos") {
Self::Mac
} else {
Self::Off
}
}
pub(super) const fn decode(value: u8) -> Self {
match value {
1 => Self::Mac,
2 => Self::OpenCode,
_ => Self::Off,
}
}
/// What the two retired switches meant: Apple Intelligence on wins on a
/// Mac (its OpenCode fallback is gone); elsewhere only OpenCode counted.
pub(super) fn from_retired(apple_intelligence: bool, opencode: bool) -> Self {
if cfg!(target_os = "macos") && apple_intelligence {
Self::Mac
} else if opencode {
Self::OpenCode
} else {
Self::Off
}
}
}
impl Default for MeetingSummaries {
fn default() -> Self {
Self::platform_default()
}
}
/// How long a finished meeting is kept, counted from when it ended.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum MeetingRetention {
Day,
Week,
Month,
Forever,
}
impl MeetingRetention {
pub const ALL: [Self; 4] = [Self::Day, Self::Week, Self::Month, Self::Forever];
pub const fn label(self) -> &'static str {
match self {
Self::Day => "24 hours",
Self::Week => "7 days",
Self::Month => "30 days",
Self::Forever => "Forever",
}
}
pub const fn max_age_ms(self) -> Option<u64> {
const DAY_MS: u64 = 24 * 60 * 60 * 1_000;
match self {
Self::Day => Some(DAY_MS),
Self::Week => Some(7 * DAY_MS),
Self::Month => Some(30 * DAY_MS),
Self::Forever => None,
}
}
/// The default for meetings recorded since it began.
pub const DEFAULT: Self = Self::Day;
pub(super) const fn encode(retention: Option<Self>) -> u8 {
match retention {
Some(Self::Day) => 0,
Some(Self::Week) => 1,
Some(Self::Month) => 2,
Some(Self::Forever) => 3,
None => 4,
}
}
const fn decode(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Day),
1 => Some(Self::Week),
2 => Some(Self::Month),
3 => Some(Self::Forever),
_ => None,
}
}
}
/// The connected calendar and its meeting reminders.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(default)]
pub struct CalendarSettings {
/// Set once the user clicks Connect calendar and macOS grants access;
/// Hex never asks for calendar access before that.
pub connected: bool,
/// Calendars left out of reminders, by EventKit identifier. Every
/// calendar is included by default, so new ones are too.
pub excluded_calendars: Vec<String>,
/// Show a reminder capsule before each meeting.
pub remind: bool,
/// How many minutes before a meeting starts the reminder shows; zero
/// shows it at the start.
pub lead_minutes: u8,
}
/// The reminder lead times Settings offers, in minutes.
pub const CALENDAR_LEAD_MINUTES: [u8; 4] = [0, 1, 2, 5];
impl Default for CalendarSettings {
fn default() -> Self {
Self {
connected: false,
excluded_calendars: Vec::new(),
remind: true,
lead_minutes: 1,
}
}
}
impl CalendarSettings {
/// Whether reminders should run: connected, and wanted.
pub fn reminders_active(&self) -> bool {
self.connected && self.remind
}
/// The lead time, snapped to an offered choice.
pub fn lead(&self) -> std::time::Duration {
let minutes = if CALENDAR_LEAD_MINUTES.contains(&self.lead_minutes) {
self.lead_minutes
} else {
1
};
std::time::Duration::from_secs(u64::from(minutes) * 60)
}
pub fn includes(&self, calendar: &str) -> bool {
!self
.excluded_calendars
.iter()
.any(|excluded| excluded == calendar)
}
}
/// The call services Settings always lists, by provider key (the app's
/// canonical bundle ID, or the website host for browser services) and
/// English name.
pub const KNOWN_MEETING_PROVIDERS: [(&str, &str); 8] = [
("com.tinyspeck.slackmacgap", "Slack huddles"),
("us.zoom.xos", "Zoom"),
("meet.google.com", "Google Meet"),
("com.microsoft.teams2", "Microsoft Teams"),
("com.apple.FaceTime", "FaceTime"),
("net.whatsapp.WhatsApp", "WhatsApp"),
("com.gather.GatherV2", "Gather"),
("com.hnc.Discord", "Discord"),
];
/// The other call services Hex names and offers, by the same provider keys.
pub const MORE_MEETING_PROVIDERS: [(&str, &str); 10] = [
("org.whispersystems.signal-desktop", "Signal"),
("ru.keepcoder.Telegram", "Telegram"),
("com.tencent.xinWeChat", "WeChat"),
("jp.naver.line.mac", "LINE"),
("com.webex.meetingmanager", "Webex"),
("im.riot.app", "Element"),
("com.apple.mobilephone", "Phone"),
("voice.google.com", "Google Voice"),
("messenger.com", "Messenger"),
("web.groupme.com", "GroupMe"),
];
/// The providers Settings always lists: the common services, then the rest.
pub fn known_meeting_providers() -> impl Iterator<Item = (&'static str, &'static str)> {
KNOWN_MEETING_PROVIDERS
.into_iter()
.chain(MORE_MEETING_PROVIDERS)
}
/// What Hex does when it detects a call from a provider.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum MeetingPolicy {
/// Offer to record.
#[default]
Ask,
/// Start recording without an offer.
AlwaysRecord,
/// Neither offer nor record.
NeverOffer,
}
/// A website host or an app's canonical bundle ID, the name shown in
/// Settings, and the user's choice for its calls. Unlisted providers Ask.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct MeetingProviderChoice {
pub key: String,
pub label: String,
/// Always written; missing only in a legacy `never_offer` entry.
#[serde(default = "legacy_never_offer")]
pub policy: MeetingPolicy,
}
fn legacy_never_offer() -> MeetingPolicy {
MeetingPolicy::NeverOffer
}
pub(super) const DEFAULT_SHOW_RECORDING_INDICATOR: bool = true;
impl Default for MeetingSettings {
fn default() -> Self {
Self {
enabled: false,
output_folder: None,
summaries: MeetingSummaries::platform_default(),
summarize_with_apple_intelligence: None,
summarize_with_opencode: None,
show_recording_indicator: DEFAULT_SHOW_RECORDING_INDICATOR,
recording_indicator_corner: MeetingIndicatorCorner::TopRight,
providers: Vec::new(),
calendar: CalendarSettings::default(),
retention: None,
audio_retention: None,
stop_when_call_ends: false,
export: MeetingExportSettings::default(),
opencode_model: None,
}
}
}
impl MeetingSettings {
/// Whether meetings may record and process: always in developer builds,
/// otherwise once turned on, and never under a managed lock.
pub fn available(&self) -> bool {
crate::labs::Feature::Meetings.managed().is_none()
&& (crate::DEVELOPER_FEATURES_ENABLED || self.enabled)
}
pub fn resolved_output_folder(&self) -> PathBuf {
self.output_folder
.clone()
.filter(|folder| !folder.as_os_str().is_empty())
.unwrap_or_else(default_meeting_output_folder)
}
}
/// Whether meeting detection and recording may run: always in developer
/// builds, otherwise only after the user opts in.
pub fn meetings_enabled() -> bool {
MEETINGS_ENABLED.load(Ordering::Acquire)
}
/// Why meetings can't record now.
pub fn meetings_off_reason() -> &'static str {
match crate::labs::Feature::Meetings.managed() {
Some(lock) => lock.refusal(),
None => "Meetings are off; turn them on with `hex settings set meetings.enabled on`",
}
}
/// Who writes meeting notes, as last applied.
pub fn meeting_summaries() -> MeetingSummaries {
MeetingSummaries::decode(MEETING_SUMMARIES.load(Ordering::Acquire))
}
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn meeting_indicator_enabled() -> bool {
MEETING_INDICATOR_ENABLED.load(Ordering::Acquire)
}
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn meeting_indicator_corner() -> MeetingIndicatorCorner {
MeetingIndicatorCorner::decode(MEETING_INDICATOR_CORNER.load(Ordering::Acquire))
}
/// The user's choices for detected calls, by website or app.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn meeting_provider_choices() -> Vec<MeetingProviderChoice> {
MEETING_PROVIDERS
.get_or_init(Default::default)
.read()
.unwrap_or_else(|error| error.into_inner())
.clone()
}
/// The connected calendar's reminder settings, as last applied.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
/// [`MeetingSettings::retention`] for the running meeting controller.
/// The retention the user chose, `None` until they choose. A process that
/// never loaded settings (`hex mcp`, `hex meetings`) reads it from
/// `settings.json` without migrating or writing anything.
pub fn meeting_retention() -> Option<MeetingRetention> {
match MEETING_RETENTION.load(Ordering::Acquire) {
RETENTION_UNSET if cfg!(test) => None,
RETENTION_UNSET => stored_meeting_retention(),
value => MeetingRetention::decode(value),
}
}
fn stored_meeting_retention() -> Option<MeetingRetention> {
stored_retention("retention")
}
/// [`MeetingSettings::audio_retention`] for the running meeting controller;
/// `None` means audio follows `meetings.retention`. A process that never
/// loaded settings reads it from `settings.json` without writing anything.
pub fn meeting_audio_retention() -> Option<MeetingRetention> {
match MEETING_AUDIO_RETENTION.load(Ordering::Acquire) {
RETENTION_UNSET if cfg!(test) => None,
RETENTION_UNSET => stored_audio_retention(),
value => MeetingRetention::decode(value),
}
}
fn stored_retention(field: &str) -> Option<MeetingRetention> {
let data = fs::read(path().ok()?).ok()?;
let settings: serde_json::Value = serde_json::from_slice(&data).ok()?;
retention_in(&settings, field)
}
fn stored_audio_retention() -> Option<MeetingRetention> {
let data = fs::read(path().ok()?).ok()?;
let settings: serde_json::Value = serde_json::from_slice(&data).ok()?;
audio_retention_in(&settings)
}
fn retention_in(settings: &serde_json::Value, field: &str) -> Option<MeetingRetention> {
serde_json::from_value(settings.get("meetings")?.get(field)?.clone()).ok()
}
/// The audio retention a settings file holds. A file the
/// `meeting-labs-settings` migration hasn't seen keeps it only while its
/// retired Labs switch was on, as the migration will.
fn audio_retention_in(settings: &serde_json::Value) -> Option<MeetingRetention> {
let migrated = settings
.get("migrations")
.and_then(serde_json::Value::as_array)
.is_some_and(|ids| {
ids.iter()
.any(|id| id.as_str() == Some(MEETING_LABS_SETTINGS_MIGRATION))
});
let lab_on = settings
.pointer("/labs/expire_meeting_audio")
.and_then(serde_json::Value::as_bool)
== Some(true);
(migrated || lab_on)
.then(|| retention_in(settings, "audio_retention"))
.flatten()
}
/// Meetings › Settings' Stop when the call ends, as last applied (macOS;
/// read on each pass of the meeting controller).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn meeting_stop_when_call_ends() -> bool {
MEETING_STOP_WHEN_CALL_ENDS.load(Ordering::Acquire)
}
/// Meetings › Settings › Export's Descriptive meeting file names, as last
/// applied (read when notes are applied and when a meeting is renamed).
pub fn meeting_descriptive_filenames() -> bool {
MEETING_DESCRIPTIVE_FILENAMES.load(Ordering::Acquire)
}
/// Meetings › Settings › Export's Separate notes file, as last applied
/// (read at final export and when notes are written).
pub fn meeting_notes_file() -> bool {
MEETING_NOTES_FILE.load(Ordering::Acquire)
}
pub fn calendar_settings() -> CalendarSettings {
CALENDAR_SETTINGS
.get_or_init(Default::default)
.read()
.unwrap_or_else(|error| error.into_inner())
.clone()
}
/// Sets one provider's policy; returns whether the settings changed.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn set_meeting_provider(meetings: &mut MeetingSettings, choice: MeetingProviderChoice) -> bool {
match meetings
.providers
.iter_mut()
.find(|known| known.key == choice.key)
{
Some(known) if known.policy == choice.policy => false,
Some(known) => {
known.policy = choice.policy;
true
}
None => {
meetings.providers.push(choice);
true
}
}
}
/// Saves a choice made from a meeting capsule while the Settings window is
/// closed.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn save_meeting_provider(choice: MeetingProviderChoice) {
match AppSettings::load() {
Ok(mut settings) => {
let base = settings.clone();
if set_meeting_provider(&mut settings.meetings, choice)
&& let Err(error) = base.update(&settings)
{
tracing::warn!(%error, "could not save a meeting provider choice");
}
}
Err(error) => tracing::warn!(%error, "could not load settings to save a meeting choice"),
}
}
/// Saves the corner the recording capsule was dragged to.
pub fn save_meeting_indicator_corner(corner: MeetingIndicatorCorner) {
match AppSettings::load() {
Ok(mut settings) => {
if settings.meetings.recording_indicator_corner == corner {
return;
}
let base = settings.clone();
settings.meetings.recording_indicator_corner = corner;
if let Err(error) = base.update(&settings) {
tracing::warn!(%error, "could not save the recording capsule's corner");
}
}
Err(error) => tracing::warn!(%error, "could not load settings to save the capsule corner"),
}
}
pub fn meeting_output_folder() -> PathBuf {
MEETING_OUTPUT_FOLDER
.get_or_init(Default::default)
.read()
.unwrap_or_else(|error| error.into_inner())
.clone()
.unwrap_or_else(default_meeting_output_folder)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn settings_lists_the_common_providers_first_then_the_rest() {
let on = known_meeting_providers().collect::<Vec<_>>();
assert_eq!(on[..KNOWN_MEETING_PROVIDERS.len()], KNOWN_MEETING_PROVIDERS);
assert_eq!(
on.len(),
KNOWN_MEETING_PROVIDERS.len() + MORE_MEETING_PROVIDERS.len()
);
assert!(on.contains(&("org.whispersystems.signal-desktop", "Signal")));
assert!(on.contains(&("ru.keepcoder.Telegram", "Telegram")));
assert!(on.contains(&("com.tencent.xinWeChat", "WeChat")));
assert!(on.contains(&("jp.naver.line.mac", "LINE")));
assert!(on.contains(&("com.webex.meetingmanager", "Webex")));
assert!(on.contains(&("im.riot.app", "Element")));
assert!(on.contains(&("com.apple.mobilephone", "Phone")));
assert!(on.contains(&("voice.google.com", "Google Voice")));
assert!(on.contains(&("messenger.com", "Messenger")));
assert!(on.contains(&("web.groupme.com", "GroupMe")));
}
#[test]
fn an_unmigrated_file_keeps_audio_retention_only_with_its_lab() {
use MeetingRetention::Day;
let read = |json: &str| audio_retention_in(&serde_json::from_str(json).unwrap());
assert_eq!(read(r#"{"meetings":{"audio_retention":"day"}}"#), None);
assert_eq!(
read(r#"{"meetings":{"audio_retention":"day"},"labs":{"expire_meeting_audio":true}}"#),
Some(Day)
);
assert_eq!(
read(
r#"{"meetings":{"audio_retention":"day"},"migrations":["meeting-labs-settings"]}"#
),
Some(Day)
);
assert_eq!(read(r#"{"migrations":["meeting-labs-settings"]}"#), None);
assert_eq!(MeetingSettings::default().audio_retention, None);
}
}