Skip to main content

ferroui_native/
platform_behavior_inhibition.rs

1use crate::frn_string::to_c_string;
2use crate::interop::*;
3use ferroui_base::input::LocalBoxFuture;
4use ferroui_base::platform::IPlatformBehaviorInhibition;
5use ferroui_microcom::ComPtr;
6
7/// Controls platform behaviours an application may need to inhibit.
8pub struct PlatformBehaviorInhibition {
9    native: ComPtr<IFrnPlatformBehaviorInhibition>,
10}
11
12impl PlatformBehaviorInhibition {
13    pub(crate) fn new(native: ComPtr<IFrnPlatformBehaviorInhibition>) -> Self {
14        Self { native }
15    }
16}
17
18impl IPlatformBehaviorInhibition for PlatformBehaviorInhibition {
19    /// Prevents (or allows again) the system from putting the application
20    /// to sleep; `reason` is shown by the system as the reason.
21    ///
22    /// The native call completes synchronously: the returned future is
23    /// complete.
24    fn set_inhibit_app_sleep(&self, inhibit_app_sleep: bool, reason: &str) -> LocalBoxFuture<()> {
25        self.native.set_inhibit_app_sleep(inhibit_app_sleep, Some(&to_c_string(reason)));
26        Box::pin(std::future::ready(()))
27    }
28}