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.");