Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop close button[X] on Authorization prompt from closing manta-signer #166

Merged
merged 6 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

### Security

Expand Down
40 changes: 39 additions & 1 deletion ui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ use manta_signer::{
storage::Store,
tokio::time::sleep,
};
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{
async_runtime::spawn, CustomMenuItem, Manager, RunEvent, Runtime, State, SystemTray,
SystemTrayEvent, SystemTrayMenu, Window, WindowEvent,
};

/// App State
/// Keeps track of flags that we need
/// for specific behaviors
struct AppState {
/// Authorising currently
pub authorising: AtomicBool,
}

impl AppState{
pub const fn new() -> Self {
AppState {authorising: AtomicBool::new(false)}
}

pub fn set_authorising(&self, auth: bool) {
self.authorising.store(auth, Ordering::Relaxed);
}

pub fn get_authorising(&self) -> bool {
self.authorising.load(Ordering::Relaxed)
}
}

static APP_STATE: AppState = AppState::new();

/// User
pub struct User {
/// Main Window
Expand Down Expand Up @@ -120,12 +145,16 @@ impl Authorizer for User {
where
T: Serialize,
{
// starting authorization
APP_STATE.set_authorising(true);
self.emit("authorize", prompt);
Box::pin(async move {})
}

#[inline]
fn sleep(&mut self) -> UnitFuture {
// stopped authorizing
APP_STATE.set_authorising(false);
Box::pin(async move { self.validate_password().await })
}
}
Expand Down Expand Up @@ -237,7 +266,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_authorising() {
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