cranpose 0.9.30

Build desktop, mobile and web apps with composable Rust functions
Documentation
use std::sync::Arc;

use cranpose_services::{
    HostController, PlatformDirectories, set_application_id, set_host_controller,
};
use objc2::MainThreadMarker;
use objc2_foundation::NSBundle;
use objc2_ui_kit::UIApplication;

struct IosHost;

impl HostController for IosHost {
    fn set_keep_screen_on(&self, enabled: bool) {
        let Some(mtm) = MainThreadMarker::new() else {
            return;
        };
        UIApplication::sharedApplication(mtm).setIdleTimerDisabled(enabled);
    }

    fn platform_directories(&self) -> Option<PlatformDirectories> {
        Some(crate::apple_mobile::sandbox_directories())
    }

    fn exit(&self) {}

    fn background(&self) {}

    fn durable_save_deadline(&self) -> std::time::Duration {
        std::time::Duration::from_secs(5)
    }
}

fn bundle_identifier() -> Option<String> {
    let bundle = NSBundle::mainBundle();
    bundle
        .bundleIdentifier()
        .map(|identifier| identifier.to_string())
}

pub(crate) fn register() {
    if let Some(identifier) = bundle_identifier()
        && let Err(error) = set_application_id(&identifier)
    {
        log::warn!("cranpose: the iOS bundle identifier is not a usable application id: {error}");
    }
    set_host_controller(Arc::new(IosHost));
    crate::pipeline_cache_file::publish();
}