Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use libwebauthn::{
use crate::{
credential_service::{hybrid::HybridEvent, usb::UsbEvent},
dbus::{CredentialRequest, CredentialResponse},
view_model::{Device, Transport},
gui::view_model::{Device, Transport},
};

use hybrid::{HybridHandler, HybridState, HybridStateInternal};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use futures_lite::Stream;
use tokio::sync::{mpsc, oneshot};

use crate::dbus::{CredentialRequest, CredentialResponse};
use crate::view_model::Device;
use crate::gui::view_model::Device;

use super::hybrid::{HybridHandler, HybridState};
use super::usb::{UsbHandler, UsbState};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing::{debug, warn};

use crate::{
dbus::{CredentialRequest, GetAssertionResponseInternal},
view_model::Credential,
gui::view_model::Credential,
};

use super::{AuthenticatorResponse, CredentialResponse, Error};
Expand Down
6 changes: 4 additions & 2 deletions xyz-iinuwa-credential-manager-portal-gtk/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ use zbus::{
};

use crate::credential_service::CredentialManagementClient;
use crate::gui::ViewRequest;
use crate::view_model::{CredentialType, Operation};
use crate::gui::{
view_model::{CredentialType, Operation},
ViewRequest,
};
use crate::webauthn::{
self, GetPublicKeyCredentialUnsignedExtensionsResponse, PublicKeyCredentialParameters,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
pub mod view_model;

use std::thread;

use async_std::channel::Receiver;
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};
use tokio::sync::oneshot;

use crate::application::ExampleApplication;
use crate::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
use crate::{
credential_service::CredentialServiceClient,
view_model::{self, Operation, ViewEvent, ViewUpdate},
};
use crate::credential_service::CredentialServiceClient;

use view_model::{Operation, ViewEvent, ViewUpdate};

pub struct ViewRequest {
pub operation: Operation,
Expand Down Expand Up @@ -45,27 +42,8 @@ fn run_gui<C: CredentialServiceClient + Send + Sync + 'static>(client: C, reques
println!("event loop ended?");
});

start_gtk_app(tx_event, rx_update);
view_model::gtk::start_gtk_app(tx_event, rx_update);

async_std::task::block_on(event_loop.cancel());
response_tx.send(()).unwrap();
}

fn start_gtk_app(
tx_event: async_std::channel::Sender<ViewEvent>,
rx_update: async_std::channel::Receiver<ViewUpdate>,
) {
// Prepare i18n
gettextrs::setlocale(LocaleCategory::LcAll, "");
gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");

if glib::application_name().is_none() {
glib::set_application_name(&gettext("Credential Manager"));
}
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
gio::resources_register(&res);

let app = ExampleApplication::new(tx_event, rx_update);
app.run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{gdk, gio, glib};

use super::{window::ExampleApplicationWindow, ViewModel};
use crate::config::{APP_ID, PKGDATADIR, PROFILE, VERSION};
use crate::view_model::gtk::ViewModel;
use crate::view_model::{ViewEvent, ViewUpdate};
use crate::window::ExampleApplicationWindow;
use crate::gui::view_model::{ViewEvent, ViewUpdate};

mod imp {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ impl CredentialObject {
}
}

impl From<crate::view_model::Credential> for CredentialObject {
fn from(value: crate::view_model::Credential) -> Self {
impl From<crate::gui::view_model::Credential> for CredentialObject {
fn from(value: crate::gui::view_model::Credential) -> Self {
Self::new(&value.id, &value.name, &value.username)
}
}

impl From<&crate::view_model::Credential> for CredentialObject {
fn from(value: &crate::view_model::Credential) -> Self {
impl From<&crate::gui::view_model::Credential> for CredentialObject {
fn from(value: &crate::gui::view_model::Credential) -> Self {
Self::new(&value.id, &value.name, &value.username)
}
}

impl From<CredentialObject> for crate::view_model::Credential {
impl From<CredentialObject> for crate::gui::view_model::Credential {
fn from(value: CredentialObject) -> Self {
Self {
id: value.id(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;

use crate::view_model::Transport;
use crate::gui::view_model::Transport;

mod imp {
use super::*;
Expand Down Expand Up @@ -62,21 +62,21 @@ fn transport_name(transport: &Transport) -> &'static str {
// Transport::PasskeyProvider => ("symbolic-link-symbolic", "ACME Password Manager"),
}
}
impl From<crate::view_model::Device> for DeviceObject {
fn from(value: crate::view_model::Device) -> Self {
impl From<crate::gui::view_model::Device> for DeviceObject {
fn from(value: crate::gui::view_model::Device) -> Self {
let name = transport_name(&value.transport);
Self::new(&value.id, &value.transport, name)
}
}

impl From<&crate::view_model::Device> for DeviceObject {
fn from(value: &crate::view_model::Device) -> Self {
impl From<&crate::gui::view_model::Device> for DeviceObject {
fn from(value: &crate::gui::view_model::Device) -> Self {
let name = transport_name(&value.transport);
Self::new(&value.id, &value.transport, name)
}
}

impl TryFrom<DeviceObject> for crate::view_model::Device {
impl TryFrom<DeviceObject> for crate::gui::view_model::Device {
type Error = String;

fn try_from(value: DeviceObject) -> Result<Self, Self::Error> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
mod application;
pub mod credential;
pub mod device;
mod window;

use async_std::channel::{Receiver, Sender};
use gettextrs::{gettext, LocaleCategory};
use glib::clone;
use gtk::gdk::Texture;
use gtk::gdk_pixbuf::Pixbuf;
Expand All @@ -12,13 +15,16 @@ use gtk::subclass::prelude::*;
use qrcode::QrCode;
use tracing::debug;

use self::credential::CredentialObject;
use self::device::DeviceObject;
use crate::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
use application::ExampleApplication;

use super::Transport;
use super::{Credential, Device};
use super::{ViewEvent, ViewUpdate};

use self::credential::CredentialObject;
use self::device::DeviceObject;

mod imp {
use std::cell::RefCell;

Expand Down Expand Up @@ -51,7 +57,7 @@ mod imp {
#[property(get, set)]
pub failed: RefCell<bool>,

// pub(super) vm: RefCell<Option<crate::view_model::ViewModel>>,
// pub(super) vm: RefCell<Option<crate::gui::view_model::ViewModel>>,
pub(super) rx: RefCell<Option<Receiver<ViewUpdate>>>,
pub(super) tx: RefCell<Option<Sender<ViewEvent>>>,
// hybrid_qr_state: HybridState,
Expand Down Expand Up @@ -337,3 +343,22 @@ impl ViewModel {
tx.send(event).await.unwrap();
}
}

pub fn start_gtk_app(
tx_event: async_std::channel::Sender<ViewEvent>,
rx_update: async_std::channel::Receiver<ViewUpdate>,
) {
// Prepare i18n
gettextrs::setlocale(LocaleCategory::LcAll, "");
gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");

if glib::application_name().is_none() {
glib::set_application_name(&gettext("Credential Manager"));
}
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
gio::resources_register(&res);

let app = ExampleApplication::new(tx_event, rx_update);
app.run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use gtk::{
};
use gtk::{prelude::*, Picture};

use crate::application::ExampleApplication;
use super::application::ExampleApplication;
use super::{device::DeviceObject, ViewModel};
use crate::config::{APP_ID, PROFILE};
use crate::view_model::gtk::{device::DeviceObject, ViewModel};
use crate::view_model::Transport;
use crate::gui::view_model::Transport;

mod imp {
use gtk::Picture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ where
devices: Vec<Device>,
selected_device: Option<Device>,

providers: Vec<Provider>,

// providers: Vec<Provider>,
usb_pin_tx: Option<Arc<Mutex<mpsc::Sender<String>>>>,
usb_cred_tx: Option<Arc<Mutex<mpsc::Sender<String>>>>,

hybrid_qr_state: HybridState,
hybrid_qr_code_data: Option<Vec<u8>>,

hybrid_linked_state: HybridState,
// hybrid_linked_state: HybridState,
}

impl<C: CredentialServiceClient + Send> ViewModel<C> {
Expand All @@ -60,52 +58,12 @@ impl<C: CredentialServiceClient + Send> ViewModel<C> {
title: String::default(),
devices: Vec::new(),
selected_device: None,
providers: Vec::new(),
usb_pin_tx: None,
usb_cred_tx: None,
hybrid_qr_state: HybridState::default(),
hybrid_qr_code_data: None,
hybrid_linked_state: HybridState::default(),
}
}
fn start_authentication(&self) {} // open page
fn cancel_authentication(&self) {}

fn start_fingerprint_authentication(&self) {
todo!("not implemented");
}
fn cancel_fingerprint_authentication(&self) {}

fn start_hybrid_qr_authentication(&self) {}
fn cancel_hybrid_qr_authentication(&self) {
todo!("not implemented");
}

fn start_hybrid_linked_authentication(&self) {
todo!("not implemented");
}
fn cancel_hybrid_linked_authentication(&self) {
todo!("not implemented");
}

// Can this be used for internal uv method too?
fn start_usb_authentication(&self) {
todo!("not implemented");
}
fn cancel_usb_authentication(&self) {
todo!("not implemented");
}
fn send_usb_device_pin(&self) {
todo!("not implemented");
}

fn select_uv_method(&self) {
todo!("not implemented");
}

fn finish_authentication(&self) {
todo!("not implemented");
}

async fn update_title(&mut self) {
self.title = match self.operation {
Expand Down Expand Up @@ -396,7 +354,7 @@ pub enum FingerprintSensorState {
#[derive(Debug)]
pub enum CredentialType {
Passkey,
Password,
// Password,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -466,10 +424,6 @@ pub enum Transport {
Usb,
}

pub enum Error {
ConversionError,
}

impl TryInto<Transport> for String {
type Error = String;

Expand Down
4 changes: 0 additions & 4 deletions xyz-iinuwa-credential-manager-portal-gtk/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod application;
mod cbor;
#[rustfmt::skip]
mod config;
Expand All @@ -7,10 +6,7 @@ mod credential_service;
mod dbus;
mod gui;
mod serde;
#[allow(dead_code)]
mod view_model;
mod webauthn;
mod window;

use std::{error::Error, sync::Arc};

Expand Down