Skip to content

Commit

Permalink
Stop close button[X] on Authorization prompt from closing manta-signer (
Browse files Browse the repository at this point in the history
#166)

* Fixing Auth window

Signed-off-by: Apokalip <simeon@manta.network>

* Adding authorization abort

Signed-off-by: Apokalip <simeon@manta.network>

* Update CHANGELOG.md

Signed-off-by: Simeon Zahariev <43317481+Apokalip@users.noreply.github.com>

* add documentation

Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>

Signed-off-by: Apokalip <simeon@manta.network>
Signed-off-by: Simeon Zahariev <43317481+Apokalip@users.noreply.github.com>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Co-authored-by: Brandon H. Gomes <bhgomes@pm.me>
  • Loading branch information
Apokalip and bhgomes authored Aug 24, 2022
1 parent 30b8780 commit d0df86d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion ui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ use tauri::{
pub struct AppState {
/// UI is Connected
pub ui_connected: AtomicBool,

/// Currently Authorising
pub authorizing: AtomicBool,
}

impl AppState {
Expand All @@ -61,6 +64,7 @@ impl AppState {
pub const fn new() -> Self {
Self {
ui_connected: AtomicBool::new(false),
authorizing: AtomicBool::new(false),
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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 })
}
}
Expand Down Expand Up @@ -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."),
}
}
Expand Down
11 changes: 9 additions & 2 deletions ui/src/pages/Authorize.js
Original file line number Diff line number Diff line change
@@ -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 = ({
Expand All @@ -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.");
Expand Down

1 comment on commit d0df86d

@vercel
Copy link

@vercel vercel bot commented on d0df86d Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.