Skip to content

Commit

Permalink
wip user confirm
Browse files Browse the repository at this point in the history
TODO: timeout for the user confirmation.
  • Loading branch information
benma committed Jun 30, 2024
1 parent 13881ba commit f11c4a8
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 32 deletions.
201 changes: 201 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bitbox-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
webbrowser = "1.0"
env_logger = "0.11"
futures = { workspace = true }
futures-util = { workspace = true }
Expand Down
20 changes: 20 additions & 0 deletions bitbox-bridge/resources/confirmation_dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Confirmation</title>
</head>
<body>
<h1>Confirm Action</h1>
<p>{{ message }}</p>
<button onclick="sendResponse(true)">OK</button>
<button onclick="sendResponse(false)">Cancel</button>
<script>
function sendResponse(userChoice) {
fetch(`/confirm/response/{{ counter }}/${userChoice}`, { method: 'POST' })
.then(() => window.close()) // Optionally close the window/tab
.catch(err => console.error('Error sending response:', err));
}
</script>
</body>
</html>
21 changes: 20 additions & 1 deletion bitbox-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// limitations under the License.

use futures::channel::mpsc;
use std::collections::HashSet;
use std::net::SocketAddr;
use std::sync::{Arc, Mutex};
use tokio::runtime::Runtime;

#[macro_use]
Expand Down Expand Up @@ -90,9 +92,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = SocketAddr::new("127.0.0.1".parse()?, port);

println!("listening on http://{}", addr);
let server = web::create(usb_devices, notify_tx, addr);
let state = web::ConfirmState::new();
let remembered_allowed_origins = Arc::new(Mutex::new(HashSet::new()));
let server = web::create(
usb_devices,
notify_tx,
state.clone(),
remembered_allowed_origins.clone(),
addr,
);

rt.block_on(async move {
let s = state.clone();
let r = remembered_allowed_origins.clone();
tokio::spawn(async move {
let foo = web::user_confirm_origin(s, r, "ORIGIN".into(), &format!("http://{}", addr))

Check failure on line 109 in bitbox-bridge/src/main.rs

View workflow job for this annotation

GitHub Actions / Lint

useless conversion to the same type: `&str`

Check failure on line 109 in bitbox-bridge/src/main.rs

View workflow job for this annotation

GitHub Actions / Lint

use of a disallowed/placeholder name `foo`
.await
.unwrap();
println!("RESULT 1 {}", foo);
});

tokio::select! {
_ = stop_request => info!("Requested to stop by environment"),
_ = server => info!("Warp returned"),
Expand Down
Loading

0 comments on commit f11c4a8

Please sign in to comment.