The reference belongs to shared hand-off state. The private note belongs to this screen's retained local state; other screens and the clipboard service do not need access to it. That separation prevents accidental inclusion in the copy request without requiring the service to filter a whole work-order object.
{"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"}
pub mod screen;
pub mod state;
pub use screen::ClipboardScreen;
pub use state::ClipboardState;
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum ClipboardStatus {
#[default]
Idle,
Writing,
Reading,
WriteAccepted,
ReadText,
Empty,
Failed,
InvalidResult,
}
impl ClipboardStatus {
pub fn pending(&self) -> bool {
matches!(self, Self::Writing | Self::Reading)
}
pub fn message_key(&self) -> &'static str {
match self {
Self::Idle => "clipboard.idle",
Self::Writing => "clipboard.writing",
Self::Reading => "clipboard.reading",
Self::WriteAccepted => "clipboard.write_accepted",
Self::ReadText => "clipboard.read_text",
Self::Empty => "clipboard.empty",
Self::Failed => "clipboard.failed",
Self::InvalidResult => "clipboard.invalid",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClipboardState {
pub public_reference: String,
pub last_pasted: Option<String>,
pub status: ClipboardStatus,
pub locale: Locale,
}
impl Default for ClipboardState {
fn default() -> Self {
Self {
public_reference: String::new(),
last_pasted: None,
status: ClipboardStatus::Idle,
locale: Locale::from("en-US"),
}
}
}
impl GlobalState for ClipboardState {}
pub fn copy_reference(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
if state.status.pending() || state.public_reference.trim().is_empty() {
return;
}
state.status = ClipboardStatus::Writing;
let ok = cx
.effects
.bind(CopyAccepted, reduce_with!(on_copy_accepted));
let err = cx.effects.bind(CopyFailed, reduce_with!(on_copy_failed));
cx.effects
.clipboard()
.write_text(ClipboardWriteTextRequest {
text: state.public_reference.clone(),
})
.on_ok(ok)
.on_err(err);
}
pub fn paste_reference(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
if state.status.pending() {
return;
}
state.status = ClipboardStatus::Reading;
let ok = cx
.effects
.bind(PasteReceived, reduce_with!(on_paste_received));
let err = cx.effects.bind(PasteFailed, reduce_with!(on_paste_failed));
cx.effects.clipboard().read_text().on_ok(ok).on_err(err);
}
#[fission_reducer(CopyAccepted)]
fn on_copy_accepted(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
state.status = if cx.input.capability_ok(WRITE_CLIPBOARD_TEXT).is_some() {
ClipboardStatus::WriteAccepted
} else {
ClipboardStatus::InvalidResult
};
}
#[fission_reducer(CopyFailed)]
fn on_copy_failed(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
state.status = if cx.input.capability_error(WRITE_CLIPBOARD_TEXT).is_some() {
ClipboardStatus::Failed
} else {
ClipboardStatus::InvalidResult
};
}
#[fission_reducer(PasteReceived)]
fn on_paste_received(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
let Some(result) = cx.input.capability_ok(READ_CLIPBOARD_TEXT) else {
state.status = ClipboardStatus::InvalidResult;
return;
};
state.last_pasted = result.text.filter(|text| !text.is_empty());
state.status = if state.last_pasted.is_some() {
ClipboardStatus::ReadText
} else {
ClipboardStatus::Empty
};
}
#[fission_reducer(PasteFailed)]
fn on_paste_failed(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
state.status = if cx.input.capability_error(READ_CLIPBOARD_TEXT).is_some() {
ClipboardStatus::Failed
} else {
ClipboardStatus::InvalidResult
};
}
{"id":"fission-tabs-1","index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"}
use super::state::{copy_reference, paste_reference, ClipboardState};
use fission::prelude::*;
fission_component! {
pub ClipboardScreen<ClipboardState> {
state {
private_note: String = String::new(),
}
}
view(screen, state, cx) {
let tokens = &cx.view.env().theme.tokens;
let pending = state.status.pending();
} => SafeArea(
child: Scroll(
child: Container(
Column(gap: tokens.spacing.m, children: [
Text(cx.tr("clipboard.title"))
.size(tokens.typography.heading2_size),
Text(cx.tr("clipboard.explanation"))
.color(tokens.colors.text_secondary),
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"); },
),
]),
FormControl(
label: Some(cx.tr("clipboard.reference")),
required: true,
child: TextInput(
value: state.public_reference.clone(),
bind(on_input): to(state.public_reference),
semantics_identifier: Some("clipboard.reference".into()),
),
),
TextInput(
value: screen.private_note.clone(),
bind(on_input): to(screen.private_note),
label: Some(TextContent::Key("clipboard.private_note".into())),
helper_text: Some(TextContent::Key("clipboard.private_help".into())),
multiline: true,
semantics_identifier: Some("clipboard.private-note".into()),
),
Button(
child: Text(cx.tr("clipboard.copy")),
key: "copy-reference",
disabled: pending || state.public_reference.trim().is_empty(),
on_press: reduce { copy_reference(state, cx); },
),
Button(
child: Text(cx.tr("clipboard.paste")),
key: "paste-reference",
disabled: pending,
on_press: reduce { paste_reference(state, cx); },
),
if pending {
Spinner(
motion: Some(SpinnerMotion::Default),
label: Some(cx.tr(state.status.message_key())),
)
},
Text(cx.tr(state.status.message_key())),
if let Some(text) = &state.last_pasted {
Column(gap: tokens.spacing.s, children: [
Text(cx.tr("clipboard.last_pasted")),
TextInput(
value: text.clone(),
read_only: true,
multiline: true,
label: Some(TextContent::Key("clipboard.pasted_text".into())),
),
])
},
]),
)
.padding_all(tokens.spacing.l)
.bg(tokens.colors.surface),
),
)
}
{"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 clipboard translations");
env.i18n.add_bundle(TranslationBundle {
locale: Locale::from(locale),
messages,
});
}
env
}
pub fn sync_env(state: &crate::app::ClipboardState, 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::{ClipboardScreen, ClipboardState};
use fission::prelude::*;
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
DesktopApp::<ClipboardState, _>::new(ClipboardScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
MobileApp::<ClipboardState, _>::new(ClipboardScreen)
.with_env(i18n::create_env())
.with_sync_env(i18n::sync_env)
.run()
}
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
let _ = MobileApp::<ClipboardState, _>::new(ClipboardScreen)
.with_env(i18n::create_env())
.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::<ClipboardState, _>::new(ClipboardScreen)
.with_env(i18n::create_env())
.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::ClipboardState, _>::new(app::ClipboardScreen)
.with_env(i18n::create_env())
.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"}
clipboard.title: "Share a work reference"
clipboard.explanation: "Copy only the reference you intend to share. Clipboard contents can be visible to other apps."
clipboard.reference: "Reference to share"
clipboard.private_note: "Private note"
clipboard.private_help: "This note stays in this screen. The copy action never reads it."
clipboard.copy: "Copy reference"
clipboard.paste: "Read clipboard text"
clipboard.idle: "Nothing has been copied or read by this screen."
clipboard.writing: "Requesting a copy of the reference…"
clipboard.reading: "Reading clipboard text at your request…"
clipboard.write_accepted: "The host completed the copy request."
clipboard.read_text: "The host returned the text shown below."
clipboard.empty: "The host returned no text."
clipboard.failed: "Clipboard access failed or is unavailable. Your reference and note are unchanged."
clipboard.invalid: "The host returned an unexpected result. Your reference and note are unchanged."
clipboard.last_pasted: "Last successful read"
clipboard.pasted_text: "Clipboard text"
language.english: "English"
language.spanish: "Español"
{"id":"fission-tabs-1","index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
clipboard.title: "Comparte una referencia de trabajo"
clipboard.explanation: "Copia solo la referencia que quieras compartir. Otras apps pueden ver el contenido del portapapeles."
clipboard.reference: "Referencia para compartir"
clipboard.private_note: "Nota privada"
clipboard.private_help: "Esta nota permanece en la pantalla. La acción de copiar nunca la lee."
clipboard.copy: "Copiar referencia"
clipboard.paste: "Leer texto del portapapeles"
clipboard.idle: "Esta pantalla no ha copiado ni leído nada."
clipboard.writing: "Solicitando la copia de la referencia…"
clipboard.reading: "Leyendo el portapapeles a petición tuya…"
clipboard.write_accepted: "El host ha completado la solicitud de copia."
clipboard.read_text: "El host ha devuelto el texto que se muestra debajo."
clipboard.empty: "El host no ha devuelto texto."
clipboard.failed: "El acceso al portapapeles ha fallado o no está disponible. La referencia y la nota no cambian."
clipboard.invalid: "El host ha devuelto un resultado inesperado. La referencia y la nota no cambian."
clipboard.last_pasted: "Última lectura correcta"
clipboard.pasted_text: "Texto del portapapeles"
language.english: "Inglés"
language.spanish: "Español"
{"id":"fission-tabs-1"}