//! Rows only some OSes show, chosen by //! [`Capabilities`](super::platform::Capabilities): macOS's permission //! warnings, Meetings › Settings, Show Dock icon, and the Hex Microphone //! driver row Voice Filter shows; Launch at login on macOS and Windows. Their //! state is [`PlatformState`](super::platform::PlatformState) //! data and their actions are [`PlatformRequest`]s. use rune::{El, Icon, row, text}; use super::controls::{ ButtonKind, CardRow, Choice, DESCRIPTION, Paint, button, card, folder_label, folding, icon_row, icon_toggle_row, note, section, select, setting_row, }; use super::lists::{PermissionControl, permission_control, small_button}; use super::paste_access::PasteAccess; use super::platform::{CalendarRequest, MeetingRequest, NotesAvailability, Os, PlatformRequest}; use super::settings::toggle_menu; use super::{Menu, Pane, ShortcutTarget, Ui, icons}; use crate::app_settings::{ AppSettings, CALENDAR_LEAD_MINUTES, HotkeyBinding, MeetingRetention, MeetingSummaries, ModifierSide, }; use crate::audio::hex_microphone::DriverActionState; use crate::calendar::{CalendarAccess, CallProvider}; use crate::desktop::i18n::{tr, tr_fill, tr_named}; use crate::desktop::onboarding::{PermissionAction, PermissionKind, PermissionWarning}; use crate::labs::Feature; /// A permission's row key, its name as System Settings lists it, and what /// Hex cannot do without it. fn permission_copy( kind: PermissionKind, accessibility_renamed: bool, accessibility_drag: bool, ) -> (&'static str, &'static str, &'static str) { match kind { PermissionKind::Microphone => ( "permission-microphone", tr("Microphone"), tr("Hex cannot record dictation until microphone access is restored."), ), PermissionKind::Accessibility => ( "permission-accessibility", accessibility_name(accessibility_renamed, accessibility_drag), tr("Hex cannot recognize the dictation shortcut or paste into other apps."), ), PermissionKind::SystemAudio => ( "permission-system-audio", tr("Screen & System Audio Recording"), tr("Required to hear the other participants"), ), PermissionKind::ScreenRecording => ( "permission-screen-recording", tr("Screen Recording"), tr("Lets Annotate record your screen"), ), } } /// What System Settings calls the Accessibility list: macOS 27 renamed it to /// Device Control and Data Access, and 27.3 renamed it and stopped taking a /// dragged tile, so the newer name goes with the copy that adds Hex with +. pub(super) fn accessibility_name(renamed: bool, drag_supported: bool) -> &'static str { if renamed && !drag_supported { tr("System & App Protection Override") } else if renamed { tr("Device Control and Data Access") } else { tr("Accessibility") } } /// The missing permissions above everything else, while the tour is closed. pub(super) fn permissions_section(ui: &Ui, p: Paint) -> Option { if ui.tour.is_some() { return None; } if let Some(paste) = paste_permission(ui, p) { return Some(section( p, "permissions", tr("Permissions needed"), vec![paste], )); } if !ui.platform.caps.permissions { return None; } let warnings = crate::desktop::onboarding::permission_warnings(ui.platform.permissions); if warnings.is_empty() { return None; } let rows = warnings .into_iter() .map(|warning: PermissionWarning| { let (key, name, description) = permission_copy( warning.kind, ui.platform.accessibility_renamed, ui.platform.accessibility_drag_supported, ); if warning.action == PermissionAction::Restart { return setting_row( p, key, name, Some(tr("Turns on when Hex restarts")), button( p, &format!("{key}-restart"), tr("Restart Hex"), ButtonKind::Secondary, |ui: &mut Ui, _| { ui.ask(PlatformRequest::Permission(PermissionAction::Restart)) }, ), ); } let stale = warning.kind == PermissionKind::Accessibility && ui.platform.stale(warning.kind); let description = if stale { tr("An older Hex entry can keep this off") } else { description }; let action = if stale { PermissionAction::ResetAndPrompt(warning.kind) } else { warning.action }; let control = permission_control( p, &format!("{key}-allow"), ui.platform.control_for(warning.kind, false), ButtonKind::Secondary, move |ui: &mut Ui| ui.ask(PlatformRequest::Permission(action)), ); setting_row(p, key, name, Some(description), control) }) .collect(); Some(section(p, "permissions", tr("Permissions needed"), rows)) } /// The desktop's paste permission on GNOME and KDE Wayland until it is /// allowed, for people who skipped onboarding (#932). fn paste_permission(ui: &Ui, p: Paint) -> Option { let paste = ui .platform .paste .filter(|paste| *paste != PasteAccess::Allowed)?; let description = if paste == PasteAccess::Declined { tr("Without it, Hex copies your words and you press Ctrl+V.") } else { tr("Hex only sends the paste keystroke. It never sees your screen.") }; let control = permission_control( p, "permission-paste-allow", if paste == PasteAccess::Asking { PermissionControl::Waiting } else { PermissionControl::Allow }, ButtonKind::Secondary, super::paste_access::ask, ); Some(setting_row( p, "permission-paste", tr("Paste into apps"), Some(description), control, )) } /// Records which untrusted permission rows are currently visible in the window /// so the macOS host clears retired Hex bundle IDs' stale TCC rows once in the /// background when a row appears. pub(super) fn update_shown_permissions(ui: &mut Ui) { use crate::desktop::onboarding::PermissionState; let visible = ui.window.as_ref().is_none_or(rune::AppHandle::is_visible); let mut shown = Vec::new(); if visible && ui.platform.caps.permissions { let setup_showing = ui.first_run.is_some() || (ui.tour.is_none() && !ui.labs_open && ui.pane == Pane::General); if setup_showing && matches!( ui.platform.permissions.accessibility, PermissionState::NeedsRequest | PermissionState::NeedsSettings ) { shown.push(PermissionKind::Accessibility); } if ui.tour.is_none() && !ui.labs_open { if ui.pane == Pane::Meetings && super::meetings::available(ui) && ui.meetings.view == super::meetings::View::Settings && !ui.platform.system_audio { shown.push(PermissionKind::SystemAudio); } #[cfg(hex_capture)] if ui.pane == Pane::Annotate && ui.settings.capture.enabled && ui .platform .scrawl .as_ref() .is_some_and(|view| !view.screen_recording && !view.screen_needs_restart) { shown.push(PermissionKind::ScreenRecording); } } } ui.platform.permissions_shown = shown; } /// Fixture setup for General's missing-permissions scenes (`waiting` vs `stale`). pub(super) fn mac_permissions_fixture(ui: &mut Ui, stale: bool) { use crate::desktop::onboarding::PermissionState; *ui = super::mac_fixture(); ui.platform.permissions.microphone = PermissionState::NeedsSettings; ui.platform.permissions.accessibility = PermissionState::NeedsSettings; if stale { ui.platform.note_stale(PermissionKind::Accessibility); } else { ui.platform.note_asked(PermissionKind::Accessibility); } ui.platform.login_item = Some(crate::desktop::login_item::LoginItemStatus::RequiresApproval); ui.platform.accessibility_renamed = true; } /// A save error where the OS has no listener card to show it in. pub(super) fn error_section(ui: &Ui, p: Paint) -> Option { if ui.platform.caps.listener_control { return None; } let error = ui.error.as_deref()?; Some(section( p, "save-error", tr("Status"), super::settings::error_notes(p, error).into(), )) } fn notes_description(availability: NotesAvailability) -> &'static str { match availability { NotesAvailability::Available => tr("Titles and short summaries, written on this Mac"), NotesAvailability::DeviceNotEligible => tr("This Mac does not support Apple Intelligence"), NotesAvailability::NotEnabled => { tr("Turn on Apple Intelligence in System Settings to write them on this Mac") } NotesAvailability::ModelNotReady => tr("The Apple Intelligence model is still downloading"), NotesAvailability::UnsupportedSystem => tr("Requires macOS 26 or later"), NotesAvailability::Unknown => tr("Apple Intelligence is unavailable"), } } /// The second line of Summaries' On this Mac option: what it does, or why /// it can't be chosen and the fix. fn on_this_mac_detail(availability: NotesAvailability) -> &'static str { match availability { NotesAvailability::Available => tr("Apple Intelligence. Nothing leaves this Mac"), NotesAvailability::NotEnabled => tr("Turn on Apple Intelligence in System Settings"), other => notes_description(other), } } /// Why Labs › Clean up with Apple Intelligence can't run on this Mac now: the /// same words Summaries uses, so every Apple Intelligence row gives one /// reason. `None` while it can run. pub(super) fn clean_up_note(availability: NotesAvailability) -> Option { let reason = match availability { NotesAvailability::Available => return None, NotesAvailability::DeviceNotEligible => tr("This Mac does not support Apple Intelligence"), NotesAvailability::NotEnabled => tr("Turn on Apple Intelligence in System Settings"), NotesAvailability::ModelNotReady => tr("The Apple Intelligence model is still downloading"), NotesAvailability::UnsupportedSystem => tr("Requires macOS 26 or later"), NotesAvailability::Unknown => tr("Apple Intelligence is unavailable"), }; Some(reason.to_owned()) } /// Meetings › Settings › After a meeting › Summaries: who writes a meeting's /// title and summary, with the OpenCode model nested under it while OpenCode /// writes them. A Mac picks Off, On this Mac, or OpenCode; elsewhere a /// switch turns OpenCode on. Nothing falls back: an unavailable choice stays /// chosen and says how to fix it. fn summaries_rows(ui: &Ui, p: Paint, layer: &mut Vec) -> Vec { let chosen = ui.settings.meetings.summaries; let managed = opencode_managed(); let mut rows: Vec = Vec::new(); if ui.platform.caps.os == Os::Macos { let notes = ui.platform.notes; let (description, color) = match chosen { MeetingSummaries::Off => (tr("No titles or summaries"), p.muted()), MeetingSummaries::Mac if notes.is_available() => (notes_description(notes), p.muted()), MeetingSummaries::Mac => (notes_description(notes), p.warning()), MeetingSummaries::OpenCode => { (tr("Sends the transcript to your OpenCode model"), p.muted()) } }; let label = |choice: MeetingSummaries| match choice { MeetingSummaries::Off => tr("Off"), MeetingSummaries::Mac => tr("On this Mac"), MeetingSummaries::OpenCode => "OpenCode", }; let options = [ SummariesOption { choice: MeetingSummaries::Off, detail: None, disabled: false, }, SummariesOption { choice: MeetingSummaries::Mac, detail: Some(on_this_mac_detail(notes)), disabled: !notes.is_available(), }, SummariesOption { choice: MeetingSummaries::OpenCode, detail: Some(if managed { super::managed_note() } else { tr("Sends the transcript to your OpenCode model") }), disabled: managed, }, ]; let menu = Menu::Pick("meeting-summaries"); let labels: Vec<&str> = options.iter().map(|option| label(option.choice)).collect(); let trigger = rune_kit::Select::new("meeting-summaries-control", &labels) .appearance(rune_kit::SelectAppearance::Inline) .current(Some(label(chosen))) .open(ui.open == Some(menu)) .on_toggle(move |ui: &mut Ui| toggle_menu(ui, menu)) .trigger(p.k) .label(tr("Summaries")) .a11y_value(label(chosen)); let mut picker = rune_kit::Menu::new("meeting-summaries-menu") .trigger(trigger) .placement(rune_kit::Placement::BottomEnd) .gutter(4.0) .min_width(380.0) .open(ui.open == Some(menu)) .on_close(|ui: &mut Ui| ui.open = None); for option in options { let mut item = rune_kit::MenuItem::new(label(option.choice)) .checked(option.choice == chosen) .disabled(option.disabled); if let Some(detail) = option.detail { item = item.description(detail); } let choice = option.choice; picker = picker.item(item.on_select(move |ui: &mut Ui| { ui.open = None; ui.update(|settings| settings.meetings.summaries = choice); })); if choice == MeetingSummaries::Off { picker = picker.separator(); } } rows.push( super::controls::icon_described_row( p, "meeting-summaries", &icons::SPARKLES, tr("Summaries"), Some((description.to_owned(), color)), picker.build(p.k, layer).mr(-8.0), ) .into(), ); } else if managed { rows.push( super::controls::managed_row( p, "meeting-summaries", Some(&icons::SPARKLES), tr("Summaries"), ) .into(), ); } else { rows.push( icon_toggle_row( p, "meeting-summaries", &icons::SPARKLES, tr("Summaries"), tr("Titles and short summaries. Sends the transcript to your OpenCode model"), chosen == MeetingSummaries::OpenCode, |ui: &mut Ui| { let summaries = match ui.settings.meetings.summaries { MeetingSummaries::OpenCode => MeetingSummaries::Off, _ => MeetingSummaries::OpenCode, }; ui.update(|settings| settings.meetings.summaries = summaries); }, ) .into(), ); } let model = if summary_model_shown(ui) { super::models::rows(ui, p, super::models::Target::MeetingSummary, layer) .into_iter() .map(super::controls::nested) .chain(super::models::unavailable( ui, p, crate::desktop::opencode_catalog::OpenCodeFeature::MeetingSummary, )) .collect() } else { Vec::new() }; rows.push(folding("summary-model", model)); rows } /// One of Summaries' options on a Mac. struct SummariesOption { choice: MeetingSummaries, detail: Option<&'static str>, disabled: bool, } /// Whether an organization turned OpenCode processing off. pub(super) fn opencode_managed() -> bool { crate::policy::Policy::current().locks(crate::policy::Lock::OpenCodeProcessing) } /// The Meetings (beta) switch: the opt-in card's only row, and the first row /// of Meetings › Settings. pub(super) fn meetings_toggle(ui: &Ui, p: Paint) -> El { if crate::labs::Feature::Meetings.managed().is_some() { return super::controls::managed_row( p, "meetings-enabled", Some(Pane::Meetings.icon()), tr("Meetings (beta)"), ); } icon_toggle_row( p, "meetings-enabled", Pane::Meetings.icon(), tr("Meetings (beta)"), tr("Offer to record calls and save local transcripts"), ui.settings.meetings.enabled, |ui: &mut Ui| { let enabled = !ui.settings.meetings.enabled; ui.update(|settings| settings.meetings.enabled = enabled); }, ) } /// Meetings › Settings: the opt-in (and the system-audio permission while /// it's missing); once on, When a call starts (the Calls row and calendar /// reminders), summaries and how long meetings and their audio are kept, the /// export folder and file choices; behind Advanced the indicator and the /// granted permission. pub(super) fn meetings_settings(ui: &Ui, p: Paint, layer: &mut Vec) -> Vec { use super::general::advanced_toggle; let meetings = &ui.settings.meetings; let mut rows = vec![meetings_toggle(ui, p)]; let mut more = Vec::new(); // Only macOS asks before Hex may hear the other participants. if meetings.enabled && ui.platform.caps.permissions { let permitted = ui.platform.system_audio; let stale = !permitted && ui.platform.stale(PermissionKind::SystemAudio); let system_audio = icon_row( p, "meeting-system-audio", &icons::SPEAKER, tr("Screen & System Audio Recording"), Some(if permitted { tr("Captures the other participants' audio") } else if stale { tr("An older Hex entry can keep this off") } else { tr("Required to hear the other participants") }), permission_control( p, "meeting-system-audio-allow", ui.platform .control_for(PermissionKind::SystemAudio, permitted), ButtonKind::Secondary, move |ui: &mut Ui| { if stale { ui.ask(PlatformRequest::Permission( PermissionAction::ResetAndPrompt(PermissionKind::SystemAudio), )); } else { // macOS prompts once; after that the switch is in // System Settings, with the guide beside it. ui.ask(PlatformRequest::SystemAudio); } }, ), ); // A grant made here stays in place to show Allowed. if permitted && !ui.platform.asked(PermissionKind::SystemAudio) { more.push(system_audio); } else { rows.push(system_audio); } } let mut after = Vec::new(); let mut export: Vec = Vec::new(); if meetings.enabled { more.push(icon_toggle_row( p, "meeting-indicator", &icons::PILL, tr("Show recording indicator"), tr("Floating pill while a meeting records"), meetings.show_recording_indicator, |ui: &mut Ui| { let show = !ui.settings.meetings.show_recording_indicator; ui.update(|settings| settings.meetings.show_recording_indicator = show); }, )); after.extend(summaries_rows(ui, p, layer)); after.push(retention_row(ui, p, layer).into()); after.push(audio_retention_row(ui, p, layer).into()); export.push( icon_row( p, "meeting-folder", &icons::FOLDER, tr("Transcript folder"), Some(tr("Finished meetings are saved here as Markdown")), row() .key("controls") .gap(8.0) .center_y() .child(button( p, "reveal-meeting-folder", tr("Reveal"), ButtonKind::Secondary, |ui: &mut Ui, _| { ui.ask(PlatformRequest::Meeting(MeetingRequest::RevealFolder)) }, )) .child(button( p, "choose-meeting-folder", &folder_label(&ui.settings.meetings.resolved_output_folder()), ButtonKind::Secondary, |ui: &mut Ui, _| { ui.ask(PlatformRequest::Meeting(MeetingRequest::ChooseFolder)) }, )), ) .into(), ); if let Some(error) = &ui.platform.meeting_folder_error { export.push(note("meeting-folder-error", error, p.danger()).into()); } export.push( icon_toggle_row( p, "meeting-descriptive-filenames", &icons::PEN, tr("Descriptive meeting file names"), tr("Rename exported Markdown to the meeting's title"), meetings.export.descriptive_filenames, |ui: &mut Ui| { let on = !ui.settings.meetings.export.descriptive_filenames; ui.update(|settings| settings.meetings.export.descriptive_filenames = on); }, ) .into(), ); export.push( icon_toggle_row( p, "meeting-notes-file", &icons::BOOK, tr("Separate notes file"), tr("Save notes in a separate file beside the transcript"), meetings.export.notes_file, |ui: &mut Ui| { let on = !ui.settings.meetings.export.notes_file; ui.update(|settings| settings.meetings.export.notes_file = on); }, ) .into(), ); } let mut sections = vec![card(p, "meetings", rows)]; if meetings.enabled { sections.push(call_start_section(ui, p, layer)); sections.push(section(p, "after-meeting", tr("After a meeting"), after)); sections.push(section(p, "meeting-export", tr("Export"), export)); sections.push(advanced_toggle(ui, p, Pane::Meetings)); if super::general::advanced_open(ui, Pane::Meetings) { sections.push(card(p, "advanced", more)); } } sections } /// How long finished meetings are kept before they move to the Trash. fn retention_row(ui: &Ui, p: Paint, layer: &mut Vec) -> El { let chosen = ui.settings.meetings.retention; let retention = chosen.unwrap_or(MeetingRetention::DEFAULT); let control = super::general::pick_select( ui, p, "meeting-retention", tr("Keep meetings"), MeetingRetention::ALL .iter() .map(|retention| tr(retention.label())) .collect(), MeetingRetention::ALL .iter() .position(|choice| *choice == retention) .unwrap_or_default(), |ui, index| { ui.update(|settings| settings.meetings.retention = Some(MeetingRetention::ALL[index])); }, layer, ); icon_row( p, "meeting-retention", &icons::CLOCK, tr("Keep meetings"), match chosen { None => Some(tr( "Moves new meetings' audio, transcripts, and notes to the Trash", )), Some(MeetingRetention::Forever) => None, Some(_) => Some(tr("Moves audio, transcripts, and notes to the Trash")), }, control, ) } /// How long finished meetings keep their audio, apart from their text. /// Unchosen follows Keep meetings. fn audio_retention_row(ui: &Ui, p: Paint, layer: &mut Vec) -> El { let chosen = ui.settings.meetings.audio_retention; let mut labels = vec![tr("Same as meetings").to_owned()]; labels.extend( MeetingRetention::ALL .iter() .map(|retention| tr(retention.label()).to_owned()), ); let selected = chosen .and_then(|chosen| { MeetingRetention::ALL .iter() .position(|choice| *choice == chosen) }) .map(|index| index + 1) .unwrap_or_default(); let control = super::general::quiet_select( ui, p, Menu::Pick("meeting-audio-retention"), "meeting-audio-retention-control".into(), tr("Keep audio"), labels, selected, |ui, index| { ui.update(|settings| { settings.meetings.audio_retention = index .checked_sub(1) .map(|index| MeetingRetention::ALL[index]); }); }, layer, ); icon_row( p, "meeting-audio-retention", &icons::CLOCK, tr("Keep audio"), match chosen { None => Some(tr( "Follows Keep meetings unless you choose a shorter window", )), Some(MeetingRetention::Forever) => None, Some(_) => Some(tr( "Moves audio to the Trash and keeps transcripts and notes", )), }, control, ) } /// Whether the summary model picker shows: Meetings › Settings with /// Summaries set to OpenCode. The window reads the OpenCode catalog only /// while it does. pub(super) fn summary_model_shown(ui: &Ui) -> bool { ui.pane == Pane::Meetings && !ui.labs_open && super::meetings::available(ui) && ui.meetings.view == super::meetings::View::Settings && ui.settings.meetings.enabled && ui.settings.meetings.summaries == MeetingSummaries::OpenCode && !opencode_managed() } /// What the summary model row says about a saved `provider/model` it can't /// use, such as one typed with `hex settings`; `None` when it can. pub(super) fn summary_model_problem(saved: &str) -> Option<&'static str> { (!saved.trim().is_empty() && crate::meeting::generator::parse_model(saved).is_none()).then(|| { tr("Write it as provider/model, such as openai/gpt-5.4-mini. Until then, Hex uses OpenCode's default model") }) } static ZOOM_ICON: Icon = Icon { name: "hex-provider-zoom", view: 16.0, body: include_str!("../../assets/icons/providers/zoom.svg"), }; static MEET_ICON: Icon = Icon { name: "hex-provider-meet", view: 16.0, body: include_str!("../../assets/icons/providers/meet.svg"), }; static TEAMS_ICON: Icon = Icon { name: "hex-provider-teams", view: 16.0, body: include_str!("../../assets/icons/providers/teams.svg"), }; static SLACK_ICON: Icon = Icon { name: "hex-provider-slack", view: 16.0, body: include_str!("../../assets/icons/providers/slack.svg"), }; static WEBEX_ICON: Icon = Icon { name: "hex-provider-webex", view: 16.0, body: include_str!("../../assets/icons/providers/webex.svg"), }; static CALL_ICON: Icon = Icon { name: "hex-provider-call", view: 16.0, body: include_str!("../../assets/icons/providers/call.svg"), }; /// A call service's icon, as the calendar list and the Meetings list show it. pub(super) fn provider_icon(provider: CallProvider) -> &'static Icon { match provider { CallProvider::Zoom => &ZOOM_ICON, CallProvider::GoogleMeet => &MEET_ICON, CallProvider::Teams => &TEAMS_ICON, CallProvider::Slack => &SLACK_ICON, CallProvider::Webex => &WEBEX_ICON, } } /// The filled generic call icon for apps without a dedicated service mark, /// matching the brand icons' filled style. pub(super) fn call_icon() -> &'static Icon { &CALL_ICON } /// When a call starts: the Calls row, then, where calendars are read, /// Connect calendar (the only thing that asks macOS for access), the /// reminder switch, lead time, included calendars, and the next few /// meetings. fn call_start_section(ui: &Ui, p: Paint, layer: &mut Vec) -> El { let mut rows = vec![super::calls::settings_row(ui, p)]; if ui.platform.caps.calendar { calendar_rows(ui, p, layer, &mut rows); } section(p, "call-start", tr("When a call starts"), rows) } fn calendar_rows(ui: &Ui, p: Paint, layer: &mut Vec, rows: &mut Vec) { let view = &ui.platform.calendar; let calendar = &ui.settings.meetings.calendar; if view.access.blocked() { rows.push(icon_row( p, "calendar-blocked", &icons::CALENDAR, tr("Calendar access is off"), Some(tr( "Allow Hex under Privacy & Security › Calendars to get meeting reminders", )), button( p, "calendar-privacy", tr("Open settings"), ButtonKind::Secondary, |ui: &mut Ui, _| { ui.ask(PlatformRequest::Calendar( CalendarRequest::OpenPrivacySettings, )) }, ), )); } else if !calendar.connected || view.access != CalendarAccess::FullAccess { rows.push(icon_row( p, "calendar-connect", &icons::CALENDAR, tr("Remind me before meetings"), Some(tr("Names each recording after its calendar event")), button( p, "calendar-connect-button", if view.connecting { tr("Connecting…") } else { tr("Connect calendar") }, ButtonKind::Secondary, |ui: &mut Ui, _| { if !ui.platform.calendar.connecting { ui.ask(PlatformRequest::Calendar(CalendarRequest::Connect)); } }, ), )); } else { rows.push(icon_toggle_row( p, "calendar-remind", &icons::BELL, tr("Remind me before meetings"), tr("Shows a reminder with Record and Join buttons"), calendar.remind, |ui: &mut Ui| { let remind = !ui.settings.meetings.calendar.remind; ui.update(|settings| settings.meetings.calendar.remind = remind); }, )); if calendar.remind { let lead = calendar.lead().as_secs() / 60; let control = super::general::pick_select( ui, p, "calendar-lead", tr("Remind me"), vec![tr("At start"), tr("1 min"), tr("2 min"), tr("5 min")], CALENDAR_LEAD_MINUTES .iter() .position(|minutes| u64::from(*minutes) == lead) .unwrap_or(1), |ui, index| { ui.update(|settings| { settings.meetings.calendar.lead_minutes = CALENDAR_LEAD_MINUTES[index]; }); }, layer, ); rows.push(icon_row( p, "calendar-lead", &icons::CLOCK, tr("Remind me"), None, control, )); } rows.push(calendars_row(ui, p, layer)); if view.upcoming.is_empty() { rows.push(note( "calendar-none", tr("No meetings in the next two days"), p.muted(), )); } rows.extend(view.upcoming.iter().enumerate().map(|(index, meeting)| { let provider = meeting.provider.map(|provider| { row() .key("provider") .gap(6.0) .center_y() .label(provider.label()) .child( rune::icon(provider_icon(provider), 16.0) .key("icon") .color(p.muted()), ) .child( text(provider.label()) .key("name") .font(DESCRIPTION) .color(p.muted()), ) }); setting_row( p, &format!("upcoming{index}"), &meeting.title, Some(&meeting.when), provider.unwrap_or_else(|| row().key("provider")), ) })); } if let Some(error) = &view.error { rows.push(note("calendar-error", error, p.danger())); } } /// Which calendars remind: all by default, each one switched in the menu. fn calendars_row(ui: &Ui, p: Paint, layer: &mut Vec) -> El { let calendar = &ui.settings.meetings.calendar; let calendars = &ui.platform.calendar.calendars; let included = calendars .iter() .filter(|info| calendar.includes(&info.id)) .count(); let label = if included == calendars.len() { tr("All calendars").to_string() } else { tr_named( "{included} of {total} calendars", &[ ("included", &included.to_string()), ("total", &calendars.len().to_string()), ], ) }; let choices = calendars .iter() .map(|info| { let id = info.id.clone(); Choice { label: if info.source.is_empty() { info.title.clone() } else { format!("{} · {}", info.title, info.source) }, detail: None, selected: calendar.includes(&info.id), choose: Box::new(move |ui: &mut Ui| { let id = id.clone(); ui.update(|settings| { let excluded = &mut settings.meetings.calendar.excluded_calendars; if let Some(index) = excluded.iter().position(|known| *known == id) { excluded.remove(index); } else { excluded.push(id); } }); }), } }) .collect(); let select = select( p, "calendar-calendars-control", tr("Calendars"), &label, ui.open == Some(Menu::Calendars), choices, |ui: &mut Ui| toggle_menu(ui, Menu::Calendars), layer, ); // Labs › Select all calendars adds one bulk button; off, the row is the // select alone, exactly as before. let control = if bulk_select_on(ui) && !calendars.is_empty() { row() .key("calendar-calendars-controls") .gap(8.0) .center_y() .child(small_button( p, "calendar-select-all", if included == calendars.len() { tr("Deselect all") } else { tr("Select all") }, |ui: &mut Ui, _| { // Read the calendars and the direction now, at the click, // not when the row was drawn. let ids: Vec = ui .platform .calendar .calendars .iter() .map(|info| info.id.clone()) .collect(); let all_included = ids .iter() .all(|id| ui.settings.meetings.calendar.includes(id)); ui.update(move |settings| { let excluded = &mut settings.meetings.calendar.excluded_calendars; if all_included { // Deselect all: the setting stores exclusions, so // calendars added later are still included. *excluded = ids; } else { excluded.clear(); } }); }, )) .child(select) } else { select }; setting_row(p, "calendar-calendars", tr("Calendars"), None, control) } /// Whether Labs › Select all calendars adds the Calendars row's bulk button. /// The lab is UI only: its own toggle, in this build, with no organization /// lock, as `in_place_on` reads its lab (`src/rune_ui/model_import.rs:73`). fn bulk_select_on(ui: &Ui) -> bool { let feature = Feature::CalendarSelectAll; feature.shipped() && feature.managed().is_none() && feature.on(&ui.settings) } /// The virtual microphone driver's row: install, update, or uninstall it. pub(super) fn driver_row(ui: &Ui, p: Paint) -> El { let title = tr("Hex Microphone"); let Some(status) = &ui.platform.hex_microphone else { return setting_row( p, "hex-mic-driver", title, Some(tr("Checking…")), row().key("none"), ); }; let action = |key: &str, label: &str, request: PlatformRequest| { button( p, key, label, ButtonKind::Secondary, move |ui: &mut Ui, _| ui.ask(request.clone()), ) }; let mut controls = row().key("controls").gap(8.0).center_y().flex_wrap(); let in_use = status.driver_loaded && status.mic_in_use; let mut description = if in_use && !status.active_apps.is_empty() { tr_fill("In use by {}", &status.active_apps.join(", ")) } else if in_use { tr("In use").into() } else if status.driver_loaded { tr("Select Hex Microphone as the input in your call app").into() } else if status.driver_bundle_installed { tr("Hex Microphone is installed but unavailable").into() } else { tr("Installation briefly restarts system audio").into() }; match &status.action_state { DriverActionState::Installing => { description = tr("Installing driver and restarting Core Audio…").into() } DriverActionState::Uninstalling => { description = tr("Removing driver and restarting Core Audio…").into() } state => { if let DriverActionState::Failed(reason) = state { description = format!("{} · {}", tr("Failed"), reason); } if matches!(state, DriverActionState::Cancelled) { description = format!("{} · {}", tr("Cancelled"), description); } if status.driver_bundle_installed { if status.needs_update() || !status.driver_loaded { controls = controls.child(action( "update", if status.needs_update() { tr("Update") } else { tr("Retry") }, PlatformRequest::InstallHexMicrophone, )); } controls = controls.child(action( "uninstall", tr("Uninstall"), PlatformRequest::UninstallHexMicrophone, )); } else { controls = controls.child(action( "install", tr("Install Hex Microphone"), PlatformRequest::InstallHexMicrophone, )); } } } setting_row(p, "hex-mic-driver", title, Some(&description), controls) } /// `target`'s modifier-only shortcut moved to `side`, unless that collides /// with another shortcut. pub(super) fn side_binding( settings: &AppSettings, target: ShortcutTarget, side: ModifierSide, ) -> Option { let mut candidate = super::settings::binding(settings, target)?.clone(); candidate.standalone_side()?; candidate.set_standalone_side(side); (!super::settings::conflicts(settings, target, &candidate)).then_some(candidate) } pub(super) const SIDES: [ModifierSide; 3] = [ ModifierSide::Left, ModifierSide::Either, ModifierSide::Right, ]; /// The side [`side_selector`] shows for `target`, if it shows one: the /// keycaps beside it then leave the side to it. pub(super) fn picked_side(ui: &Ui, target: ShortcutTarget) -> Option { if !ui.platform.caps.modifier_sides { return None; } super::settings::binding(&ui.settings, target)?.standalone_side() }