diff --git a/src-tauri/src/oath.rs b/src-tauri/src/oath.rs index a63f96d..36104be 100644 --- a/src-tauri/src/oath.rs +++ b/src-tauri/src/oath.rs @@ -55,7 +55,6 @@ pub async fn register_oath(uuid: String, label: String, issuer: Option, "sha256" => Digest::Sha256, _ => return Err("Unsupported credential type".to_string()) }; - println!("label: {:?}", label); let credential = Credential{ label, issuer, diff --git a/src-tauri/src/solo.rs b/src-tauri/src/solo.rs index 00b274b..632e420 100644 --- a/src-tauri/src/solo.rs +++ b/src-tauri/src/solo.rs @@ -15,7 +15,6 @@ pub struct Solo2Info { impl From for Solo2Info { fn from(solo2: Solo2) -> Solo2Info { let uuid = solo2.uuid().simple().to_string(); - println!("uuid: {}", uuid); Solo2Info { uuid: uuid.to_uppercase(), version: solo2.version(), @@ -45,7 +44,6 @@ pub struct Solo2List(pub Mutex>); #[memoize] pub fn get_secure_status(uuid: String) -> Option { - println!("get_secure_status: {}", uuid); let converted_uuid = Uuid::from_str(&uuid).unwrap(); let mut device = Solo2::having(converted_uuid).unwrap(); let mut admin = Admin::select(&mut device).unwrap(); diff --git a/src-tauri/src/update.rs b/src-tauri/src/update.rs index 36fba5c..9b2b378 100644 --- a/src-tauri/src/update.rs +++ b/src-tauri/src/update.rs @@ -1,11 +1,18 @@ +use serde::Serialize; use solo2::{Device, Firmware, Uuid, UuidSelectable}; -use tauri::{command, State}; +use tauri::{command, State, Window}; use crate::solo::Solo2List; +#[derive (Serialize, Clone)] +struct ProgressData { + completed: usize, + total: usize, + uuid: String, +} #[command] -pub async fn update_key(uuid: String, file: Option, state: State<'_, Solo2List>) -> Result<(), String> { +pub async fn update_key(uuid: String, file: Option, state: State<'_, Solo2List>, window: Window) -> Result<(), String> { let list = state.0.lock().await; if list.contains_key(&uuid) { let firmware = match file { @@ -20,12 +27,18 @@ pub async fn update_key(uuid: String, file: Option, state: State<'_, Sol }; let converted_uuid = Uuid::from_u128(u128::from_str_radix(&uuid, 16).unwrap()); let device = Device::having(converted_uuid).unwrap(); - match device.program(firmware, true) { + let total = firmware.len() as u64; + let bar = indicatif::ProgressBar::new(total); + let progress = |bytes: usize| { + window.emit("update_progress", ProgressData{completed: bytes, total: total as usize, uuid: uuid.clone()}).unwrap(); + bar.set_position(bytes as u64); + }; + + match device.program(firmware, true, Some(&progress)) { Ok(_) => Ok(()), Err(e) => Err(e.to_string()), } } else { - println!("List: {:?}", list); Err("Key not found".to_string()) } } diff --git a/src/lib/KeyCard.svelte b/src/lib/KeyCard.svelte index 0512a0c..e89c3e3 100644 --- a/src/lib/KeyCard.svelte +++ b/src/lib/KeyCard.svelte @@ -15,18 +15,34 @@ TextBox, } from "fluent-svelte"; import { parse, gt, major } from "semver"; - import type { Solo2 } from "src/types"; + import type { Solo2, UpdateData } from "$types"; import { saveKeyName } from "$lib/keyName"; import { link } from "svelte-spa-router"; + import { listen } from "@tauri-apps/api/event"; export let key: Solo2; export let latest_version = "0.0.0"; let dialogOpen = false; let updating = false; + let updateProgress = 0; let expanding = false; let selected_file: string | undefined; let keyName = key.name ?? key.uuid; let editingKeyName = false; + listen("update_progress", async (data) => { + const updateData = data.payload as UpdateData; + if (updateData.uuid === key.uuid) { + const progress = Math.round( + 100 * (updateData.completed / updateData.total) + ); + if (progress === 100) { + updating = false; + } else { + updating = true; + updateProgress = progress; + } + } + }); async function update() { updating = true; try { @@ -210,7 +226,7 @@ style="width: 85px" > {#if updating} - + {:else} Update {/if} diff --git a/src/routes/keys.svelte b/src/routes/keys.svelte index d7f98f3..94b53b6 100644 --- a/src/routes/keys.svelte +++ b/src/routes/keys.svelte @@ -3,8 +3,9 @@ import { addNamesToKeys } from "$lib/keyName"; import { listen } from "@tauri-apps/api/event"; import { invoke } from "@tauri-apps/api/tauri"; - import type { Solo2List } from "src/types"; + import type { Solo2List } from "$types"; import { onMount } from "svelte"; + import type { UpdateData } from "../types"; let keyList: Solo2List; let latest_version: string; diff --git a/src/types.ts b/src/types.ts index 7305bb2..2f9707e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,3 +7,9 @@ export interface Solo2 { export interface Solo2List { [uuid: string]: Solo2; } + +export interface UpdateData { + uuid: string; + completed: number; + total: number; +} diff --git a/tsconfig.json b/tsconfig.json index 78682ff..cf00427 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "$lib/*": ["./src/lib/*"], "$routes/*": ["./src/routes/*"], "$assets/*": ["./src/assets/*"], - "$icons/*": ["./src/assets/icons/*"] + "$icons/*": ["./src/assets/icons/*"], + "$types": ["./src/types.ts"] }, "allowSyntheticDefaultImports": true, "target": "ESNext",