desktop_app_blocker_api/spec.rs
1use crate::blocker::app::AppBlockAction;
2
3/// The `BlockerSpec` trait defines the interface for a blocking policy,
4/// providing methods to specify what actions should be taken for blocking
5/// different system features such as applications, processes, system settings,
6/// etc. This trait contains both platform-independent and platform-specific methods.
7pub trait BlockerSpec {
8 /// Retrieves the action to be performed when blocking an application.
9 ///
10 /// This defines what happens when an app needs to be blocked, such as
11 /// terminating, hiding, or restricting its access.
12 ///
13 /// # Returns
14 /// `AppBlockAction` - the specified action to take when blocking an app.
15 fn app_block_action(&self) -> &AppBlockAction;
16
17 /// Retrieves the action to be performed when the user attempts to bypass
18 /// or escape the block.
19 ///
20 /// This defines the action to be taken when a user tries to circumvent
21 /// the blocking policy.
22 ///
23 /// # Returns
24 /// `AppBlockAction` - the specified action to take when an escape attempt occurs.
25 fn escape_block_action(&self) -> &AppBlockAction;
26
27 /// Indicates whether the Task Manager (or Activity Monitor) should
28 /// be blocked.
29 ///
30 /// # Returns
31 /// `true` if Task Manager/Activity Monitor should be blocked,
32 /// `false` otherwise.
33 fn should_block_task_manager(&self) -> bool;
34
35 /// Determines whether a window with the given title should be blocked.
36 ///
37 /// This is applicable to all platforms except macOS.
38 ///
39 /// # Parameters
40 /// - `title`: The title of the window to check for blocking.
41 ///
42 /// # Returns
43 /// `true` if the window should be blocked, `false` otherwise.
44 #[cfg(target_os = "windows")]
45 fn should_block_window(&self, process_name: &str, window_title: &str, full_path: Option<&String>) -> bool;
46
47 /// Indicates whether terminal applications should be blocked.
48 ///
49 /// # Returns
50 /// `true` if terminal applications should be blocked, `false` otherwise.
51 fn should_block_terminal(&self) -> bool;
52
53 /// Indicates whether system settings should be blocked.
54 ///
55 /// # Returns
56 /// `true` if system settings should be blocked, `false` otherwise.
57 fn should_block_system_settings(&self) -> bool;
58
59 /// Indicates whether sign-out buttons should be blocked.
60 ///
61 /// This is applicable only to Windows platforms.
62 ///
63 /// # Returns
64 /// `true` if sign-out buttons should be blocked, `false` otherwise.
65 #[cfg(target_os = "windows")]
66 fn should_block_sign_out_buttons(&self) -> bool;
67
68 /// Indicates whether installers should be blocked.
69 ///
70 /// This is applicable only to Windows platforms.
71 ///
72 /// # Returns
73 /// `true` if installers should be blocked, `false` otherwise.
74 #[cfg(target_os = "windows")]
75 fn should_block_installers(&self) -> bool;
76
77 /// Determines whether an application with the specified bundle ID should be blocked.
78 ///
79 /// This is applicable only to macOS platforms.
80 ///
81 /// # Parameters
82 /// - `bundle_id`: The bundle ID of the application to check for blocking.
83 ///
84 /// # Returns
85 /// `true` if the application should be blocked, `false` otherwise.
86 #[cfg(target_os = "macos")]
87 fn should_block_bundle_id(&self, bundle_id: &str) -> bool;
88}