From 36e7798d61dd2026bbb123d8a37070434575de34 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Tue, 19 Dec 2023 19:28:57 +1100 Subject: [PATCH] display sigchat device linking qr-code --- apps/sigchat/locales/i18n.json | 4 ++-- apps/sigchat/src/manager.rs | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/apps/sigchat/locales/i18n.json b/apps/sigchat/locales/i18n.json index 3d9df3197..a7a03527e 100644 --- a/apps/sigchat/locales/i18n.json +++ b/apps/sigchat/locales/i18n.json @@ -20,8 +20,8 @@ "en-tts": "Please provide a name for this device" }, "sigchat.account.link.scan": { - "en": "Please scan with primary Signal device", - "en-tts": "Please scan with primary Signal device" + "en": "Please scan with primary Signal device, and then", + "en-tts": "Please scan with primary Signal device, and then" }, "sigchat.account.offline": { "en": "Read Signal offline", diff --git a/apps/sigchat/src/manager.rs b/apps/sigchat/src/manager.rs index 179932844..6b845e094 100644 --- a/apps/sigchat/src/manager.rs +++ b/apps/sigchat/src/manager.rs @@ -6,7 +6,8 @@ mod trust_mode; use crate::{Account, DEFAULT_DEVICE_NAME, DEFAULT_HOST_NAME}; use group_permission::GroupPermission; use link_state::LinkState; -use std::io::Error; +use locales::t; +use modals::Modals; use signal_ws::SignalWS; use std::io::{Error, ErrorKind}; pub use trust_mode::TrustMode; @@ -144,8 +145,30 @@ impl Manager { match ws.read() { Ok(Message::Binary(uuid)) => { log::info!("raw uuid ProtoBuffer: {:?}", uuid); - ws.close(); - Ok(false) + let uuid = "TODO decode uuid ProtoBuffer"; + let pub_key = "TODO generateIdentityKeyPair()"; + match url::Url::parse_with_params( + "sgnl://linkdevice", + &[("uuid", &uuid), ("pub_key", &pub_key)], + ) { + Ok(device_link_uri) => { + log::info!("device_link_uri: {device_link_uri}"); + let xns = xous_names::XousNames::new().unwrap(); + let modals = + Modals::new(&xns).expect("can't connect to Modals server"); + modals + .show_notification( + t!("sigchat.account.link.scan", locales::LANG), + Some(device_link_uri.as_str()), + ) + .expect("qrcode failed"); + Ok(false) + } + Err(e) => { + log::info!("{}", format!("{e}")); + Err(link_err) + } + } } Ok(_) => { log::warn!("unexpected Provisioning msg.");