Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion native/gpui/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async fn session(config:&Config,commands:&mut mpsc::Receiver<Command>,queued:&mu
continue;
}
if let Some(tag)=v.asks.remove(&id) {let _=events.send(Event::Answer(tag,x)).await;continue;}
if let Some(tag)=v.rpcs.remove(&id) {if tag=="hubupd" {if x["ok"]==true {let _=events.send(Event::Data("hubupd",x["result"].clone())).await;}continue;}if tag=="thread-context" {let _=events.send(Event::Data("thread-context",x)).await;continue;}if tag=="kicad" {let m=v.rpc_names.remove(&id).unwrap_or_default();let why=if x["ok"]==true {String::new()} else {rpc_error(&x)};eprintln!("GPUI_LOG {}",json!({"kicad_rpc_reply":m,"id":id,"at_ms":crate::screens::kcomment::epoch_ms() as u64,"ok":x["ok"]==true,"state":x["state"],"mode":x["mode"],"pid":x["pid"],"warm":x["warm"],"started":x["started"],"why":x["why"],"prewarming":x["prewarming"],"error":why.chars().take(160).collect::<String>()}));let _=events.send(Event::KicadReply(m,x)).await;continue;}if tag=="star" {let _=events.send(Event::Star(if x["ok"]==true {x["result"]["offer"].clone()} else {Value::Null})).await;continue;}if tag=="tmnotice" {let _=events.send(Event::TmNotice(if x["ok"]==true {x["result"]["notice"].clone()} else {Value::Null})).await;continue;}if tag=="gpnotice" {let _=events.send(Event::GpNotice(if x["ok"]==true {x["result"]["notice"].clone()} else {Value::Null})).await;continue;}if tag==crate::streamer::TAG {if x["ok"]==true {let _=events.send(Event::Data(crate::streamer::TAG,x["result"].clone())).await;}continue;}if tag=="google" && x["ok"]==true {let _=events.send(Event::Data(tag.clone(),x["result"].clone())).await;}if tag=="acct" || (tag=="acct-moveall" && x["ok"]==true) {let _=events.send(Event::Data(tag.clone(),x["result"].clone())).await;}if tag=="steps" {let _=events.send(Event::Steps(if x["ok"]==true {x["result"].clone()} else {Value::Null})).await;continue;}if tag.starts_with("probe") {let slot:usize=tag[5..].parse().unwrap_or(0);let m=x["result"]["matches"].as_array().map(|a|a.iter().filter_map(|p|Some((p[0].as_u64()? as usize,p[1].as_u64()? as usize))).collect()).unwrap_or_default();let _=events.send(Event::Probe(slot,m)).await;continue;}if tag=="resolve" {let _=events.send(Event::Refs(serde_json::json!({"resolved":x["result"]["resolved"].clone(),"error":x["result"]["error"].clone()}))).await;continue;}if tag=="refs" {let _=events.send(Event::Refs(if x["ok"]==true {x["result"].clone()} else {Value::Null})).await;continue;}if tag=="names"||tag=="xsel"||tag=="xsel-tap" {let _=events.send(Event::Data(if tag=="names" {"names"} else if tag=="xsel" {"xsel"} else {"xsel-tap"},x)).await;continue;}if tag=="pick" {let _=events.send(Event::Pick(if x["ok"]==true {x["result"]["info"].as_str().unwrap_or("").to_string()} else {String::new()})).await;continue;}let ok=x["ok"]==true;let why=if ok&&tag.starts_with("hook"){crate::screens::bots::hook_answer(&x).to_string()}else if ok&&tag.starts_with("files"){x["result"].to_string()}else{crate::screens::settings::reply_error(&x)};let _=events.send(Event::Rpc(tag,ok,why)).await;continue;}
if let Some(tag)=v.rpcs.remove(&id) {if tag=="home-move-dismiss" {if x["ok"]==true {if !v.view_id.is_empty()&&v.pending.is_empty(){let request=v.request("view.update",json!({}));sink.send(Message::Binary(wire::encode(&request).into())).await?;}else{v.dirty=true;}}continue;}if tag=="hubupd" {if x["ok"]==true {let _=events.send(Event::Data("hubupd",x["result"].clone())).await;}continue;}if tag=="thread-context" {let _=events.send(Event::Data("thread-context",x)).await;continue;}if tag=="kicad" {let m=v.rpc_names.remove(&id).unwrap_or_default();let why=if x["ok"]==true {String::new()} else {rpc_error(&x)};eprintln!("GPUI_LOG {}",json!({"kicad_rpc_reply":m,"id":id,"at_ms":crate::screens::kcomment::epoch_ms() as u64,"ok":x["ok"]==true,"state":x["state"],"mode":x["mode"],"pid":x["pid"],"warm":x["warm"],"started":x["started"],"why":x["why"],"prewarming":x["prewarming"],"error":why.chars().take(160).collect::<String>()}));let _=events.send(Event::KicadReply(m,x)).await;continue;}if tag=="star" {let _=events.send(Event::Star(if x["ok"]==true {x["result"]["offer"].clone()} else {Value::Null})).await;continue;}if tag=="tmnotice" {let _=events.send(Event::TmNotice(if x["ok"]==true {x["result"]["notice"].clone()} else {Value::Null})).await;continue;}if tag=="gpnotice" {let _=events.send(Event::GpNotice(if x["ok"]==true {x["result"]["notice"].clone()} else {Value::Null})).await;continue;}if tag==crate::streamer::TAG {if x["ok"]==true {let _=events.send(Event::Data(crate::streamer::TAG,x["result"].clone())).await;}continue;}if tag=="google" && x["ok"]==true {let _=events.send(Event::Data(tag.clone(),x["result"].clone())).await;}if tag=="acct" || (tag=="acct-moveall" && x["ok"]==true) {let _=events.send(Event::Data(tag.clone(),x["result"].clone())).await;}if tag=="steps" {let _=events.send(Event::Steps(if x["ok"]==true {x["result"].clone()} else {Value::Null})).await;continue;}if tag.starts_with("probe") {let slot:usize=tag[5..].parse().unwrap_or(0);let m=x["result"]["matches"].as_array().map(|a|a.iter().filter_map(|p|Some((p[0].as_u64()? as usize,p[1].as_u64()? as usize))).collect()).unwrap_or_default();let _=events.send(Event::Probe(slot,m)).await;continue;}if tag=="resolve" {let _=events.send(Event::Refs(serde_json::json!({"resolved":x["result"]["resolved"].clone(),"error":x["result"]["error"].clone()}))).await;continue;}if tag=="refs" {let _=events.send(Event::Refs(if x["ok"]==true {x["result"].clone()} else {Value::Null})).await;continue;}if tag=="names"||tag=="xsel"||tag=="xsel-tap" {let _=events.send(Event::Data(if tag=="names" {"names"} else if tag=="xsel" {"xsel"} else {"xsel-tap"},x)).await;continue;}if tag=="pick" {let _=events.send(Event::Pick(if x["ok"]==true {x["result"]["info"].as_str().unwrap_or("").to_string()} else {String::new()})).await;continue;}let ok=x["ok"]==true;let why=if ok&&tag.starts_with("hook"){crate::screens::bots::hook_answer(&x).to_string()}else if ok&&tag.starts_with("files"){x["result"].to_string()}else{crate::screens::settings::reply_error(&x)};let _=events.send(Event::Rpc(tag,ok,why)).await;continue;}
if dock_watch.as_ref().is_some_and(|(rid, _)| *rid == id) {
let (_, mut watch) = dock_watch.take().unwrap();
watch["tiles"] = x["result"]["tiles"].clone();
Expand Down Expand Up @@ -555,6 +555,7 @@ async fn session(config:&Config,commands:&mut mpsc::Receiver<Command>,queued:&mu
"gitpush.notice"=>{let _=events.send(Event::GpNotice(x["notice"].clone())).await;},
"browser.download"=>{let s=|k:&str|x[k].as_str().unwrap_or("").to_string();let _=events.send(Event::BrowserDownload(s("bot"),s("id"),s("name"),s("error"))).await;},
"info"=>{
if x["info"].get("home.move").is_some() { v.dirty = true; }
// the merged project rows moved with no log line (a machine's origins learned, it away or back): the view is asked for again
if x["info"].get("mirrors.gen").is_some()&&!v.view_id.is_empty()&&v.pending.is_empty(){let request=v.request("view.update",json!({}));sink.send(Message::Binary(wire::encode(&request).into())).await?;}
if let Some(m)=x["info"].as_object(){for(k,val) in m{if k=="hub.back"{if let Some(t)=val.as_str().and_then(|v|serde_json::from_str::<Value>(v).ok()).and_then(|v|v["text"].as_str().map(str::to_string)).filter(|t|!t.is_empty()){let _=events.send(Event::Note(crate::i18n::trs(&t))).await;}}if k=="hub.offer"{let _=events.send(Event::HubOffer(val.as_str().unwrap_or("").to_string())).await;}if k=="kicad.update"||k=="kicad.install"{let _=events.send(Event::KicadUpdate(k.clone(),val.as_str().unwrap_or("").to_string())).await;}if k.starts_with("kicad.progress."){let _=events.send(Event::KicadProgress(val.as_str().unwrap_or("").to_string())).await;}if k.starts_with("mgmt.")||k.starts_with("review.clicked."){let _=events.send(Event::Mgmt(k.clone(),val.as_str().unwrap_or("").to_string())).await;}if k.starts_with("kicad.comment."){let _=events.send(Event::KicadComment(val.as_str().unwrap_or("").to_string())).await;}if k.starts_with("kicad.reload."){let _=events.send(Event::KicadReload(val.as_str().unwrap_or("").to_string())).await;}if let Some(d)=k.strip_prefix("editor.kicad."){let _=events.send(Event::KicadEditor(d.to_string(),val.as_str().unwrap_or("").to_string())).await;}if let Some(owner)=k.strip_prefix("browser.tabs."){let _=events.send(Event::BrowserTabs(owner.to_string(),val.as_str().unwrap_or("").to_string())).await;}}}},
Expand Down
48 changes: 46 additions & 2 deletions native/gpui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,24 @@ impl Backplane {
crew.push(div().id("crew-rooms").flex().flex_wrap().items_center().px(px(7.)).pb(px(6.)).max_h(px(3. * 22. + 6.)).overflow_y_scroll().children(chips).into_any_element());
}
if let Some((line, bad)) = home_away_line(&self.data["home"]) {
rows.push(div().id("home-away-row").px_3().py_1().border_b_1().border_color(c("line")).bg(c("panel")).text_size(crate::scale::tpx(11.)).text_color(if bad { c("bad") } else { c("dim") }).child(line).into_any_element());
let dismissible = home_move_dismissible(&self.data["home"]);
let mut row = div().id("home-away-row").px_3().py_1().border_b_1().border_color(c("line")).bg(c("panel"))
.flex().items_center().gap_1()
.text_size(crate::scale::tpx(11.)).text_color(if bad { c("bad") } else { c("dim") })
.child(div().flex_1().min_w_0().child(line));
if dismissible {
row = row.child(
/* i18n-ok: a ui: id the drivers press */ with_rect(div().id("home-away-dismiss"), || "ui:Dismiss home move".to_string())
.flex_shrink_0().px_1().cursor_pointer().text_color(c("dim")).hover(|s| s.text_color(c("text")).bg(c("raise")))
.tooltip(crate::keys::tip_raw(&crate::i18n::t("approval.dismiss"), "", light))
.on_click(cx.listener(|this, _, _, cx| {
let _ = this.tx.try_send(home_move_dismiss_cmd());
cx.notify();
}))
.child("×"),
);
}
rows.push(row.into_any_element());
}
let new_here = crate::keys::new_target(&self.data, &self.selected, self.project_page.as_deref());
// the hub's sections (Needs you, Pinned, Active, groups, Quiet: screens/sections.rs); an older hub sends projects and the Active view
Expand Down Expand Up @@ -1715,9 +1732,20 @@ pub(crate) fn home_away_line(home: &Value) -> Option<(String, bool)> {
Some((s, false))
}

/// Whether the sidebar home status banner represents a failed move that the user can dismiss.
pub(crate) fn home_move_dismissible(home: &Value) -> bool {
home.get("moving").and_then(|m| m["state"].as_str()) == Some("failed")
}

/// Command sent when the user dismisses a failed home-move banner.
pub(crate) fn home_move_dismiss_cmd() -> Command {
Command::Rpc("home.move.dismiss".into(), crate::screens::settings::Secret(serde_json::json!({})), "home-move-dismiss")
}

#[cfg(test)]
mod home_tests {
use super::home_away_line;
use super::{home_away_line, home_move_dismiss_cmd, home_move_dismissible};
use crate::hub::Command;
use serde_json::{json, Value};

#[test]
Expand All @@ -1733,6 +1761,22 @@ mod home_tests {
/* i18n-ok: test */ assert_eq!(fail, Some(("Home move failed: disk full".into(), true)));
}

#[test]
fn home_move_dismiss_only_applies_to_failed_moves() {
assert!(!home_move_dismissible(&Value::Null));
assert!(!home_move_dismissible(&json!({"kind":"local","name":"desk","online":true})));
assert!(!home_move_dismissible(&json!({"kind":"peer","name":"desk","online":false})));
assert!(!home_move_dismissible(&json!({"kind":"peer","name":"desk","online":true,"moving":{"to":"laptop","state":"moving","step":"copying"}})));
assert!(home_move_dismissible(&json!({"kind":"peer","name":"desk","online":true,"moving":{"to":"laptop","state":"failed","note":"that machine is away"}})));
match home_move_dismiss_cmd() {
Command::Rpc(method, _, tag) => {
assert_eq!(method, "home.move.dismiss");
assert_eq!(tag, "home-move-dismiss");
}
other => panic!("unexpected command: {other:?}"),
}
}

#[test]
fn card_refs_excludes_inline_model_cards_and_keeps_others() {
let refs = json!([
Expand Down
32 changes: 27 additions & 5 deletions native/host/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ async fn call(hub: &Arc<Hub>, c: &mut Conn, m: &str, p: &Value, is_browser: bool
"ask.answer" => { rpc(hub, c, "ask.answer", json!({"id":s(p, "ask"),"answer":s(p, "answer")})).await?; Ok(json!({})) }
// the same answer every client gets (its `result`, not the reply around it); the phones draw it
"update.status" | "update.check" | "app.update" | "update.now" => Ok(rpc(hub, c, m, json!({})).await?["result"].clone()),
"hub.offer.take" | "hub.offer.done" => Ok(rpc(hub, c, m, p.clone()).await?["result"].clone()),
"hub.offer.take" | "hub.offer.done" | "home.move.dismiss" => Ok(rpc(hub, c, m, p.clone()).await?["result"].clone()),
"update.channel" => { let ch = s(p, "channel"); if !["stable", "beta", "nightly"].contains(&ch) { return Err(err("no such channel")) } rpc(hub, c, "setting.set", json!({"key":"update.channel","value":ch})).await?; Ok(rpc(hub, c, "update.status", json!({})).await?["result"].clone()) }
// Improvements: the projects of every machine a request may go to (searched on the hub) and the last one chosen, as the desktop gets them
"improvements.projects" | "improvements.project" => Ok(rpc(hub, c, m, p.clone()).await?["result"].clone()),
Expand Down Expand Up @@ -1196,10 +1196,21 @@ async fn socket_with_reg<S: AsyncRead + AsyncWrite + Unpin + Send>(
let lines = hub.store.range(seen, len.min(seen + 2000)).unwrap_or_default();
seen += lines.len();
let inv_changed = lines.iter().any(|l| l.contains("\"accounts.inventory\""));
let home_changed = lines.iter().any(|l| l.contains("\"home.moving\"") || l.contains("\"home.at\""));
for f in deltas(&hub, &lines, &mut subs).await {
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&f, json_mode)).await? { return Ok(()) }
sent = true;
}
if home_changed && !subs.lists().is_empty() {
let h = crate::net::home::now(&hub).await;
if h != home_sent {
home_sent = h.clone();
for sub in subs.lists() {
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&d(sub, "home", json!({"home": h})), json_mode)).await? { return Ok(()) }
}
sent = true;
}
}
if inv_changed {
let cur = crate::settings::provider_notice::for_hub(&hub).await.map_or(Value::Null, |n| n.json());
if cur != no_provider_sent {
Expand Down Expand Up @@ -1239,11 +1250,22 @@ async fn socket_with_reg<S: AsyncRead + AsyncWrite + Unpin + Send>(
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&f, json_mode)).await? { return Ok(()) }
},
// hub info (set_info): what a phone draws of it (phone_info), as `{"t":"info","info":{...}}`
Out::Value(v) if v["t"] == "info" => if let Some(f) = phone_info_frame(&v) {
if let Some(raw) = f["info"].get(crate::settings::provider_notice::INFO_KEY) {
no_provider_sent = raw.as_str().and_then(|s| if s.is_empty() { None } else { serde_json::from_str(s).ok() }).unwrap_or(Value::Null);
Out::Value(v) if v["t"] == "info" => {
if v["info"].get("home.move").is_some() && !subs.lists().is_empty() {
let h = crate::net::home::now(&hub).await;
if h != home_sent {
home_sent = h.clone();
for sub in subs.lists() {
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&d(sub, "home", json!({"home": h})), json_mode)).await? { return Ok(()) }
}
}
}
if let Some(f) = phone_info_frame(&v) {
if let Some(raw) = f["info"].get(crate::settings::provider_notice::INFO_KEY) {
no_provider_sent = raw.as_str().and_then(|s| if s.is_empty() { None } else { serde_json::from_str(s).ok() }).unwrap_or(Value::Null);
}
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&f, json_mode)).await? { return Ok(()) }
}
if !send_frame(&mut tx, &hub, browser.as_ref(), conn.client, pack(&f, json_mode)).await? { return Ok(()) }
},
Out::Value(v) => if ext::wants_value(&v) {
// a plot's "none" is binary like the plots (one decoder in the app); a browser frame's announcement is JSON
Expand Down
4 changes: 3 additions & 1 deletion native/host/src/data/webpolicy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ fn classify(method: &str, params: &Value) -> Option<Policy> {
| "clone.start"
| "clone.cancel"
| "clone.retry"
| "clone.signin" => Activity,
| "clone.signin"
| "home.move.dismiss" => Activity,
"attachment.get"
| "badge.list"
| "bot.cat"
Expand Down Expand Up @@ -232,6 +233,7 @@ mod tests {
assert_eq!(policy("ring.hear", &json!({"note":"n1","engine":"local"})), Policy::Activity);
for m in ["ring.page", "ring.page.act", "ring.setup", "ring.send", "ring.get", "ring.search"] { assert_eq!(policy(m, &Value::Null), Policy::Denied, "{m}"); }
assert_eq!(policy("project.home", &json!({"project":"p1"})), Policy::Passive);
assert_eq!(policy("home.move.dismiss", &Value::Null), Policy::Activity);
assert_eq!(policy("devices.page", &Value::Null), Policy::Devices);
assert_eq!(policy("devices.page.act", &Value::Null), Policy::Denied);
}
Expand Down
3 changes: 2 additions & 1 deletion native/host/src/net/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ pub async fn read(hub: &Arc<Hub>) -> Facts {
let home_id = at["mid"].as_str().filter(|id| !id.is_empty()).map(str::to_string)
.or_else(|| bots.as_ref().and_then(|b| b.mid_known(&link))).unwrap_or_default();
let queued = if link.is_empty() { 0 } else { crate::net::farsend::global().map_or(0, |o| o.items().iter().filter(|h| h.link == link).count()) };
let now = crate::hub::now_ms() / 1000;
// the machine coming home says so in `home.moving`; the one sending has the job (net/homemove.rs `home.status`)
let here: Value = serde_json::from_str(&hub.setting("home.moving").await.unwrap_or_default()).unwrap_or(Value::Null);
let moving = if here.is_object() { here } else { crate::net::homemove::job() };
let moving = crate::net::homemove::active_move(&here, now).unwrap_or_else(|| crate::net::homemove::job_at(now));
Facts { away_since: if link.is_empty() { None } else { hub.mirrors().away_since(&link) }, at, boat_link: boat["link"].as_str().unwrap_or("").to_string(),
me_id, me_name: NAME.get_or_init(crate::net::botnet::name).await.clone(), home_id, queued, moving }
}
Expand Down
Loading
Loading