app_ui/bubble_ipc.rs
1//! JS bridge for the webcam-bubble toggle command (M-BUBBLE.0 / AUT-273).
2//!
3//! One-function module mirroring [`crate::camera_ipc`]'s shape — wraps
4//! a `__screen*` helper declared inline in `index.html`, which in turn
5//! calls `window.__TAURI__.core.invoke("toggle_webcam_bubble")`.
6//!
7//! Async + ignores the return value — toggling the bubble cannot fail
8//! in any way the UI needs to react to. If the window can't be found
9//! the Rust-side command logs via `tracing::warn!` (see
10//! [`crate::commands::toggle_webcam_bubble`](../../app/src/commands.rs)
11//! in the screen-app crate) and the click is a no-op.
12
13use wasm_bindgen::JsValue;
14use wasm_bindgen::prelude::*;
15
16#[wasm_bindgen]
17extern "C" {
18 /// `__screenToggleBubble()` in `index.html` — returns `Promise<void>`.
19 #[wasm_bindgen(js_name = __screenToggleBubble, catch)]
20 pub async fn toggle_webcam_bubble_js() -> Result<JsValue, JsValue>;
21
22 /// `__screenSetBubbleVisibility(visible)` in `index.html` —
23 /// returns `Promise<void>`. ISS-05 fix; explicit setter so the
24 /// recorder's `camera_enabled` signal can drive the bubble's
25 /// visibility without the toggle-drift the always-flip path had.
26 #[wasm_bindgen(js_name = __screenSetBubbleVisibility, catch)]
27 pub async fn set_webcam_bubble_visibility_js(visible: bool) -> Result<JsValue, JsValue>;
28
29 /// `__screenSetBubbleClickthrough(enabled)` in `index.html` —
30 /// returns `Promise<void>`. M-BUBBLE.1 v0 / AUT-274.
31 #[wasm_bindgen(js_name = __screenSetBubbleClickthrough, catch)]
32 pub async fn set_bubble_clickthrough_js(enabled: bool) -> Result<JsValue, JsValue>;
33}
34
35/// Fire-and-forget toggle. Spawns the IPC call as a wasm-bindgen
36/// future so the click handler returns immediately; failures are
37/// logged to the JS console via `web_sys::console::warn_1` rather
38/// than surfaced to the user (the Rust side warns via `tracing`).
39pub fn toggle_webcam_bubble() {
40 wasm_bindgen_futures::spawn_local(async {
41 if let Err(err) = toggle_webcam_bubble_js().await {
42 web_sys::console::warn_2(
43 &JsValue::from_str("[bubble_ipc] toggle_webcam_bubble failed:"),
44 &err,
45 );
46 }
47 });
48}
49
50/// Fire-and-forget setter. Use when the UI owns the source of truth
51/// for the bubble's desired state (e.g. the recorder's
52/// `camera_enabled` signal). Idempotent on the Rust side, so safe to
53/// call on every toggle click + on page mount for initial alignment.
54/// ISS-05.
55pub fn set_webcam_bubble_visibility(visible: bool) {
56 wasm_bindgen_futures::spawn_local(async move {
57 if let Err(err) = set_webcam_bubble_visibility_js(visible).await {
58 web_sys::console::warn_2(
59 &JsValue::from_str("[bubble_ipc] set_webcam_bubble_visibility failed:"),
60 &err,
61 );
62 }
63 });
64}
65
66/// Fire-and-forget click-through toggle. `enabled = true` makes the
67/// bubble pass mouse events through; `false` restores normal
68/// interaction (drag works again). Failures log to the JS console;
69/// the Rust side also logs via `tracing::warn!`. M-BUBBLE.1 v0 /
70/// AUT-274.
71pub fn set_bubble_clickthrough(enabled: bool) {
72 wasm_bindgen_futures::spawn_local(async move {
73 if let Err(err) = set_bubble_clickthrough_js(enabled).await {
74 web_sys::console::warn_2(
75 &JsValue::from_str("[bubble_ipc] set_bubble_clickthrough failed:"),
76 &err,
77 );
78 }
79 });
80}