fret_runtime/
window_menu_bar_focus.rs1use std::collections::HashMap;
2
3use fret_core::AppWindowId;
4
5#[derive(Debug, Default)]
12pub struct WindowMenuBarFocusService {
13 by_window: HashMap<AppWindowId, bool>,
14}
15
16impl WindowMenuBarFocusService {
17 pub fn present(&self, window: AppWindowId) -> bool {
18 self.by_window.get(&window).copied().unwrap_or(false)
19 }
20
21 pub fn set_present(&mut self, window: AppWindowId, present: bool) {
22 self.by_window.insert(window, present);
23 }
24
25 pub fn remove_window(&mut self, window: AppWindowId) {
26 self.by_window.remove(&window);
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn present_defaults_to_false() {
36 let svc = WindowMenuBarFocusService::default();
37 assert!(!svc.present(AppWindowId::default()));
38 }
39
40 #[test]
41 fn set_present_updates_window() {
42 let mut svc = WindowMenuBarFocusService::default();
43 let window = AppWindowId::default();
44 svc.set_present(window, true);
45 assert!(svc.present(window));
46 svc.set_present(window, false);
47 assert!(!svc.present(window));
48 }
49}