diff --git a/.envrc b/.envrc index 3550a30..cffc922 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake +use flake . --impure diff --git a/flake.lock b/flake.lock index 57a4201..e1d7514 100644 --- a/flake.lock +++ b/flake.lock @@ -6,11 +6,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1769064677, - "narHash": "sha256-Upa108vGOlaOBGQTmmLEKuWekBm519u42A/oYSjTs+4=", + "lastModified": 1770102568, + "narHash": "sha256-VYwA9FmakKJ3zLfAd7bdj9xIB9PzfISLoYh6eZl+EuQ=", "owner": "nix-community", "repo": "fenix", - "rev": "439e81e0b40781e16c444ca1c7fcd1cf8c5c406c", + "rev": "592daa37b5a3175c61541329b64d6c1972303bc1", "type": "github" }, "original": { @@ -23,11 +23,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1768135262, - "narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=", + "lastModified": 1769996383, + "narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac", + "rev": "57928607ea566b5db3ad13af0e57e921e6b12381", "type": "github" }, "original": { @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1768886240, - "narHash": "sha256-C2TjvwYZ2VDxYWeqvvJ5XPPp6U7H66zeJlRaErJKoEM=", + "lastModified": 1770019141, + "narHash": "sha256-VKS4ZLNx4PNrABoB0L8KUpc1fE7CLpQXQs985tGfaCU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "80e4adbcf8992d3fd27ad4964fbb84907f9478b0", + "rev": "cb369ef2efd432b3cdf8622b0ffc0a97a02f3137", "type": "github" }, "original": { @@ -54,11 +54,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1765674936, - "narHash": "sha256-k00uTP4JNfmejrCLJOwdObYC9jHRrr/5M/a/8L2EIdo=", + "lastModified": 1769909678, + "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "2075416fcb47225d9b68ac469a5c4801a9c4dd85", + "rev": "72716169fe93074c333e8d0173151350670b824c", "type": "github" }, "original": { @@ -69,11 +69,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1769018530, - "narHash": "sha256-MJ27Cy2NtBEV5tsK+YraYr2g851f3Fl1LpNHDzDX15c=", + "lastModified": 1770115704, + "narHash": "sha256-KHFT9UWOF2yRPlAnSXQJh6uVcgNcWlFqqiAZ7OVlHNc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "88d3861acdd3d2f0e361767018218e51810df8a1", + "rev": "e6eae2ee2110f3d31110d5c222cd395303343b08", "type": "github" }, "original": { @@ -93,11 +93,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1768996281, - "narHash": "sha256-s+TolkG0f98fR6RtBEmymBb8RHmZ04U3SL8cjoqog2k=", + "lastModified": 1770026591, + "narHash": "sha256-VZlloygYDmozJwbZZkCSNpiPhNdOW/AA0b6LmNBZ3xU=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "2d124215693f13dcf6ad097a02acdd473c80e447", + "rev": "74eca73f3b0a41b80228b8e499c7547cc8b2effa", "type": "github" }, "original": { diff --git a/shell.nix b/shell.nix index d9d961e..ec072a7 100644 --- a/shell.nix +++ b/shell.nix @@ -2,22 +2,22 @@ let libraries = with pkgs; [ - at-spi2-atk - atkmm - cairo - gdk-pixbuf - glib - gtk3 - harfbuzz - librsvg - libsoup_3 - pango - webkitgtk_4_1 - libcanberra-gtk3 pcsclite hidapi - mesa + mesa udev + libxkbcommon + vulkan-loader + wayland + libglvnd + wayland-protocols + libunwind + libdrm + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + xorg.libxcb ]; packages = with pkgs; [ @@ -28,29 +28,17 @@ let openssl_3 librsvg git - + # Development tools rustc mold cargo deno nodejs_22 - - # Tauri 2 dependencies - at-spi2-atk - atkmm - cairo - gdk-pixbuf - glib - gtk3 - harfbuzz - librsvg - libsoup_3 - pango - webkitgtk_4_1 - libcanberra-gtk3 - packagekit - + + # GPUI + libxkbcommon + # Hardware pcsclite hidapi @@ -62,14 +50,14 @@ pkgs.mkShell { shellHook = '' export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH - export GTK_PATH=${pkgs.libcanberra-gtk3}/lib/gtk-3.0:${pkgs.packagekit}/lib/gtk-3.0:$GTK_PATH + # export GTK_PATH=${pkgs.libcanberra-gtk3}/lib/gtk-3.0:${pkgs.packagekit}/lib/gtk-3.0:$GTK_PATH export XDG_DATA_DIRS=$GSETTINGS_SCHEMAS_PATH:$XDG_DATA_DIRS export RUSTFLAGS="-C link-arg=-fuse-ld=mold" - + # Try to uncomment the following lines if you encounter EGL_BAD_PARAMETER errors: # export LIBGL_ALWAYS_SOFTWARE=1 # export WEBKIT_DISABLE_COMPOSITING_MODE=1 - + echo "Nix development environment loaded!" echo "Available tools: rustc, cargo, deno, node, tauri" ''; diff --git a/src/ui/rootview.rs b/src/ui/rootview.rs index 5e8405f..b6e4447 100644 --- a/src/ui/rootview.rs +++ b/src/ui/rootview.rs @@ -66,10 +66,9 @@ impl ApplicationRoot { match io::read_device_details() { Ok(status) => { - self.state.device_status = Some(status); + self.state.device_status = Some(status.clone()); self.state.error = None; - // If successful, try to get FIDO info match io::get_fido_info() { Ok(fido) => { self.state.fido_info = Some(fido); @@ -79,6 +78,12 @@ impl ApplicationRoot { self.state.fido_info = None; } } + + if let Some(config_view) = &self.config_view { + config_view.update(cx, |view, cx| { + view.update_device_status(Some(status), cx); + }); + } } Err(e) => { self.state.device_status = None; @@ -171,13 +176,6 @@ impl Render for ApplicationRoot { ) }) }); - view.update(cx, |view, cx| { - view.update_status( - self.state.device_status.clone(), - window, - cx, - ); - }); view.clone().into_any_element() } ActiveView::Security => { diff --git a/src/ui/views/config.rs b/src/ui/views/config.rs index ff84eef..b1bc9a2 100644 --- a/src/ui/views/config.rs +++ b/src/ui/views/config.rs @@ -1,6 +1,5 @@ use crate::device::io; use crate::device::types::{AppConfigInput, FullDeviceStatus}; -use crate::ui::colors; use crate::ui::components::{card::Card, page_view::PageView}; use crate::ui::ui_types::{LedDriverType, UsbIdentityPreset}; use gpui::*; @@ -67,6 +66,7 @@ pub struct ConfigView { loading: bool, device_status: Option, is_custom_vendor: bool, + _task: Option>, } impl ConfigView { @@ -209,10 +209,11 @@ impl ConfigView { loading: false, device_status: device_status.clone(), is_custom_vendor, + _task: None, } } - fn apply_changes(&mut self, window: &mut Window, cx: &mut Context) { + fn apply_changes(&mut self, _window: &mut Window, cx: &mut Context) { let status = if let Some(s) = &self.device_status { s } else { @@ -256,10 +257,8 @@ impl ConfigView { } } - // Get Driver Value let driver_idx = self.led_driver_select.read(cx).selected_index(cx); if let Some(idx) = driver_idx { - // Map index back to enum value safely if let Some(driver) = LedDriverType::all().get(idx.row) { let val = driver.value(); if Some(val) != current_config.led_driver { @@ -293,7 +292,6 @@ impl ConfigView { changes.enable_secp256k1 = Some(self.enable_secp256k1); } - // Check if we have any changes let has_changes = changes.vid.is_some() || changes.pid.is_some() || changes.product_name.is_some() @@ -314,28 +312,50 @@ impl ConfigView { self.loading = true; cx.notify(); - let result = io::write_config(changes, status.method.clone(), None); + let entity = cx.entity().downgrade(); + let method = status.method.clone(); - self.loading = false; + self._task = Some(cx.spawn(async move |_, cx| { + use std::time::Duration; - match result { - Ok(msg) => { - log::info!("Success: {}", msg); + cx.background_executor() + .timer(Duration::from_millis(500)) + .await; - if let Ok(new_status) = io::read_device_details() { - log::info!( - "Refreshed device status. LED Steady: {}", - new_status.config.led_steady - ); - self.update_status(Some(new_status), window, cx); + let result = io::write_config(changes, method, None); + + let _ = entity.update(cx, |this, cx| { + this.loading = false; + + match result { + Ok(msg) => { + log::info!("Success: {}", msg); + + if let Ok(new_status) = io::read_device_details() { + log::info!( + "Refreshed device status. LED Steady: {}", + new_status.config.led_steady + ); + + let config = &new_status.config; + + this.led_dimmable = config.led_dimmable; + this.led_steady = config.led_steady; + this.power_cycle = config.power_cycle_on_reset; + this.enable_secp256k1 = config.enable_secp256k1; + + this.device_status = Some(new_status); + cx.notify(); + } + } + Err(e) => { + log::error!("Error saving config: {}", e); + } } - } - Err(e) => { - log::error!("Error saving config: {}", e); - } - } - cx.notify(); + cx.notify(); + }); + })); } pub fn update_status( @@ -395,6 +415,25 @@ impl ConfigView { cx.notify(); } + pub(crate) fn update_device_status( + &mut self, + status: Option, + cx: &mut Context, + ) { + 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() @@ -528,7 +567,7 @@ impl ConfigView { .child(content) } - fn render_touch_card(&self, theme: &Theme) -> impl IntoElement { + fn render_touch_card(&self, _theme: &Theme) -> impl IntoElement { let content = v_flex().gap_4().child( v_flex() .gap_2()