From f522674a1c7373b0021d1442dcecd16bf45c625b Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Tue, 12 Sep 2023 11:47:33 -0700 Subject: [PATCH] don't remove request from state until after re-hiding window --- src-tauri/Cargo.lock | 2 +- src-tauri/src/errors.rs | 2 ++ src-tauri/src/state.rs | 12 ++++++------ todo.md | 2 ++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 1579058..c13c957 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1040,7 +1040,7 @@ dependencies = [ [[package]] name = "creddy" -version = "0.2.3" +version = "0.3.0" dependencies = [ "argon2", "auto-launch", diff --git a/src-tauri/src/errors.rs b/src-tauri/src/errors.rs index f8cd51e..5096154 100644 --- a/src-tauri/src/errors.rs +++ b/src-tauri/src/errors.rs @@ -116,6 +116,8 @@ pub enum SendResponseError { NotFound, #[error("The specified request was already closed by the client")] Abandoned, + #[error("A response has already been received for the specified request")] + Fulfilled, #[error("Could not renew AWS sesssion: {0}")] SessionRenew(#[from] GetSessionError), } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 337b6ae..8d1f3d7 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -28,7 +28,7 @@ pub struct AppState { pub config: RwLock, pub session: RwLock, pub request_count: RwLock, - pub open_requests: RwLock>>, + pub open_requests: RwLock>>>, pub pending_terminal_request: RwLock, pub bans: RwLock>>, server: RwLock, @@ -92,7 +92,7 @@ impl AppState { }; let mut open_requests = self.open_requests.write().await; - open_requests.insert(*count, chan); // `count` is the request id + open_requests.insert(*count, Some(chan)); // `count` is the request id *count } @@ -113,11 +113,11 @@ impl AppState { } let mut open_requests = self.open_requests.write().await; - let chan = open_requests - .remove(&response.id) - .ok_or(SendResponseError::NotFound) - ?; + let req = open_requests + .get_mut(&response.id) + .ok_or(SendResponseError::NotFound)?; + let chan = req.take().ok_or(SendResponseError::Fulfilled)?; chan.send(response.approval) .map_err(|_e| SendResponseError::Abandoned) } diff --git a/todo.md b/todo.md index 64f8e5a..2576af6 100644 --- a/todo.md +++ b/todo.md @@ -6,6 +6,7 @@ * Additional hotkey configuration (approve/deny at the very least) * Logging * Icon +* Auto-updates * SSH key handling ## Maybe @@ -14,3 +15,4 @@ * Rehide after terminal launch from locked * Generalize Request across both credentials and terminal launch? * Make hotkey configuration a little more tolerant of slight mistiming +* Distinguish between request that was denied and request that was canceled (e.g. due to error)