From d0df86da9a9f5ceb54c28d9cceaefb01141a2b50 Mon Sep 17 00:00:00 2001 From: Simeon Zahariev <43317481+Apokalip@users.noreply.github.com> Date: Thu, 25 Aug 2022 02:02:02 +0300 Subject: [PATCH] Stop close button[X] on Authorization prompt from closing manta-signer (#166) * Fixing Auth window Signed-off-by: Apokalip * Adding authorization abort Signed-off-by: Apokalip * Update CHANGELOG.md Signed-off-by: Simeon Zahariev <43317481+Apokalip@users.noreply.github.com> * add documentation Signed-off-by: Brandon H. Gomes Signed-off-by: Apokalip Signed-off-by: Simeon Zahariev <43317481+Apokalip@users.noreply.github.com> Signed-off-by: Brandon H. Gomes Co-authored-by: Brandon H. Gomes --- CHANGELOG.md | 1 + ui/src-tauri/src/main.rs | 29 ++++++++++++++++++++++++++++- ui/src/pages/Authorize.js | 11 +++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b83d64b..0459b04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed ### Fixed +- [\#166](https://github.com/Manta-Network/manta-signer/pull/166) Stop close button[X] on Authorization prompt(Private to Anything) from closing manta-signer - [\#164](https://github.com/Manta-Network/manta-signer/pull/164) Adding some communication between UI and backend to ensure sync at connection start ### Security diff --git a/ui/src-tauri/src/main.rs b/ui/src-tauri/src/main.rs index 65c2cfcd..fc609839 100644 --- a/ui/src-tauri/src/main.rs +++ b/ui/src-tauri/src/main.rs @@ -53,6 +53,9 @@ use tauri::{ pub struct AppState { /// UI is Connected pub ui_connected: AtomicBool, + + /// Currently Authorising + pub authorizing: AtomicBool, } impl AppState { @@ -61,6 +64,7 @@ impl AppState { pub const fn new() -> Self { Self { ui_connected: AtomicBool::new(false), + authorizing: AtomicBool::new(false), } } @@ -75,6 +79,18 @@ impl AppState { pub fn set_ui_connected(&self, ui_connected: bool) { self.ui_connected.store(ui_connected, Ordering::Relaxed) } + + /// Returns the authorizing status. + #[inline] + pub fn get_authorizing(&self) -> bool { + self.authorizing.load(Ordering::Relaxed) + } + + /// Sets the authorizing status. + #[inline] + pub fn set_authorizing(&self, auth: bool) { + self.authorizing.store(auth, Ordering::Relaxed); + } } /// Application State @@ -186,12 +202,14 @@ impl Authorizer for User { where T: Serialize, { + APP_STATE.set_authorizing(true); self.emit("authorize", prompt); Box::pin(async move {}) } #[inline] fn sleep(&mut self) -> UnitFuture { + APP_STATE.set_authorizing(false); Box::pin(async move { self.validate_password().await }) } } @@ -314,7 +332,16 @@ fn main() { api.prevent_close(); match label.as_str() { "about" => window(app, "about").hide().expect("Unable to hide window."), - "main" => app.exit(0), + "main" => { + if APP_STATE.get_authorizing() { + window(app, "main").hide().expect("Unable to hide window."); + window(app, "main") + .emit("abort_auth", "Aborting Authorization") + .expect("Failed to abort authorization"); + } else { + app.exit(0); + } + } _ => unreachable!("There are no other windows."), } } diff --git a/ui/src/pages/Authorize.js b/ui/src/pages/Authorize.js index 21f398cb..8861b271 100644 --- a/ui/src/pages/Authorize.js +++ b/ui/src/pages/Authorize.js @@ -1,4 +1,5 @@ -import React, { useState } from 'react'; +import { once } from '@tauri-apps/api/event'; +import React, { useState, useEffect } from 'react'; import { Button, Header, Input } from 'semantic-ui-react'; const Authorize = ({ @@ -8,7 +9,13 @@ const Authorize = ({ hideWindow, }) => { const [password, setPassword] = useState(''); - const [passwordInvalid, setPasswordInvalid] = useState(false) + const [passwordInvalid, setPasswordInvalid] = useState(false); + + useEffect(() => { + once("abort_auth", async () => { + await onClickDecline(); + }); + }); const onClickAuthorize = async () => { console.log("[INFO]: Authorizing.");