Skip to main content

cranpose_services/
lib.rs

1//! Multiplatform service abstractions used by Cranpose applications.
2
3#![deny(unsafe_code)]
4
5#[cfg(test)]
6use cranpose_core::{location_key, Composition, MemoryApplier};
7
8pub mod app_info;
9pub mod audio;
10pub mod background;
11pub mod camera;
12pub mod device_info;
13pub mod file_picker;
14pub mod haptics;
15pub mod http;
16pub mod image_picker;
17pub mod launch_args;
18pub mod navigation;
19pub mod network_status;
20pub mod notifier;
21#[cfg(not(target_arch = "wasm32"))]
22pub mod peer;
23pub mod purchases;
24mod registry;
25pub mod share_sheet;
26pub mod theme;
27pub mod uri_handler;
28pub mod writable_folder;
29
30pub use app_info::{
31    app_info, build_version, clear_platform_app_info, set_platform_app_info, version_name, AppInfo,
32    AppInfoRef,
33};
34pub use audio::{
35    clear_platform_audio, default_audio, local_audio, rememberSoundBank, set_platform_audio,
36    AudioBus, AudioClip, AudioError, AudioPlayer, AudioPlayerRef, NoopAudioPlayer, PlaybackParams,
37    ProvideAudio, SoundBank, SoundBankEntry, SoundBankFailure, SoundId, SoundSpec, VoiceId,
38};
39pub use background::{
40    background_active, background_activity, clear_platform_background_activity,
41    set_background_active, set_platform_background_activity, BackgroundActivity,
42    BackgroundActivityRef,
43};
44pub use camera::{
45    camera, clear_platform_camera, set_platform_camera, Camera, CameraError, CameraFrame,
46    CameraLens, CameraRef, CameraStill, FlashMode,
47};
48pub use device_info::{
49    clear_platform_device_info, device_info, set_platform_device_info, DeviceInfo, DeviceInfoRef,
50};
51pub use file_picker::{
52    clear_platform_file_picker, default_file_picker, local_file_picker, set_platform_file_picker,
53    FileFilter, FilePicker, FilePickerError, FilePickerOptions, FilePickerRef, FolderStream,
54    FolderStreamRef, PickedEntry, PickedEntryRef, PickedKind, PickerFuture, ProvideFilePicker,
55    ResumedPick, SaveFileRequest,
56};
57pub use haptics::{
58    clear_platform_haptics, default_haptics, local_haptics, set_platform_haptics, HapticEffect,
59    HapticError, HapticFeedback, HapticPattern, Haptics, HapticsRef, ProvideHaptics,
60};
61pub use http::{
62    default_http_client, local_http_client, map_ordered_concurrent, HttpClient, HttpClientRef,
63    HttpError, HttpFuture,
64};
65pub use image_picker::{
66    clear_platform_image_picker, default_image_picker, local_image_picker,
67    set_platform_image_picker, ImagePicker, ImagePickerError, ImagePickerRef, ImageSource,
68    ProvideImagePicker, IMAGE_EXTENSIONS,
69};
70pub use launch_args::{
71    clear_platform_launch_args, isDebuggable, is_debuggable, launch_args,
72    launch_args_from_command_line, local_launch_args, set_platform_launch_args, LaunchArgValue,
73    LaunchArgs, LaunchArgsRef, ProvideLaunchArgs,
74};
75pub use navigation::{
76    back_interception_enabled, exit_requested, push_back_request, request_exit,
77    set_back_interception, set_back_request_listener, take_back_requests, take_exit_request,
78};
79pub use network_status::{
80    clear_platform_network_monitor, network_monitor, network_status, set_platform_network_monitor,
81    NetworkMonitor, NetworkMonitorRef, NetworkStatus,
82};
83pub use notifier::{
84    clear_platform_notifier, default_notifier, local_notifier, push_notification_deeplink,
85    set_platform_notifier, take_notification_deeplink, Notifier, NotifierRef, NotifyRequest,
86    ProvideNotifier,
87};
88#[cfg(not(target_arch = "wasm32"))]
89pub use peer::{
90    content_length, fetch_range, fetch_to_writer, ByteSource, BytesSource, FetchResult, PeerError,
91    PeerServer, SourceResolver,
92};
93pub use purchases::{
94    clear_platform_purchases, note_store_news, purchases, set_platform_purchases,
95    set_store_listener, store_available, store_state, Product, PurchaseEvent, Purchases,
96    PurchasesRef, StorePhase, StoreState,
97};
98pub use share_sheet::{
99    clear_platform_share_sheet, default_share_sheet, local_share_sheet, set_platform_share_sheet,
100    ProvideShareSheet, ShareContent, ShareError, ShareSheet, ShareSheetRef,
101};
102pub use theme::{
103    clear_platform_system_theme, default_system_theme, isSystemInDarkTheme, local_system_theme,
104    set_platform_system_theme, ProvideSystemTheme, SystemTheme,
105};
106pub use uri_handler::{
107    clear_platform_uri_handler, default_uri_handler, local_uri_handler, set_platform_uri_handler,
108    ProvideUriHandler, UriHandler, UriHandlerError, UriHandlerRef,
109};
110pub use writable_folder::{
111    clear_platform_writable_folder_picker, open_writable_folder, pick_writable_folder,
112    set_platform_writable_folder_picker, set_writable_folder_store_factory,
113    take_resumed_writable_folder, FolderError, WritableFolderPicker, WritableFolderPickerRef,
114    WritableFolderStore, WritableFolderStoreRef,
115};
116
117/// Convenience alias used in unit tests.
118#[cfg(test)]
119pub(crate) type TestComposition = Composition<MemoryApplier>;
120
121/// Build a composition with a simple in-memory applier and run the provided closure once.
122#[cfg(test)]
123pub(crate) fn run_test_composition(build: impl FnMut()) -> TestComposition {
124    let mut composition = Composition::new(MemoryApplier::new());
125    composition
126        .render(location_key(file!(), line!(), column!()), build)
127        .expect("initial render succeeds");
128    composition
129}