Repository navigation
Expand file tree
/
Copy pathplatform_settings.rs
More file actions
924 lines (899 loc) · 33.1 KB
/
Copy pathplatform_settings.rs
File metadata and controls
924 lines (899 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
//! 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, Choice, DESCRIPTION, Paint, button, card, icon_row, icon_toggle_row, note, section,
select, setting_row,
};
use super::lists::{PermissionControl, Tone, permission_control, tone_tag};
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, KNOWN_MEETING_PROVIDERS, MeetingPolicy,
MeetingProviderChoice, MeetingRetention, 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};
/// 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,
) -> (&'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),
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.
pub(super) fn accessibility_name(renamed: bool) -> &'static str {
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<El> {
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);
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<El> {
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<El> {
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("Meeting 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 use this")
}
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"),
}
}
fn folder_label(ui: &Ui) -> String {
let folder = ui.settings.meetings.resolved_output_folder();
dirs::home_dir()
.and_then(|home| {
folder
.strip_prefix(home)
.ok()
.map(|relative| format!("~/{}", relative.display()))
})
.unwrap_or_else(|| folder.display().to_string())
}
/// 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, how long meetings are kept, Calendar and each detected call provider's Ask /
/// Always record / Never offer choice; behind Advanced the indicator,
/// folder, Apple Intelligence notes, and the granted permission.
pub(super) fn meetings_settings(ui: &Ui, p: Paint, layer: &mut Vec<El>) -> Vec<El> {
use super::general::{advanced_open, 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);
}
}
if meetings.enabled {
rows.push(retention_row(ui, p, layer));
more.push(icon_toggle_row(
p,
"meeting-indicator",
&icons::PILL,
tr("Show recording indicator"),
tr("Floating pill to copy live transcript turns or stop recording"),
meetings.show_recording_indicator,
|ui: &mut Ui| {
let show = !ui.settings.meetings.show_recording_indicator;
ui.update(|settings| settings.meetings.show_recording_indicator = show);
},
));
more.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),
ButtonKind::Secondary,
|ui: &mut Ui, _| ui.ask(PlatformRequest::Meeting(MeetingRequest::ChooseFolder)),
)),
));
if ui.platform.caps.os == Os::Macos {
more.push(icon_toggle_row(
p,
"meeting-notes",
&icons::SPARKLES,
tr("Summarize with Apple Intelligence"),
notes_description(ui.platform.notes),
meetings.summarize_with_apple_intelligence,
|ui: &mut Ui| {
let enabled = !ui.settings.meetings.summarize_with_apple_intelligence;
ui.update(|settings| {
settings.meetings.summarize_with_apple_intelligence = enabled
});
},
));
}
more.push(if opencode_managed() {
super::controls::managed_row(
p,
"meeting-notes-opencode",
Some(&icons::SPARKLES),
tr("Summarize with OpenCode"),
)
} else {
icon_toggle_row(
p,
"meeting-notes-opencode",
&icons::SPARKLES,
tr("Summarize with OpenCode"),
if ui.platform.caps.os == Os::Macos {
tr("When Apple Intelligence is off or unavailable. Sends the transcript to your OpenCode model")
} else {
tr("Meeting titles and short summaries. Sends the transcript to your OpenCode model")
},
meetings.summarize_with_opencode,
|ui: &mut Ui| {
let enabled = !ui.settings.meetings.summarize_with_opencode;
ui.update(|settings| settings.meetings.summarize_with_opencode = enabled);
},
)
});
if let Some(error) = &ui.platform.meeting_folder_error {
// A failed folder change shows where it happened, opening the fold.
more.push(note("meeting-folder-error", error, p.danger()));
}
}
let mut sections = vec![card(p, "meetings", rows)];
if meetings.enabled {
sections.extend(calendar_section(ui, p, layer));
sections.push(detected_calls_section(ui, p, layer));
sections.push(advanced_toggle(ui, p, Pane::Meetings));
if advanced_open(ui, Pane::Meetings) || ui.platform.meeting_folder_error.is_some() {
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>) -> El {
let chosen = ui.settings.meetings.retention;
let retention = chosen.unwrap_or(MeetingRetention::DEFAULT);
let control = super::general::pick_select(
ui,
p,
"meeting-retention",
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(
"Audio, transcripts, notes, and Hex's Markdown copy move to the Trash. Meetings from before this setting stay until you choose",
)),
Some(MeetingRetention::Forever) => None,
Some(_) => Some(tr(
"Audio, transcripts, notes, and Hex's Markdown copy move to the Trash",
)),
},
control,
)
}
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"),
};
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,
}
}
/// Calendar reminders: Connect calendar (the only thing that asks macOS for
/// access), then the reminder switch, lead time, included calendars, and
/// the next few meetings.
fn calendar_section(ui: &Ui, p: Paint, layer: &mut Vec<El>) -> Option<El> {
if !ui.platform.caps.calendar {
return None;
}
let view = &ui.platform.calendar;
let calendar = &ui.settings.meetings.calendar;
let mut rows = Vec::new();
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",
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()));
}
Some(section(p, "calendar", tr("Calendar"), rows))
}
/// Which calendars remind: all by default, each one switched in the menu.
fn calendars_row(ui: &Ui, p: Paint, layer: &mut Vec<El>) -> 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();
setting_row(
p,
"calendar-calendars",
tr("Calendars"),
None,
select(
p,
"calendar-calendars-control",
&label,
ui.open == Some(Menu::Calendars),
choices,
|ui: &mut Ui| toggle_menu(ui, Menu::Calendars),
layer,
),
)
}
/// The known services, then every other website or app the user chose for,
/// each with Ask / Always record / Never offer.
fn detected_calls_section(ui: &Ui, p: Paint, layer: &mut Vec<El>) -> El {
let choices = &ui.settings.meetings.providers;
let known = KNOWN_MEETING_PROVIDERS
.iter()
.map(|(key, label)| (key.to_string(), label.to_string(), tr(label).to_owned()));
let others = choices
.iter()
.filter(|choice| {
!KNOWN_MEETING_PROVIDERS
.iter()
.any(|(key, _)| *key == choice.key)
})
.map(|choice| {
(
choice.key.clone(),
choice.label.clone(),
choice.label.clone(),
)
});
let labels = [tr("Ask"), tr("Always record"), tr("Never offer")];
let rows = known
.chain(others)
.enumerate()
.map(|(index, (key, label, shown))| {
let policy = choices
.iter()
.find(|choice| choice.key == key)
.map_or(MeetingPolicy::Ask, |choice| choice.policy);
let selected = POLICIES.iter().position(|known| *known == policy);
let control = super::general::quiet_select(
ui,
p,
Menu::Call(index),
format!("call{index}-policy-control"),
labels.to_vec(),
selected.unwrap_or(0),
move |ui, index| {
let choice = MeetingProviderChoice {
key: key.clone(),
label: label.clone(),
policy: POLICIES[index],
};
ui.update(|settings| {
crate::app_settings::set_meeting_provider(&mut settings.meetings, choice);
});
},
layer,
);
setting_row(p, &format!("call{index}"), &shown, None, control)
})
.collect::<Vec<_>>();
section(p, "detected-calls", tr("Detected calls"), rows)
}
/// In the order of the Detected calls segments.
const POLICIES: [MeetingPolicy; 3] = [
MeetingPolicy::Ask,
MeetingPolicy::AlwaysRecord,
MeetingPolicy::NeverOffer,
];
/// The virtual microphone driver's row: install, update, or uninstall it.
pub(super) fn driver_row(ui: &Ui, p: Paint) -> El {
let title = tr("Virtual microphone driver");
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 install = || {
action(
"install",
tr("Install"),
PlatformRequest::InstallHexMicrophone,
)
};
let uninstall = || {
action(
"uninstall",
tr("Uninstall"),
PlatformRequest::UninstallHexMicrophone,
)
};
let state_tag = |label: &str, tone: Tone| tone_tag(p, "state", label, tone);
let controls = row().key("controls").gap(8.0).center_y();
let (description, controls) = match &status.action_state {
DriverActionState::Installing => (
tr("Installing driver and restarting Core Audio…").to_string(),
controls.child(state_tag(tr("Installing…"), Tone::Neutral)),
),
DriverActionState::Uninstalling => (
tr("Removing driver and restarting Core Audio…").to_string(),
controls.child(state_tag(tr("Uninstalling…"), Tone::Neutral)),
),
state if status.needs_update() => {
let installed = status.installed_version.as_deref().unwrap_or("1.0.0");
(
match state {
DriverActionState::Cancelled => tr("Update cancelled").into(),
DriverActionState::Failed(reason) => {
tr_fill("Could not update driver: {}", reason)
}
_ => tr_fill("Update driver to v{}", &status.bundled_version),
},
controls
.child(state_tag(
&tr_fill("v{} installed", installed),
Tone::Accent,
))
.child(action(
"update",
tr("Update"),
PlatformRequest::InstallHexMicrophone,
))
.child(uninstall()),
)
}
state if status.driver_loaded => {
let version = status
.installed_version
.as_deref()
.unwrap_or(&status.bundled_version);
(
match state {
DriverActionState::Cancelled => tr("Uninstall cancelled").into(),
DriverActionState::Failed(reason) => {
tr_fill("Could not update driver: {}", reason)
}
_ if !status.active_apps.is_empty() => tr_fill(
"Streaming 48 kHz audio to {}",
&status.active_apps.join(", "),
),
_ => {
tr("Choose Hex Microphone as your input in Slack, Zoom, or Discord").into()
}
},
controls
.child(state_tag(&tr_fill("Installed v{}", version), Tone::Success))
.child(uninstall()),
)
}
DriverActionState::DoneUninstalled => (
tr("Driver removed").into(),
controls
.child(state_tag(tr("Removed"), Tone::Neutral))
.child(install()),
),
DriverActionState::Cancelled => (
tr("Installation cancelled").into(),
controls
.child(state_tag(tr("Cancelled"), Tone::Neutral))
.child(install()),
),
DriverActionState::Failed(reason) => (
tr_fill("Could not install driver: {}", reason),
controls
.child(state_tag(tr("Failed"), Tone::Danger))
.child(install()),
),
_ => (
tr("Install the CoreAudio driver to choose Hex Microphone in Slack, Zoom, or Discord")
.into(),
controls.child(install()),
),
};
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<HotkeyBinding> {
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<ModifierSide> {
if !ui.platform.caps.modifier_sides {
return None;
}
super::settings::binding(&ui.settings, target)?.standalone_side()
}