akanjs 3.2.0-rc.12 → 3.2.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/ARCHITECTURE.md +17 -17
  2. package/CHANGELOG.md +18 -0
  3. package/client/csrTypes.ts +2 -0
  4. package/client/index.ts +1 -0
  5. package/client/route/RouteDefinition.ts +24 -7
  6. package/client/route/routeArgs.ts +7 -0
  7. package/client/router.ts +12 -2
  8. package/package.json +1 -1
  9. package/server/akanApp.ts +103 -1270
  10. package/server/akanServer.ts +1 -1
  11. package/server/gateway/childSupervisor.ts +325 -0
  12. package/server/gateway/devHostChannel.ts +40 -0
  13. package/server/gateway/gatewayChildren.ts +135 -0
  14. package/server/gateway/gatewayConfig.ts +182 -0
  15. package/server/gateway/gatewayHttpProxy.ts +231 -0
  16. package/server/gateway/gatewayLogging.ts +111 -0
  17. package/server/gateway/gatewayRooms.ts +134 -0
  18. package/server/gateway/gatewayStatus.ts +116 -0
  19. package/server/gateway/gatewayStatusPage.ts +54 -0
  20. package/server/gateway/gatewayWebSocketRelay.ts +149 -0
  21. package/server/mcp/McpDispatcher.ts +6 -24
  22. package/signal/SignalFailure.ts +21 -0
  23. package/signal/agentTurnStream.ts +5 -2
  24. package/types/client/csrTypes.d.ts +2 -0
  25. package/types/client/index.d.ts +1 -1
  26. package/types/client/route/RouteDefinition.d.ts +2 -2
  27. package/types/client/route/routeArgs.d.ts +6 -0
  28. package/types/client/router.d.ts +2 -1
  29. package/types/server/akanApp.d.ts +2 -20
  30. package/types/server/gateway/childSupervisor.d.ts +33 -0
  31. package/types/server/gateway/devHostChannel.d.ts +13 -0
  32. package/types/server/gateway/gatewayChildren.d.ts +47 -0
  33. package/types/server/gateway/gatewayConfig.d.ts +82 -0
  34. package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
  35. package/types/server/gateway/gatewayLogging.d.ts +16 -0
  36. package/types/server/gateway/gatewayRooms.d.ts +22 -0
  37. package/types/server/gateway/gatewayStatus.d.ts +62 -0
  38. package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
  39. package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
  40. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  41. package/types/signal/SignalFailure.d.ts +1 -0
  42. package/types/signal/agentTurnStream.d.ts +1 -0
  43. package/types/ui/Agent/Chat.d.ts +5 -2
  44. package/types/ui/Agent/ChatHeader.d.ts +13 -0
  45. package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
  46. package/types/ui/overlayLayer.d.ts +6 -1
  47. package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
  48. package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
  49. package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +14 -10
  50. package/types/vendor/use-agentic/failureCode.d.ts +4 -0
  51. package/types/vendor/use-agentic/types.d.ts +6 -0
  52. package/types/webkit/CsrGuards.d.ts +2 -0
  53. package/ui/Agent/Chat.tsx +96 -116
  54. package/ui/Agent/ChatHeader.tsx +59 -0
  55. package/ui/Agent/ChatPendingCards.tsx +49 -0
  56. package/ui/Agent/fetchRunner.ts +8 -1
  57. package/ui/BottomSheet.tsx +1 -1
  58. package/ui/Dialog/LegacyModal.tsx +1 -1
  59. package/ui/Dialog/Modal.tsx +1 -1
  60. package/ui/Popconfirm.tsx +1 -1
  61. package/ui/overlayLayer.ts +22 -1
  62. package/vendor/@akanjs/native/CHANGELOG.md +6 -1
  63. package/vendor/@akanjs/native/native/desktop/src/external.rs +213 -111
  64. package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
  65. package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +275 -0
  66. package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
  67. package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
  68. package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
  69. package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
  70. package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
  71. package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
  72. package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
  73. package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
  74. package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
  75. package/vendor/@akanjs/native/plugins/external-view/src/index.ts +14 -10
  76. package/vendor/use-agentic/AgentSession.ts +11 -11
  77. package/vendor/use-agentic/CHANGELOG.md +6 -0
  78. package/vendor/use-agentic/Compaction.ts +2 -1
  79. package/vendor/use-agentic/ToolRunner.ts +3 -15
  80. package/vendor/use-agentic/Transcript.ts +6 -3
  81. package/vendor/use-agentic/WIRE.md +12 -1
  82. package/vendor/use-agentic/failureCode.ts +44 -0
  83. package/vendor/use-agentic/httpRunner.ts +14 -3
  84. package/vendor/use-agentic/types.ts +6 -0
  85. package/webkit/CsrGuards.ts +7 -2
  86. package/webkit/useLocation.ts +3 -2
@@ -1,6 +1,6 @@
1
1
  //! The external-view plugin (plugins/external-view): a third-party page shown first-party inside an app
2
2
  //! window, as signage needs it. Nothing of the app reaches it: no init script, no IPC, no app scheme. It runs
3
- //! in a browser profile of its own (a data folder on Windows, a data store on macOS 14+), so its storage is
3
+ //! in a browser profile of its own (a data folder on Windows and Linux, a data store on macOS 14+), so its storage is
4
4
  //! neither the app's nor cleared with it, and its top level navigates only to the origins it was opened for
5
5
  //! (frames load web content from anywhere); popups, downloads, device permissions and a link another program
6
6
  //! would open are refused. Its web process ending reloads it (UserEvent::ExternalGone).
@@ -20,6 +20,8 @@ use wry::{Rect, WebView, RGBA};
20
20
  use crate::{json, push_event, send, UserEvent};
21
21
  #[cfg(target_os = "windows")]
22
22
  use crate::win::external as platform;
23
+ #[cfg(target_os = "linux")]
24
+ use crate::linux::external as platform;
23
25
 
24
26
  #[derive(Clone, Copy, Debug, PartialEq)]
25
27
  pub(crate) enum Bounds {
@@ -58,6 +60,9 @@ pub(crate) struct View {
58
60
  /// Its window hides the pointer (window.setCursorVisible): the view does too, in every document it loads.
59
61
  cursor_hidden: bool,
60
62
  cursor: platform::Cursor,
63
+ /// When it was last opened or shown (Views::shows): the visible view shown last holds the keyboard.
64
+ #[cfg(target_os = "linux")]
65
+ shown: u64,
61
66
  }
62
67
 
63
68
  /// What a view built again in an old one's place keeps: restarts, streak, last reload, visible, pointer hidden.
@@ -72,6 +77,8 @@ impl View {
72
77
  (self.restarts, self.gone_streak, self.reloaded_at, self.visible) = (restarts, gone_streak, reloaded_at, visible);
73
78
  if !visible {
74
79
  let _ = self.webview.set_visible(false);
80
+ #[cfg(target_os = "linux")]
81
+ platform::set_visible(&self.webview, false);
75
82
  }
76
83
  if cursor_hidden {
77
84
  self.cursor_hidden = true;
@@ -83,6 +90,45 @@ impl View {
83
90
  #[derive(Default)]
84
91
  pub(crate) struct Views {
85
92
  map: HashMap<String, View>,
93
+ #[cfg(target_os = "linux")]
94
+ shows: u64,
95
+ }
96
+
97
+ /// Linux has no sendKey: a visible view holds the keyboard focus instead, so a key reaches it as the user's own.
98
+ #[cfg(target_os = "linux")]
99
+ impl Views {
100
+ fn raise(&mut self, view: &str) {
101
+ if let Some(v) = self.map.get_mut(view) {
102
+ self.shows += 1;
103
+ v.shown = self.shows;
104
+ }
105
+ }
106
+
107
+ fn keyboard_view(&self, window: u32) -> Option<&View> {
108
+ self.map.values().filter(|v| v.window == window && v.visible).max_by_key(|v| v.shown)
109
+ }
110
+
111
+ /// The visible view shown last takes the keyboard; with none shown, the window's page does. `any` is a webview on the
112
+ /// window: its page or one of its views.
113
+ fn give_keyboard(&self, window: u32, any: &WebView) {
114
+ match self.keyboard_view(window) {
115
+ Some(view) => platform::focus(&view.webview),
116
+ None => platform::focus_page(any),
117
+ }
118
+ }
119
+
120
+ fn give_keyboard_by(&self, view: &str) {
121
+ if let Some(v) = self.map.get(view) {
122
+ self.give_keyboard(v.window, &v.webview);
123
+ }
124
+ }
125
+
126
+ /// The window is active again: the view that holds the keyboard takes it back from whatever had it.
127
+ pub(crate) fn refocus(&self, window: u32) {
128
+ if let Some(view) = self.keyboard_view(window) {
129
+ platform::focus(&view.webview);
130
+ }
131
+ }
86
132
  }
87
133
 
88
134
  pub(crate) struct OpenOptions {
@@ -169,7 +215,6 @@ pub(crate) fn allowed(allow: &[String], url: &str) -> bool {
169
215
  url == "about:blank" || origin_of(url).is_some_and(|origin| allow.contains(&origin))
170
216
  }
171
217
 
172
- #[cfg_attr(target_os = "linux", allow(dead_code))]
173
218
  pub(crate) fn admits(allow: &[String], url: &str, sub_frame: bool) -> bool {
174
219
  if sub_frame {
175
220
  crate::navigation::scheme(url).is_some_and(|s| crate::contract::FRAME_SCHEMES.contains(&s.as_str()))
@@ -201,16 +246,13 @@ fn navigation_handler(view: String, allow: Rc<RefCell<Vec<String>>>) -> impl Fn(
201
246
  //? WebView2 runs a document-created script in every frame (wry's main-frame-only flag is WebKit's). Run first, this
202
247
  //? marks a frame's window so that the init script, declaring the same name, fails before it declares anything: a throw
203
248
  //? or a wrapper would leave its let bindings uninitialized there, or change their scope. That error goes unreported.
204
- #[cfg_attr(target_os = "linux", allow(dead_code))]
205
249
  const TOP_ONLY: &str = r#"if(window.top!==window.self){Object.defineProperty(window,"__akanTopOnly",{value:true});addEventListener("error",e=>{e.preventDefault();e.stopImmediatePropagation()},{capture:true,once:true})}"#;
206
250
 
207
251
  /// The init script, declaring the name TOP_ONLY marks a frame with: on a line of its own after the script's last.
208
- #[cfg_attr(target_os = "linux", allow(dead_code))]
209
252
  fn top_only(script: &str) -> String {
210
253
  format!("{script}\n;let __akanTopOnly;")
211
254
  }
212
255
 
213
- #[cfg_attr(target_os = "linux", allow(dead_code))]
214
256
  fn fnv1a(view: &str, basis: u64) -> u64 {
215
257
  view.bytes().fold(basis, |hash, byte| (hash ^ byte as u64).wrapping_mul(0x0000_0100_0000_01b3))
216
258
  }
@@ -218,7 +260,6 @@ fn fnv1a(view: &str, basis: u64) -> u64 {
218
260
  /// A view's data folder: its id hashed (FNV-1a, stable where std's hasher is not), so ids differing only in case and
219
261
  /// device names (CON, NUL) get folders of their own, and a long id no long path. XOR-folded to 32 bits, as FNV's
220
262
  /// authors fold a hash: WebView2's profile path must fit MAX_PATH below the app's own.
221
- #[cfg_attr(target_os = "linux", allow(dead_code))]
222
263
  fn folder(view: &str) -> String {
223
264
  let hash = fnv1a(view, 0xcbf2_9ce4_8422_2325);
224
265
  format!("{:08x}", (hash >> 32) as u32 ^ hash as u32)
@@ -267,6 +308,19 @@ fn discard(view: View) {
267
308
  view.live.set(false);
268
309
  let _ = view.webview.set_visible(false);
269
310
  let _ = view.webview.load_url("about:blank");
311
+ #[cfg(target_os = "linux")]
312
+ platform::discard(&view.webview);
313
+ }
314
+
315
+ fn place(webview: &WebView, bounds: Bounds, inner: LogicalSize<f64>) -> Result<(), String> {
316
+ #[cfg(target_os = "linux")]
317
+ {
318
+ let _ = inner;
319
+ platform::place(webview, bounds);
320
+ Ok(())
321
+ }
322
+ #[cfg(not(target_os = "linux"))]
323
+ webview.set_bounds(rect(bounds, inner)).map_err(|e| e.to_string())
270
324
  }
271
325
 
272
326
  /// Ends in a row: an end within a minute of the last reload follows the one before (lib.rs WebviewGone).
@@ -345,7 +399,7 @@ impl Views {
345
399
  background: RGBA,
346
400
  opts: OpenOptions,
347
401
  ) -> Result<String, String> {
348
- #[cfg(not(target_os = "windows"))]
402
+ #[cfg(target_os = "macos")]
349
403
  if opts.muted {
350
404
  return Err(platform::NO_MUTE.into());
351
405
  }
@@ -353,7 +407,12 @@ impl Views {
353
407
  let Some(open) = self.map.get(&opts.view) else {
354
408
  let view = build(window, inner, data_root, devtools, background, &opts).inspect_err(|_| platform::reclaim(page))?;
355
409
  let answer = state(&opts.view, &view);
356
- self.map.insert(opts.view, view);
410
+ self.map.insert(opts.view.clone(), view);
411
+ #[cfg(target_os = "linux")]
412
+ {
413
+ self.raise(&opts.view);
414
+ self.give_keyboard(opts.window, page);
415
+ }
357
416
  return Ok(answer);
358
417
  };
359
418
  if open.window != opts.window {
@@ -374,7 +433,12 @@ impl Views {
374
433
  platform::reclaim(page);
375
434
  fresh.restore(kept);
376
435
  let answer = state(&opts.view, &fresh);
377
- self.map.insert(opts.view, fresh);
436
+ self.map.insert(opts.view.clone(), fresh);
437
+ #[cfg(target_os = "linux")]
438
+ {
439
+ self.raise(&opts.view);
440
+ self.give_keyboard(opts.window, page);
441
+ }
378
442
  return Ok(answer);
379
443
  }
380
444
  let view = self.map.get_mut(&opts.view).expect("looked up above");
@@ -385,12 +449,18 @@ impl Views {
385
449
  platform::set_muted(&view.webview, opts.muted)?;
386
450
  view.muted = opts.muted;
387
451
  }
388
- view.webview.set_bounds(rect(view.bounds, inner)).map_err(|e| e.to_string())?;
452
+ place(&view.webview, view.bounds, inner)?;
389
453
  if view.url != opts.url {
390
454
  view.webview.load_url(&opts.url).map_err(|e| e.to_string())?;
391
455
  view.url = opts.url;
392
456
  }
393
- Ok(state(&opts.view, view))
457
+ let answer = state(&opts.view, view);
458
+ #[cfg(target_os = "linux")]
459
+ {
460
+ self.raise(&opts.view);
461
+ self.give_keyboard(opts.window, page);
462
+ }
463
+ Ok(answer)
394
464
  }
395
465
 
396
466
  pub(crate) fn close(&mut self, view: &str, page: &WebView) -> Result<String, String> {
@@ -398,6 +468,8 @@ impl Views {
398
468
  let window = closed.window;
399
469
  discard(closed);
400
470
  platform::reclaim(page);
471
+ #[cfg(target_os = "linux")]
472
+ self.give_keyboard(window, page);
401
473
  push_event(&event(view, window, r#""event":"closed""#));
402
474
  Ok("null".into())
403
475
  }
@@ -413,7 +485,7 @@ impl Views {
413
485
  pub(crate) fn fit(&self, window: u32, inner: LogicalSize<f64>) {
414
486
  //? WebView2 keeps a child's physical rect when the window's DPI changes: fixed bounds are applied again too.
415
487
  for view in self.map.values().filter(|v| v.window == window) {
416
- let _ = view.webview.set_bounds(rect(view.bounds, inner));
488
+ let _ = place(&view.webview, view.bounds, inner);
417
489
  }
418
490
  }
419
491
 
@@ -424,24 +496,37 @@ impl Views {
424
496
  }
425
497
  v.webview.load_url(url).map_err(|e| e.to_string())?;
426
498
  v.url = url.to_string();
499
+ #[cfg(target_os = "linux")]
500
+ self.give_keyboard_by(view);
427
501
  Ok("null".into())
428
502
  }
429
503
 
430
504
  pub(crate) fn reload(&self, view: &str) -> Result<String, String> {
431
505
  self.get(view)?.webview.reload().map_err(|e| e.to_string())?;
506
+ #[cfg(target_os = "linux")]
507
+ self.give_keyboard_by(view);
432
508
  Ok("null".into())
433
509
  }
434
510
 
435
511
  pub(crate) fn set_visible(&mut self, view: &str, visible: bool) -> Result<String, String> {
436
512
  let v = self.get_mut(view)?;
437
513
  v.webview.set_visible(visible).map_err(|e| e.to_string())?;
514
+ #[cfg(target_os = "linux")]
515
+ platform::set_visible(&v.webview, visible);
438
516
  v.visible = visible;
517
+ #[cfg(target_os = "linux")]
518
+ {
519
+ if visible {
520
+ self.raise(view);
521
+ }
522
+ self.give_keyboard_by(view);
523
+ }
439
524
  Ok("null".into())
440
525
  }
441
526
 
442
527
  pub(crate) fn set_bounds(&mut self, view: &str, bounds: Bounds, inner: LogicalSize<f64>) -> Result<String, String> {
443
528
  let v = self.get_mut(view)?;
444
- v.webview.set_bounds(rect(bounds, inner)).map_err(|e| e.to_string())?;
529
+ place(&v.webview, bounds, inner)?;
445
530
  v.bounds = bounds;
446
531
  Ok("null".into())
447
532
  }
@@ -451,6 +536,12 @@ impl Views {
451
536
  Ok("null".into())
452
537
  }
453
538
 
539
+ #[cfg(target_os = "linux")]
540
+ pub(crate) fn clear_data_then(&self, view: &str, done: impl FnOnce(Result<String, String>) + Send + 'static) -> Result<(), String> {
541
+ platform::clear_data(&self.get(view)?.webview, Reply::new(done));
542
+ Ok(())
543
+ }
544
+
454
545
  pub(crate) fn set_muted(&mut self, view: &str, muted: bool) -> Result<String, String> {
455
546
  let v = self.get_mut(view)?;
456
547
  platform::set_muted(&v.webview, muted)?;
@@ -468,7 +559,8 @@ impl Views {
468
559
  Ok(())
469
560
  }
470
561
 
471
- /// A Chrome DevTools Protocol method on the view's page: trusted input, a screenshot (Windows only).
562
+ /// A Chrome DevTools Protocol method on the view's page: trusted input, a screenshot (Windows; Linux answers the two
563
+ /// desktop.ts sends).
472
564
  pub(crate) fn cdp(&self, view: &str, method: &str, params: &str, done: impl FnOnce(Result<String, String>) + Send + 'static) -> Result<(), String> {
473
565
  platform::cdp(&self.get(view)?.webview, method, params, Reply::new(done));
474
566
  Ok(())
@@ -513,7 +605,10 @@ impl Views {
513
605
  v.reload_pending = false;
514
606
  v.reloaded_at = Some(Instant::now());
515
607
  if !v.dead {
516
- return v.webview.reload().map_err(|e| e.to_string());
608
+ v.webview.reload().map_err(|e| e.to_string())?;
609
+ #[cfg(target_os = "linux")]
610
+ self.give_keyboard_by(view);
611
+ return Ok(());
517
612
  }
518
613
  let old = self.map.remove(view).expect("looked up above");
519
614
  let opts = OpenOptions {
@@ -536,6 +631,8 @@ impl Views {
536
631
  })?;
537
632
  fresh.restore(kept);
538
633
  self.map.insert(view.to_string(), fresh);
634
+ #[cfg(target_os = "linux")]
635
+ self.give_keyboard(opts.window, page);
539
636
  Ok(())
540
637
  }
541
638
 
@@ -560,107 +657,114 @@ fn build(
560
657
  background: RGBA,
561
658
  opts: &OpenOptions,
562
659
  ) -> Result<View, String> {
563
- #[cfg(target_os = "linux")]
660
+ use wry::{NewWindowResponse, PageLoadEvent, PermissionResponse, WebViewBuilder};
661
+ let data = data_root.join(folder(&opts.view));
662
+ let mut context = wry::WebContext::new(Some(data));
663
+ let allow = Rc::new(RefCell::new(opts.allow.clone()));
664
+ let live = Rc::new(Cell::new(true));
665
+ let (view_id, window_id, loaded) = (opts.view.clone(), opts.window, live.clone());
666
+ let mut builder = WebViewBuilder::new_with_web_context(&mut context)
667
+ .with_url(&opts.url)
668
+ .with_bounds(rect(opts.bounds, inner))
669
+ // WebView2 paints a new view white until the remote page's first frame; the app's backgroundColor covers that gap.
670
+ .with_background_color(background)
671
+ .with_autoplay(opts.autoplay)
672
+ .with_devtools(devtools)
673
+ //? wry focuses a new webview on Windows: the remote page would take the keys meant for the app (a scanner, a PIN).
674
+ .with_focused(false)
675
+ .with_new_window_req_handler(|_, _| NewWindowResponse::Deny)
676
+ .with_download_started_handler(|_, _| false)
677
+ .with_permission_handler(|_| PermissionResponse::Deny)
678
+ .with_on_page_load_handler(move |ev, url| {
679
+ if !loaded.get() {
680
+ return;
681
+ }
682
+ let state = match ev {
683
+ PageLoadEvent::Started => "started",
684
+ PageLoadEvent::Finished => "finished",
685
+ };
686
+ push_event(&event(&view_id, window_id, &format!(r#""event":"load","state":"{state}","url":{}"#, json::quote(&url))));
687
+ });
688
+ //? WebKitGTK asks wry's handler about every frame without saying which: platform::guard decides at the response.
689
+ #[cfg(not(target_os = "linux"))]
564
690
  {
565
- let _ = (window, inner, data_root, devtools, background, opts);
566
- Err("UNSUPPORTED: external views are not on Linux yet".into())
691
+ builder = builder.with_navigation_handler(navigation_handler(opts.view.clone(), allow.clone()));
692
+ }
693
+ #[cfg(any(target_os = "windows", target_os = "macos"))]
694
+ if crate::unattended() {
695
+ builder = builder.with_initialization_script_for_main_only(crate::KIOSK_SCRIPT, false);
567
696
  }
697
+ if let Some(script) = opts.init_script.as_deref().filter(|s| !s.is_empty()) {
698
+ builder = builder.with_initialization_script_for_main_only(TOP_ONLY, true).with_initialization_script_for_main_only(top_only(script), true);
699
+ }
700
+ #[cfg(target_os = "windows")]
701
+ {
702
+ use wry::WebViewBuilderExtWindows;
703
+ // The browser's keys (Ctrl+P, F5, zoom, F12) are off, as on the app's own page (lib.rs open_window).
704
+ builder = builder.with_browser_accelerator_keys(false);
705
+ }
706
+ #[cfg(target_os = "macos")]
707
+ {
708
+ use wry::WebViewBuilderExtDarwin;
709
+ let (gone_view, alive) = (opts.view.clone(), live.clone());
710
+ builder = builder.with_data_store_identifier(store_id(&opts.view)).with_on_web_content_process_terminate_handler(move || {
711
+ if alive.get() {
712
+ send(UserEvent::ExternalGone { view: gone_view.clone(), reason: "terminated" });
713
+ }
714
+ });
715
+ }
716
+ #[cfg(target_os = "linux")]
717
+ let webview = platform::build(builder, window, opts.bounds)?;
568
718
  #[cfg(not(target_os = "linux"))]
719
+ let webview = builder.build_as_child(window).map_err(|e| format!("external view: {e}"))?;
720
+ #[cfg(target_os = "linux")]
721
+ platform::guard(&webview, &opts.view, allow.clone());
722
+ platform::watch(&webview, &opts.view, opts.window, opts.console);
723
+ #[cfg(target_os = "windows")]
569
724
  {
570
- use wry::{NewWindowResponse, PageLoadEvent, PermissionResponse, WebViewBuilder};
571
- let data = data_root.join(folder(&opts.view));
572
- let mut context = wry::WebContext::new(Some(data));
573
- let allow = Rc::new(RefCell::new(opts.allow.clone()));
574
- let live = Rc::new(Cell::new(true));
575
- let (view_id, window_id, loaded) = (opts.view.clone(), opts.window, live.clone());
576
- let mut builder = WebViewBuilder::new_with_web_context(&mut context)
577
- .with_url(&opts.url)
578
- .with_bounds(rect(opts.bounds, inner))
579
- // WebView2 paints a new view white until the remote page's first frame; the app's backgroundColor covers that gap.
580
- .with_background_color(background)
581
- .with_autoplay(opts.autoplay)
582
- .with_devtools(devtools)
583
- //? wry focuses a new webview on Windows: the remote page would take the keys meant for the app (a scanner, a PIN).
584
- .with_focused(false)
585
- .with_navigation_handler(navigation_handler(opts.view.clone(), allow.clone()))
586
- .with_new_window_req_handler(|_, _| NewWindowResponse::Deny)
587
- .with_download_started_handler(|_, _| false)
588
- .with_permission_handler(|_| PermissionResponse::Deny)
589
- .with_on_page_load_handler(move |ev, url| {
590
- if !loaded.get() {
591
- return;
592
- }
593
- let state = match ev {
594
- PageLoadEvent::Started => "started",
595
- PageLoadEvent::Finished => "finished",
596
- };
597
- push_event(&event(&view_id, window_id, &format!(r#""event":"load","state":"{state}","url":{}"#, json::quote(&url))));
598
- });
599
- #[cfg(any(target_os = "windows", target_os = "macos"))]
725
+ platform::guard_frames(&webview, &opts.view);
600
726
  if crate::unattended() {
601
- builder = builder.with_initialization_script_for_main_only(crate::KIOSK_SCRIPT, false);
602
- }
603
- if let Some(script) = opts.init_script.as_deref().filter(|s| !s.is_empty()) {
604
- builder = builder.with_initialization_script_for_main_only(TOP_ONLY, true).with_initialization_script_for_main_only(top_only(script), true);
727
+ crate::win::kiosk::lock(&webview, &format!("external view {}", opts.view));
605
728
  }
606
- #[cfg(target_os = "windows")]
607
- {
608
- use wry::WebViewBuilderExtWindows;
609
- // The browser's keys (Ctrl+P, F5, zoom, F12) are off, as on the app's own page (lib.rs open_window).
610
- builder = builder.with_browser_accelerator_keys(false);
611
- }
612
- #[cfg(target_os = "macos")]
613
- {
614
- use wry::WebViewBuilderExtDarwin;
615
- let (gone_view, alive) = (opts.view.clone(), live.clone());
616
- builder = builder.with_data_store_identifier(store_id(&opts.view)).with_on_web_content_process_terminate_handler(move || {
617
- if alive.get() {
618
- send(UserEvent::ExternalGone { view: gone_view.clone(), reason: "terminated" });
619
- }
620
- });
621
- }
622
- let webview = builder.build_as_child(window).map_err(|e| format!("external view: {e}"))?;
623
- platform::watch(&webview, &opts.view, opts.window, opts.console);
624
- #[cfg(target_os = "windows")]
625
- {
626
- platform::guard_frames(&webview, &opts.view);
627
- if crate::unattended() {
628
- crate::win::kiosk::lock(&webview, &format!("external view {}", opts.view));
629
- }
630
- }
631
- // Release builds: no Print, Save as or Inspect in its right-click menu either.
632
- #[cfg(target_os = "windows")]
633
- crate::page_menu::install(devtools, &webview);
634
- if opts.muted {
635
- platform::set_muted(&webview, true)?;
636
- }
637
- let view = View {
638
- webview,
639
- _context: context,
640
- window: opts.window,
641
- bounds: opts.bounds,
642
- allow,
643
- url: opts.url.clone(),
644
- visible: true,
645
- restarts: 0,
646
- gone_streak: 0,
647
- reloaded_at: None,
648
- reload_pending: false,
649
- dead: false,
650
- live,
651
- init_script: opts.init_script.clone(),
652
- muted: opts.muted,
653
- autoplay: opts.autoplay,
654
- console: opts.console,
655
- cursor_hidden: false,
656
- cursor: platform::Cursor::default(),
657
- };
658
- platform::track_frames(&view.webview, &opts.view, &view.cursor);
659
- Ok(view)
660
729
  }
730
+ #[cfg(target_os = "linux")]
731
+ if crate::unattended() {
732
+ crate::linux::kiosk::lock(&webview);
733
+ }
734
+ // Release builds: no Print, Save as or Inspect in its right-click menu either.
735
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
736
+ crate::page_menu::install(devtools, &webview);
737
+ if opts.muted {
738
+ platform::set_muted(&webview, true)?;
739
+ }
740
+ let view = View {
741
+ webview,
742
+ _context: context,
743
+ window: opts.window,
744
+ bounds: opts.bounds,
745
+ allow,
746
+ url: opts.url.clone(),
747
+ visible: true,
748
+ restarts: 0,
749
+ gone_streak: 0,
750
+ reloaded_at: None,
751
+ reload_pending: false,
752
+ dead: false,
753
+ live,
754
+ init_script: opts.init_script.clone(),
755
+ muted: opts.muted,
756
+ autoplay: opts.autoplay,
757
+ console: opts.console,
758
+ cursor_hidden: false,
759
+ cursor: platform::Cursor::default(),
760
+ #[cfg(target_os = "linux")]
761
+ shown: 0,
762
+ };
763
+ platform::track_frames(&view.webview, &opts.view, &view.cursor);
764
+ Ok(view)
661
765
  }
662
766
 
663
- #[cfg(not(target_os = "windows"))]
767
+ #[cfg(target_os = "macos")]
664
768
  mod platform {
665
769
  use wry::WebView;
666
770
 
@@ -668,13 +772,12 @@ mod platform {
668
772
 
669
773
  pub(crate) type Cursor = ();
670
774
 
671
- pub(super) const NO_MUTE: &str = "UNSUPPORTED: a view is muted on Windows only";
775
+ pub(super) const NO_MUTE: &str = "UNSUPPORTED: a view is not muted on macOS";
672
776
 
673
777
  pub(super) fn reclaim(_page: &WebView) {}
674
778
 
675
779
  pub(super) fn set_cursor_hidden(_webview: &WebView, _hidden: bool, _cursor: &Cursor) {}
676
780
 
677
- #[cfg_attr(target_os = "linux", allow(dead_code))]
678
781
  pub(super) fn track_frames(_webview: &WebView, _view: &str, _cursor: &Cursor) {}
679
782
 
680
783
  pub(super) fn set_muted(_webview: &WebView, _muted: bool) -> Result<(), String> {
@@ -682,10 +785,9 @@ mod platform {
682
785
  }
683
786
 
684
787
  pub(super) fn cdp(_webview: &WebView, method: &str, _params: &str, reply: Reply) {
685
- reply.send(Err(format!("UNSUPPORTED: {method} reaches a view on Windows only")));
788
+ reply.send(Err(format!("UNSUPPORTED: {method} reaches no view on macOS")));
686
789
  }
687
790
 
688
- #[cfg_attr(target_os = "linux", allow(dead_code))]
689
791
  pub(super) fn watch(_webview: &WebView, _view: &str, _window: u32, _console: bool) {}
690
792
  }
691
793
 
@@ -1566,12 +1566,13 @@ fn open_window(target: &EventLoopWindowTarget<UserEvent>, shell: &Shell, context
1566
1566
  use wry::WebViewBuilderExtDarwin;
1567
1567
  builder.with_on_web_content_process_terminate_handler(move || send(UserEvent::WebviewGone { window: id, reason: "terminated" }))
1568
1568
  };
1569
- // Linux: inside tao's GTK box, which works on Wayland as well as X11 (wry's build() is X11 only).
1569
+ // Linux: inside tao's GTK box, which works on Wayland as well as X11 (wry's build() is X11 only), on the overlay
1570
+ // external views lie on.
1570
1571
  #[cfg(target_os = "linux")]
1571
1572
  let webview = {
1572
1573
  use tao::platform::unix::WindowExtUnix;
1573
1574
  use wry::WebViewBuilderExtUnix;
1574
- builder.build_gtk(window.default_vbox().ok_or("webview: the window has no GTK box")?)
1575
+ builder.build_gtk(&linux::external::page_layer(window.default_vbox().ok_or("webview: the window has no GTK box")?))
1575
1576
  };
1576
1577
  #[cfg(not(target_os = "linux"))]
1577
1578
  let webview = builder.build(&window);
@@ -1785,15 +1786,20 @@ impl Windows {
1785
1786
  }
1786
1787
  }
1787
1788
 
1788
- /// evaluate and cdp answer from the engine's callback: true when this took the op.
1789
+ /// evaluate and cdp (and clearData on Linux) answer from the engine's callback: true when this took the op.
1789
1790
  fn external_async(&self, id: u64, json: &str) -> bool {
1790
1791
  let Ok(cmd) = json::parse(json) else { return false };
1791
1792
  let op = cmd.get("op").and_then(|v| v.as_str()).unwrap_or("");
1792
- if op != "externalView.evaluate" && op != "externalView.cdp" {
1793
+ let clear = cfg!(target_os = "linux") && op == "externalView.clearData";
1794
+ if op != "externalView.evaluate" && op != "externalView.cdp" && !clear {
1793
1795
  return false;
1794
1796
  }
1795
1797
  let started = (|| -> Result<(), String> {
1796
1798
  let view = cmd.get("view").and_then(|v| v.as_str()).ok_or("view must be a string")?;
1799
+ #[cfg(target_os = "linux")]
1800
+ if clear {
1801
+ return self.external.clear_data_then(view, move |result| reply(id, result));
1802
+ }
1797
1803
  if op == "externalView.evaluate" {
1798
1804
  let script = cmd.get("script").and_then(|v| v.as_str()).ok_or("script must be a string")?;
1799
1805
  //? Sent on as a JSON string: the engine's text is spliced into the reply, and not every engine's is JSON.
@@ -2145,6 +2151,8 @@ pub unsafe extern "C" fn akan_native_run(config_json: *const c_char) -> i32 {
2145
2151
  push_event(&format!(r#"{{"type":"window","event":"focused","window":{id},"value":{focused}}}"#));
2146
2152
  if focused {
2147
2153
  windows.focused(id);
2154
+ #[cfg(target_os = "linux")]
2155
+ windows.external.refocus(id);
2148
2156
  }
2149
2157
  }
2150
2158
  WindowEvent::Resized(_) => {