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