Skip to content

Commit 6243e5f

Browse files
committed
Add completed-state to have option to keep window open (not yet working, because of cancel-request intervening)
1 parent e0a9443 commit 6243e5f

5 files changed

Lines changed: 44 additions & 8 deletions

File tree

credentialsd-common/src/model.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct Device {
4040
pub enum Operation {
4141
Create,
4242
Get,
43+
SetDevicePin,
4344
}
4445

4546
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)]
@@ -139,6 +140,14 @@ impl ViewUpdateFailure {
139140
}
140141
}
141142

143+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
144+
pub enum ViewUpdateSuccess {
145+
/// Success that requires the window to close
146+
CloseWindow,
147+
/// Success that requires the window to stay open
148+
KeepWindowOpen(String),
149+
}
150+
142151
#[derive(Debug, Clone, Serialize, Deserialize)]
143152
pub enum ViewUpdate {
144153
SetTitle((String, String)),
@@ -159,7 +168,7 @@ pub enum ViewUpdate {
159168
HybridConnecting,
160169
HybridConnected,
161170

162-
Completed,
171+
Completed(ViewUpdateSuccess),
163172
Cancelled,
164173
Failed(ViewUpdateFailure),
165174
}

credentialsd-ui/src/gui/view_model/gtk/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod device;
44
mod window;
55

66
use async_std::channel::{Receiver, Sender};
7-
use credentialsd_common::model::ViewUpdateFailure;
7+
use credentialsd_common::model::{ViewUpdateFailure, ViewUpdateSuccess};
88
use credentialsd_common::server::WindowHandle;
99
use gettextrs::{LocaleCategory, gettext, ngettext};
1010
use glib::clone;
@@ -203,10 +203,15 @@ impl ViewModel {
203203
));
204204
view_model.set_qr_spinner_visible(false);
205205
}
206-
ViewUpdate::Completed => {
206+
ViewUpdate::Completed(ViewUpdateSuccess::CloseWindow) => {
207207
view_model.set_qr_spinner_visible(false);
208208
view_model.set_completed(true);
209209
}
210+
ViewUpdate::Completed(ViewUpdateSuccess::KeepWindowOpen(text)) => {
211+
view_model.set_qr_spinner_visible(false);
212+
// These are already gettext messages
213+
view_model.set_prompt(text);
214+
}
210215
ViewUpdate::Failed(error) => {
211216
view_model.set_qr_spinner_visible(false);
212217
view_model.set_failed(true);

credentialsd-ui/src/gui/view_model/mod.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use async_std::{
77
channel::{Receiver, Sender},
88
sync::Mutex as AsyncMutex,
99
};
10-
use credentialsd_common::model::RequestingApplication;
10+
use credentialsd_common::model::{RequestingApplication, ViewUpdateSuccess};
1111
use credentialsd_common::server::ViewRequest;
1212
use gettextrs::gettext;
1313
use serde::{Deserialize, Serialize};
@@ -89,6 +89,7 @@ impl<F: FlowController + Send> ViewModel<F> {
8989
// TRANSLATORS: %s1 is the "relying party" (think: domain name) where the request is coming from
9090
gettext("Use a passkey for %s1")
9191
}
92+
Operation::SetDevicePin => gettext("Setting Pin on device"),
9293
}
9394
.to_string();
9495
title = title.replace("%s1", &self.rp_id);
@@ -108,6 +109,7 @@ impl<F: FlowController + Send> ViewModel<F> {
108109
// TRANSLATORS: %s3 is the absolute path (think: /usr/bin/firefox) of the requesting application
109110
gettext("<b>\"%s2\"</b> (process ID: %i1, binary: %s3) is asking to use a credential to sign in to \"%s1\". Only proceed if you trust this process.")
110111
}
112+
Operation::SetDevicePin => gettext("Setting Pin on device"),
111113
}
112114
.to_string();
113115
subtitle = subtitle.replace("%s1", &self.rp_id);
@@ -216,6 +218,7 @@ impl<F: FlowController + Send> ViewModel<F> {
216218
Event::View(ViewEvent::SetNewDevicePin(pin)) => {
217219
if let Some(device) = &self.selected_device {
218220
let mut cred_service = self.flow_controller.lock().await;
221+
self.operation = Operation::SetDevicePin;
219222
let resp = match device.transport {
220223
Transport::Usb => cred_service.set_usb_device_pin(pin).await,
221224
Transport::Nfc => cred_service.set_nfc_device_pin(pin).await,
@@ -282,7 +285,15 @@ impl<F: FlowController + Send> ViewModel<F> {
282285
.unwrap();
283286
}
284287
UsbState::Completed => {
285-
self.tx_update.send(ViewUpdate::Completed).await.unwrap();
288+
let t = if matches!(self.operation, Operation::SetDevicePin) {
289+
ViewUpdateSuccess::KeepWindowOpen(gettext(
290+
"Pin successfully set! Please try registering again.",
291+
))
292+
} else {
293+
ViewUpdateSuccess::CloseWindow
294+
};
295+
296+
self.tx_update.send(ViewUpdate::Completed(t)).await.unwrap();
286297
}
287298
UsbState::SelectingDevice => {
288299
self.tx_update
@@ -353,7 +364,14 @@ impl<F: FlowController + Send> ViewModel<F> {
353364
.unwrap();
354365
}
355366
NfcState::Completed => {
356-
self.tx_update.send(ViewUpdate::Completed).await.unwrap();
367+
let t = if matches!(self.operation, Operation::SetDevicePin) {
368+
ViewUpdateSuccess::KeepWindowOpen(gettext(
369+
"Pin successfully set! Please try registering again.",
370+
))
371+
} else {
372+
ViewUpdateSuccess::CloseWindow
373+
};
374+
self.tx_update.send(ViewUpdate::Completed(t)).await.unwrap();
357375
}
358376
NfcState::Idle | NfcState::Waiting => {}
359377
NfcState::SelectingCredential { creds } => {
@@ -429,7 +447,10 @@ impl<F: FlowController + Send> ViewModel<F> {
429447
}
430448
HybridState::Completed => {
431449
self.hybrid_qr_code_data = None;
432-
self.tx_update.send(ViewUpdate::Completed).await.unwrap();
450+
self.tx_update
451+
.send(ViewUpdate::Completed(ViewUpdateSuccess::CloseWindow))
452+
.await
453+
.unwrap();
433454
}
434455
HybridState::UserCancelled => {
435456
self.hybrid_qr_code_data = None;

credentialsd/src/dbus/flow_control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ where
326326
);
327327
break;
328328
}
329-
UsbState::SelectCredential { cred_tx, .. } => {
329+
UsbState::SelectingCredential { cred_tx, .. } => {
330330
// TODO: This is not great. The user potentially already selected a device,
331331
// but we are starting a new request cycle, so they have to select one
332332
// again... But the previous cycle has already ended.

credentialsd/src/webauthn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ pub fn format_client_data_json(
682682
let op_str = match op {
683683
Operation::Create => "webauthn.create",
684684
Operation::Get => "webauthn.get",
685+
_ => unreachable!(),
685686
};
686687
let mut client_data_json = format!(
687688
r#"{{"type":"{}","challenge":"{}","origin":"{}""#,

0 commit comments

Comments
 (0)