BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / notify / rules.rs

rules.rs

rules.rs 24.0 KiB Download Raw
1use std::collections::HashMap;
2use std::time::{Duration, Instant};
3
4use calling::Progress;
5use chrono::{DateTime, Utc};
6use store::{ChannelNotificationLevel, ChannelNotifications};
7use teams_core::{
8 DesktopNotifications, MeetingChatNotifications, NotificationAccountSettings, NotificationPreset,
9};
10
11use super::sound_settings::SoundSettings;
12use super::sounds::Ringtone;
13use crate::call::{CallKind, CallModel};
14
15pub const SOUND_THROTTLE: Duration = Duration::from_secs(10);
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
18pub enum Corner {
19 TopLeft,
20 TopRight,
21 BottomLeft,
22 #[default]
23 BottomRight,
24}
25
26impl Corner {
27 pub const ALL: [Corner; 4] = [
28 Corner::TopLeft,
29 Corner::TopRight,
30 Corner::BottomLeft,
31 Corner::BottomRight,
32 ];
33
34 pub fn label(self) -> &'static str {
35 match self {
36 Corner::TopLeft => "Top left",
37 Corner::TopRight => "Top right",
38 Corner::BottomLeft => "Bottom left",
39 Corner::BottomRight => "Bottom right",
40 }
41 }
42
43 pub fn key(self) -> &'static str {
44 match self {
45 Corner::TopLeft => "top_left",
46 Corner::TopRight => "top_right",
47 Corner::BottomLeft => "bottom_left",
48 Corner::BottomRight => "bottom_right",
49 }
50 }
51
52 pub fn from_key(key: &str) -> Option<Corner> {
53 Corner::ALL.into_iter().find(|corner| corner.key() == key)
54 }
55
56 pub fn is_bottom(self) -> bool {
57 matches!(self, Corner::BottomLeft | Corner::BottomRight)
58 }
59
60 pub fn is_right(self) -> bool {
61 matches!(self, Corner::TopRight | Corner::BottomRight)
62 }
63
64 pub fn next(self) -> Corner {
65 let index = Corner::ALL
66 .iter()
67 .position(|corner| *corner == self)
68 .unwrap_or(0);
69 Corner::ALL[(index + 1) % Corner::ALL.len()]
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq)]
74pub struct Settings {
75 pub account: NotificationAccountSettings,
76 pub corner: Corner,
77 pub flash: bool,
78 pub close_to_tray: bool,
79 pub do_not_disturb: bool,
80 pub mute_in_calls: bool,
81 pub sounds: SoundSettings,
82}
83
84impl Default for Settings {
85 fn default() -> Self {
86 Settings {
87 account: NotificationAccountSettings::default(),
88 corner: Corner::BottomRight,
89 flash: true,
90 close_to_tray: true,
91 do_not_disturb: false,
92 mute_in_calls: false,
93 sounds: SoundSettings::default(),
94 }
95 }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub enum ChatKind {
100 Direct,
101 Group { member_count: usize },
102 Channel { team: String, channel: String },
103}
104
105#[derive(Debug, Clone, PartialEq, Eq)]
106pub enum Preview {
107 Text(String),
108 Image,
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
112pub struct ChannelSignals {
113 pub mentions_channel: bool,
114 pub in_my_thread: bool,
115 pub hidden: bool,
116 pub is_reply: bool,
117 pub notifications: ChannelNotifications,
118}
119
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
121pub struct ChatSignals {
122 pub meeting: bool,
123 pub participated: bool,
124 pub desktop: DesktopNotifications,
125}
126
127#[derive(Debug, Clone, PartialEq, Eq)]
128pub struct Incoming {
129 pub conversation_id: String,
130 pub message_id: String,
131 pub kind: ChatKind,
132 pub chat_title: String,
133 pub sender_id: Option<String>,
134 pub sender_name: String,
135 pub preview: Preview,
136 pub mentions_me: bool,
137 pub muted: bool,
138 pub signals: ChannelSignals,
139 pub chat: ChatSignals,
140 pub created_at: DateTime<Utc>,
141}
142
143impl Incoming {
144 pub fn is_direct(&self) -> bool {
145 self.kind == ChatKind::Direct
146 }
147}
148
149#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
150pub struct Environment {
151 pub chat_in_foreground: bool,
152 pub system_quiet: bool,
153 pub own_do_not_disturb: bool,
154 pub own_busy: bool,
155 pub in_call: bool,
156}
157
158impl Environment {
159 pub fn busy(&self) -> bool {
160 self.in_call || self.own_busy
161 }
162}
163
164pub fn in_call(server_in_call: bool, native_call: Option<&CallModel>) -> bool {
165 server_in_call || native_call.is_some_and(CallModel::is_active)
166}
167
168pub fn should_ringback(native_call: Option<&CallModel>) -> bool {
169 native_call.is_some_and(|model| {
170 !model.incoming
171 && model.kind != CallKind::Meeting
172 && model.is_connecting()
173 && matches!(model.progress, Some(Progress::Calling | Progress::Ringing))
174 })
175}
176
177#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178pub struct Decision {
179 pub toast: bool,
180 pub sound: bool,
181}
182
183pub fn alerts(incoming: &Incoming) -> bool {
184 channel_alerts(incoming) && (!incoming.muted || incoming.mentions_me)
185}
186
187fn channel_alerts(incoming: &Incoming) -> bool {
188 if !matches!(incoming.kind, ChatKind::Channel { .. }) || incoming.mentions_me {
189 return true;
190 }
191 let signals = incoming.signals;
192 if signals.hidden {
193 return false;
194 }
195 if signals.mentions_channel || signals.in_my_thread {
196 return true;
197 }
198 let notifications = signals.notifications;
199 notifications.level != ChannelNotificationLevel::Off
200 && (!signals.is_reply || notifications.include_replies)
201}
202
203fn channel_toasts(incoming: &Incoming) -> bool {
204 if !matches!(incoming.kind, ChatKind::Channel { .. }) || incoming.mentions_me {
205 return true;
206 }
207 let signals = incoming.signals;
208 signals.mentions_channel
209 || signals.in_my_thread
210 || signals.notifications.level == ChannelNotificationLevel::BannerAndFeed
211}
212
213fn account_toasts(account: &NotificationAccountSettings, incoming: &Incoming) -> bool {
214 if matches!(incoming.kind, ChatKind::Channel { .. }) {
215 return if incoming.mentions_me {
216 account.personal_mentions.shows_banner()
217 } else {
218 account.preset != NotificationPreset::MentionsAndReplies
219 || incoming.signals.in_my_thread
220 };
221 }
222 let chat = incoming.chat;
223 if chat.desktop == DesktopNotifications::Off {
224 return false;
225 }
226 if incoming.mentions_me {
227 return account.personal_mentions.shows_banner();
228 }
229 let meeting_muted = chat.meeting
230 && match account.meeting_chats {
231 MeetingChatNotifications::Mute => true,
232 MeetingChatNotifications::MuteUntilJoin => !chat.participated,
233 MeetingChatNotifications::Unmute => false,
234 };
235 !meeting_muted
236 && (chat.desktop == DesktopNotifications::On || account.chat_messages.shows_banner())
237}
238
239pub fn shows_preview(settings: &Settings) -> bool {
240 settings.account.show_preview
241}
242
243const SILENT: Decision = Decision {
244 toast: false,
245 sound: false,
246};
247
248pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment) -> Decision {
249 let suppressed = !alerts(incoming)
250 || !channel_toasts(incoming)
251 || environment.chat_in_foreground
252 || environment.system_quiet
253 || environment.own_do_not_disturb
254 || settings.do_not_disturb
255 || (settings.mute_in_calls && environment.in_call)
256 || !account_toasts(&settings.account, incoming);
257 if suppressed {
258 return SILENT;
259 }
260 Decision {
261 toast: true,
262 sound: settings.sounds.notification_sound
263 && (settings.sounds.sound_when_busy || !environment.busy()),
264 }
265}
266
267fn busy_allows_sound(settings: &Settings, busy: bool) -> bool {
268 !busy || settings.sounds.sound_when_busy
269}
270
271pub fn ringtone_for(settings: &Settings, in_call: bool, busy: bool) -> Option<Ringtone> {
272 let audible = settings.sounds.call_and_meeting_sound && busy_allows_sound(settings, busy);
273 audible.then_some(if in_call {
274 Ringtone::Beep
275 } else {
276 settings.sounds.ringtones.regular
277 })
278}
279
280pub fn meeting_start_sound(settings: &Settings, busy: bool) -> bool {
281 settings.sounds.call_and_meeting_sound && busy_allows_sound(settings, busy)
282}
283
284#[derive(Default)]
285pub struct SoundThrottle {
286 last_played: HashMap<String, Instant>,
287}
288
289impl SoundThrottle {
290 pub fn allow(&mut self, conversation_id: &str, now: Instant) -> bool {
291 let allowed = self
292 .last_played
293 .get(conversation_id)
294 .is_none_or(|last| now.duration_since(*last) >= SOUND_THROTTLE);
295 if allowed {
296 self.last_played.insert(conversation_id.to_owned(), now);
297 }
298 allowed
299 }
300}
301
302pub fn should_flash(settings: &Settings, toast_shown: bool, window_active: bool) -> bool {
303 settings.flash && toast_shown && !window_active
304}
305
306#[cfg(test)]
307mod tests {
308 use calling::{CallState, EndReason};
309 use teams_core::ActivityAlert;
310
311 use super::*;
312
313 fn incoming(kind: ChatKind) -> Incoming {
314 Incoming {
315 conversation_id: "chat".into(),
316 message_id: "1".into(),
317 kind,
318 chat_title: "Chat".into(),
319 sender_id: Some("u1".into()),
320 sender_name: "Mara".into(),
321 preview: Preview::Text("Hello".into()),
322 mentions_me: false,
323 muted: false,
324 signals: ChannelSignals::default(),
325 chat: ChatSignals::default(),
326 created_at: Utc::now(),
327 }
328 }
329
330 fn channel() -> Incoming {
331 incoming(ChatKind::Channel {
332 team: "Team".into(),
333 channel: "General".into(),
334 })
335 }
336
337 fn group() -> Incoming {
338 incoming(ChatKind::Group { member_count: 5 })
339 }
340
341 #[test]
342 fn plain_message_gets_toast_and_sound() {
343 let decision = decide(&Settings::default(), &group(), Environment::default());
344 assert_eq!(
345 decision,
346 Decision {
347 toast: true,
348 sound: true
349 }
350 );
351 }
352
353 #[test]
354 fn foreground_chat_is_silent() {
355 let environment = Environment {
356 chat_in_foreground: true,
357 ..Default::default()
358 };
359 assert_eq!(decide(&Settings::default(), &group(), environment), SILENT);
360 }
361
362 #[test]
363 fn focus_assist_and_dnd_are_silent() {
364 for environment in [
365 Environment {
366 system_quiet: true,
367 ..Default::default()
368 },
369 Environment {
370 own_do_not_disturb: true,
371 ..Default::default()
372 },
373 ] {
374 assert_eq!(decide(&Settings::default(), &group(), environment), SILENT);
375 }
376 let settings = Settings {
377 do_not_disturb: true,
378 ..Default::default()
379 };
380 assert_eq!(decide(&settings, &group(), Environment::default()), SILENT);
381 }
382
383 #[test]
384 fn in_call_follows_server_presence_or_a_live_native_call() {
385 let model = |state| {
386 let mut model = CallModel::incoming("Bea", "8:orgid:b", "Bea");
387 model.state = state;
388 model
389 };
390 let since = std::time::Instant::now();
391 assert!(!in_call(false, None));
392 assert!(in_call(true, None));
393 assert!(in_call(false, Some(&model(CallState::Connecting))));
394 assert!(in_call(false, Some(&model(CallState::Connected { since }))));
395 assert!(in_call(
396 false,
397 Some(&model(CallState::Reconnecting { since }))
398 ));
399 assert!(!in_call(false, Some(&model(CallState::Idle))));
400 assert!(!in_call(
401 false,
402 Some(&model(CallState::Ended {
403 reason: EndReason::LocalHangup
404 }))
405 ));
406 }
407
408 #[test]
409 fn ringback_plays_only_while_an_outgoing_non_meeting_call_is_connecting() {
410 let callees = [("8:orgid:a".to_owned(), "Ana".to_owned())];
411 let outgoing = |progress: Option<Progress>, state: CallState| {
412 let mut model = CallModel::people("Ana", &callees);
413 model.progress = progress;
414 model.state = state;
415 model
416 };
417 let since = std::time::Instant::now();
418 assert!(!should_ringback(None));
419 assert!(!should_ringback(Some(&outgoing(
420 None,
421 CallState::Connecting
422 ))));
423 assert!(should_ringback(Some(&outgoing(
424 Some(Progress::Calling),
425 CallState::Connecting
426 ))));
427 assert!(should_ringback(Some(&outgoing(
428 Some(Progress::Ringing),
429 CallState::Connecting
430 ))));
431 assert!(!should_ringback(Some(&outgoing(
432 Some(Progress::Ringing),
433 CallState::Connected { since }
434 ))));
435 let ended = CallState::Ended {
436 reason: EndReason::LocalHangup,
437 };
438 assert!(!should_ringback(Some(&outgoing(
439 Some(Progress::Ringing),
440 ended
441 ))));
442 let mut meeting = CallModel::meeting("Standup", false);
443 meeting.progress = Some(Progress::Calling);
444 assert!(!should_ringback(Some(&meeting)));
445 let mut incoming = CallModel::incoming("Bea", "8:orgid:b", "Bea");
446 incoming.progress = Some(Progress::Ringing);
447 assert!(!should_ringback(Some(&incoming)));
448 }
449
450 #[test]
451 fn calls_and_busy_keep_the_sound_unless_the_busy_setting_is_off() {
452 let busy_environments = [
453 Environment {
454 in_call: true,
455 ..Default::default()
456 },
457 Environment {
458 own_busy: true,
459 ..Default::default()
460 },
461 ];
462 let quiet_when_busy = Settings {
463 sounds: SoundSettings {
464 sound_when_busy: false,
465 ..Default::default()
466 },
467 ..Default::default()
468 };
469 for environment in busy_environments {
470 assert!(decide(&Settings::default(), &group(), environment).sound);
471 assert_eq!(
472 decide(&quiet_when_busy, &group(), environment),
473 Decision {
474 toast: true,
475 sound: false
476 }
477 );
478 }
479 assert!(decide(&quiet_when_busy, &group(), Environment::default()).sound);
480 }
481
482 #[test]
483 fn incoming_calls_ring_the_chosen_tone_and_beep_during_a_call() {
484 let mut settings = Settings::default();
485 settings.sounds.ringtones.regular = Ringtone::Bop;
486 assert_eq!(ringtone_for(&settings, false, false), Some(Ringtone::Bop));
487 assert_eq!(ringtone_for(&settings, true, true), Some(Ringtone::Beep));
488 settings.sounds.sound_when_busy = false;
489 assert_eq!(ringtone_for(&settings, false, true), None);
490 assert_eq!(ringtone_for(&settings, false, false), Some(Ringtone::Bop));
491 settings.sounds.call_and_meeting_sound = false;
492 assert_eq!(ringtone_for(&settings, false, false), None);
493 assert!(!meeting_start_sound(&settings, false));
494 }
495
496 #[test]
497 fn meeting_start_sound_follows_the_call_and_busy_settings() {
498 let mut settings = Settings::default();
499 assert!(meeting_start_sound(&settings, false));
500 assert!(meeting_start_sound(&settings, true));
501 settings.sounds.sound_when_busy = false;
502 assert!(!meeting_start_sound(&settings, true));
503 }
504
505 #[test]
506 fn mute_in_calls_drops_the_toast_only_while_in_a_call() {
507 let settings = Settings {
508 mute_in_calls: true,
509 ..Default::default()
510 };
511 let in_call = Environment {
512 in_call: true,
513 ..Default::default()
514 };
515 assert_eq!(decide(&settings, &group(), in_call), SILENT);
516 assert!(decide(&settings, &group(), Environment::default()).toast);
517 }
518
519 #[test]
520 fn muted_chat_only_alerts_and_notifies_for_mentions() {
521 let mut muted = group();
522 muted.muted = true;
523 assert!(!alerts(&muted));
524 assert_eq!(
525 decide(&Settings::default(), &muted, Environment::default()),
526 SILENT
527 );
528 muted.mentions_me = true;
529 assert!(alerts(&muted));
530 assert!(decide(&Settings::default(), &muted, Environment::default()).toast);
531 }
532
533 fn with_account(change: impl FnOnce(&mut NotificationAccountSettings)) -> Settings {
534 let mut settings = Settings::default();
535 change(&mut settings.account);
536 settings
537 }
538
539 fn toasts(settings: &Settings, incoming: &Incoming) -> bool {
540 decide(settings, incoming, Environment::default()).toast
541 }
542
543 fn mention(mut incoming: Incoming) -> Incoming {
544 incoming.mentions_me = true;
545 incoming
546 }
547
548 #[test]
549 fn chat_message_notifications_off_keeps_personal_mentions() {
550 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
551 assert!(!toasts(&settings, &group()));
552 assert!(!toasts(&settings, &incoming(ChatKind::Direct)));
553 assert!(toasts(&settings, &mention(group())));
554 }
555
556 #[test]
557 fn personal_mentions_only_in_activity_give_no_banner() {
558 let settings = with_account(|account| account.personal_mentions = ActivityAlert::OnlyFeed);
559 assert!(!toasts(&settings, &mention(group())));
560 assert!(!toasts(&settings, &mention(channel())));
561 assert!(toasts(&settings, &group()));
562 }
563
564 #[test]
565 fn mentions_and_replies_preset_drops_plain_channel_posts() {
566 let settings =
567 with_account(|account| account.preset = NotificationPreset::MentionsAndReplies);
568 let mut post = channel_with(ChannelNotificationLevel::BannerAndFeed, true);
569 assert!(!toasts(&settings, &post));
570 post.signals.in_my_thread = true;
571 assert!(toasts(&settings, &post));
572 assert!(toasts(&settings, &mention(channel())));
573 assert!(toasts(&settings, &group()));
574 }
575
576 fn meeting_chat(participated: bool) -> Incoming {
577 let mut message = group();
578 message.chat.meeting = true;
579 message.chat.participated = participated;
580 message
581 }
582
583 #[test]
584 fn meeting_chats_stay_quiet_until_i_take_part() {
585 let settings = Settings::default();
586 assert!(!toasts(&settings, &meeting_chat(false)));
587 assert!(toasts(&settings, &meeting_chat(true)));
588 assert!(toasts(&settings, &mention(meeting_chat(false))));
589 }
590
591 #[test]
592 fn meeting_chat_mute_and_unmute() {
593 let muted = with_account(|account| account.meeting_chats = MeetingChatNotifications::Mute);
594 assert!(!toasts(&muted, &meeting_chat(true)));
595 assert!(toasts(&muted, &mention(meeting_chat(true))));
596 let unmuted =
597 with_account(|account| account.meeting_chats = MeetingChatNotifications::Unmute);
598 assert!(toasts(&unmuted, &meeting_chat(false)));
599 }
600
601 #[test]
602 fn per_chat_desktop_preference_overrides_the_account() {
603 let mut silenced = group();
604 silenced.chat.desktop = DesktopNotifications::Off;
605 assert!(!toasts(&Settings::default(), &silenced));
606 assert!(!toasts(&Settings::default(), &mention(silenced)));
607 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
608 let mut selected = group();
609 selected.chat.desktop = DesktopNotifications::On;
610 assert!(toasts(&settings, &selected));
611 }
612
613 fn channel_with(level: ChannelNotificationLevel, include_replies: bool) -> Incoming {
614 let mut message = channel();
615 message.signals.notifications = ChannelNotifications {
616 level,
617 include_replies,
618 };
619 message
620 }
621
622 fn toast_of(incoming: &Incoming) -> bool {
623 decide(&Settings::default(), incoming, Environment::default()).toast
624 }
625
626 #[test]
627 fn banner_and_activity_posts_toast_and_feed() {
628 let post = channel_with(ChannelNotificationLevel::BannerAndFeed, false);
629 assert!(channel_alerts(&post));
630 assert!(toast_of(&post));
631 }
632
633 #[test]
634 fn activity_only_posts_feed_without_a_toast() {
635 let post = channel_with(ChannelNotificationLevel::Feed, false);
636 assert!(channel_alerts(&post));
637 assert_eq!(
638 decide(&Settings::default(), &post, Environment::default()),
639 SILENT
640 );
641 assert!(channel_alerts(&channel()));
642 }
643
644 #[test]
645 fn off_channel_stays_silent_except_for_mentions_and_my_threads() {
646 let mut post = channel_with(ChannelNotificationLevel::Off, true);
647 assert!(!channel_alerts(&post));
648 assert_eq!(
649 decide(&Settings::default(), &post, Environment::default()),
650 SILENT
651 );
652 post.signals.is_reply = true;
653 assert!(!channel_alerts(&post));
654 let triggers: [fn(&mut Incoming); 3] = [
655 |incoming| incoming.mentions_me = true,
656 |incoming| incoming.signals.mentions_channel = true,
657 |incoming| incoming.signals.in_my_thread = true,
658 ];
659 for trigger in triggers {
660 let mut mention = channel_with(ChannelNotificationLevel::Off, false);
661 trigger(&mut mention);
662 assert!(channel_alerts(&mention));
663 assert!(toast_of(&mention));
664 }
665 }
666
667 #[test]
668 fn replies_need_include_replies_or_my_thread() {
669 for level in [
670 ChannelNotificationLevel::Feed,
671 ChannelNotificationLevel::BannerAndFeed,
672 ] {
673 let mut reply = channel_with(level, false);
674 reply.signals.is_reply = true;
675 assert!(!channel_alerts(&reply));
676 reply.signals.in_my_thread = true;
677 assert!(channel_alerts(&reply));
678 let mut included = channel_with(level, true);
679 included.signals.is_reply = true;
680 assert!(channel_alerts(&included));
681 }
682 let mut banner_reply = channel_with(ChannelNotificationLevel::BannerAndFeed, true);
683 banner_reply.signals.is_reply = true;
684 assert!(toast_of(&banner_reply));
685 let mut feed_reply = channel_with(ChannelNotificationLevel::Feed, true);
686 feed_reply.signals.is_reply = true;
687 assert!(!toast_of(&feed_reply));
688 }
689
690 #[test]
691 fn hidden_channel_only_alerts_for_mentions_of_me() {
692 let triggers: [fn(&mut Incoming); 3] = [
693 |incoming| incoming.signals.mentions_channel = true,
694 |incoming| incoming.signals.in_my_thread = true,
695 |incoming| {
696 incoming.signals.notifications.level = ChannelNotificationLevel::BannerAndFeed
697 },
698 ];
699 for trigger in triggers {
700 let mut message = channel();
701 trigger(&mut message);
702 message.signals.hidden = true;
703 assert!(!channel_alerts(&message));
704 }
705 let mut mention = channel();
706 mention.signals.hidden = true;
707 mention.mentions_me = true;
708 assert!(channel_alerts(&mention));
709 }
710
711 #[test]
712 fn chats_ignore_channel_signals() {
713 assert!(channel_alerts(&group()));
714 assert!(channel_alerts(&incoming(ChatKind::Direct)));
715 }
716
717 #[test]
718 fn sound_setting_off_keeps_toast() {
719 let settings = Settings {
720 sounds: SoundSettings {
721 notification_sound: false,
722 ..Default::default()
723 },
724 ..Default::default()
725 };
726 let decision = decide(&settings, &group(), Environment::default());
727 assert_eq!(
728 decision,
729 Decision {
730 toast: true,
731 sound: false
732 }
733 );
734 }
735
736 #[test]
737 fn throttle_allows_once_per_window_per_chat() {
738 let mut throttle = SoundThrottle::default();
739 let start = Instant::now();
740 assert!(throttle.allow("a", start));
741 assert!(!throttle.allow("a", start + Duration::from_secs(9)));
742 assert!(throttle.allow("b", start + Duration::from_secs(9)));
743 assert!(throttle.allow("a", start + Duration::from_secs(10)));
744 }
745
746 #[test]
747 fn flash_needs_toast_inactive_window_and_setting() {
748 let settings = Settings::default();
749 assert!(should_flash(&settings, true, false));
750 assert!(!should_flash(&settings, true, true));
751 assert!(!should_flash(&settings, false, false));
752 let off = Settings {
753 flash: false,
754 ..Default::default()
755 };
756 assert!(!should_flash(&off, true, false));
757 }
758
759 #[test]
760 fn corner_keys_round_trip() {
761 for corner in Corner::ALL {
762 assert_eq!(Corner::from_key(corner.key()), Some(corner));
763 }
764 assert_eq!(Corner::BottomRight.next(), Corner::TopLeft);
765 }
766}