One ScanStatus replaces a collection of independent pending, complete, failed and unsupported booleans. The screen cannot therefore be both scanning and successfully finished because one callback forgot to clear a flag.
The manual draft belongs to the component. Its confirmed label belongs to application state for the next local workflow step. The label rule rejects empty, excessively long or control-character input; it does not establish that a physical probe exists or that the user selected the correct one.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/app/state.rs","value":"src-app-state-rs"},{"index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"},{"index":3,"label":"src/i18n.rs","value":"src-i18n-rs"},{"index":4,"label":"src/lib.rs","value":"src-lib-rs"},{"index":5,"label":"preview/lib.rs","value":"preview-lib-rs"},{"index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
mod screen;
pub mod state;
pub use screen::ProbeScreen;
pub use state::ProbeState;
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ScanStatus {
Idle,
Pending,
Unsupported,
Failed,
Returned(Vec<BluetoothDevice>),
}
impl ScanStatus {
pub fn key(&self) -> &'static str {
match self {
Self::Idle => "probe.idle",
Self::Pending => "probe.pending",
Self::Unsupported => "probe.unsupported",
Self::Failed => "probe.failed",
Self::Returned(devices) if devices.is_empty() => "probe.empty",
Self::Returned(_) => "probe.returned",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProbeState {
pub locale: Locale,
pub scan: ScanStatus,
pub error: Option<String>,
pub confirmed_label: Option<String>,
}
impl Default for ProbeState {
fn default() -> Self {
Self {
locale: Locale::from("en-US"),
scan: ScanStatus::Idle,
error: None,
confirmed_label: None,
}
}
}
impl GlobalState for ProbeState {}
pub fn valid_label(label: &str) -> bool {
let label = label.trim();
!label.is_empty() && label.chars().count() <= 64 && !label.chars().any(char::is_control)
}
pub fn scan(state: &mut ProbeState, cx: &mut ReducerContext<ProbeState>) {
if state.scan == ScanStatus::Pending {
return;
}
state.scan = ScanStatus::Pending;
state.error = None;
let ok = cx.effects.bind(ScanReturned, reduce_with!(scan_returned));
let err = cx.effects.bind(ScanFailed, reduce_with!(scan_failed));
cx.effects
.bluetooth()
.scan_devices(BluetoothScanRequest {
service_uuids: vec!["0000181a-0000-1000-8000-00805f9b34fb".into()],
timeout_ms: Some(4_000),
include_paired: true,
allow_duplicates: false,
})
.on_ok(ok)
.on_err(err);
}
#[fission_reducer(ScanReturned)]
fn scan_returned(state: &mut ProbeState, cx: &mut ReducerContext<ProbeState>) {
state.scan = match cx.input.capability_ok(SCAN_BLUETOOTH_DEVICES) {
Some(result) => ScanStatus::Returned(result.devices),
None => ScanStatus::Failed,
};
}
#[fission_reducer(ScanFailed)]
fn scan_failed(state: &mut ProbeState, cx: &mut ReducerContext<ProbeState>) {
let error = cx.input.capability_error(SCAN_BLUETOOTH_DEVICES);
state.scan = if error
.as_ref()
.is_some_and(|error| error.code == "unsupported")
{
ScanStatus::Unsupported
} else {
ScanStatus::Failed
};
state.error = error
.map(|error| format!("{}: {}", error.code, error.message))
.or_else(|| {
cx.input
.capability_error_message(SCAN_BLUETOOTH_DEVICES)
.map(str::to_owned)
});
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn label_rule_accepts_text_not_a_fake_probe_read() {
assert!(valid_label(" CR-204 "));
assert!(valid_label("Sonda Álvarez"));
assert!(!valid_label(" "));
assert!(!valid_label("probe\nsecond-line"));
assert!(!valid_label(&"x".repeat(65)));
}
}
{"id":"fission-tabs-1","index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"}
use super::state::{scan, valid_label, ProbeState, ScanStatus};
use fission::prelude::*;
fission_component! {
pub ProbeScreen<ProbeState> {
state {
label: String = String::new(),
attempted: bool = false,
}
}
view(form, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let error = (form.attempted && !valid_label(&form.label))
.then(|| cx.tr("probe.invalid_label"));
} => SafeArea(
child: Scroll(
child: Container(Column(gap: tokens.spacing.m, children: [
Text(cx.tr("probe.heading")).size(tokens.typography.heading2_size),
Text(cx.tr("probe.explanation")),
Row(gap: tokens.spacing.s, children: [
Button(
child: Text(cx.tr("language.english")), key: "english",
on_press: reduce { state.locale = Locale::from("en-US"); },
),
Button(
child: Text(cx.tr("language.spanish")), key: "spanish",
on_press: reduce { state.locale = Locale::from("es-ES"); },
),
]),
Button(
child: Text(cx.tr("probe.scan")), key: "scan-probe",
disabled: state.scan == ScanStatus::Pending,
on_press: reduce { scan(state, cx); },
),
if state.scan == ScanStatus::Pending {
Spinner(motion: Some(SpinnerMotion::Default), label: Some(cx.tr("probe.pending")))
},
Text(cx.tr(state.scan.key())),
if let Some(error) = &state.error { Code(text: error.clone()) },
if let ScanStatus::Returned(devices) = &state.scan {
Text(cx.tr("probe.count").replace("{count}", &devices.len().to_string()))
},
Divider(),
FormControl(
label: Some(cx.tr("probe.label")),
helper: Some(cx.tr("probe.label_help")),
error: error, required: true,
child: TextInput(
value: form.label.clone(), bind(on_input): to(form.label),
semantics_identifier: Some("probe.label".into()),
),
),
Button(
child: Text(cx.tr("probe.confirm")), key: "confirm-label",
on_press: reduce {
form.attempted = true;
if valid_label(&form.label) {
state.confirmed_label = Some(form.label.trim().to_owned());
}
},
),
if let Some(label) = &state.confirmed_label {
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("probe.confirmed")),
Text(label.clone()),
])
},
Text(cx.tr("probe.session")).color(tokens.colors.text_secondary),
]))
.padding_all(tokens.spacing.l),
),
)
}
{"id":"fission-tabs-1","index":3,"label":"src/i18n.rs","value":"src-i18n-rs"}
use fission::i18n::{Locale, TranslationBundle};
use fission::prelude::*;
use std::collections::HashMap;
pub fn create_env() -> Env {
let mut env = Env::default();
env.locale = Locale::from("en-US");
for (locale, source) in [
("en-US", include_str!("../i18n/en-US.yaml")),
("es-ES", include_str!("../i18n/es-ES.yaml")),
] {
let messages: HashMap<String, String> =
serde_yaml::from_str(source).expect("valid probe translations");
env.i18n.add_bundle(TranslationBundle {
locale: Locale::from(locale),
messages,
});
}
env
}
pub fn sync_env(state: &crate::app::ProbeState, env: &mut Env) {
env.locale = state.locale.clone();
}
{"id":"fission-tabs-1","index":4,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod i18n;
use app::{ProbeScreen, ProbeState};
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<ProbeState, _>::new(ProbeScreen)
.with_env(i18n::create_env())
.with_bluetooth_host(UnsupportedBluetoothHost)
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
MobileApp::<ProbeState, _>::new(ProbeScreen)
.with_env(i18n::create_env())
.with_bluetooth_host(UnsupportedBluetoothHost)
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
let _ = MobileApp::<ProbeState, _>::new(ProbeScreen)
.with_env(i18n::create_env())
.with_bluetooth_host(UnsupportedBluetoothHost)
.with_sync_env(i18n::sync_env)
.run_with_android_app(app_handle);
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn run_web() -> Result<(), wasm_bindgen::JsValue> {
console_error_panic_hook::set_once();
WebApp::<ProbeState, _>::new(ProbeScreen)
.with_env(i18n::create_env())
.with_bluetooth_host(UnsupportedBluetoothHost)
.with_sync_env(i18n::sync_env)
.run()
.map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":5,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod i18n;
use fission::prelude::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
WebApp::<app::ProbeState, _>::new(app::ProbeScreen)
.with_env(i18n::create_env())
.with_bluetooth_host(UnsupportedBluetoothHost)
.with_sync_env(i18n::sync_env)
.mount("#fission-web-mount")
.run()
.map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
probe.heading: "Identify the inspection probe"
probe.explanation: "This iOS build has no Bluetooth provider. Try the actual unsupported scan path, or use the label printed on the probe."
probe.scan: "Try Bluetooth probe discovery"
probe.idle: "No scan has been requested."
probe.pending: "Waiting for the probe scan…"
probe.unsupported: "Bluetooth scanning is unsupported by this host. The manual label path is still available."
probe.failed: "The scan failed or returned no usable result. You can retry or enter the printed label."
probe.empty: "The installed host completed the scan without matching devices. This is not an unsupported result."
probe.returned: "The installed host returned devices. Discovery alone does not connect to or read a probe."
probe.count: "Returned device records: {count}"
probe.label: "Printed probe label"
probe.label_help: "Enter the label exactly as printed. This identifies a draft record; it does not measure temperature."
probe.invalid_label: "Enter a label of up to 64 characters without control characters."
probe.confirm: "Use this printed label"
probe.confirmed: "Label selected for the next local step"
probe.session: "The selection is kept in memory only. No sensor has been read and no inspection has been submitted."
language.english: "English"
language.spanish: "Español"
{"id":"fission-tabs-1","index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
probe.heading: "Identificar la sonda de inspección"
probe.explanation: "Esta compilación de iOS no tiene un proveedor Bluetooth. Prueba el resultado real no compatible o usa la etiqueta impresa de la sonda."
probe.scan: "Probar la detección de sondas Bluetooth"
probe.idle: "No se ha solicitado ningún escaneo."
probe.pending: "Esperando el escaneo de sondas…"
probe.unsupported: "Este host no admite el escaneo Bluetooth. La etiqueta manual sigue disponible."
probe.failed: "El escaneo ha fallado o no devolvió un resultado utilizable. Puedes reintentar o introducir la etiqueta."
probe.empty: "El proveedor instalado terminó sin dispositivos compatibles. Esto no equivale a una operación no admitida."
probe.returned: "El proveedor instalado devolvió dispositivos. Detectarlos no conecta con la sonda ni la lee."
probe.count: "Registros de dispositivos devueltos: {count}"
probe.label: "Etiqueta impresa de la sonda"
probe.label_help: "Introduce la etiqueta tal como está impresa. Identifica un borrador; no mide la temperatura."
probe.invalid_label: "Introduce una etiqueta de hasta 64 caracteres sin caracteres de control."
probe.confirm: "Usar esta etiqueta impresa"
probe.confirmed: "Etiqueta seleccionada para el siguiente paso local"
probe.session: "La selección solo está en memoria. No se ha leído ningún sensor ni enviado una inspección."
language.english: "Inglés"
language.spanish: "Español"
{"id":"fission-tabs-1"}