[fractal/fractal-next] verification: Ask for confirmation after scanning
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] verification: Ask for confirmation after scanning
- Date: Mon, 21 Mar 2022 11:41:10 +0000 (UTC)
commit 40a77bd6f69793b787554ff03cbf6f151f90e309
Author: Julian Sparber <julian sparber net>
Date: Mon Mar 21 12:22:35 2022 +0100
verification: Ask for confirmation after scanning
data/resources/ui/identity-verification-widget.ui | 61 ++++++++++++++++++++++
.../verification/identity_verification_widget.rs | 43 +++++++++++++++
src/session/verification/identity_verification.rs | 26 ++++++++-
3 files changed, 128 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/ui/identity-verification-widget.ui
b/data/resources/ui/identity-verification-widget.ui
index 9c0fa913b..6e9b9bac7 100644
--- a/data/resources/ui/identity-verification-widget.ui
+++ b/data/resources/ui/identity-verification-widget.ui
@@ -405,7 +405,68 @@
</property>
</object>
</child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="name">confirm-scanned-qr-code</property>
+ <property name="child">
+ <object class="AdwClamp">
+ <property name="maximum-size">400</property>
+ <property name="tightening-threshold">300</property>
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">18</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">Confirm Scan</property>
+ <property name="wrap">True</property>
+ <property name="wrap-mode">word-char</property>
+ <property name="justify">center</property>
+ <style>
+ <class name="title-1"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkPicture">
+ <property
name="file">resource:///org/gnome/FractalNext/assets/setup-complete.svg</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label16">
+ <property name="wrap">True</property>
+ <property name="wrap-mode">word-char</property>
+ <property name="justify">center</property>
+ </object>
+ </child>
+ <child>
+ <object class="SpinnerButton" id="confirm_scanning_btn">
+ <property name="label" translatable="yes">Confirm</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="suggested-action"/>
+ <class name="pill"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="SpinnerButton" id="cancel_scanning_btn">
+ <property name="label" translatable="yes">Cancel</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="pill"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </property>
+ </object>
+ </child>
</object>
</child>
</template>
</interface>
+
diff --git a/src/session/content/verification/identity_verification_widget.rs
b/src/session/content/verification/identity_verification_widget.rs
index d11f3a833..94bf9b9b8 100644
--- a/src/session/content/verification/identity_verification_widget.rs
+++ b/src/session/content/verification/identity_verification_widget.rs
@@ -59,6 +59,10 @@ mod imp {
pub name_handler: RefCell<Option<SignalHandlerId>>,
pub supported_methods_handler: RefCell<Option<SignalHandlerId>>,
#[template_child]
+ pub confirm_scanning_btn: TemplateChild<SpinnerButton>,
+ #[template_child]
+ pub cancel_scanning_btn: TemplateChild<SpinnerButton>,
+ #[template_child]
pub label1: TemplateChild<gtk::Label>,
#[template_child]
pub label2: TemplateChild<gtk::Label>,
@@ -84,6 +88,8 @@ mod imp {
pub label14: TemplateChild<gtk::Label>,
#[template_child]
pub label15: TemplateChild<gtk::Label>,
+ #[template_child]
+ pub label16: TemplateChild<gtk::Label>,
}
#[glib::object_subclass]
@@ -205,6 +211,24 @@ mod imp {
}
}));
+ self.confirm_scanning_btn
+ .connect_clicked(clone!(@weak obj => move |button| {
+ button.set_loading(true);
+ obj.imp().cancel_scanning_btn.set_sensitive(false);
+ if let Some(request) = obj.request() {
+ request.confirm_scanning();
+ }
+ }));
+
+ self.cancel_scanning_btn
+ .connect_clicked(clone!(@weak obj => move |button| {
+ button.set_loading(true);
+ obj.imp().confirm_scanning_btn.set_sensitive(false);
+ if let Some(request) = obj.request() {
+ request.cancel(true);
+ }
+ }));
+
self.qr_code_scanner
.connect_code_detected(clone!(@weak obj => move |_, data| {
obj.finish_scanning(data);
@@ -327,6 +351,10 @@ impl IdentityVerificationWidget {
priv_.start_emoji_btn.set_sensitive(true);
priv_.start_emoji_btn2.set_loading(false);
priv_.start_emoji_btn2.set_sensitive(true);
+ priv_.confirm_scanning_btn.set_loading(false);
+ priv_.confirm_scanning_btn.set_sensitive(true);
+ priv_.cancel_scanning_btn.set_loading(false);
+ priv_.cancel_scanning_btn.set_sensitive(true);
self.clean_emoji();
}
@@ -379,6 +407,11 @@ impl IdentityVerificationWidget {
VerificationState::QrV1Scan => {
self.start_scanning();
}
+ VerificationState::QrV1Scanned => {
+ priv_
+ .main_stack
+ .set_visible_child_name("confirm-scanned-qr-code");
+ }
VerificationState::SasV1 => {
self.clean_emoji();
match request.sas_data().unwrap() {
@@ -473,6 +506,9 @@ impl IdentityVerificationWidget {
"This session is ready to send and receive secure messages.",
));
priv_.done_btn.set_label(&gettext("Get Started"));
+ priv_.label16.set_label(&gettext(
+ "Does the other session show a confirmation shield?",
+ ));
}
VerificationMode::OtherSession => {
priv_
@@ -500,6 +536,9 @@ impl IdentityVerificationWidget {
priv_.label15.set_label(&gettext(
"Accept the verification request from another session or device.",
));
+ priv_.label16.set_label(&gettext(
+ "Does the other session show a confirmation shield?",
+ ));
}
VerificationMode::User => {
let name = request.user().display_name();
@@ -529,6 +568,10 @@ impl IdentityVerificationWidget {
"Ask <b>{}</b> to accept the verification request.",
name
));
+ priv_.label16.set_label(&gettext!(
+ "Does <b>{}</b> see a confirmation shield on there session?",
+ name
+ ));
}
}
}
diff --git a/src/session/verification/identity_verification.rs
b/src/session/verification/identity_verification.rs
index f6a31f3a3..8d63e4029 100644
--- a/src/session/verification/identity_verification.rs
+++ b/src/session/verification/identity_verification.rs
@@ -37,6 +37,7 @@ pub enum State {
SasV1,
QrV1Show,
QrV1Scan,
+ QrV1Scanned,
Completed,
Cancelled,
Dismissed,
@@ -132,6 +133,7 @@ pub enum UserAction {
Cancel,
StartSas,
Scanned(QrVerificationData),
+ ConfirmScanning,
}
#[derive(Debug, PartialEq)]
@@ -581,6 +583,18 @@ impl IdentityVerification {
}
}
+ pub fn confirm_scanning(&self) {
+ if self.state() == State::QrV1Scanned {
+ if let Some(sync_sender) = &*self.imp().sync_sender.borrow() {
+ let result = sync_sender.try_send(Message::UserAction(UserAction::ConfirmScanning));
+
+ if let Err(error) = result {
+ error!("Failed to send message to tokio runtime: {}", error);
+ }
+ }
+ }
+ }
+
pub fn state(&self) -> State {
self.imp().state.get()
}
@@ -806,6 +820,9 @@ macro_rules! wait {
break;
}
},
+ Message::UserAction(UserAction::ConfirmScanning) => {
+ break;
+ },
Message::UserAction(UserAction::StartSas) => {
if true $(&& $allow_action)? {
return $this.start_sas().await;
@@ -867,6 +884,9 @@ macro_rules! wait_without_scanning_sas {
},
Message::UserAction(UserAction::StartSas) => {
},
+ Message::UserAction(UserAction::ConfirmScanning) => {
+ break;
+ },
Message::UserAction(UserAction::Match) => {
if $this.request.is_passive() {
return Ok(State::Passive);
@@ -1002,7 +1022,10 @@ impl Context {
wait![self, request.has_been_scanned()];
- // FIXME: we should automatically confirm
+ self.send_state(State::QrV1Scanned);
+
+ wait![self];
+
request.confirm().await?;
debug!("Wait for done state");
@@ -1021,7 +1044,6 @@ impl Context {
.await?
.expect("Scanning Qr Code should be supported");
- // FIXME: we should automatically confirm
request.confirm().await?;
debug!("Wait for done state");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]