Skip to content

Commit

Permalink
Merge branch 'main' into proving_key_bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Apokalip authored Jan 23, 2023
2 parents 26f6d2a + 9f709e6 commit 00a31fd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ where
#[inline]
pub async fn cancel_signing(&mut self) {
self.state.lock().currently_signing = false;

// Forcefully sleep because the authorizer gets stuck awake if we exit recovery window
self.authorizer.lock().await.authorizer.sleep();
}

/// Starts the signer server with `config` and `authorizer`.
Expand Down
40 changes: 36 additions & 4 deletions ui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct AppState {
/// UI is Connected
pub ui_connected: AtomicBool,

/// User has logged in and the Signer is running
/// Used to stop signer window from closing from the X button
pub ready: AtomicBool,

/// Currently Authorising
pub authorizing: AtomicBool,
}
Expand All @@ -74,6 +78,7 @@ impl AppState {
pub const fn new() -> Self {
Self {
ui_connected: AtomicBool::new(false),
ready: AtomicBool::new(false),
authorizing: AtomicBool::new(false),
}
}
Expand All @@ -90,6 +95,18 @@ impl AppState {
self.ui_connected.store(ui_connected, Ordering::Relaxed)
}

/// Returns the ready status.
#[inline]
pub fn get_ready(&self) -> bool {
self.ready.load(Ordering::Relaxed)
}

/// Sets the ready status.
#[inline]
pub fn set_ready(&self, ready: bool) {
self.ready.store(ready, Ordering::Relaxed)
}

/// Returns the authorizing status.
#[inline]
pub fn get_authorizing(&self) -> bool {
Expand Down Expand Up @@ -259,6 +276,7 @@ impl Authorizer for User {
#[inline]
fn sleep(&mut self) -> UnitFuture {
APP_STATE.set_authorizing(false);
self.emit("abort_auth", &());
Box::pin(async move { self.validate_password().await })
}
}
Expand Down Expand Up @@ -296,6 +314,17 @@ fn disconnect_ui() {
APP_STATE.set_ui_connected(false);
}

/// TRUE: Called when Signer is ready: User has logged in and signer has minimized to the background/tray
/// This is to prevent signer closure from the [X] button when opening windows from the tray
/// Exiting through the tray menu should be the only way
///
/// False: When there was recovery/aborting recovery and the server
/// needs to restart/reset up
#[tauri::command]
fn set_signer_ready(ready: bool) {
APP_STATE.set_ready(ready);
}

/// Sends the current `password` into storage from the UI.
#[tauri::command]
async fn send_password(
Expand Down Expand Up @@ -662,6 +691,7 @@ fn main() {
reset_account,
connect_ui,
disconnect_ui,
set_signer_ready,
address,
get_recovery_phrase,
cancel_sign,
Expand All @@ -684,11 +714,13 @@ fn main() {
match label.as_str() {
"about" => window(app, "about").hide().expect("Unable to hide window."),
"main" => {
if APP_STATE.get_authorizing() {
if APP_STATE.get_ready() {
window(app, "main").hide().expect("Unable to hide window.");
window(app, "main")
.emit("abort_auth", "Aborting Authorization")
.expect("Failed to abort authorization");
if APP_STATE.get_authorizing() {
window(app, "main")
.emit_all("abort_auth", "Aborting Authorization")
.expect("Failed to abort authorization");
}
} else {
app.exit(0);
}
Expand Down
5 changes: 3 additions & 2 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ function App() {
+ "Delete Account: " + deleteAccount + " Restart App: " + restartApp
);
await endConnection();
await invoke('disconnect_ui');

const payload = {
delete: deleteAccount,
Expand All @@ -252,6 +251,7 @@ function App() {

const endInitialConnectionPhase = async () => {
console.log("[INFO]: End Initial Connection Phase");
await invoke("set_signer_ready", { ready: true });
setIsConnected(true);

if (!activeListeners.authorize) {
Expand Down Expand Up @@ -282,6 +282,8 @@ function App() {

const endConnection = async () => {
console.log("[INFO]: Ending connection.");
await invoke('disconnect_ui');
await invoke("set_signer_ready", { ready: false });
setIsConnected(false);
}

Expand Down Expand Up @@ -343,7 +345,6 @@ function App() {
<Reset
isConnected={isConnected}
hideWindow={hideWindow}
endConnection={endConnection}
restartServer={restartServer}
cancelReset={cancelReset}
/>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/Authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Authorize = ({
};

const onClickDecline = async () => {
("[INFO]: Declining Transaction.");
console.log("[INFO]: Declining Transaction.");
setPassword('');
setPasswordInvalid(false)
await stopPasswordPrompt();
Expand Down
2 changes: 0 additions & 2 deletions ui/src/pages/Reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import "../App.css";
const Reset = ({
isConnected,
hideWindow,
endConnection,
restartServer,
cancelReset
}) => {

const onClickReset = async () => {
await endConnection();
restartServer(true, true);
}

Expand Down
10 changes: 8 additions & 2 deletions ui/src/pages/ViewPhrase/ViewPhrasePage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { once } from '@tauri-apps/api/event';
import { Button, Form, Input } from 'semantic-ui-react';
import { useEffect } from 'react';
import mainLogo from "../../icons/manta.png";
import "../../App.css";

Expand All @@ -13,7 +14,12 @@ const ViewPhrasePage = ({
onClickCancel
}) => {


useEffect(() => {
once("abort_auth", async () => {
await onClickCancel();
});
});

return (<>

<div className='main-logo-container view-phrase'>
Expand Down

0 comments on commit 00a31fd

Please sign in to comment.