Terminal: the socket's end says itself whether the sign-in was refused
The closing callback gets the End as it is (End::unauthorized), instead of lib.rs reading the code back out of the JSON sent to the page -- which left End::unauthorized unused and CI's -D warnings refused the build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+22
-13
No files matched your search
+13
-11
@@ -546,18 +546,20 @@ fn terminal_open(
|
|||||||
};
|
};
|
||||||
let url = terminal::url(&app_url, &target, cols, rows)?;
|
let url = terminal::url(&app_url, &target, cols, rows)?;
|
||||||
let h = handle.clone();
|
let h = handle.clone();
|
||||||
Ok(app.terminals.open(url, token, move |down| {
|
let on_end = handle.clone();
|
||||||
if down.kind == "end" {
|
Ok(app.terminals.open(
|
||||||
h.state::<App>().terminals.forget(down.id);
|
url,
|
||||||
let refused = down.data.get("code").and_then(Value::as_u64)
|
token,
|
||||||
== Some(u64::from(terminal::CLOSE_UNAUTHORIZED))
|
move |down| {
|
||||||
|| down.data.get("status").and_then(Value::as_u64) == Some(401);
|
|
||||||
if refused {
|
|
||||||
token_refused(&h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let _ = h.emit("terminal", down);
|
let _ = h.emit("terminal", down);
|
||||||
}))
|
},
|
||||||
|
move |id, end| {
|
||||||
|
on_end.state::<App>().terminals.forget(id);
|
||||||
|
if end.unauthorized() {
|
||||||
|
token_refused(&on_end);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Keys typed (or pasted) into a terminal, as text: sent to the shell as its bytes.
|
/// Keys typed (or pasted) into a terminal, as text: sent to the shell as its bytes.
|
||||||
|
|||||||
@@ -167,14 +167,21 @@ pub struct Sessions {
|
|||||||
|
|
||||||
impl Sessions {
|
impl Sessions {
|
||||||
/// Open a terminal's socket on its own thread. `emit` gets every frame, the `end` last;
|
/// Open a terminal's socket on its own thread. `emit` gets every frame, the `end` last;
|
||||||
/// the id is the page's handle on it.
|
/// `ended` is told how it ended just before. The id is the page's handle on it.
|
||||||
pub fn open(&self, url: String, token: String, emit: impl Fn(Down) + Send + 'static) -> u64 {
|
pub fn open(
|
||||||
|
&self,
|
||||||
|
url: String,
|
||||||
|
token: String,
|
||||||
|
emit: impl Fn(Down) + Send + 'static,
|
||||||
|
ended: impl FnOnce(u64, &End) + Send + 'static,
|
||||||
|
) -> u64 {
|
||||||
let id = self.next.fetch_add(1, Ordering::SeqCst) + 1;
|
let id = self.next.fetch_add(1, Ordering::SeqCst) + 1;
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
self.open.lock().unwrap().insert(id, tx);
|
self.open.lock().unwrap().insert(id, tx);
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let send = |kind: &'static str, data: Value| emit(Down { id, kind, data });
|
let send = |kind: &'static str, data: Value| emit(Down { id, kind, data });
|
||||||
let end = run(&url, &token, &rx, &send);
|
let end = run(&url, &token, &rx, &send);
|
||||||
|
ended(id, &end);
|
||||||
send("end", serde_json::to_value(&end).unwrap_or(Value::Null));
|
send("end", serde_json::to_value(&end).unwrap_or(Value::Null));
|
||||||
});
|
});
|
||||||
id
|
id
|
||||||
|
|||||||
Reference in new issue
Block a user