1use super::*;
2
3pub(crate) fn run_dynamic_http_wasm(mgr: &WasmDynamicManager, status_sig: Signal<String>) {
10 #[cfg(not(target_arch = "wasm32"))]
11 {
12 let bytes: Vec<u8> = build_partial_widget_wasm(DYNAMIC_HTTP_MODULE_TITLE, 3, 0x059669);
13 let bytes_srv: Vec<u8> = bytes.clone();
14 match TcpListener::bind(DYNAMIC_HTTP_BIND_ADDR) {
15 Ok(listener) => {
16 let port: u16 = listener
17 .local_addr()
18 .map(|addr: SocketAddr| addr.port())
19 .unwrap_or(0);
20 drop(spawn(move || {
21 if let Ok((mut stream, _)) = listener.accept() {
22 let mut req_buf: [u8; 512] = [0; 512];
23 let _: Result<usize, Error> = stream.read(&mut req_buf);
24 let hdr: String = format!(
25 "HTTP/1.1 200 OK\r\nContent-Type: application/wasm\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
26 bytes_srv.len()
27 );
28 let _: Result<(), Error> = stream.write_all(hdr.as_bytes());
29 let _: Result<(), Error> = stream.write_all(&bytes_srv);
30 let _: Result<(), Error> = stream.flush();
31 }
32 }));
33 let url: String = format!("http://127.0.0.1:{port}/live-module-v3.wasm");
34 let req: WasmDownloadRequest =
35 WasmDownloadRequest::partial(url.clone(), SLOT_WASM_WIDGET.to_string(), 3)
36 .with_checksum(compute_wasm_checksum(&bytes))
37 .with_signature(compute_wasm_signature(
38 &bytes,
39 3,
40 WASM_SHOWCASE_SIGNING_KEY,
41 ))
42 .with_allow_downgrade(true);
43 match mgr.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
44 Ok(v) => {
45 let _: bool = status_sig.set(format!(
46 "Downloaded {} bytes over real HTTP ({url}) -> executed & mounted .wasm v{v} natively!",
47 bytes.len()
48 ));
49 }
50 Err(e) => {
51 let _: bool = status_sig.set(format!("HTTP .wasm download failed: {e}"));
52 }
53 }
54 }
55 Err(err) => {
56 let _: bool = status_sig.set(format!("Local HTTP server bind error: {err}"));
57 }
58 }
59 }
60 #[cfg(target_arch = "wasm32")]
61 {
62 let bytes: Vec<u8> = build_partial_widget_wasm(TITLE_WASM_PARTIAL_V1, 1, 0x2563EB);
63 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
64 URL_WASM_PARTIAL_V1.to_string(),
65 SLOT_WASM_WIDGET.to_string(),
66 1,
67 )
68 .with_checksum(compute_wasm_checksum(&bytes))
69 .with_signature(compute_wasm_signature(&bytes, 1, WASM_SHOWCASE_SIGNING_KEY))
70 .with_allow_downgrade(true);
71 match mgr.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
72 Ok(v) => {
73 let _: bool = status_sig.set(format!(
74 "Fetched & executed .wasm v{v} natively in browser sandbox"
75 ));
76 }
77 Err(e) => {
78 let _: bool = status_sig.set(format!("WASM fetch failed: {e}"));
79 }
80 }
81 }
82}
83
84pub(crate) fn mount_dynamic_native_banner(
96 next_v: u64,
97 hub_click: DynamicUpdateHub,
98 tokens: ThemeTokens,
99) -> NodeId {
100 let banner_title: String = format!("Native Hot-Swapped Banner v{next_v} (Zero Restart)");
101 let on_claim = move |_: &UiEvent| {
102 hub_click.dispatch_action(DynamicActionEvent::new(
103 SLOT_PROMO_BANNER.to_string(),
104 DYNAMIC_ACTION_CLAIM_OFFER.to_string(),
105 format!("native-v{next_v}"),
106 ));
107 };
108 view! {
109 row {
110 style: {
111 width: Length::Percent(100.0)
112 flex_wrap: FlexWrap::Wrap
113 padding: Edges::all(SPACE_MD)
114 gap: SPACE_MD
115 align: AlignItems::Center
116 background: Color::hex(0x064E3B)
117 radius: 8.0
118 overflow: Overflow::Hidden
119 }
120 text {
121 style: {
122 flex_grow: 1.0
123 flex_shrink: 1.0
124 min_width: Length::Px(0.0)
125 font_size: 14.0
126 font_weight: FontWeight::Bold
127 color: Color::hex(0xECFDF5)
128 }
129 { banner_title }
130 }
131 EuvButton {
132 label: BTN_CLAIM_OFFER.to_string()
133 tokens: tokens
134 on_click: on_claim
135 }
136 }
137 }
138}
139
140pub(crate) fn mount_dynamic_partial_wasm_card(
151 state: &ShowcaseState,
152 tokens: ThemeTokens,
153) -> NodeId {
154 let p: ThemePalette = tokens.get_palette();
155 let g: ThemeGeometry = tokens.get_geometry();
156 let wasm_mgr: WasmDynamicManager = state.get_wasm_manager().clone();
157 let wasm_reg: RegistryWasmFetcher = state.get_wasm_registry().clone();
158 let wasm_offline_sig: Signal<bool> = state.get_wasm_offline();
159 let wasm_status_sig: Signal<String> = state.get_wasm_fault_status();
160 let partial_scope: WasmDynamicScope = WasmDynamicScope::Partial {
161 slot_id: SLOT_WASM_WIDGET.to_string(),
162 };
163 let partial_state_sig: Signal<WasmLoadState> = wasm_mgr.state_signal(&partial_scope);
164 let global_state_sig: Signal<WasmLoadState> = wasm_mgr.state_signal(&WasmDynamicScope::Global);
165 let wasm_tel_sig: Signal<WasmDynamicTelemetry> = wasm_mgr.telemetry();
166 let m_http: WasmDynamicManager = wasm_mgr.clone();
167 let m_p1: WasmDynamicManager = wasm_mgr.clone();
168 let m_p2: WasmDynamicManager = wasm_mgr.clone();
169 let m_prb: WasmDynamicManager = wasm_mgr.clone();
170 let m_pun: WasmDynamicManager = wasm_mgr;
171 let on_http = move |_: &UiEvent| {
172 run_dynamic_http_wasm(&m_http, wasm_status_sig);
173 };
174 let on_p1 = move |_: &UiEvent| {
175 let bytes: Vec<u8> = build_partial_widget_wasm(TITLE_WASM_PARTIAL_V1, 1, 0x2563EB);
176 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
177 URL_WASM_PARTIAL_V1.to_string(),
178 SLOT_WASM_WIDGET.to_string(),
179 1,
180 )
181 .with_checksum(compute_wasm_checksum(&bytes))
182 .with_signature(compute_wasm_signature(&bytes, 1, WASM_SHOWCASE_SIGNING_KEY))
183 .with_allow_downgrade(true);
184 match m_p1.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
185 Ok(v) => {
186 let _: bool = wasm_status_sig.set(format!(
187 "Mounted Partial .wasm v{v} natively (verified checksum + signature)"
188 ));
189 }
190 Err(e) => {
191 let _: bool = wasm_status_sig.set(format!("Partial v1 failed: {e}"));
192 }
193 }
194 };
195 let on_p2 = move |_: &UiEvent| {
196 let bytes: Vec<u8> = build_partial_widget_wasm(DYNAMIC_PARTIAL_V2_TITLE, 2, 0x7C3AED);
197 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
198 URL_WASM_PARTIAL_V2.to_string(),
199 SLOT_WASM_WIDGET.to_string(),
200 2,
201 )
202 .with_checksum(compute_wasm_checksum(&bytes))
203 .with_signature(compute_wasm_signature(&bytes, 2, WASM_SHOWCASE_SIGNING_KEY))
204 .with_allow_downgrade(true);
205 match m_p2.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
206 Ok(v) => {
207 let _: bool = wasm_status_sig.set(format!(
208 "Hot-swapped Partial .wasm v{v} natively (sibling UI untouched)"
209 ));
210 }
211 Err(e) => {
212 let _: bool = wasm_status_sig.set(format!("Partial v2 failed: {e}"));
213 }
214 }
215 };
216 let on_offline = move |_: &UiEvent| {
217 let next: bool = !wasm_offline_sig.get_untracked();
218 let _: bool = wasm_offline_sig.set(next);
219 wasm_reg.set_offline(next);
220 let msg: &str = if next {
221 DYNAMIC_OFFLINE_ON_MSG
222 } else {
223 DYNAMIC_OFFLINE_OFF_MSG
224 };
225 let _: bool = wasm_status_sig.set(msg.to_string());
226 };
227 let on_rollback_partial = move |_: &UiEvent| match m_prb
228 .rollback_partial(SLOT_WASM_WIDGET, DYNAMIC_ROLLBACK_REASON)
229 {
230 Ok(v) => {
231 let _: bool = wasm_status_sig.set(format!("Rolled back partial WASM slot to v{v}"));
232 }
233 Err(e) => {
234 let _: bool = wasm_status_sig.set(format!("Rollback: {e}"));
235 }
236 };
237 let on_unmount = move |_: &UiEvent| {
238 m_pun.unmount_partial(SLOT_WASM_WIDGET);
239 let _: bool = wasm_status_sig.set(DYNAMIC_UNMOUNT_MSG.to_string());
240 };
241 let wasm_tel_text = move || -> String {
242 let st: WasmLoadState = partial_state_sig.get();
243 let gst: WasmLoadState = global_state_sig.get();
244 let tel: WasmDynamicTelemetry = wasm_tel_sig.get();
245 format!(
246 "Partial={st:?} | Global={gst:?} | OK={}/{} Cache={} Retries={} Rollbacks={} Traps={} FuelStops={} Rejects={} Events={}",
247 tel.get_downloads_succeeded(),
248 tel.get_downloads_started(),
249 tel.get_cache_hits(),
250 tel.get_retries_performed(),
251 tel.get_rollbacks_executed(),
252 tel.get_sandbox_traps_caught(),
253 tel.get_fuel_exhaustions_caught(),
254 tel.get_integrity_rejections(),
255 tel.get_events_handled()
256 )
257 };
258 view! {
259 EuvCard {
260 title: DYNAMIC_PARTIAL_CARD_TITLE.to_string()
261 tokens: tokens
262 subtitle: DYNAMIC_PARTIAL_CARD_SUB
263 column {
264 style: {
265 width: Length::Percent(100.0)
266 gap: SPACE_MD
267 }
268 EuvActionRow {
269 EuvButton {
270 label: DYNAMIC_BTN_HTTP_WASM.to_string()
271 tokens: tokens
272 on_click: on_http
273 }
274 EuvButton {
275 label: DYNAMIC_BTN_PARTIAL_V1.to_string()
276 tokens: tokens
277 outline()
278 on_click: on_p1
279 }
280 EuvButton {
281 label: DYNAMIC_BTN_PARTIAL_V2.to_string()
282 tokens: tokens
283 outline()
284 on_click: on_p2
285 }
286 EuvButton {
287 label: DYNAMIC_BTN_TOGGLE_OFFLINE.to_string()
288 tokens: tokens
289 outline()
290 on_click: on_offline
291 }
292 EuvButton {
293 label: DYNAMIC_BTN_ROLLBACK_PARTIAL.to_string()
294 tokens: tokens
295 outline()
296 on_click: on_rollback_partial
297 }
298 EuvButton {
299 label: DYNAMIC_BTN_UNMOUNT_SLOT.to_string()
300 tokens: tokens
301 ghost()
302 on_click: on_unmount
303 }
304 }
305 slot {
306 id: SLOT_WASM_WIDGET
307 row {
308 style: {
309 width: Length::Percent(100.0)
310 padding: Edges::all(SPACE_MD)
311 background: p.get_muted()
312 border: (g.get_border_width(), p.get_border())
313 radius: g.get_radius_md()
314 overflow: Overflow::Hidden
315 }
316 text {
317 style: {
318 width: Length::Percent(100.0)
319 font_size: 13.0
320 color: p.get_muted_foreground()
321 }
322 { DYNAMIC_SLOT_WASM_FALLBACK }
323 }
324 }
325 }
326 text {
327 style: {
328 width: Length::Percent(100.0)
329 font_size: 12.0
330 font_family: FontFamily::Monospace
331 color: p.get_muted_foreground()
332 }
333 { wasm_tel_text }
334 }
335 }
336 }
337 }
338}
339
340pub(crate) fn mount_dynamic_global_wasm_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
351 let p: ThemePalette = tokens.get_palette();
352 let wasm_mgr: WasmDynamicManager = state.get_wasm_manager().clone();
353 let wasm_status_sig: Signal<String> = state.get_wasm_fault_status();
354 let m_g1: WasmDynamicManager = wasm_mgr.clone();
355 let m_g2: WasmDynamicManager = wasm_mgr.clone();
356 let m_gbad: WasmDynamicManager = wasm_mgr.clone();
357 let m_grb: WasmDynamicManager = wasm_mgr;
358 let on_g1 = move |_: &UiEvent| {
359 let bytes: Vec<u8> = build_global_app_wasm(DYNAMIC_GLOBAL_V1_TITLE, 1);
360 let req: WasmDownloadRequest =
361 WasmDownloadRequest::global(URL_WASM_GLOBAL_V1.to_string(), 1)
362 .with_checksum(compute_wasm_checksum(&bytes))
363 .with_signature(compute_wasm_signature(&bytes, 1, WASM_SHOWCASE_SIGNING_KEY))
364 .with_allow_downgrade(true);
365 match m_g1.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
366 Ok(v) => {
367 let _: bool = wasm_status_sig
368 .set(format!("Global .wasm v{v} took over root shell natively!"));
369 }
370 Err(e) => {
371 let _: bool = wasm_status_sig.set(format!("Global v1 failed: {e}"));
372 }
373 }
374 };
375 let on_g2 = move |_: &UiEvent| {
376 let bytes: Vec<u8> = build_global_app_wasm(DYNAMIC_GLOBAL_V2_TITLE, 2);
377 let req: WasmDownloadRequest =
378 WasmDownloadRequest::global(URL_WASM_GLOBAL_V2.to_string(), 2)
379 .with_checksum(compute_wasm_checksum(&bytes))
380 .with_signature(compute_wasm_signature(&bytes, 2, WASM_SHOWCASE_SIGNING_KEY))
381 .with_allow_downgrade(true);
382 match m_g2.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
383 Ok(v) => {
384 let _: bool =
385 wasm_status_sig.set(format!("Upgraded Global .wasm to v{v} atomically"));
386 }
387 Err(e) => {
388 let _: bool = wasm_status_sig.set(format!("Global v2 failed: {e}"));
389 }
390 }
391 };
392 let on_gbad = move |_: &UiEvent| {
393 let req: WasmDownloadRequest = WasmDownloadRequest::global(URL_WASM_TRAP.to_string(), 99);
394 match m_gbad.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
395 Ok(v) => {
396 let _: bool = wasm_status_sig.set(format!("Unexpected global mount v{v}"));
397 }
398 Err(e) => {
399 let _: bool =
400 wasm_status_sig.set(format!("Global fault isolated & LKG preserved: {e}"));
401 }
402 }
403 };
404 let on_restore = move |_: &UiEvent| {
405 m_grb.restore_native_global();
406 let _: bool = wasm_status_sig.set(STATUS_RESTORED_NATIVE_SHELL.to_string());
407 };
408 let status_text = move || -> String { wasm_status_sig.get() };
409 view! {
410 EuvCard {
411 title: DYNAMIC_GLOBAL_CARD_TITLE.to_string()
412 tokens: tokens
413 subtitle: DYNAMIC_GLOBAL_CARD_SUB
414 column {
415 style: {
416 width: Length::Percent(100.0)
417 gap: SPACE_MD
418 }
419 EuvActionRow {
420 EuvButton {
421 label: DYNAMIC_BTN_GLOBAL_V1.to_string()
422 tokens: tokens
423 on_click: on_g1
424 }
425 EuvButton {
426 label: DYNAMIC_BTN_GLOBAL_V2.to_string()
427 tokens: tokens
428 outline()
429 on_click: on_g2
430 }
431 EuvButton {
432 label: DYNAMIC_BTN_GLOBAL_FAULT.to_string()
433 tokens: tokens
434 destructive()
435 on_click: on_gbad
436 }
437 EuvButton {
438 label: DYNAMIC_BTN_RESTORE_NATIVE.to_string()
439 tokens: tokens
440 outline()
441 on_click: on_restore
442 }
443 }
444 text {
445 style: {
446 width: Length::Percent(100.0)
447 font_size: 12.5
448 font_weight: FontWeight::Medium
449 color: p.get_primary()
450 }
451 { status_text }
452 }
453 }
454 }
455 }
456}
457
458pub(crate) fn mount_dynamic_fault_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
469 let p: ThemePalette = tokens.get_palette();
470 let wasm_mgr: WasmDynamicManager = state.get_wasm_manager().clone();
471 let wasm_status_sig: Signal<String> = state.get_wasm_fault_status();
472 let m_retry: WasmDynamicManager = wasm_mgr.clone();
473 let on_retry = move |_: &UiEvent| {
474 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
475 URL_WASM_TIMEOUT_RETRY.to_string(),
476 SLOT_WASM_WIDGET.to_string(),
477 10,
478 )
479 .with_allow_downgrade(true);
480 match m_retry.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY) {
481 Ok(v) => {
482 let _: bool =
483 wasm_status_sig.set(format!("PASS Timeout->Retry recovered and mounted v{v}!"));
484 }
485 Err(e) => {
486 let _: bool = wasm_status_sig.set(format!("Retry failed: {e}"));
487 }
488 }
489 };
490 let m_tamper: WasmDynamicManager = wasm_mgr.clone();
491 let on_tamper = move |_: &UiEvent| {
492 let good: Vec<u8> = build_partial_widget_wasm(TITLE_WASM_PARTIAL_V1, 1, 0x2563EB);
493 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
494 URL_WASM_TAMPERED.to_string(),
495 SLOT_WASM_WIDGET.to_string(),
496 13,
497 )
498 .with_checksum(compute_wasm_checksum(&good))
499 .with_allow_downgrade(true);
500 let res: String = format!(
501 "Blocked Tampered Checksum -> {:?}",
502 m_tamper.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY)
503 );
504 let _: bool = wasm_status_sig.set(res);
505 };
506 let m_sig: WasmDynamicManager = wasm_mgr.clone();
507 let on_sig = move |_: &UiEvent| {
508 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
509 URL_WASM_PARTIAL_V1.to_string(),
510 SLOT_WASM_WIDGET.to_string(),
511 14,
512 )
513 .with_signature(DYNAMIC_FORGED_SIG.to_string())
514 .with_allow_downgrade(true);
515 let res: String = format!(
516 "Blocked Forged Signature -> {:?}",
517 m_sig.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY)
518 );
519 let _: bool = wasm_status_sig.set(res);
520 };
521 let m_cancel: WasmDynamicManager = wasm_mgr.clone();
522 let on_cancel = move |_: &UiEvent| {
523 let gen_id: u64 = m_cancel.cancel_scope(&WasmDynamicScope::Partial {
524 slot_id: SLOT_WASM_WIDGET.to_string(),
525 });
526 let _: bool = wasm_status_sig.set(format!(
527 "Cancelled scope request cleanly (generation #{gen_id} blocks stale responses)"
528 ));
529 };
530 let standard_faults: [(&str, &str, u64, &str); 7] = [
531 (
532 DYNAMIC_BTN_FAULT_500,
533 URL_WASM_HTTP_500,
534 11,
535 DYNAMIC_FAULT_MSG_500,
536 ),
537 (
538 DYNAMIC_BTN_FAULT_CORRUPT,
539 URL_WASM_CORRUPTED,
540 12,
541 DYNAMIC_FAULT_MSG_CORRUPT,
542 ),
543 (
544 DYNAMIC_BTN_FAULT_ABI,
545 URL_WASM_BAD_ABI,
546 15,
547 DYNAMIC_FAULT_MSG_ABI,
548 ),
549 (
550 DYNAMIC_BTN_FAULT_EXPORT,
551 URL_WASM_MISSING_EXPORT,
552 16,
553 DYNAMIC_FAULT_MSG_EXPORT,
554 ),
555 (
556 DYNAMIC_BTN_FAULT_FUEL,
557 URL_WASM_FUEL_BOMB,
558 17,
559 DYNAMIC_FAULT_MSG_FUEL,
560 ),
561 (
562 DYNAMIC_BTN_FAULT_TRAP,
563 URL_WASM_TRAP,
564 18,
565 DYNAMIC_FAULT_MSG_TRAP,
566 ),
567 (
568 DYNAMIC_BTN_FAULT_BIG,
569 URL_WASM_OVERSIZED,
570 19,
571 DYNAMIC_FAULT_MSG_BIG,
572 ),
573 ];
574 let standard_btns: Vec<NodeId> = standard_faults
575 .into_iter()
576 .map(|(label, url, ver, prefix): (&str, &str, u64, &str)| {
577 let mgr_c: WasmDynamicManager = wasm_mgr.clone();
578 let on_fault = move |_: &UiEvent| {
579 let req: WasmDownloadRequest = WasmDownloadRequest::partial(
580 url.to_string(),
581 SLOT_WASM_WIDGET.to_string(),
582 ver,
583 )
584 .with_allow_downgrade(true);
585 let res: String = format!(
586 "{prefix} -> {:?}",
587 mgr_c.load_and_mount(req, WASM_SHOWCASE_SIGNING_KEY)
588 );
589 let _: bool = wasm_status_sig.set(res);
590 };
591 view! {
592 EuvButton {
593 label: label.to_string()
594 tokens: tokens
595 outline()
596 sm()
597 on_click: on_fault
598 }
599 }
600 })
601 .collect();
602 let status_text = move || -> String { wasm_status_sig.get() };
603 view! {
604 EuvCard {
605 title: DYNAMIC_FAULT_CARD_TITLE.to_string()
606 tokens: tokens
607 subtitle: DYNAMIC_FAULT_CARD_SUB
608 column {
609 style: {
610 width: Length::Percent(100.0)
611 gap: SPACE_MD
612 }
613 EuvActionRow {
614 EuvButton {
615 label: DYNAMIC_BTN_FAULT_RETRY.to_string()
616 tokens: tokens
617 outline()
618 sm()
619 on_click: on_retry
620 }
621 EuvButton {
622 label: DYNAMIC_BTN_FAULT_TAMPER.to_string()
623 tokens: tokens
624 outline()
625 sm()
626 on_click: on_tamper
627 }
628 EuvButton {
629 label: DYNAMIC_BTN_FAULT_SIG.to_string()
630 tokens: tokens
631 outline()
632 sm()
633 on_click: on_sig
634 }
635 ..standard_btns
636 EuvButton {
637 label: DYNAMIC_BTN_FAULT_CANCEL.to_string()
638 tokens: tokens
639 outline()
640 sm()
641 on_click: on_cancel
642 }
643 }
644 text {
645 style: {
646 width: Length::Percent(100.0)
647 font_size: 12.5
648 font_weight: FontWeight::Medium
649 color: p.get_primary()
650 }
651 { status_text }
652 }
653 }
654 }
655 }
656}
657
658pub(crate) fn mount_dynamic_component_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
669 let p: ThemePalette = tokens.get_palette();
670 let g: ThemeGeometry = tokens.get_geometry();
671 let hub: DynamicUpdateHub = state.get_dynamic_hub().clone();
672 let sibling_counter: Signal<i32> = state.get_sibling_counter();
673 let hub_v1: DynamicUpdateHub = hub.clone();
674 let hub_v2: DynamicUpdateHub = hub.clone();
675 let hub_rb: DynamicUpdateHub = hub.clone();
676 let hub_m1: DynamicUpdateHub = hub.clone();
677 let hub_mrb: DynamicUpdateHub = hub;
678 let sibling_text = move || -> String {
679 let count: i32 = sibling_counter.get();
680 format!("Sibling State Preserved: count={count}")
681 };
682 let on_inc_sibling = move |_: &UiEvent| {
683 let _: bool = sibling_counter.update(|v: &mut i32| *v += 1);
684 };
685 let on_push_banner_v1 = move |_: &UiEvent| {
686 let next_v: u64 = hub_v1
687 .component_version(SLOT_PROMO_BANNER)
688 .saturating_add(1);
689 let mut badge: DynamicNodeSpec = DynamicNodeSpec::badge(format!("OTA v{next_v}"));
690 badge
691 .get_mut_style()
692 .set_background_hex(Some(0x1D4ED8))
693 .set_color_hex(Some(0xFFFFFF));
694 let mut title: DynamicNodeSpec = DynamicNodeSpec::text(format!(
695 "Dynamic JSON Banner v{next_v}: Surgical Component Patch"
696 ));
697 title
698 .get_mut_style()
699 .set_bold(true)
700 .set_color_hex(Some(0x1E3A8A));
701 let mut offer_btn: DynamicNodeSpec = DynamicNodeSpec::button(
702 BTN_CLAIM_OFFER.to_string(),
703 DYNAMIC_ACTION_CLAIM_OFFER.to_string(),
704 );
705 offer_btn.set_payload(format!("json-v{next_v}"));
706 let mut box_spec: DynamicNodeSpec = DynamicNodeSpec::row()
707 .child(badge)
708 .child(title)
709 .child(offer_btn);
710 box_spec
711 .get_mut_style()
712 .set_full_width(true)
713 .set_padding(Some(SPACE_MD))
714 .set_radius(Some(SPACE_SM))
715 .set_background_hex(Some(0xEFF6FF))
716 .set_border_width(Some(1.0))
717 .set_border_hex(Some(0x93C5FD));
718 let mut upd: DynamicComponentUpdate =
719 DynamicComponentUpdate::new(SLOT_PROMO_BANNER.to_string(), next_v, box_spec);
720 upd.sign();
721 if let Ok(json) = upd.to_json() {
722 let _: Result<u64, DynamicUpdateError> = hub_v1.apply_component_json(&json);
723 }
724 };
725 let on_push_banner_v2 = move |_: &UiEvent| {
726 let next_v: u64 = hub_v2
727 .component_version(SLOT_PROMO_BANNER)
728 .saturating_add(1)
729 .max(2);
730 let hub_act: DynamicUpdateHub = hub_v2.clone();
731 let _: Result<u64, DynamicUpdateError> =
732 hub_v2.swap_component_builder(SLOT_PROMO_BANNER.to_string(), next_v, move || {
733 mount_dynamic_native_banner(next_v, hub_act.clone(), tokens)
734 });
735 };
736 let on_rollback_banner = move |_: &UiEvent| {
737 let _: Result<u64, DynamicUpdateError> = hub_rb.rollback_component(SLOT_PROMO_BANNER);
738 };
739 let on_patch_metrics = move |_: &UiEvent| {
740 let next_v: u64 = hub_m1
741 .component_version(SLOT_METRICS_WIDGET)
742 .saturating_add(1);
743 let mut card_spec: DynamicNodeSpec = DynamicNodeSpec::card(format!(
744 "Live Metrics Widget v{next_v}"
745 ))
746 .child(DynamicNodeSpec::text(format!(
747 "Updated independently without touching promo_banner or sibling state (rev {next_v})."
748 )));
749 card_spec
750 .get_mut_style()
751 .set_background_hex(Some(0xFEFCE8))
752 .set_border_width(Some(1.0))
753 .set_border_hex(Some(0xFACC15));
754 let mut upd: DynamicComponentUpdate =
755 DynamicComponentUpdate::new(SLOT_METRICS_WIDGET.to_string(), next_v, card_spec);
756 upd.sign();
757 let _: Result<u64, DynamicUpdateError> = hub_m1.apply_component(upd);
758 };
759 let on_rollback_metrics = move |_: &UiEvent| {
760 let _: Result<u64, DynamicUpdateError> = hub_mrb.rollback_component(SLOT_METRICS_WIDGET);
761 };
762 view! {
763 EuvCard {
764 title: DYNAMIC_COMP_CARD_TITLE.to_string()
765 tokens: tokens
766 subtitle: DYNAMIC_COMP_CARD_SUB
767 column {
768 style: {
769 width: Length::Percent(100.0)
770 gap: SPACE_MD
771 }
772 EuvActionRow {
773 EuvButton {
774 label: BTN_INC_SIBLING.to_string()
775 tokens: tokens
776 outline()
777 on_click: on_inc_sibling
778 }
779 }
780 text {
781 style: {
782 width: Length::Percent(100.0)
783 font_size: 13.0
784 font_weight: FontWeight::SemiBold
785 color: p.get_primary()
786 }
787 { sibling_text }
788 }
789 EuvActionRow {
790 EuvButton {
791 label: BTN_PUSH_BANNER_V1.to_string()
792 tokens: tokens
793 on_click: on_push_banner_v1
794 }
795 EuvButton {
796 label: BTN_PUSH_BANNER_V2.to_string()
797 tokens: tokens
798 outline()
799 on_click: on_push_banner_v2
800 }
801 EuvButton {
802 label: BTN_ROLLBACK_BANNER.to_string()
803 tokens: tokens
804 outline()
805 on_click: on_rollback_banner
806 }
807 }
808 slot {
809 id: SLOT_PROMO_BANNER
810 row {
811 style: {
812 width: Length::Percent(100.0)
813 padding: Edges::all(SPACE_MD)
814 background: p.get_muted()
815 border: (g.get_border_width(), p.get_border())
816 radius: g.get_radius_md()
817 overflow: Overflow::Hidden
818 }
819 text {
820 style: {
821 width: Length::Percent(100.0)
822 font_size: 13.0
823 color: p.get_foreground()
824 }
825 { DYNAMIC_SLOT_BANNER_FALLBACK }
826 }
827 }
828 }
829 EuvActionRow {
830 EuvButton {
831 label: BTN_PATCH_METRICS.to_string()
832 tokens: tokens
833 on_click: on_patch_metrics
834 }
835 EuvButton {
836 label: BTN_ROLLBACK_METRICS.to_string()
837 tokens: tokens
838 outline()
839 on_click: on_rollback_metrics
840 }
841 }
842 slot {
843 id: SLOT_METRICS_WIDGET
844 row {
845 style: {
846 width: Length::Percent(100.0)
847 padding: Edges::all(SPACE_MD)
848 background: p.get_muted()
849 border: (g.get_border_width(), p.get_border())
850 radius: g.get_radius_md()
851 overflow: Overflow::Hidden
852 }
853 text {
854 style: {
855 width: Length::Percent(100.0)
856 font_size: 13.0
857 color: p.get_muted_foreground()
858 }
859 { DYNAMIC_SLOT_METRICS_FALLBACK }
860 }
861 }
862 }
863 }
864 }
865 }
866}
867
868pub(crate) fn mount_dynamic_page_slot_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
879 let p: ThemePalette = tokens.get_palette();
880 let g: ThemeGeometry = tokens.get_geometry();
881 let hub: DynamicUpdateHub = state.get_dynamic_hub().clone();
882 let action_log: Signal<String> = state.get_dynamic_action_log();
883 let route_sig: Signal<String> = state.get_route();
884 let tel_sig: Signal<DynamicTelemetry> = hub.telemetry();
885 let banner_rev: Signal<u64> = hub.component_revision_signal(SLOT_PROMO_BANNER);
886 let metrics_rev: Signal<u64> = hub.component_revision_signal(SLOT_METRICS_WIDGET);
887 let panel_rev: Signal<u64> = hub.page_revision_signal(ROUTE_DYNAMIC_PANEL);
888 let hub_p1: DynamicUpdateHub = hub.clone();
889 let hub_bundle: DynamicUpdateHub = hub.clone();
890 let hub_prb: DynamicUpdateHub = hub.clone();
891 let hub_inject: DynamicUpdateHub = hub.clone();
892 let hub_for_status: DynamicUpdateHub = hub;
893 let on_update_page = move |_: &UiEvent| {
894 let next_v: u64 = hub_p1.page_version(ROUTE_DYNAMIC_PANEL).saturating_add(1);
895 let spec: DynamicNodeSpec =
896 DynamicNodeSpec::card(format!("Hot-Updated Dynamic Page Panel v{next_v}"))
897 .child(DynamicNodeSpec::badge(format!("Page Revision v{next_v}")))
898 .child(DynamicNodeSpec::text(
899 DYNAMIC_PAGE_REPLACED_BODY.to_string(),
900 ));
901 let mut upd: DynamicPageUpdate = DynamicPageUpdate::new(
902 ROUTE_DYNAMIC_PANEL.to_string(),
903 format!("Dynamic Panel v{next_v}"),
904 next_v,
905 spec,
906 );
907 upd.sign();
908 let _: Result<u64, DynamicUpdateError> = hub_p1.apply_page(upd);
909 };
910 let on_apply_bundle = move |_: &UiEvent| {
911 let next_comp_v: u64 = hub_bundle
912 .component_version(SLOT_METRICS_WIDGET)
913 .saturating_add(1);
914 let next_page_v: u64 = hub_bundle
915 .page_version(ROUTE_DYNAMIC_PANEL)
916 .saturating_add(1);
917 let mut comp_upd: DynamicComponentUpdate = DynamicComponentUpdate::new(
918 SLOT_METRICS_WIDGET.to_string(),
919 next_comp_v,
920 DynamicNodeSpec::card(format!("Atomic Bundle Metrics v{next_comp_v}")).child(
921 DynamicNodeSpec::text(DYNAMIC_ATOMIC_METRICS_BODY.to_string()),
922 ),
923 );
924 comp_upd.sign();
925 let mut page_upd: DynamicPageUpdate = DynamicPageUpdate::new(
926 ROUTE_DYNAMIC_PANEL.to_string(),
927 format!("Atomic Panel v{next_page_v}"),
928 next_page_v,
929 DynamicNodeSpec::card(format!("Atomic Bundle Page Panel v{next_page_v}"))
930 .child(DynamicNodeSpec::text(DYNAMIC_ATOMIC_PAGE_BODY.to_string())),
931 );
932 page_upd.sign();
933 let bundle: DynamicUpdateBundle =
934 DynamicUpdateBundle::new(DYNAMIC_ATOMIC_BUNDLE_ID.to_string(), next_page_v)
935 .push_component(comp_upd)
936 .push_page(page_upd);
937 if let Ok(json) = bundle.to_json() {
938 let _: Result<DynamicTelemetry, DynamicUpdateError> =
939 hub_bundle.apply_bundle_json(&json);
940 }
941 };
942 let on_rollback_page = move |_: &UiEvent| {
943 let _: Result<u64, DynamicUpdateError> = hub_prb.rollback_page(ROUTE_DYNAMIC_PANEL);
944 };
945 let on_inject_route = move |_: &UiEvent| {
946 let next_v: u64 = hub_inject.page_version(ROUTE_PROMO_LIVE).saturating_add(1);
947 let mut back_btn: DynamicNodeSpec = DynamicNodeSpec::button(
948 BTN_RETURN_DYNAMIC.to_string(),
949 DYNAMIC_ACTION_RETURN.to_string(),
950 );
951 back_btn.set_payload(format!("from-promo-v{next_v}"));
952 let page_spec: DynamicNodeSpec = DynamicNodeSpec::column().child(
953 DynamicNodeSpec::card(format!("Runtime-Injected Page /promo-live (v{next_v})"))
954 .child(DynamicNodeSpec::badge(DYNAMIC_PROMO_BADGE.to_string()))
955 .child(DynamicNodeSpec::text(DYNAMIC_PROMO_BODY.to_string()))
956 .child(back_btn),
957 );
958 let mut upd: DynamicPageUpdate = DynamicPageUpdate::new(
959 ROUTE_PROMO_LIVE.to_string(),
960 DYNAMIC_PROMO_TITLE.to_string(),
961 next_v,
962 page_spec,
963 );
964 upd.sign();
965 if let Ok(json) = upd.to_json()
966 && hub_inject.apply_page_json(&json).is_ok()
967 {
968 let _: bool = route_sig.set_if_changed(ROUTE_PROMO_LIVE.to_string());
969 }
970 };
971 let versions_text = move || -> String {
972 let _: u64 = banner_rev.get();
973 let _: u64 = metrics_rev.get();
974 let _: u64 = panel_rev.get();
975 let tel: DynamicTelemetry = tel_sig.get();
976 format!(
977 "Versions: banner=v{} metrics=v{} panel=v{} | Applied: comp={} page={} rollbacks={} rejected={} | Last Action: {}",
978 hub_for_status.component_version(SLOT_PROMO_BANNER),
979 hub_for_status.component_version(SLOT_METRICS_WIDGET),
980 hub_for_status.page_version(ROUTE_DYNAMIC_PANEL),
981 tel.get_components_applied(),
982 tel.get_pages_applied(),
983 tel.get_rollbacks(),
984 tel.get_rejected(),
985 action_log.get(),
986 )
987 };
988 view! {
989 EuvCard {
990 title: DYNAMIC_PAGE_CARD_TITLE.to_string()
991 tokens: tokens
992 subtitle: DYNAMIC_PAGE_CARD_SUB
993 column {
994 style: {
995 width: Length::Percent(100.0)
996 gap: SPACE_MD
997 }
998 EuvActionRow {
999 EuvButton {
1000 label: BTN_UPDATE_PAGE_V1.to_string()
1001 tokens: tokens
1002 on_click: on_update_page
1003 }
1004 EuvButton {
1005 label: BTN_APPLY_BUNDLE.to_string()
1006 tokens: tokens
1007 outline()
1008 on_click: on_apply_bundle
1009 }
1010 EuvButton {
1011 label: BTN_ROLLBACK_PAGE.to_string()
1012 tokens: tokens
1013 outline()
1014 on_click: on_rollback_page
1015 }
1016 EuvButton {
1017 label: BTN_INJECT_ROUTE.to_string()
1018 tokens: tokens
1019 outline()
1020 on_click: on_inject_route
1021 }
1022 }
1023 page_slot {
1024 route: ROUTE_DYNAMIC_PANEL
1025 column {
1026 style: {
1027 width: Length::Percent(100.0)
1028 padding: Edges::all(SPACE_MD)
1029 background: p.get_muted()
1030 border: (g.get_border_width(), p.get_border())
1031 radius: g.get_radius_md()
1032 overflow: Overflow::Hidden
1033 }
1034 text {
1035 style: {
1036 width: Length::Percent(100.0)
1037 font_size: 13.0
1038 color: p.get_foreground()
1039 }
1040 { DYNAMIC_PAGE_FALLBACK }
1041 }
1042 }
1043 }
1044 text {
1045 style: {
1046 width: Length::Percent(100.0)
1047 font_size: 12.0
1048 font_family: FontFamily::Monospace
1049 color: p.get_muted_foreground()
1050 }
1051 { versions_text }
1052 }
1053 }
1054 }
1055 }
1056}
1057
1058pub fn mount_dynamic_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
1069 state.ensure_wasm_registry_loaded();
1070 let partial_card: NodeId = mount_dynamic_partial_wasm_card(state, tokens);
1071 let global_card: NodeId = mount_dynamic_global_wasm_card(state, tokens);
1072 let fault_card: NodeId = mount_dynamic_fault_card(state, tokens);
1073 let comp_card: NodeId = mount_dynamic_component_card(state, tokens);
1074 let page_card: NodeId = mount_dynamic_page_slot_card(state, tokens);
1075 let wasm_grid: NodeId = mount_responsive_grid(vec![partial_card, global_card], 2);
1076 let slots_grid: NodeId = mount_responsive_grid(vec![comp_card, page_card], 2);
1077 view! {
1078 EuvPage {
1079 title: DYNAMIC_TITLE.to_string()
1080 subtitle: DYNAMIC_SUBTITLE.to_string()
1081 tokens: tokens
1082 { wasm_grid }
1083 { fault_card }
1084 { slots_grid }
1085 }
1086 }
1087}