Volume control

Volume control crosses into host policy. Some platforms let apps adjust system streams; others only let an app control its own media element or expose hardware buttons outside app control.
This example reads and adjusts an active volume stream where the host permits it. Unsupported is a normal result; do not confuse system volume with the volume of media your app owns.
Do not assume system volume is writable. Treat unsupported as a normal platform outcome and keep in-app media volume separate when that is all the host allows.

1. Start with the state the screen needs

Add the smallest state fields the screen needs to render honestly. For this flow, useful state is:
#[derive(Debug, Default)]
struct VolumeControlState {
    volume: Option<VolumeLevel>,
    adjusting: bool,
    volume_error: Option<String>,
}

impl GlobalState for VolumeControlState {}
Keep the reported level and any error in app state. Update them from the typed completion actions.

2. Configure the target and host

Run this once from the project root:
fission add-capability volume-control --project-dir .
That command records the capability in fission.toml and updates generated platform files where Fission can do so safely. It does not replace product-specific review of native manifests, usage text, entitlements, service identifiers, domains, or store policy.
The CLI adds Android MODIFY_AUDIO_SETTINGS. iOS does not expose broad app-controlled system volume. Desktop providers can map to mixer APIs when appropriate, but packaged apps may have store policy constraints.
This is the difference between the Fission API, a provider, and packaging configuration:
•
The Fission API is the typed volume request your reducer makes; the read or adjustment call is shown below.
•
The provider is the shell-side Rust implementation that turns that typed request into the correct OS, browser, or hardware call.
•
Packaging configuration is the manifest, plist, entitlement, service-worker, protocol, domain, or store metadata that lets the platform permit that call in a real installed app.
If the API exists but the provider is missing, the request returns a typed unsupported error. If the provider exists but packaging is missing, the operating system or browser may deny the request before the provider can complete it.

3. Define reducers for success and failure

The volume request completes after its starting reducer returns. Handle the resulting level or error in completion reducers.
#[fission_reducer(VolumeChanged)]
fn on_volume_changed(state: &mut VolumeControlState, ctx: &mut ReducerContext<VolumeControlState>) {
    state.adjusting = false;
    state.volume = ctx.input.capability_ok(ADJUST_VOLUME_LEVEL);
    state.volume_error = None;
}

#[fission_reducer(VolumeChangeFailed)]
fn on_volume_change_failed(state: &mut VolumeControlState, ctx: &mut ReducerContext<VolumeControlState>) {
    state.adjusting = false;
    state.volume_error = Some(
        ctx.input.capability_error(ADJUST_VOLUME_LEVEL)
            .map(|error| error.message)
            .or_else(|| ctx.input.capability_error_message(ADJUST_VOLUME_LEVEL).map(str::to_owned))
            .unwrap_or_else(|| "Volume adjustment unavailable".into()),
    );
}
Unsupported system-volume control is expected on some targets. Keep the app usable when the host cannot adjust it.

4. Request the capability from a reducer

Call the capability from the reducer that handles the user's intent. The reducer queues a host effect and returns. The runtime later dispatches either the success reducer or the failure reducer.
#[fission_reducer(RaiseVolume)]
fn on_raise_volume(state: &mut VolumeControlState, ctx: &mut ReducerContext<VolumeControlState>) {
    if state.adjusting { return; }
    state.adjusting = true;
    state.volume_error = None;
    let changed = ctx.effects.bind(VolumeChanged, reduce_with!(on_volume_changed));
    let failed = ctx.effects.bind(VolumeChangeFailed, reduce_with!(on_volume_change_failed));
    ctx.effects
        .volume()
        .adjust_level(VolumeAdjustRequest {
            stream: VolumeStream::Media,
            direction: VolumeAdjustDirection::Up,
            step: 5,
        })
        .on_ok(changed)
        .on_err(failed);
}
The host may clamp the request or reject it. Display its returned level rather than add five to local state and assume that reflects system volume. Bind the callbacks before queuing the request; completion data comes from ctx.input, not from a default VolumeLevel authored in the callback action.

5. Trigger the reducer from the UI

Bind each control to a reducer that requests the current level or an adjustment:


fission_component! {
    pub RaiseVolumeButton<VolumeControlState>
    view(_button, state, cx) {
        let run = cx.bind(RaiseVolume, reduce!(on_raise_volume));
    } =>
    Column(children: [
        Button(
            child: Text(cx.tr("volume.raise")),
            disabled: state.adjusting,
            on_press: run,
        ),
        if state.adjusting { Spinner(motion: SpinnerMotion::Default, label: cx.tr("volume.adjusting")) },
        if let Some(volume) = &state.volume {
            Text(volume.level.to_string())
        },
        if let Some(error) = &state.volume_error {
            Alert(kind: AlertKind::Warning, title: error.clone())
        },
    ])
}
The reducer requests the change, and a completion reducer updates the displayed level or error.

6. Provide and test the host behavior

Register a VolumeHost with .with_volume_host(...). Use MemoryVolumeHost in tests. Providers should clamp or reject invalid levels and return unsupported where the target cannot expose system volume.
Test get, set, adjustments up and down, mute state, clamping, reported volume levels, unsupported hosts, and provider errors. UI tests should verify the displayed value comes from the returned VolumeLevel, not optimistic local state.

Platform expectations

Android supports app-level audio setting changes. Windows, macOS, and Linux can support mixer integration through host providers. iOS is limited. Web generally controls element volume, not system volume.
For a cross-platform summary, read the capability matrix. For exact request fields, provider traits, and generated configuration, see the Volume control reference.

Finished capability flow

A complete Volume control integration has all of these pieces in place:
Piece
What should exist
Configuration
fission.toml declares the capability and generated platform files contain the permission text, manifest entry, entitlement, domain, or protocol metadata the target needs.
State
App state records the in-flight flag, the successful value, and the user-facing error separately.
Reducers
One reducer starts the host request, one handles success, and one handles denial, unsupported hosts, cancellation, or provider errors.
Provider
The shell registers a real provider for production and a memory provider for tests.
Tests
At least one test covers success and one covers permission denial or unsupported host behavior.

Diagnose capability failures

Capability failures should be safe to retry and easy to explain. Start by checking fission.toml, then run fission doctor, then inspect the generated target files. If the provider is missing, the request should return an unsupported error. If the provider exists but the platform configuration is wrong, the OS or browser will usually deny the request before the provider can complete it. Keep those cases distinct in the UI so users know whether they can retry, change settings, connect hardware, or choose another path.