app.rs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use async_recursion::async_recursion;
  19. use chrono::{NaiveDate, NaiveDateTime};
  20. use darkfi_serial::Encodable;
  21. use futures::{stream::FuturesUnordered, StreamExt};
  22. use smol::Task;
  23. use std::{
  24. sync::{Arc, Mutex as SyncMutex},
  25. thread,
  26. };
  27. use crate::{
  28. error::Error,
  29. expr::Op,
  30. gfx2::{GraphicsEventPublisherPtr, RenderApiPtr, Vertex},
  31. prop::{Property, PropertyBool, PropertyStr, PropertySubType, PropertyType, Role},
  32. scene::{
  33. CallArgType, MethodResponseFn, Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId,
  34. SceneNodeType, Slot,
  35. },
  36. text2::TextShaperPtr,
  37. ui::{chatview, Button, ChatView, EditBox, Image, Mesh, RenderLayer, Stoppable, Text, Window},
  38. ExecutorPtr,
  39. DarkIrcBackendPtr,
  40. };
  41. //fn print_type_of<T>(_: &T) {
  42. // println!("{}", std::any::type_name::<T>())
  43. //}
  44. #[cfg(target_os = "android")]
  45. const CHATDB_PATH: &str = "/data/data/darkfi.darkwallet/chatdb/";
  46. #[cfg(target_os = "android")]
  47. //const KING_PATH: &str = "/data/data/darkfi.darkwallet/assets/king.png";
  48. const KING_PATH: &str = "king.png";
  49. #[cfg(target_os = "linux")]
  50. const CHATDB_PATH: &str = "chatdb";
  51. #[cfg(target_os = "linux")]
  52. const KING_PATH: &str = "assets/king.png";
  53. const LIGHTMODE: bool = false;
  54. pub struct AsyncRuntime {
  55. signal: async_channel::Sender<()>,
  56. shutdown: async_channel::Receiver<()>,
  57. exec_threadpool: SyncMutex<Option<thread::JoinHandle<()>>>,
  58. ex: ExecutorPtr,
  59. tasks: SyncMutex<Vec<Task<()>>>,
  60. }
  61. impl AsyncRuntime {
  62. pub fn new(ex: ExecutorPtr) -> Self {
  63. let (signal, shutdown) = async_channel::unbounded::<()>();
  64. Self {
  65. signal,
  66. shutdown,
  67. exec_threadpool: SyncMutex::new(None),
  68. ex,
  69. tasks: SyncMutex::new(vec![]),
  70. }
  71. }
  72. pub fn start(&self) {
  73. let n_threads = thread::available_parallelism().unwrap().get();
  74. let shutdown = self.shutdown.clone();
  75. let ex = self.ex.clone();
  76. let exec_threadpool = thread::spawn(move || {
  77. easy_parallel::Parallel::new()
  78. // N executor threads
  79. .each(0..n_threads, |_| smol::future::block_on(ex.run(shutdown.recv())))
  80. .run();
  81. });
  82. *self.exec_threadpool.lock().unwrap() = Some(exec_threadpool);
  83. debug!(target: "async_runtime", "Started runtime");
  84. }
  85. pub fn push_task(&self, task: Task<()>) {
  86. self.tasks.lock().unwrap().push(task);
  87. }
  88. pub fn stop(&self) {
  89. // Go through event graph and call stop on everything
  90. // Depth first
  91. debug!(target: "app", "Stopping async runtime...");
  92. let tasks = std::mem::take(&mut *self.tasks.lock().unwrap());
  93. // Close all tasks
  94. smol::future::block_on(async {
  95. // Perform cleanup code
  96. // If not finished in certain amount of time, then just exit
  97. let futures = FuturesUnordered::new();
  98. for task in tasks {
  99. futures.push(task.cancel());
  100. }
  101. let _: Vec<_> = futures.collect().await;
  102. });
  103. if !self.signal.close() {
  104. error!(target: "app", "exec threadpool was already shutdown");
  105. }
  106. let exec_threadpool = std::mem::replace(&mut *self.exec_threadpool.lock().unwrap(), None);
  107. let exec_threadpool = exec_threadpool.expect("threadpool wasnt started");
  108. exec_threadpool.join().unwrap();
  109. debug!(target: "app", "Stopped app");
  110. }
  111. }
  112. pub type AppPtr = Arc<App>;
  113. pub struct App {
  114. sg: SceneGraphPtr2,
  115. ex: ExecutorPtr,
  116. render_api: RenderApiPtr,
  117. event_pub: GraphicsEventPublisherPtr,
  118. text_shaper: TextShaperPtr,
  119. darkirc_backend: DarkIrcBackendPtr,
  120. tasks: SyncMutex<Vec<Task<()>>>,
  121. }
  122. impl App {
  123. pub fn new(
  124. sg: SceneGraphPtr2,
  125. ex: ExecutorPtr,
  126. render_api: RenderApiPtr,
  127. event_pub: GraphicsEventPublisherPtr,
  128. text_shaper: TextShaperPtr,
  129. darkirc_backend: DarkIrcBackendPtr,
  130. ) -> Arc<Self> {
  131. Arc::new(Self { sg, ex, render_api, event_pub, text_shaper, darkirc_backend, tasks: SyncMutex::new(vec![]) })
  132. }
  133. pub async fn start(self: Arc<Self>) {
  134. debug!(target: "app", "App::start()");
  135. // Setup UI
  136. let mut sg = self.sg.lock().await;
  137. let window = sg.add_node("window", SceneNodeType::Window);
  138. let mut prop = Property::new("screen_size", PropertyType::Float32, PropertySubType::Pixel);
  139. prop.set_array_len(2);
  140. // Window not yet initialized so we can't set these.
  141. //prop.set_f32(Role::App, 0, screen_width);
  142. //prop.set_f32(Role::App, 1, screen_height);
  143. window.add_property(prop).unwrap();
  144. let mut prop = Property::new("scale", PropertyType::Float32, PropertySubType::Pixel);
  145. prop.set_defaults_f32(vec![1.]).unwrap();
  146. window.add_property(prop).unwrap();
  147. let window_id = window.id;
  148. // Create Window
  149. // Window::new(window, weak sg)
  150. drop(sg);
  151. let pimpl = Window::new(
  152. self.ex.clone(),
  153. self.sg.clone(),
  154. window_id,
  155. self.render_api.clone(),
  156. self.event_pub.clone(),
  157. )
  158. .await;
  159. // -> reads any props it needs
  160. // -> starts procs
  161. let mut sg = self.sg.lock().await;
  162. let node = sg.get_node_mut(window_id).unwrap();
  163. node.pimpl = pimpl;
  164. sg.link(window_id, SceneGraph::ROOT_ID).unwrap();
  165. // Testing
  166. let node = sg.get_node(window_id).unwrap();
  167. node.set_property_f32(Role::App, "scale", 2.).unwrap();
  168. drop(sg);
  169. self.make_me_a_schema_plox().await;
  170. debug!(target: "app", "Schema loaded");
  171. // Access drawable in window node and call draw()
  172. self.trigger_redraw().await;
  173. // Start the backend
  174. //if let Err(err) = self.darkirc_backend.start(self.sg.clone(), self.ex.clone()).await {
  175. // error!(target: "app", "backend error: {err}");
  176. //}
  177. }
  178. pub fn stop(&self) {
  179. smol::future::block_on(async {
  180. self.async_stop().await;
  181. });
  182. }
  183. async fn async_stop(&self) {
  184. self.darkirc_backend.stop().await;
  185. let sg = self.sg.lock().await;
  186. let window_id = sg.lookup_node("/window").unwrap().id;
  187. self.stop_node(&sg, window_id).await;
  188. drop(sg);
  189. }
  190. #[async_recursion]
  191. async fn stop_node(&self, sg: &SceneGraph, node_id: SceneNodeId) {
  192. let node = sg.get_node(node_id).unwrap();
  193. for child_inf in node.get_children2() {
  194. self.stop_node(sg, child_inf.id).await;
  195. }
  196. match &node.pimpl {
  197. Pimpl::Window(win) => win.stop().await,
  198. Pimpl::RenderLayer(layer) => layer.stop().await,
  199. Pimpl::Mesh(mesh) => mesh.stop().await,
  200. Pimpl::Text(txt) => txt.stop().await,
  201. Pimpl::EditBox(ebox) => ebox.stop().await,
  202. Pimpl::ChatView(_) | Pimpl::Image(_) | Pimpl::Button(_) => {}
  203. _ => panic!("unhandled pimpl type"),
  204. };
  205. }
  206. async fn make_me_a_schema_plox(&self) {
  207. let mut tasks = vec![];
  208. // Create a layer called view
  209. let mut sg = self.sg.lock().await;
  210. let layer_node_id = create_layer(&mut sg, "view");
  211. // Customize our layer
  212. let node = sg.get_node(layer_node_id).unwrap();
  213. let prop = node.get_property("rect").unwrap();
  214. prop.set_f32(Role::App, 0, 0.).unwrap();
  215. prop.set_f32(Role::App, 1, 0.).unwrap();
  216. let code = vec![Op::LoadVar("w".to_string())];
  217. prop.set_expr(Role::App, 2, code).unwrap();
  218. let code = vec![Op::LoadVar("h".to_string())];
  219. prop.set_expr(Role::App, 3, code).unwrap();
  220. node.set_property_bool(Role::App, "is_visible", true).unwrap();
  221. // Setup the pimpl
  222. let node_id = node.id;
  223. drop(sg);
  224. let pimpl =
  225. RenderLayer::new(self.ex.clone(), self.sg.clone(), node_id, self.render_api.clone())
  226. .await;
  227. let mut sg = self.sg.lock().await;
  228. let node = sg.get_node_mut(node_id).unwrap();
  229. node.pimpl = pimpl;
  230. let window_id = sg.lookup_node("/window").unwrap().id;
  231. sg.link(node_id, window_id).unwrap();
  232. // Create a bg mesh
  233. let node_id = create_mesh(&mut sg, "bg");
  234. let node = sg.get_node_mut(node_id).unwrap();
  235. let prop = node.get_property("rect").unwrap();
  236. prop.set_f32(Role::App, 0, 0.).unwrap();
  237. prop.set_f32(Role::App, 1, 0.).unwrap();
  238. let code = vec![Op::LoadVar("w".to_string())];
  239. prop.set_expr(Role::App, 2, code).unwrap();
  240. let code = vec![Op::LoadVar("h".to_string())];
  241. prop.set_expr(Role::App, 3, code).unwrap();
  242. let c = if LIGHTMODE { 1. } else { 0. };
  243. // Setup the pimpl
  244. let node_id = node.id;
  245. let (x1, y1) = (0., 0.);
  246. let (x2, y2) = (1., 1.);
  247. let verts = vec![
  248. // top left
  249. Vertex { pos: [x1, y1], color: [c, c, c, 1.], uv: [0., 0.] },
  250. // top right
  251. Vertex { pos: [x2, y1], color: [c, c, c, 1.], uv: [1., 0.] },
  252. // bottom left
  253. Vertex { pos: [x1, y2], color: [c, c, c, 1.], uv: [0., 1.] },
  254. // bottom right
  255. Vertex { pos: [x2, y2], color: [c, c, c, 1.], uv: [1., 1.] },
  256. ];
  257. let indices = vec![0, 2, 1, 1, 2, 3];
  258. drop(sg);
  259. let pimpl = Mesh::new(
  260. self.ex.clone(),
  261. self.sg.clone(),
  262. node_id,
  263. self.render_api.clone(),
  264. verts,
  265. indices,
  266. )
  267. .await;
  268. let mut sg = self.sg.lock().await;
  269. let node = sg.get_node_mut(node_id).unwrap();
  270. node.pimpl = pimpl;
  271. sg.link(node_id, layer_node_id).unwrap();
  272. // Create button bg
  273. let node_id = create_mesh(&mut sg, "btnbg");
  274. let node = sg.get_node_mut(node_id).unwrap();
  275. let prop = node.get_property("rect").unwrap();
  276. let code = vec![Op::Sub((
  277. Box::new(Op::LoadVar("w".to_string())),
  278. Box::new(Op::ConstFloat32(220.)),
  279. ))];
  280. prop.set_expr(Role::App, 0, code).unwrap();
  281. prop.set_f32(Role::App, 1, 10.).unwrap();
  282. prop.set_f32(Role::App, 2, 200.).unwrap();
  283. prop.set_f32(Role::App, 3, 60.).unwrap();
  284. // Setup the pimpl
  285. let (x1, y1) = (0., 0.);
  286. let (x2, y2) = (1., 1.);
  287. let verts = if LIGHTMODE {
  288. vec![
  289. // top left
  290. Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
  291. // top right
  292. Vertex { pos: [x2, y1], color: [1., 0., 0., 1.], uv: [1., 0.] },
  293. // bottom left
  294. Vertex { pos: [x1, y2], color: [1., 0., 0., 1.], uv: [0., 1.] },
  295. // bottom right
  296. Vertex { pos: [x2, y2], color: [1., 0., 0., 1.], uv: [1., 1.] },
  297. ]
  298. } else {
  299. vec![
  300. // top left
  301. Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
  302. // top right
  303. Vertex { pos: [x2, y1], color: [1., 0., 1., 1.], uv: [1., 0.] },
  304. // bottom left
  305. Vertex { pos: [x1, y2], color: [0., 0., 1., 1.], uv: [0., 1.] },
  306. // bottom right
  307. Vertex { pos: [x2, y2], color: [1., 1., 0., 1.], uv: [1., 1.] },
  308. ]
  309. };
  310. let indices = vec![0, 2, 1, 1, 2, 3];
  311. drop(sg);
  312. let pimpl = Mesh::new(
  313. self.ex.clone(),
  314. self.sg.clone(),
  315. node_id,
  316. self.render_api.clone(),
  317. verts,
  318. indices,
  319. )
  320. .await;
  321. let mut sg = self.sg.lock().await;
  322. let node = sg.get_node_mut(node_id).unwrap();
  323. node.pimpl = pimpl;
  324. sg.link(node_id, layer_node_id).unwrap();
  325. // Create the button
  326. let node_id = create_button(&mut sg, "btn");
  327. let node = sg.get_node_mut(node_id).unwrap();
  328. node.set_property_bool(Role::App, "is_active", true).unwrap();
  329. let prop = node.get_property("rect").unwrap();
  330. let code = vec![Op::Sub((
  331. Box::new(Op::LoadVar("w".to_string())),
  332. Box::new(Op::ConstFloat32(220.)),
  333. ))];
  334. prop.set_expr(Role::App, 0, code).unwrap();
  335. prop.set_f32(Role::App, 1, 10.).unwrap();
  336. prop.set_f32(Role::App, 2, 200.).unwrap();
  337. prop.set_f32(Role::App, 3, 60.).unwrap();
  338. let (sender, btn_click_recvr) = async_channel::unbounded();
  339. let slot_click = Slot { name: "button_clicked".to_string(), notify: sender };
  340. node.register("click", slot_click).unwrap();
  341. drop(sg);
  342. let pimpl =
  343. Button::new(self.ex.clone(), self.sg.clone(), node_id, self.event_pub.clone()).await;
  344. let mut sg = self.sg.lock().await;
  345. let node = sg.get_node_mut(node_id).unwrap();
  346. node.pimpl = pimpl;
  347. sg.link(node_id, layer_node_id).unwrap();
  348. // Create another mesh
  349. let node_id = create_mesh(&mut sg, "box");
  350. let node = sg.get_node_mut(node_id).unwrap();
  351. let prop = node.get_property("rect").unwrap();
  352. prop.set_f32(Role::App, 0, 10.).unwrap();
  353. prop.set_f32(Role::App, 1, 10.).unwrap();
  354. prop.set_f32(Role::App, 2, 60.).unwrap();
  355. prop.set_f32(Role::App, 3, 60.).unwrap();
  356. // Setup the pimpl
  357. let (x1, y1) = (0., 0.);
  358. let (x2, y2) = (1., 1.);
  359. let verts = if LIGHTMODE {
  360. vec![
  361. // top left
  362. Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
  363. // top right
  364. Vertex { pos: [x2, y1], color: [1., 0., 0., 1.], uv: [1., 0.] },
  365. // bottom left
  366. Vertex { pos: [x1, y2], color: [1., 0., 0., 1.], uv: [0., 1.] },
  367. // bottom right
  368. Vertex { pos: [x2, y2], color: [1., 0., 0., 1.], uv: [1., 1.] },
  369. ]
  370. } else {
  371. vec![
  372. // top left
  373. Vertex { pos: [x1, y1], color: [1., 0., 0., 1.], uv: [0., 0.] },
  374. // top right
  375. Vertex { pos: [x2, y1], color: [1., 0., 1., 1.], uv: [1., 0.] },
  376. // bottom left
  377. Vertex { pos: [x1, y2], color: [0., 0., 1., 1.], uv: [0., 1.] },
  378. // bottom right
  379. Vertex { pos: [x2, y2], color: [1., 1., 0., 1.], uv: [1., 1.] },
  380. ]
  381. };
  382. let indices = vec![0, 2, 1, 1, 2, 3];
  383. drop(sg);
  384. let pimpl = Mesh::new(
  385. self.ex.clone(),
  386. self.sg.clone(),
  387. node_id,
  388. self.render_api.clone(),
  389. verts,
  390. indices,
  391. )
  392. .await;
  393. let mut sg = self.sg.lock().await;
  394. let node = sg.get_node_mut(node_id).unwrap();
  395. node.pimpl = pimpl;
  396. sg.link(node_id, layer_node_id).unwrap();
  397. // Debugging tool
  398. let node_id = create_mesh(&mut sg, "debugtool");
  399. let node = sg.get_node_mut(node_id).unwrap();
  400. let prop = node.get_property("rect").unwrap();
  401. prop.set_f32(Role::App, 0, 0.).unwrap();
  402. let code =
  403. vec![Op::Div((Box::new(Op::LoadVar("h".to_string())), Box::new(Op::ConstFloat32(2.))))];
  404. prop.set_expr(Role::App, 1, code).unwrap();
  405. let code = vec![Op::LoadVar("w".to_string())];
  406. prop.set_expr(Role::App, 2, code).unwrap();
  407. prop.set_f32(Role::App, 3, 5.).unwrap();
  408. node.set_property_u32(Role::App, "z_index", 2).unwrap();
  409. // Setup the pimpl
  410. let (x1, y1) = (0., 0.);
  411. let (x2, y2) = (1., 1.);
  412. let verts = vec![
  413. // top left
  414. Vertex { pos: [x1, y1], color: [0., 1., 0., 1.], uv: [0., 0.] },
  415. // top right
  416. Vertex { pos: [x2, y1], color: [0., 1., 0., 1.], uv: [1., 0.] },
  417. // bottom left
  418. Vertex { pos: [x1, y2], color: [0., 1., 0., 1.], uv: [0., 1.] },
  419. // bottom right
  420. Vertex { pos: [x2, y2], color: [0., 1., 0., 1.], uv: [1., 1.] },
  421. ];
  422. let indices = vec![0, 2, 1, 1, 2, 3];
  423. drop(sg);
  424. let pimpl = Mesh::new(
  425. self.ex.clone(),
  426. self.sg.clone(),
  427. node_id,
  428. self.render_api.clone(),
  429. verts,
  430. indices,
  431. )
  432. .await;
  433. let mut sg = self.sg.lock().await;
  434. let node = sg.get_node_mut(node_id).unwrap();
  435. node.pimpl = pimpl;
  436. sg.link(node_id, layer_node_id).unwrap();
  437. // Debugging tool
  438. let node_id = create_mesh(&mut sg, "debugtool2");
  439. let node = sg.get_node_mut(node_id).unwrap();
  440. let prop = node.get_property("rect").unwrap();
  441. prop.set_f32(Role::App, 0, 0.).unwrap();
  442. let code = vec![Op::Sub((
  443. Box::new(Op::LoadVar("h".to_string())),
  444. Box::new(Op::ConstFloat32(200.)),
  445. ))];
  446. prop.set_expr(Role::App, 1, code).unwrap();
  447. let code = vec![Op::LoadVar("w".to_string())];
  448. prop.set_expr(Role::App, 2, code).unwrap();
  449. prop.set_f32(Role::App, 3, 5.).unwrap();
  450. node.set_property_u32(Role::App, "z_index", 2).unwrap();
  451. // Setup the pimpl
  452. let (x1, y1) = (0., 0.);
  453. let (x2, y2) = (1., 1.);
  454. let verts = vec![
  455. // top left
  456. Vertex { pos: [x1, y1], color: [0., 1., 0., 1.], uv: [0., 0.] },
  457. // top right
  458. Vertex { pos: [x2, y1], color: [0., 1., 0., 1.], uv: [1., 0.] },
  459. // bottom left
  460. Vertex { pos: [x1, y2], color: [0., 1., 0., 1.], uv: [0., 1.] },
  461. // bottom right
  462. Vertex { pos: [x2, y2], color: [0., 1., 0., 1.], uv: [1., 1.] },
  463. ];
  464. let indices = vec![0, 2, 1, 1, 2, 3];
  465. drop(sg);
  466. let pimpl = Mesh::new(
  467. self.ex.clone(),
  468. self.sg.clone(),
  469. node_id,
  470. self.render_api.clone(),
  471. verts,
  472. indices,
  473. )
  474. .await;
  475. let mut sg = self.sg.lock().await;
  476. let node = sg.get_node_mut(node_id).unwrap();
  477. node.pimpl = pimpl;
  478. sg.link(node_id, layer_node_id).unwrap();
  479. // Create KING GNU!
  480. let node_id = create_image(&mut sg, "king");
  481. let node = sg.get_node_mut(node_id).unwrap();
  482. let prop = node.get_property("rect").unwrap();
  483. prop.set_f32(Role::App, 0, 80.).unwrap();
  484. prop.set_f32(Role::App, 1, 10.).unwrap();
  485. prop.set_f32(Role::App, 2, 60.).unwrap();
  486. prop.set_f32(Role::App, 3, 60.).unwrap();
  487. node.set_property_str(Role::App, "path", KING_PATH).unwrap();
  488. // Setup the pimpl
  489. drop(sg);
  490. let pimpl =
  491. Image::new(self.ex.clone(), self.sg.clone(), node_id, self.render_api.clone()).await;
  492. let mut sg = self.sg.lock().await;
  493. let node = sg.get_node_mut(node_id).unwrap();
  494. node.pimpl = pimpl;
  495. sg.link(node_id, layer_node_id).unwrap();
  496. // Create some text
  497. let node_id = create_text(&mut sg, "label");
  498. let node = sg.get_node_mut(node_id).unwrap();
  499. let prop = node.get_property("rect").unwrap();
  500. prop.set_f32(Role::App, 0, 100.).unwrap();
  501. prop.set_f32(Role::App, 1, 100.).unwrap();
  502. prop.set_f32(Role::App, 2, 800.).unwrap();
  503. prop.set_f32(Role::App, 3, 200.).unwrap();
  504. node.set_property_f32(Role::App, "baseline", 40.).unwrap();
  505. node.set_property_f32(Role::App, "font_size", 60.).unwrap();
  506. node.set_property_str(Role::App, "text", "anon1🍆").unwrap();
  507. //node.set_property_str(Role::App, "text", "anon1").unwrap();
  508. let prop = node.get_property("text_color").unwrap();
  509. prop.set_f32(Role::App, 0, 0.).unwrap();
  510. prop.set_f32(Role::App, 1, 1.).unwrap();
  511. prop.set_f32(Role::App, 2, 0.).unwrap();
  512. prop.set_f32(Role::App, 3, 1.).unwrap();
  513. drop(sg);
  514. let pimpl = Text::new(
  515. self.ex.clone(),
  516. self.sg.clone(),
  517. node_id,
  518. self.render_api.clone(),
  519. self.text_shaper.clone(),
  520. )
  521. .await;
  522. let mut sg = self.sg.lock().await;
  523. let node = sg.get_node_mut(node_id).unwrap();
  524. node.pimpl = pimpl;
  525. sg.link(node_id, layer_node_id).unwrap();
  526. // Text edit
  527. let node_id = create_editbox(&mut sg, "editz");
  528. let node = sg.get_node(node_id).unwrap();
  529. node.set_property_bool(Role::App, "is_active", true).unwrap();
  530. let prop = node.get_property("rect").unwrap();
  531. prop.set_f32(Role::App, 0, 150.).unwrap();
  532. prop.set_f32(Role::App, 1, 150.).unwrap();
  533. prop.set_f32(Role::App, 2, 380.).unwrap();
  534. //let code = vec![Op::Sub((
  535. // Box::new(Op::LoadVar("h".to_string())),
  536. // Box::new(Op::ConstFloat32(60.)),
  537. //))];
  538. //prop.set_expr(Role::App, 1, code).unwrap();
  539. //let code = vec![Op::Sub((
  540. // Box::new(Op::LoadVar("w".to_string())),
  541. // Box::new(Op::ConstFloat32(120.)),
  542. //))];
  543. //prop.set_expr(Role::App, 2, code).unwrap();
  544. prop.set_f32(Role::App, 3, 60.).unwrap();
  545. node.set_property_f32(Role::App, "baseline", 40.).unwrap();
  546. node.set_property_f32(Role::App, "font_size", 20.).unwrap();
  547. node.set_property_f32(Role::App, "font_size", 40.).unwrap();
  548. node.set_property_str(Role::App, "text", "hello king!😁🍆jelly 🍆1234").unwrap();
  549. let prop = node.get_property("text_color").unwrap();
  550. if LIGHTMODE {
  551. prop.set_f32(Role::App, 0, 0.).unwrap();
  552. prop.set_f32(Role::App, 1, 0.).unwrap();
  553. prop.set_f32(Role::App, 2, 0.).unwrap();
  554. prop.set_f32(Role::App, 3, 1.).unwrap();
  555. } else {
  556. prop.set_f32(Role::App, 0, 1.).unwrap();
  557. prop.set_f32(Role::App, 1, 1.).unwrap();
  558. prop.set_f32(Role::App, 2, 1.).unwrap();
  559. prop.set_f32(Role::App, 3, 1.).unwrap();
  560. }
  561. let prop = node.get_property("cursor_color").unwrap();
  562. prop.set_f32(Role::App, 0, 1.).unwrap();
  563. prop.set_f32(Role::App, 1, 0.5).unwrap();
  564. prop.set_f32(Role::App, 2, 0.5).unwrap();
  565. prop.set_f32(Role::App, 3, 1.).unwrap();
  566. let prop = node.get_property("hi_bg_color").unwrap();
  567. if LIGHTMODE {
  568. prop.set_f32(Role::App, 0, 0.5).unwrap();
  569. prop.set_f32(Role::App, 1, 0.5).unwrap();
  570. prop.set_f32(Role::App, 2, 0.5).unwrap();
  571. prop.set_f32(Role::App, 3, 1.).unwrap();
  572. } else {
  573. prop.set_f32(Role::App, 0, 1.).unwrap();
  574. prop.set_f32(Role::App, 1, 1.).unwrap();
  575. prop.set_f32(Role::App, 2, 1.).unwrap();
  576. prop.set_f32(Role::App, 3, 0.5).unwrap();
  577. }
  578. let prop = node.get_property("selected").unwrap();
  579. prop.set_null(Role::App, 0).unwrap();
  580. prop.set_null(Role::App, 1).unwrap();
  581. node.set_property_u32(Role::App, "z_index", 1).unwrap();
  582. //node.set_property_bool(Role::App, "debug", true).unwrap();
  583. let editbox_text = PropertyStr::wrap(node, Role::App, "text", 0).unwrap();
  584. let editbox_focus = PropertyBool::wrap(node, Role::App, "is_focused", 0).unwrap();
  585. let task = self.ex.spawn(async move {
  586. while let Ok(_) = btn_click_recvr.recv().await {
  587. let text = editbox_text.get();
  588. editbox_text.prop().unset(Role::App, 0).unwrap();
  589. // Clicking outside the editbox makes it lose focus
  590. // So lets focus it again
  591. editbox_focus.set(true);
  592. debug!(target: "app", "sending text {text}");
  593. }
  594. });
  595. tasks.push(task);
  596. drop(sg);
  597. let pimpl = EditBox::new(
  598. self.ex.clone(),
  599. self.sg.clone(),
  600. node_id,
  601. self.render_api.clone(),
  602. self.event_pub.clone(),
  603. self.text_shaper.clone(),
  604. )
  605. .await;
  606. let mut sg = self.sg.lock().await;
  607. let node = sg.get_node_mut(node_id).unwrap();
  608. node.pimpl = pimpl;
  609. sg.link(node_id, layer_node_id).unwrap();
  610. // ChatView
  611. let (node_id, recvr) = create_chatview(&mut sg, "chatty");
  612. let node = sg.get_node(node_id).unwrap();
  613. let prop = node.get_property("rect").unwrap();
  614. prop.set_f32(Role::App, 0, 0.).unwrap();
  615. let code =
  616. vec![Op::Div((Box::new(Op::LoadVar("h".to_string())), Box::new(Op::ConstFloat32(2.))))];
  617. prop.set_expr(Role::App, 1, code).unwrap();
  618. let code = vec![Op::LoadVar("w".to_string())];
  619. prop.set_expr(Role::App, 2, code).unwrap();
  620. let code = vec![Op::Sub((
  621. Box::new(Op::Div((
  622. Box::new(Op::LoadVar("h".to_string())),
  623. Box::new(Op::ConstFloat32(2.)),
  624. ))),
  625. Box::new(Op::ConstFloat32(200.)),
  626. ))];
  627. prop.set_expr(Role::App, 3, code).unwrap();
  628. node.set_property_f32(Role::App, "font_size", 20.).unwrap();
  629. node.set_property_f32(Role::App, "line_height", 30.).unwrap();
  630. node.set_property_f32(Role::App, "baseline", 20.).unwrap();
  631. node.set_property_u32(Role::App, "z_index", 1).unwrap();
  632. //node.set_property_bool(Role::App, "debug", true).unwrap();
  633. let prop = node.get_property("timestamp_color").unwrap();
  634. prop.set_f32(Role::App, 0, 0.5).unwrap();
  635. prop.set_f32(Role::App, 1, 0.5).unwrap();
  636. prop.set_f32(Role::App, 2, 0.5).unwrap();
  637. prop.set_f32(Role::App, 3, 0.5).unwrap();
  638. let prop = node.get_property("text_color").unwrap();
  639. if LIGHTMODE {
  640. prop.set_f32(Role::App, 0, 0.).unwrap();
  641. prop.set_f32(Role::App, 1, 0.).unwrap();
  642. prop.set_f32(Role::App, 2, 0.).unwrap();
  643. prop.set_f32(Role::App, 3, 1.).unwrap();
  644. } else {
  645. prop.set_f32(Role::App, 0, 1.).unwrap();
  646. prop.set_f32(Role::App, 1, 1.).unwrap();
  647. prop.set_f32(Role::App, 2, 1.).unwrap();
  648. prop.set_f32(Role::App, 3, 1.).unwrap();
  649. }
  650. let prop = node.get_property("nick_colors").unwrap();
  651. #[rustfmt::skip]
  652. let nick_colors = [
  653. 0.00, 0.94, 1.00, 1.,
  654. 0.36, 1.00, 0.69, 1.,
  655. 0.29, 1.00, 0.45, 1.,
  656. 0.00, 0.73, 0.38, 1.,
  657. 0.21, 0.67, 0.67, 1.,
  658. 0.56, 0.61, 1.00, 1.,
  659. 0.84, 0.48, 1.00, 1.,
  660. 1.00, 0.61, 0.94, 1.,
  661. 1.00, 0.36, 0.48, 1.,
  662. 1.00, 0.30, 0.00, 1.
  663. ];
  664. for c in nick_colors {
  665. prop.push_f32(Role::App, c).unwrap();
  666. }
  667. drop(sg);
  668. let db = sled::open(CHATDB_PATH).expect("cannot open sleddb");
  669. let chat_tree = db.open_tree(b"chat").unwrap();
  670. //if chat_tree.is_empty() {
  671. // populate_tree(&chat_tree);
  672. //}
  673. debug!(target: "app", "db has {} lines", chat_tree.len());
  674. let pimpl = ChatView::new(
  675. self.ex.clone(),
  676. self.sg.clone(),
  677. node_id,
  678. self.render_api.clone(),
  679. self.event_pub.clone(),
  680. self.text_shaper.clone(),
  681. chat_tree,
  682. recvr,
  683. )
  684. .await;
  685. let mut sg = self.sg.lock().await;
  686. let node = sg.get_node_mut(node_id).unwrap();
  687. node.pimpl = pimpl;
  688. sg.link(node_id, layer_node_id).unwrap();
  689. // On android lets scale the UI up
  690. // TODO: add support for fractional scaling
  691. // This also affects mouse/touch input since coords need to be accurately translated
  692. // Also we need to think about nesting of layers.
  693. //let window_node = sg.get_node_mut(window_id).unwrap();
  694. //win_node.set_property_f32(Role::App, "scale", 1.6).unwrap();
  695. *self.tasks.lock().unwrap() = tasks;
  696. }
  697. async fn trigger_redraw(&self) {
  698. let sg = self.sg.lock().await;
  699. let window_node = sg.lookup_node("/window").expect("no window attached!");
  700. match &window_node.pimpl {
  701. Pimpl::Window(win) => win.draw(&sg).await,
  702. _ => panic!("wrong pimpl"),
  703. }
  704. }
  705. }
  706. impl Drop for App {
  707. fn drop(&mut self) {
  708. debug!(target: "app", "dropping app");
  709. self.stop();
  710. }
  711. }
  712. // Just for testing
  713. fn populate_tree(tree: &sled::Tree) {
  714. let chat_txt = include_str!("../chat.txt");
  715. for line in chat_txt.lines() {
  716. let parts: Vec<&str> = line.splitn(3, ' ').collect();
  717. assert_eq!(parts.len(), 3);
  718. let time_parts: Vec<&str> = parts[0].splitn(2, ':').collect();
  719. let (hour, min) = (time_parts[0], time_parts[1]);
  720. let hour = hour.parse::<u32>().unwrap();
  721. let min = min.parse::<u32>().unwrap();
  722. let dt: NaiveDateTime =
  723. NaiveDate::from_ymd_opt(2024, 8, 6).unwrap().and_hms_opt(hour, min, 0).unwrap();
  724. let timest = dt.and_utc().timestamp() as u64;
  725. let message_id = [0u8; 32];
  726. let nick = parts[1].to_string();
  727. let text = parts[2].to_string();
  728. // serial order is important here
  729. let timest = timest.to_be_bytes();
  730. assert_eq!(timest.len(), 8);
  731. let mut key = [0u8; 8 + 32];
  732. key[..8].clone_from_slice(&timest);
  733. let msg = chatview::ChatMsg { nick, text };
  734. let mut val = vec![];
  735. msg.encode(&mut val).unwrap();
  736. tree.insert(&key, val).unwrap();
  737. }
  738. // O(n)
  739. debug!(target: "app", "populated db with {} lines", tree.len());
  740. }
  741. pub fn create_layer(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  742. debug!(target: "app", "create_layer({name})");
  743. let node = sg.add_node(name, SceneNodeType::RenderLayer);
  744. let prop = Property::new("is_visible", PropertyType::Bool, PropertySubType::Null);
  745. node.add_property(prop).unwrap();
  746. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  747. prop.set_array_len(4);
  748. prop.allow_exprs();
  749. node.add_property(prop).unwrap();
  750. node.id
  751. }
  752. pub fn create_mesh(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  753. debug!(target: "app", "create_mesh({name})");
  754. let node = sg.add_node(name, SceneNodeType::RenderMesh);
  755. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  756. prop.set_array_len(4);
  757. prop.allow_exprs();
  758. node.add_property(prop).unwrap();
  759. let prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
  760. node.add_property(prop).unwrap();
  761. node.id
  762. }
  763. pub fn create_button(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  764. debug!(target: "app", "create_button({name})");
  765. let node = sg.add_node(name, SceneNodeType::Button);
  766. let mut prop = Property::new("is_active", PropertyType::Bool, PropertySubType::Null);
  767. prop.set_ui_text("Is Active", "An active Button can be clicked");
  768. node.add_property(prop).unwrap();
  769. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  770. prop.set_array_len(4);
  771. prop.allow_exprs();
  772. node.add_property(prop).unwrap();
  773. node.add_signal("click", "Button clicked event", vec![]).unwrap();
  774. node.id
  775. }
  776. pub fn create_image(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  777. debug!(target: "app", "create_image({name})");
  778. let node = sg.add_node(name, SceneNodeType::RenderMesh);
  779. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  780. prop.set_array_len(4);
  781. prop.allow_exprs();
  782. node.add_property(prop).unwrap();
  783. let prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
  784. node.add_property(prop).unwrap();
  785. let prop = Property::new("path", PropertyType::Str, PropertySubType::Null);
  786. node.add_property(prop).unwrap();
  787. node.id
  788. }
  789. fn create_text(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  790. debug!(target: "app", "create_text({name})");
  791. let node = sg.add_node(name, SceneNodeType::RenderText);
  792. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  793. prop.set_array_len(4);
  794. prop.allow_exprs();
  795. node.add_property(prop).unwrap();
  796. let prop = Property::new("baseline", PropertyType::Float32, PropertySubType::Pixel);
  797. node.add_property(prop).unwrap();
  798. let prop = Property::new("font_size", PropertyType::Float32, PropertySubType::Pixel);
  799. node.add_property(prop).unwrap();
  800. let prop = Property::new("text", PropertyType::Str, PropertySubType::Null);
  801. node.add_property(prop).unwrap();
  802. let mut prop = Property::new("text_color", PropertyType::Float32, PropertySubType::Color);
  803. prop.set_array_len(4);
  804. prop.set_range_f32(0., 1.);
  805. node.add_property(prop).unwrap();
  806. let prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
  807. node.add_property(prop).unwrap();
  808. let prop = Property::new("debug", PropertyType::Bool, PropertySubType::Null);
  809. node.add_property(prop).unwrap();
  810. node.id
  811. }
  812. fn create_editbox(sg: &mut SceneGraph, name: &str) -> SceneNodeId {
  813. debug!(target: "app", "create_editbox({name})");
  814. let node = sg.add_node(name, SceneNodeType::EditBox);
  815. let mut prop = Property::new("is_active", PropertyType::Bool, PropertySubType::Null);
  816. prop.set_ui_text("Is Active", "An active EditBox can be focused");
  817. node.add_property(prop).unwrap();
  818. let mut prop = Property::new("is_focused", PropertyType::Bool, PropertySubType::Null);
  819. prop.set_ui_text("Is Focused", "A focused EditBox receives input");
  820. node.add_property(prop).unwrap();
  821. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  822. prop.set_array_len(4);
  823. prop.allow_exprs();
  824. node.add_property(prop).unwrap();
  825. let mut prop = Property::new("baseline", PropertyType::Float32, PropertySubType::Pixel);
  826. node.add_property(prop).unwrap();
  827. let mut prop = Property::new("scroll", PropertyType::Float32, PropertySubType::Pixel);
  828. prop.set_range_f32(0., f32::MAX);
  829. node.add_property(prop).unwrap();
  830. let mut prop = Property::new("cursor_pos", PropertyType::Uint32, PropertySubType::Pixel);
  831. prop.set_range_u32(0, u32::MAX);
  832. node.add_property(prop).unwrap();
  833. let mut prop = Property::new("font_size", PropertyType::Float32, PropertySubType::Pixel);
  834. node.add_property(prop).unwrap();
  835. let mut prop = Property::new("text", PropertyType::Str, PropertySubType::Null);
  836. node.add_property(prop).unwrap();
  837. let mut prop = Property::new("text_color", PropertyType::Float32, PropertySubType::Color);
  838. prop.set_array_len(4);
  839. prop.set_range_f32(0., 1.);
  840. node.add_property(prop).unwrap();
  841. let mut prop = Property::new("cursor_color", PropertyType::Float32, PropertySubType::Color);
  842. prop.set_array_len(4);
  843. prop.set_range_f32(0., 1.);
  844. node.add_property(prop).unwrap();
  845. let mut prop = Property::new("hi_bg_color", PropertyType::Float32, PropertySubType::Color);
  846. prop.set_array_len(4);
  847. prop.set_range_f32(0., 1.);
  848. node.add_property(prop).unwrap();
  849. let mut prop = Property::new("selected", PropertyType::Uint32, PropertySubType::Color);
  850. prop.set_array_len(2);
  851. prop.allow_null_values();
  852. node.add_property(prop).unwrap();
  853. let mut prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
  854. node.add_property(prop).unwrap();
  855. let mut prop = Property::new("debug", PropertyType::Bool, PropertySubType::Null);
  856. node.add_property(prop).unwrap();
  857. node.id
  858. }
  859. fn create_chatview(
  860. sg: &mut SceneGraph,
  861. name: &str,
  862. ) -> (SceneNodeId, async_channel::Receiver<Vec<u8>>) {
  863. debug!(target: "app", "create_chatview({name})");
  864. let node = sg.add_node(name, SceneNodeType::ChatView);
  865. let mut prop = Property::new("rect", PropertyType::Float32, PropertySubType::Pixel);
  866. prop.set_array_len(4);
  867. prop.allow_exprs();
  868. node.add_property(prop).unwrap();
  869. let mut prop = Property::new("scroll", PropertyType::Float32, PropertySubType::Null);
  870. prop.set_ui_text("Scroll", "Scroll up from the bottom");
  871. prop.set_range_f32(0., f32::MAX);
  872. node.add_property(prop).unwrap();
  873. let prop = Property::new("font_size", PropertyType::Float32, PropertySubType::Pixel);
  874. node.add_property(prop).unwrap();
  875. let prop = Property::new("line_height", PropertyType::Float32, PropertySubType::Pixel);
  876. node.add_property(prop).unwrap();
  877. let mut prop = Property::new("timestamp_color", PropertyType::Float32, PropertySubType::Color);
  878. prop.set_array_len(4);
  879. prop.set_range_f32(0., 1.);
  880. node.add_property(prop).unwrap();
  881. let mut prop = Property::new("text_color", PropertyType::Float32, PropertySubType::Color);
  882. prop.set_array_len(4);
  883. prop.set_range_f32(0., 1.);
  884. node.add_property(prop).unwrap();
  885. let mut prop = Property::new("nick_colors", PropertyType::Float32, PropertySubType::Pixel);
  886. prop.set_unbounded();
  887. prop.set_range_f32(0., 1.);
  888. node.add_property(prop).unwrap();
  889. let prop = Property::new("baseline", PropertyType::Float32, PropertySubType::Pixel);
  890. node.add_property(prop).unwrap();
  891. let mut prop = Property::new("z_index", PropertyType::Uint32, PropertySubType::Null);
  892. node.add_property(prop).unwrap();
  893. let mut prop = Property::new("debug", PropertyType::Bool, PropertySubType::Null);
  894. node.add_property(prop).unwrap();
  895. let mut prop =
  896. Property::new("mouse_scroll_start_accel", PropertyType::Float32, PropertySubType::Pixel);
  897. prop.set_ui_text("Mouse Scroll Start Acceleration", "Initial acceperation when scrolling");
  898. prop.set_defaults_f32(vec![4.]).unwrap();
  899. node.add_property(prop).unwrap();
  900. let mut prop =
  901. Property::new("mouse_scroll_decel", PropertyType::Float32, PropertySubType::Pixel);
  902. prop.set_ui_text(
  903. "Mouse Scroll Deceleration",
  904. "Deceleration factor for mouse scroll acceleration",
  905. );
  906. prop.set_range_f32(0., 1.);
  907. prop.set_defaults_f32(vec![0.5]).unwrap();
  908. node.add_property(prop).unwrap();
  909. let mut prop =
  910. Property::new("mouse_scroll_resist", PropertyType::Float32, PropertySubType::Pixel);
  911. prop.set_ui_text("Mouse Scroll Resistance", "How quickly scrolling speed is dampened");
  912. prop.set_range_f32(0., 1.);
  913. prop.set_defaults_f32(vec![0.9]).unwrap();
  914. node.add_property(prop).unwrap();
  915. let (sender, recvr) = async_channel::unbounded::<Vec<u8>>();
  916. let method = move |data: Vec<u8>, response_fn: MethodResponseFn| {
  917. if sender.try_send(data).is_err() {
  918. response_fn(Err(Error::ChannelClosed));
  919. } else {
  920. response_fn(Ok(vec![]));
  921. }
  922. };
  923. node.add_method(
  924. "insert_line",
  925. vec![
  926. ("timestamp", "Timestamp", CallArgType::Uint64),
  927. ("id", "Message ID", CallArgType::Hash),
  928. ("nick", "Nickname", CallArgType::Str),
  929. ("text", "Text", CallArgType::Str),
  930. ],
  931. vec![],
  932. Box::new(method),
  933. )
  934. .unwrap();
  935. (node.id, recvr)
  936. }