mirror of
https://github.com/librekeys/picoforge.git
synced 2026-07-28 08:01:19 -07:00
chore(ui): fix unused code and make io functions async
This commit is contained in:
+4
-2
@@ -1,4 +1,6 @@
|
||||
//! Tauri Commands to interact with the pico-fido firmware via rescue and fido protocols.
|
||||
#![allow(unused)]
|
||||
|
||||
use crate::{device::error::PFError, device::fido, device::rescue, device::types::*};
|
||||
|
||||
pub fn read_device_details() -> Result<FullDeviceStatus, PFError> {
|
||||
@@ -11,7 +13,7 @@ pub fn read_device_details() -> Result<FullDeviceStatus, PFError> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_config(
|
||||
pub async fn write_config(
|
||||
config: AppConfigInput,
|
||||
method: DeviceMethod,
|
||||
pin: Option<String>,
|
||||
@@ -49,7 +51,7 @@ pub fn reboot(to_bootsel: bool) -> Result<String, PFError> {
|
||||
rescue::reboot_device(to_bootsel)
|
||||
}
|
||||
|
||||
pub fn get_credentials(pin: String) -> Result<Vec<StoredCredential>, String> {
|
||||
pub async fn get_credentials(pin: String) -> Result<Vec<StoredCredential>, String> {
|
||||
fido::get_credentials(pin)
|
||||
}
|
||||
|
||||
|
||||
+9
-7
@@ -43,11 +43,11 @@ impl ApplicationRoot {
|
||||
passkeys_view: None,
|
||||
logs_view: None,
|
||||
};
|
||||
this.refresh_device_status(cx);
|
||||
this.refresh_device_status(None, cx);
|
||||
this
|
||||
}
|
||||
|
||||
fn refresh_device_status(&mut self, cx: &mut Context<Self>) {
|
||||
fn refresh_device_status(&mut self, window: Option<&mut Window>, cx: &mut Context<Self>) {
|
||||
if self.device_loading {
|
||||
return;
|
||||
}
|
||||
@@ -72,9 +72,11 @@ impl ApplicationRoot {
|
||||
}
|
||||
|
||||
if let Some(config_view) = &self.config_view {
|
||||
config_view.update(cx, |view, cx| {
|
||||
view.update_device_status(Some(status.clone()), cx);
|
||||
});
|
||||
if let Some(window) = window {
|
||||
config_view.update(cx, |view, cx| {
|
||||
view.update_device_status(Some(status.clone()), window, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(passkeys_view) = &self.passkeys_view {
|
||||
@@ -120,8 +122,8 @@ impl Render for ApplicationRoot {
|
||||
.on_select(|this: &mut Self, view, _, _| {
|
||||
this.active_view = view;
|
||||
})
|
||||
.on_refresh(|this, _, cx| {
|
||||
this.refresh_device_status(cx);
|
||||
.on_refresh(|this, window, cx| {
|
||||
this.refresh_device_status(Some(window), cx);
|
||||
})
|
||||
.render(cx),
|
||||
)
|
||||
|
||||
+2
-21
@@ -309,7 +309,7 @@ impl ConfigView {
|
||||
let method = status.method.clone();
|
||||
|
||||
self._task = Some(cx.spawn(async move |_, cx| {
|
||||
let result = io::write_config(changes, method, None);
|
||||
let result = io::write_config(changes, method, None).await;
|
||||
|
||||
let _ = entity.update(cx, |this, cx| {
|
||||
this.loading = false;
|
||||
@@ -345,7 +345,7 @@ impl ConfigView {
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn update_status(
|
||||
pub(crate) fn update_device_status(
|
||||
&mut self,
|
||||
status: Option<FullDeviceStatus>,
|
||||
window: &mut Window,
|
||||
@@ -399,25 +399,6 @@ impl ConfigView {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub(crate) fn update_device_status(
|
||||
&mut self,
|
||||
status: Option<FullDeviceStatus>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.device_status == status {
|
||||
return;
|
||||
}
|
||||
self.device_status = status.clone();
|
||||
let config = status.as_ref().map(|s| &s.config);
|
||||
|
||||
self.led_dimmable = config.map(|c| c.led_dimmable).unwrap_or(true);
|
||||
self.led_steady = config.map(|c| c.led_steady).unwrap_or(false);
|
||||
self.power_cycle = config.map(|c| c.power_cycle_on_reset).unwrap_or(false);
|
||||
self.enable_secp256k1 = config.map(|c| c.enable_secp256k1).unwrap_or(true);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_identity_card(&self, theme: &Theme) -> impl IntoElement {
|
||||
let content = v_flex()
|
||||
.gap_4()
|
||||
|
||||
@@ -88,10 +88,12 @@ impl PasskeysView {
|
||||
|
||||
self._task = Some(cx.spawn(async move |_, cx| {
|
||||
let pin_for_bg = pin.clone();
|
||||
let result = cx
|
||||
.background_executor()
|
||||
.spawn(async move { io::get_credentials(pin_for_bg) })
|
||||
.await;
|
||||
// let result = cx
|
||||
// .background_executor()
|
||||
// .spawn(async move { io::get_credentials(pin_for_bg) })
|
||||
// .await;
|
||||
|
||||
let result = io::get_credentials(pin_for_bg).await;
|
||||
|
||||
let _ = entity.update(cx, |this, cx| {
|
||||
this.loading = false;
|
||||
@@ -156,10 +158,7 @@ impl PasskeysView {
|
||||
fn refresh_credentials(&mut self, pin: String, cx: &mut Context<Self>) {
|
||||
let entity = cx.entity().downgrade();
|
||||
self._task = Some(cx.spawn(async move |_, cx| {
|
||||
let result = cx
|
||||
.background_executor()
|
||||
.spawn(async move { io::get_credentials(pin) })
|
||||
.await;
|
||||
let result = io::get_credentials(pin).await;
|
||||
|
||||
let _ = entity.update(cx, |this, cx| {
|
||||
this.loading = false;
|
||||
|
||||
Reference in New Issue
Block a user