Piece | What it means | Example |
|---|---|---|
Typed API | The portable Rust request your app emits from a reducer. | ctx.effects.camera().capture_photo(...) |
Provider | The shell-side implementation that maps the request to the host. | A CameraHost that calls the platform camera API. |
Packaging configuration | Native metadata that lets the platform allow the feature. | Android CAMERA, iOS NSCameraUsageDescription, macOS bundle usage text, Windows webcam capability. |
Need | Use |
|---|---|
Show a native notification, scan NFC, open a camera, authenticate with a passkey, read clipboard, scan Bluetooth, capture microphone audio | Capability |
Parse a file, call your HTTP API, transform data, run a search over local app data | Job, command, service, or normal Rust helper |
Let the user choose files from the host and process them as streams | PICK_OPEN_FILES capability, then a job or service |
Show an in-app alert, drawer, modal, toast, popover, or validation message | Fission widgets |
fission add-capability camera --project-dir .
fission readiness package --project-dir . --target android --format apk
fission readiness package --project-dir . --target ios --format ipa
use fission::prelude::*;
#[derive(Debug, Default)]
struct ProfileState {
photo: Option<CameraCapture>,
camera_error: Option<String>,
capturing_photo: bool,
}
impl GlobalState for ProfileState {}
use fission::prelude::*;
#[fission_reducer(PhotoCaptured)]
fn on_photo_captured(state: &mut ProfileState, ctx: &mut ReducerContext<ProfileState>) {
state.capturing_photo = false;
match ctx.input.capability_ok(CAPTURE_PHOTO) {
Some(capture) => {
state.photo = Some(capture);
state.camera_error = None;
}
None => state.camera_error = Some("The host returned no photo".into()),
}
}
#[fission_reducer(PhotoCaptureFailed)]
fn on_photo_capture_failed(state: &mut ProfileState, ctx: &mut ReducerContext<ProfileState>) {
state.capturing_photo = false;
state.camera_error = Some(
ctx.input.capability_error(CAPTURE_PHOTO)
.map(|error| error.message)
.or_else(|| ctx.input.capability_error_message(CAPTURE_PHOTO).map(str::to_owned))
.unwrap_or_else(|| "The host could not capture a photo".into()),
);
}
#[fission_reducer(CaptureProfilePhoto)]
fn on_capture_profile_photo(state: &mut ProfileState, ctx: &mut ReducerContext<ProfileState>) {
if state.capturing_photo { return; }
state.capturing_photo = true;
state.photo = None;
state.camera_error = None;
let captured = ctx.effects.bind(PhotoCaptured, reduce_with!(on_photo_captured));
let failed = ctx.effects.bind(PhotoCaptureFailed, reduce_with!(on_photo_capture_failed));
ctx.effects
.camera()
.capture_photo(CameraCaptureRequest {
facing: CameraFacing::Front,
resolution: Some(CameraResolution { width: 1280, height: 720 }),
format: CameraImageFormat::Jpeg,
flash: CameraFlashMode::Off,
quality: Some(90),
..Default::default()
})
.on_ok(captured)
.on_err(failed);
}
fission_component! {
pub CapturePhotoButton<ProfileState> {}
view(_button, state, cx) {
let capture = cx.bind(CaptureProfilePhoto, reduce!(on_capture_profile_photo));
}
=> Column(children: [
Button(child: Text(cx.tr("profile.take_photo")), disabled: state.capturing_photo, on_press: capture),
if state.capturing_photo { Spinner(motion: SpinnerMotion::Default, label: cx.tr("profile.capturing_photo")) },
if state.photo.is_some() { Text(cx.tr("profile.photo_captured")) },
if let Some(error) = &state.camera_error { Alert(title: error.clone(), kind: AlertKind::Error) },
])
}
let app = DesktopApp::new(ProfileApp)
.with_camera_host(MemoryCameraHost::default())
.with_clipboard_host(MemoryClipboardHost::default())
.with_notification_host(MemoryNotificationHost);
#[test]
fn photo_failure_is_visible_to_the_ui() {
use fission::core::{ActionInput, ActionRegistry, Runtime};
let mut runtime = Runtime::default();
runtime.add_app_state(Box::new(ProfileState {
capturing_photo: true,
..Default::default()
})).unwrap();
let mut registry = ActionRegistry::<ProfileState>::new();
registry.register(reduce!(on_photo_capture_failed));
runtime.absorb_persistent_registry(registry);
runtime.dispatch_with_input(
PhotoCaptureFailed.into(),
WidgetId::from_u128(0),
&ActionInput::CapabilityErr {
capability: CAPTURE_PHOTO.name.to_owned(),
req_id: 1,
payload: None,
message: Some("The user denied camera access".into()),
},
).unwrap();
let state = runtime.get_app_state::<ProfileState>().unwrap();
assert!(!state.capturing_photo);
assert_eq!(state.camera_error.as_deref(), Some("The user denied camera access"));
}
Feature | CLI value | Start here | Reference |
|---|---|---|---|
File picker and uploads | no generated config | ||
Files and directories | filesystem | ||
Notifications | shell setup | ||
Deep links | shell setup | ||
NFC | nfc | ||
Biometrics | biometric | ||
Passkeys | passkeys | ||
Barcode scanner | barcode-scanner | ||
Camera and flashlight | camera | ||
Clipboard | no generated config | ||
Geolocation | geolocation | ||
Haptics | haptics | ||
Microphone | microphone | ||
Bluetooth | bluetooth | ||
Wi-Fi | wifi | ||
Volume control | volume-control |