Skip to content

Commit f11c4a8

Browse files
committed
wip user confirm
TODO: timeout for the user confirmation.
1 parent 13881ba commit f11c4a8

File tree

5 files changed

+425
-32
lines changed

5 files changed

+425
-32
lines changed

Cargo.lock

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bitbox-bridge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
license = "Apache-2.0"
88

99
[dependencies]
10+
webbrowser = "1.0"
1011
env_logger = "0.11"
1112
futures = { workspace = true }
1213
futures-util = { workspace = true }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Confirmation</title>
6+
</head>
7+
<body>
8+
<h1>Confirm Action</h1>
9+
<p>{{ message }}</p>
10+
<button onclick="sendResponse(true)">OK</button>
11+
<button onclick="sendResponse(false)">Cancel</button>
12+
<script>
13+
function sendResponse(userChoice) {
14+
fetch(`/confirm/response/{{ counter }}/${userChoice}`, { method: 'POST' })
15+
.then(() => window.close()) // Optionally close the window/tab
16+
.catch(err => console.error('Error sending response:', err));
17+
}
18+
</script>
19+
</body>
20+
</html>

bitbox-bridge/src/main.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// limitations under the License.
1414

1515
use futures::channel::mpsc;
16+
use std::collections::HashSet;
1617
use std::net::SocketAddr;
18+
use std::sync::{Arc, Mutex};
1719
use tokio::runtime::Runtime;
1820

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

9294
println!("listening on http://{}", addr);
93-
let server = web::create(usb_devices, notify_tx, addr);
95+
let state = web::ConfirmState::new();
96+
let remembered_allowed_origins = Arc::new(Mutex::new(HashSet::new()));
97+
let server = web::create(
98+
usb_devices,
99+
notify_tx,
100+
state.clone(),
101+
remembered_allowed_origins.clone(),
102+
addr,
103+
);
94104

95105
rt.block_on(async move {
106+
let s = state.clone();
107+
let r = remembered_allowed_origins.clone();
108+
tokio::spawn(async move {
109+
let foo = web::user_confirm_origin(s, r, "ORIGIN".into(), &format!("http://{}", addr))
110+
.await
111+
.unwrap();
112+
println!("RESULT 1 {}", foo);
113+
});
114+
96115
tokio::select! {
97116
_ = stop_request => info!("Requested to stop by environment"),
98117
_ = server => info!("Warp returned"),

0 commit comments

Comments
 (0)