Skip to content

armgit / muxin

Public Imported from GitHub
0

All your machines, one app. For you and your AI agents: agent sessions, desktops, files, logs and GitHub across your Macs, Linux and Windows machines, with an MCP server.

Droplet power that waits for the real state, powered-off machines, DigitalOcean logo

Adib Hanna558c264d2fd0
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index d072fc3..866bcfa 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -17,11 +17,12 @@ must ship with every copy of Muxen.
| portable-pty (WezTerm; terminals in `muxen-agent`) | MIT | <https://github.com/wezterm/wezterm> |
| Agent logos (`assets/icons/agent-*.svg`), SVGs from LobeHub Icons | MIT | <https://github.com/lobehub/lobe-icons> |
| Pi logo (`assets/icons/agent-pi.svg`), from Pi's press kit (Earendil) | trademark of its owner | <https://pi.dev/press-kit> |
+| DigitalOcean logo (`assets/icons/brand-digitalocean.svg`), SVG from Simple Icons | CC0-1.0 (the SVG); trademark of DigitalOcean | <https://simpleicons.org> |
| Rust crates listed in `Cargo.lock` | MIT and/or Apache-2.0 (mostly), see each crate | Generate the full list before each release, e.g. with `cargo about generate` |
The agent logos are trademarks of their owners (Anthropic, OpenAI, Google,
-SST, Sourcegraph, Earendil). Muxen shows them only to identify which CLI a session
-runs; check each owner's brand guidelines before using them in marketing.
+SST, Sourcegraph, Earendil), as is DigitalOcean's. Muxen shows them only to identify which CLI a session
+runs, or that a machine is a DigitalOcean droplet; check each owner's brand guidelines before using them in marketing.
Before shipping a release, regenerate the crate list and include the license
texts in the app bundle (for example `Muxen.app/Contents/Resources/`).
diff --git a/assets/icons/brand-digitalocean.svg b/assets/icons/brand-digitalocean.svg
new file mode 100644
index 0000000..261b49a
--- /dev/null
+++ b/assets/icons/brand-digitalocean.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 28 28"><path d="M12.04 0C5.408-.02.005 5.37.005 11.992h4.638c0-4.923 4.882-8.731 10.064-6.855a6.95 6.95 0 014.147 4.148c1.889 5.177-1.924 10.055-6.84 10.064v-4.61H7.391v4.623h4.61V24c7.86 0 13.967-7.588 11.397-15.83-1.115-3.59-3.985-6.446-7.575-7.575A12.8 12.8 0 0012.039 0zM7.39 19.362H3.828v3.564H7.39zm-3.563 0v-2.978H.85v2.978z"/></svg>
diff --git a/src/api.rs b/src/api.rs
index 0a220ff..0e41848 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -404,6 +404,27 @@ pub struct MachineSummary {
/// and whether traffic to it goes peer-to-peer or through a relay.
#[serde(skip_serializing_if = "Option::is_none")]
pub tailnet: Option<crate::fleet::model::TailnetDevice>,
+ /// A cloud machine Muxen created: provider, droplet id, region, size,
+ /// USD an hour, what it has cost so far and since when it's been idle.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub cloud: Option<CloudOut>,
+}
+
+#[derive(Debug, Clone, Serialize)]
+pub struct CloudOut {
+ /// "digitalocean"
+ pub provider: String,
+ pub droplet_id: u64,
+ pub region: String,
+ pub size: String,
+ /// USD an hour, billed while it exists (powered off too).
+ pub price_hourly: f64,
+ pub created_at: Option<DateTime<Utc>>,
+ /// USD since it was created.
+ pub cost_so_far: f64,
+ pub idle_since: Option<DateTime<Utc>>,
+ /// "on", "off" (still billed) or "starting", as last seen; null until known.
+ pub power: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
@@ -636,6 +657,17 @@ pub fn machine_summary(m: &Machine) -> MachineSummary {
error: m.probe.as_ref().filter(|p| !p.ok).and_then(|p| p.error.clone()),
unreachable: m.unreachable.clone(),
tailnet: m.tailnet.clone(),
+ cloud: m.cloud.as_ref().map(|c| CloudOut {
+ provider: c.provider.clone(),
+ droplet_id: c.id,
+ region: c.region.clone(),
+ size: c.size.clone(),
+ price_hourly: c.price_hourly,
+ created_at: c.created_at,
+ cost_so_far: (c.cost_so_far * 100.).round() / 100.,
+ idle_since: c.idle_since,
+ power: c.power.clone(),
+ }),
}
}
diff --git a/src/cloud/digitalocean.rs b/src/cloud/digitalocean.rs
index feb5414..c55ee83 100644
--- a/src/cloud/digitalocean.rs
+++ b/src/cloud/digitalocean.rs
@@ -79,7 +79,13 @@ impl Client {
if let Some(b) = body {
req = req.json(&b);
}
- let resp = req.send().await.map_err(|e| format!("Couldn't reach DigitalOcean: {e}"))?;
+ let resp = req.send().await.map_err(|e| {
+ if e.is_timeout() {
+ "DigitalOcean didn't answer within 30 seconds. Try again in a moment.".to_string()
+ } else {
+ format!("Couldn't reach DigitalOcean: {}", root_cause(&e))
+ }
+ })?;
let status = resp.status();
let text = resp.text().await.unwrap_or_default();
if status.is_success() {
@@ -193,6 +199,15 @@ impl Client {
}
}
+/// The innermost error: reqwest's own message only says the request failed.
+fn root_cause(e: &dyn std::error::Error) -> String {
+ let mut e = e;
+ while let Some(next) = e.source() {
+ e = next;
+ }
+ e.to_string()
+}
+
fn strings(v: &Value) -> Vec<String> {
v.as_array().into_iter().flatten().filter_map(|s| s.as_str().map(str::to_string)).collect()
}
diff --git a/src/config.rs b/src/config.rs
index 3ea1f3c..f0e07d6 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -616,6 +616,9 @@ pub struct PersistedState {
/// Machines on the user's tailnet, as Tailscale last saw them (kept for
/// when Tailscale is off).
pub tailnet: HashMap<String, crate::fleet::model::TailnetDevice>,
+ /// Cloud machines' power ("active", "off", ...) as the provider last
+ /// reported it, by machine id.
+ pub droplets: HashMap<String, String>,
pub check_started_at: Option<DateTime<Utc>>,
pub check_finished_at: Option<DateTime<Utc>>,
}
diff --git a/src/demo.rs b/src/demo.rs
index 4691147..f9d4fe3 100644
--- a/src/demo.rs
+++ b/src/demo.rs
@@ -316,6 +316,7 @@ impl World {
arch: Some(hw.arch.into()),
os_version: Some(hw.os_version.into()),
form_factor: Some(if hw.id.contains("laptop") || hw.id.contains("macbook") { "laptop" } else { "desktop" }.into()),
+ desktop: Some(hw.os != "windows"),
cores: Some(hw.cores),
cpu_pct: Some((cpu * 10.0).round() / 10.0),
mem_total: Some(mem_total),
diff --git a/src/fleet/build.rs b/src/fleet/build.rs
index 8463a5a..48784b1 100644
--- a/src/fleet/build.rs
+++ b/src/fleet/build.rs
@@ -35,6 +35,8 @@ pub struct Inputs<'a> {
pub tailnet: &'a HashMap<String, TailnetDevice>,
/// Tailscale on this computer, when it's installed.
pub tailscale: Option<&'a TailscaleStatus>,
+ /// Cloud machines' power as the provider last reported it, by machine id.
+ pub droplets: &'a HashMap<String, String>,
}
pub fn build(input: &Inputs) -> Snapshot {
@@ -121,9 +123,14 @@ pub fn build(input: &Inputs) -> Snapshot {
Some(_) => "offline",
};
let device = input.tailnet.get(&spec.id);
- let unreachable = probe
- .filter(|p| !p.ok && spec.is_checkable())
- .map(|p| explain_unreachable(spec, p, input.settings.check_interval_minutes > 0, device, input.tailscale));
+ let powered_off = spec.cloud.is_some() && input.droplets.get(&spec.id).is_some_and(|s| s == "off");
+ let unreachable = probe.filter(|p| !p.ok && spec.is_checkable()).map(|p| {
+ if powered_off {
+ powered_off_reason(spec, p)
+ } else {
+ explain_unreachable(spec, p, input.settings.check_interval_minutes > 0, device, input.tailscale)
+ }
+ });
machine_diagnostics(&mut diagnostics, spec, probe, unreachable.as_ref());
diagnostics.sort_by_key(|d| level_rank(&d.level));
@@ -168,6 +175,15 @@ pub fn build(input: &Inputs) -> Snapshot {
created_at,
cost_so_far: (hours.ceil() * c.price_hourly * 100.).round() / 100.,
idle_since: crate::ops::cloud::idle_since(&spec.id),
+ power: if status == "online" {
+ Some("on".into())
+ } else {
+ input.droplets.get(&spec.id).map(|s| match s.as_str() {
+ "active" => "on".into(),
+ "new" => "starting".into(),
+ other => other.to_string(),
+ })
+ },
}
}),
});
@@ -324,6 +340,7 @@ fn to_probe(p: &ProbeResult) -> Probe {
arch: p.arch.clone(),
os_version: p.os_version.clone(),
form_factor: p.form_factor.clone(),
+ desktop: p.desktop,
cores: p.cores,
cpu_pct: p.cpu_pct,
mem_total: p.mem_total,
@@ -367,6 +384,18 @@ pub fn unreachable_kind(error: &str) -> &'static str {
}
}
+/// A cloud machine the user (or the provider) powered off: nothing's wrong.
+fn powered_off_reason(spec: &MachineSpec, p: &ProbeResult) -> Unreachable {
+ Unreachable {
+ kind: "powered-off".into(),
+ title: format!("{} is powered off", spec.name),
+ detail: "It's still billed while it's off. Power it on to use it, or destroy it to stop the charges.".into(),
+ hint: None,
+ last_seen_at: p.last_seen_at,
+ error: p.error.clone().unwrap_or_default(),
+ }
+}
+
/// Why a machine can't be reached, in words for people: what probably
/// happened, and what to do about it when there's something to do.
pub fn explain_unreachable(spec: &MachineSpec, p: &ProbeResult, retrying: bool, device: Option<&TailnetDevice>, tailscale: Option<&TailscaleStatus>) -> Unreachable {
@@ -561,7 +590,12 @@ fn machine_diagnostics(out: &mut Vec<Diagnostic>, spec: &MachineSpec, probe: Opt
let Some(p) = probe else { return };
if !p.ok {
if let Some(u) = unreachable {
- let level = if comes_back_by_itself(&u.kind) { "warning" } else { "error" };
+ let level = match u.kind.as_str() {
+ // Off on purpose: worth knowing, nothing to fix.
+ "powered-off" => "info",
+ k if comes_back_by_itself(k) => "warning",
+ _ => "error",
+ };
out.push(diag(level, "unreachable", format!("{}. {}", u.title, u.detail), u.hint.clone(), None));
}
return;
@@ -961,6 +995,7 @@ mod tests {
token_source: "gh".into(),
tailnet: &HashMap::new(),
tailscale: None,
+ droplets: &HashMap::new(),
})
}
diff --git a/src/fleet/engine.rs b/src/fleet/engine.rs
index fb85a7b..3fcda98 100644
--- a/src/fleet/engine.rs
+++ b/src/fleet/engine.rs
@@ -73,6 +73,8 @@ struct State {
tailnet: HashMap<String, super::model::TailnetDevice>,
/// Tailscale on this computer; None until read, or when it isn't installed.
tailscale: Option<super::model::TailscaleStatus>,
+ /// Cloud machines' power as the provider last reported it ("active", "off", ...).
+ droplets: HashMap<String, String>,
/// Stop flags of the operations that can be cancelled.
cancels: HashMap<u64, Arc<std::sync::atomic::AtomicBool>>,
}
@@ -143,6 +145,7 @@ impl Engine {
checkouts: HashMap::new(),
tailnet: persisted.tailnet,
tailscale: None,
+ droplets: persisted.droplets,
cancels: HashMap::new(),
};
let (tx, _) = watch::channel(Arc::new(Snapshot::default()));
@@ -487,6 +490,16 @@ impl Engine {
self.publish(&mut st);
}
+ /// Records a cloud machine's power as the provider reports it ("active", "off", ...).
+ pub(crate) fn set_droplet_status(&self, machine_id: &str, status: &str) {
+ let mut st = self.state.lock().unwrap();
+ if st.droplets.get(machine_id).map(String::as_str) != Some(status) {
+ st.droplets.insert(machine_id.to_string(), status.to_string());
+ self.save_state(&mut st);
+ self.publish(&mut st);
+ }
+ }
+
/// True while another operation is changing this machine.
pub(crate) fn machine_busy(&self, machine_id: &str) -> bool {
let st = self.state.lock().unwrap();
@@ -873,13 +886,21 @@ impl Engine {
Some(w) => w.probe(&spec).await,
None => probe::probe(&spec, shell).await,
};
- (spec.id, result)
+ (spec.id, spec.cloud.as_ref().map(|c| c.id), result)
}
})
.collect();
- while let Some((id, result)) = pending.next().await {
+ while let Some((id, droplet, result)) = pending.next().await {
let reachable = result.ok;
+ if let Some(droplet) = droplet.filter(|_| self.demo.is_none()) {
+ if reachable {
+ self.set_droplet_status(&id, "active");
+ } else {
+ let (me, id) = (self.clone(), id.clone());
+ self.rt.spawn(async move { me.refresh_droplet_status(&id, droplet).await });
+ }
+ }
let mut st = self.state.lock().unwrap();
st.checking.remove(&id);
let result = result.after(st.probes.get(&id));
@@ -935,6 +956,7 @@ impl Engine {
let persisted = PersistedState {
probes: st.probes.clone(),
tailnet: st.tailnet.clone(),
+ droplets: st.droplets.clone(),
check_started_at: st.check_started_at,
check_finished_at: st.check_finished_at,
};
@@ -1036,6 +1058,7 @@ impl Engine {
token_source: st.token_source.clone(),
tailnet: &st.tailnet,
tailscale: st.tailscale.as_ref(),
+ droplets: &st.droplets,
});
snapshot.version = st.version;
snapshot.operations = st.operations.iter().cloned().collect();
diff --git a/src/fleet/model.rs b/src/fleet/model.rs
index d664551..a8b2b08 100644
--- a/src/fleet/model.rs
+++ b/src/fleet/model.rs
@@ -230,6 +230,8 @@ pub struct CloudInfo {
pub cost_so_far: f64,
/// Idle (no busy session, job or CPU) since then, as this app has seen it.
pub idle_since: Option<DateTime<Utc>>,
+ /// "on", "off" or "starting", as last seen; None until known.
+ pub power: Option<String>,
}
#[derive(Debug, Clone, Serialize, Default)]
@@ -255,6 +257,8 @@ pub struct Probe {
pub os_version: Option<String>,
/// "laptop" | "desktop", when the machine says.
pub form_factor: Option<String>,
+ /// Whether it has a graphical session to show (Linux: an X server). None: not said.
+ pub desktop: Option<bool>,
pub cores: Option<u32>,
pub cpu_pct: Option<f64>,
pub mem_total: Option<u64>,
diff --git a/src/fleet/workspaces/tests.rs b/src/fleet/workspaces/tests.rs
index 8948f43..6087c29 100644
--- a/src/fleet/workspaces/tests.rs
+++ b/src/fleet/workspaces/tests.rs
@@ -68,6 +68,7 @@ fn machine(id: &str, platform: &str, cpu: f64, working: usize, disk_free: u64, a
arch: None,
os_version: None,
form_factor: None,
+ desktop: None,
cores: Some(8),
cpu_pct: Some(cpu),
mem_total: Some(100),
diff --git a/src/ops/cloud.rs b/src/ops/cloud.rs
index ba04622..42dff53 100644
--- a/src/ops/cloud.rs
+++ b/src/ops/cloud.rs
@@ -285,25 +285,78 @@ impl Engine {
pub fn cloud_power(self: &Arc<Self>, machine_id: &str, on: bool) -> Result<u64, String> {
let (spec, _) = self.machine(machine_id).ok_or("That machine isn't in the fleet anymore.")?;
let cloud = spec.cloud.clone().ok_or_else(|| format!("{} isn't a cloud machine Muxen created.", spec.name))?;
+ if self.machine_busy(&spec.id) {
+ return Err("An operation is still running on this machine. Wait for it to finish.".into());
+ }
let title = format!("{} {}", if on { "Power on" } else { "Power off" }, spec.name);
let op = self.begin_op(if on { "cloud-power-on" } else { "cloud-power-off" }, title, Some(spec.id.clone()), None);
let me = self.clone();
- let id = spec.id.clone();
self.runtime().spawn(async move {
- let result = async {
- let client = me.do_client().await?;
- client.droplet_action(cloud.id, if on { "power_on" } else { "shutdown" }).await?;
- me.op_log(op, if on { "✓ Powering on" } else { "✓ Shutting down (still billed while off)" });
- tokio::time::sleep(Duration::from_secs(20)).await;
- me.trigger_check(Some(id));
- Ok(())
- }
- .await;
+ let result = me.run_cloud_power(op, &spec, cloud.id, on).await;
super::finish(&me, op, result);
});
Ok(op)
}
+ /// Asks DigitalOcean whether a droplet that didn't answer a check is
+ /// powered off (best effort: not signed in, or a blip, changes nothing).
+ pub(crate) async fn refresh_droplet_status(self: &Arc<Self>, machine_id: &str, droplet: u64) {
+ let Ok(client) = self.do_client().await else { return };
+ if let Ok(d) = client.droplet(droplet).await {
+ self.set_droplet_status(machine_id, &d.status);
+ }
+ }
+
+ /// Powers the droplet on or off and waits until it really is: on means
+ /// answering ssh again, off means DigitalOcean reports it off.
+ async fn run_cloud_power(self: &Arc<Self>, op: u64, spec: &MachineSpec, droplet: u64, on: bool) -> Result<(), String> {
+ let client = self.do_client().await?;
+ let want = if on { "active" } else { "off" };
+ if client.droplet(droplet).await?.status == want {
+ self.set_droplet_status(&spec.id, want);
+ self.op_log(op, if on { "It's already on." } else { "It's already off." });
+ } else {
+ self.op_log(op, if on { "▸ Powering on" } else { "▸ Shutting down" });
+ client.droplet_action(droplet, if on { "power_on" } else { "shutdown" }).await?;
+ let started = std::time::Instant::now();
+ let mut forced = false;
+ loop {
+ tokio::time::sleep(Duration::from_secs(4)).await;
+ // A blip while polling isn't a failure; the next poll tries again.
+ if client.droplet(droplet).await.is_ok_and(|d| d.status == want) {
+ self.set_droplet_status(&spec.id, want);
+ break;
+ }
+ let waited = started.elapsed();
+ if !on && !forced && waited > Duration::from_secs(60) {
+ self.op_log(op, "! It didn't shut down within a minute; turning it off");
+ client.droplet_action(droplet, "power_off").await?;
+ forced = true;
+ }
+ if waited > Duration::from_secs(180) {
+ return Err(format!("DigitalOcean didn't report it {} within 3 minutes.", if on { "on" } else { "off" }));
+ }
+ }
+ }
+ if on {
+ self.op_log(op, "▸ Waiting for it to answer ssh");
+ let started = std::time::Instant::now();
+ loop {
+ let ok = tokio::process::Command::new("ssh").args(crate::probe::ssh_args(spec)).arg("true").output().await.is_ok_and(|o| o.status.success());
+ if ok {
+ break;
+ }
+ if started.elapsed() > Duration::from_secs(120) {
+ return Err("It's on, but hasn't answered ssh within 2 minutes.".into());
+ }
+ tokio::time::sleep(Duration::from_secs(4)).await;
+ }
+ }
+ self.run_check(Some(vec![spec.id.clone()])).await;
+ self.op_log(op, if on { format!("✓ {} is on", spec.name) } else { format!("✓ {} is off (DigitalOcean still bills for it until it's destroyed)", spec.name) });
+ Ok(())
+ }
+
/// Watches cloud machines for idleness (every 10 minutes) and does what
/// Settings › Cloud says. Run by one process (the app).
#[cfg_attr(not(feature = "gui"), allow(dead_code))]
diff --git a/src/probe/mod.rs b/src/probe/mod.rs
index e0d0cb9..df53972 100644
--- a/src/probe/mod.rs
+++ b/src/probe/mod.rs
@@ -40,6 +40,9 @@ pub struct ProbeResult {
/// "laptop" | "desktop", when the machine says.
#[serde(default)]
pub form_factor: Option<String>,
+ /// Whether it has a graphical session to show (Linux: an X server). None: not said.
+ #[serde(default)]
+ pub desktop: Option<bool>,
pub cores: Option<u32>,
pub cpu_pct: Option<f64>,
pub mem_total: Option<u64>,
@@ -76,6 +79,9 @@ impl ProbeResult {
self.arch = self.arch.take().or_else(|| p.arch.clone());
self.os_version = self.os_version.take().or_else(|| p.os_version.clone());
self.form_factor = self.form_factor.take().or_else(|| p.form_factor.clone());
+ if !self.ok {
+ self.desktop = self.desktop.or(p.desktop);
+ }
}
self
}
@@ -369,6 +375,7 @@ pub fn parse(out: &str) -> ProbeResult {
"hostname" => r.hostname = text(),
"os_version" => r.os_version = text().filter(|v| v != "macOS"),
"form_factor" => r.form_factor = text(),
+ "desktop" => r.desktop = Some(value == "yes"),
"cores" => r.cores = value.parse().ok(),
"cpu_pct" => r.cpu_pct = value.parse::<f64>().ok().map(|v| v.clamp(0.0, 100.0)),
"mem_total" => r.mem_total = value.parse().ok().filter(|v| *v > 0),
diff --git a/src/probe/scripts/probe.sh b/src/probe/scripts/probe.sh
index 1c55db3..42e2744 100644
--- a/src/probe/scripts/probe.sh
+++ b/src/probe/scripts/probe.sh
@@ -58,6 +58,8 @@ linux)
"") ;;
*) kv form_factor desktop ;;
esac
+ # An X server (Xorg, or Xwayland under a Wayland desktop): Show desktop needs one.
+ if ls /tmp/.X11-unix/X* >/dev/null 2>&1; then kv desktop yes; else kv desktop no; fi
kv cores "$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null)"
kv load "$(cut -d' ' -f1-3 /proc/loadavg 2>/dev/null)"
kv uptime_s "$(cut -d. -f1 /proc/uptime 2>/dev/null)"
diff --git a/src/ui/assets.rs b/src/ui/assets.rs
index 43bf61c..30be4da 100644
--- a/src/ui/assets.rs
+++ b/src/ui/assets.rs
@@ -24,7 +24,7 @@ icons!(
"agent-claude", "agent-codex", "agent-gemini", "agent-opencode", "agent-amp", "agent-pi", "agent-github",
"circle-dot", "git-pull-request", "git-pull-request-draft", "git-merge", "message-square", "lock", "star",
"arrow-down", "arrow-up", "book-open", "star-filled", "maximize", "minimize", "panel-right", "panel-left",
- "folder", "file", "sliders-horizontal", "palette", "keyboard", "cloud",
+ "folder", "file", "sliders-horizontal", "palette", "keyboard", "cloud", "brand-digitalocean",
// The glyphs of each icon style (see kit::IconStyle): pf- Phosphor (MIT),
// so- Solar (CC BY 4.0), mc- MingCute (Apache-2.0), fl- Fluent (MIT),
// hg- Hugeicons (MIT). Generated from the Iconify sets; one file per icon.
diff --git a/src/ui/detail.rs b/src/ui/detail.rs
index c1a98d3..cb43580 100644
--- a/src/ui/detail.rs
+++ b/src/ui/detail.rs
@@ -124,10 +124,11 @@ impl Root {
let mut body = page("machine-page", &self.page_scroll).child(header);
if let Some(c) = &m.cloud {
- body = body.child(self.cloud_card(&theme, &m, c, cx));
+ body = body.child(self.cloud_card(&theme, &s, &m, c, busy, cx));
}
- if let Some(u) = m.unreachable.as_ref().filter(|_| offline) {
+ // A powered-off cloud machine says so on its cloud card.
+ if let Some(u) = m.unreachable.as_ref().filter(|u| offline && u.kind != "powered-off") {
body = body.child(self.unreachable_card(&theme, &m, u, cx));
}
@@ -237,8 +238,25 @@ impl Root {
}
/// Where a cloud machine runs, what it costs, and its power.
- fn cloud_card(&self, theme: &Theme, m: &Machine, c: &crate::fleet::model::CloudInfo, cx: &mut Context<Self>) -> impl IntoElement {
+ fn cloud_card(&self, theme: &Theme, s: &Snapshot, m: &Machine, c: &crate::fleet::model::CloudInfo, busy: bool, cx: &mut Context<Self>) -> impl IntoElement {
let off = m.status == "offline";
+ let powering = s.operations.iter().find(|o| o.status == "running" && o.machine_id.as_deref() == Some(&m.id)).and_then(|o| match o.kind.as_str() {
+ "cloud-power-on" => Some(true),
+ "cloud-power-off" => Some(false),
+ _ => None,
+ });
+ let title = match powering {
+ Some(true) => "DigitalOcean · powering on…",
+ Some(false) => "DigitalOcean · shutting down…",
+ None if off => "DigitalOcean · powered off (still billed)",
+ None => "DigitalOcean",
+ };
+ let power_label = match powering {
+ Some(true) => "Powering on…",
+ Some(false) => "Shutting down…",
+ None if off => "Power on",
+ None => "Power off",
+ };
let idle = c.idle_since.map(|t| (chrono::Utc::now() - t).num_minutes()).filter(|min| *min >= 30).map(|min| format!(" · idle {}", crate::util::short_duration(min as u64 * 60)));
let detail = format!(
"{} · {} · ${:.3}/h · ${:.2} so far{}",
@@ -255,7 +273,10 @@ impl Root {
.gap(px(12.))
.px(px(14.))
.py(px(12.))
- .child(kit::color_tile("cloud", 28.))
+ .child({
+ let (from, to) = format::machine_tile(m);
+ kit::tile(format::machine_icon(m), from, to, 28.)
+ })
.child(
div()
.flex()
@@ -263,11 +284,11 @@ impl Root {
.flex_1()
.min_w(px(0.))
.gap(px(2.))
- .child(div().text_size(px(13.)).child(if off { "DigitalOcean · powered off (still billed)" } else { "DigitalOcean" }))
+ .child(div().text_size(px(13.)).child(title))
.child(div().text_size(px(11.5)).text_color(theme.text_placeholder).child(detail)),
)
- .child(Button::new("m-cloud-power", if off { "Power on" } else { "Power off" }).icon("power").on_click(cx.listener(move |this, _, _, cx| this.cloud_power(&mid, off, cx))))
- .child(Button::new("m-cloud-destroy", "Destroy…").style(ButtonStyle::Danger).on_click(cx.listener(move |this, _, window, cx| this.confirm_remove_machine(&machine, window, cx))))
+ .child(Button::new("m-cloud-power", power_label).icon("power").disabled(busy).on_click(cx.listener(move |this, _, _, cx| this.cloud_power(&mid, off, cx))))
+ .child(Button::new("m-cloud-destroy", "Destroy…").style(ButtonStyle::Danger).disabled(busy).on_click(cx.listener(move |this, _, window, cx| this.confirm_remove_machine(&machine, window, cx))))
}
fn machine_runner_row(&self, theme: &Theme, s: &Snapshot, r: &Runner, i: usize, busy: bool, cx: &mut Context<Self>) -> AnyElement {
diff --git a/src/ui/format.rs b/src/ui/format.rs
index c568edf..740d877 100644
--- a/src/ui/format.rs
+++ b/src/ui/format.rs
@@ -99,13 +99,16 @@ pub fn diagnostics_summary(m: &Machine) -> (String, &'static str) {
/// Whether Muxen can show the machine's desktop (Linux with X11, macOS).
pub fn has_desktop(m: &Machine) -> bool {
- m.platform.starts_with("linux") || m.platform.starts_with("darwin")
+ // A Linux machine needs an X server; one checked before checks said is given the benefit of the doubt.
+ m.platform.starts_with("darwin") || (m.platform.starts_with("linux") && m.probe.as_ref().and_then(|p| p.desktop) != Some(false))
}
/// Gradient for a machine's icon tile, by OS.
pub fn machine_tile(m: &Machine) -> (u32, u32) {
use super::kit::tiles;
- if m.platform.starts_with("darwin") {
+ if m.cloud.as_ref().is_some_and(|c| c.provider == "digitalocean") {
+ tiles::DIGITALOCEAN
+ } else if m.platform.starts_with("darwin") {
tiles::MACOS
} else if m.platform.starts_with("linux") {
tiles::LINUX
@@ -124,6 +127,9 @@ pub fn machine_subtitle(m: &Machine) -> (String, &'static str) {
}
if m.status == "offline" {
let seen = m.unreachable.as_ref().and_then(|u| u.last_seen_at);
+ if is_powered_off(m) {
+ return ("Powered off".into(), "muted");
+ }
return match (is_just_offline(m), seen) {
(true, Some(t)) => (format!("Offline · seen {}", ago(Some(t))), "muted"),
(true, None) => ("Offline".into(), "muted"),
@@ -170,6 +176,9 @@ fn short_os(v: &str) -> String {
}
pub fn machine_icon(m: &Machine) -> &'static str {
+ if m.cloud.as_ref().is_some_and(|c| c.provider == "digitalocean") {
+ return "brand-digitalocean";
+ }
let name = m.name.to_ascii_lowercase();
let laptop = m.probe.as_ref().and_then(|p| p.form_factor.as_deref()) == Some("laptop");
if name.contains("nas") || name.contains("storage") {
@@ -201,18 +210,30 @@ mod tests {
/// Offline in the everyday sense (shut down, asleep, off the network), as
/// opposed to on but refusing us: nothing for the user to fix.
pub fn is_just_offline(m: &Machine) -> bool {
- m.status == "offline" && m.unreachable.as_ref().is_some_and(|u| u.kind == "offline")
+ m.status == "offline" && m.unreachable.as_ref().is_some_and(|u| matches!(u.kind.as_str(), "offline" | "powered-off"))
+}
+
+/// A cloud machine that's powered off (and still billed).
+pub fn is_powered_off(m: &Machine) -> bool {
+ m.status == "offline" && m.unreachable.as_ref().is_some_and(|u| u.kind == "powered-off")
}
/// A machine that can't be reached, in a word or two: "Offline", "Can't connect".
pub fn unreachable_word(m: &Machine) -> &'static str {
- if is_just_offline(m) { "Offline" } else { "Can't connect" }
+ if is_powered_off(m) {
+ "Powered off"
+ } else if is_just_offline(m) {
+ "Offline"
+ } else {
+ "Can't connect"
+ }
}
/// Why it can't be reached, short enough for the sidebar.
pub fn unreachable_reason(m: &Machine) -> &'static str {
match m.unreachable.as_ref().map(|u| u.kind.as_str()) {
Some("offline") => "Offline",
+ Some("powered-off") => "Powered off",
Some("refused") => "Not accepting ssh",
Some("auth") => "ssh key not accepted",
Some("unknown-host") => "Host not found",
diff --git a/src/ui/kit.rs b/src/ui/kit.rs
index e023390..ceeed87 100644
--- a/src/ui/kit.rs
+++ b/src/ui/kit.rs
@@ -171,7 +171,8 @@ pub fn tile_in(look: Look, icon_name: &str, from: u32, to: u32, size: f32) -> Di
match look.style.backdrop() {
Backdrop::Solid => el.rounded(px(size * 0.27)).bg(base).child(icon(&glyph, size * 0.58, gpui::white())),
Backdrop::Faint => el.rounded(px(size * 0.27)).bg(base.opacity(0.2)).child(icon(&glyph, size * 0.62, tone)),
- Backdrop::None => el.child(icon(&glyph, size * 0.86, if look.style.colored() { tone } else { look.muted })),
+ // A provider's logo keeps its color even in Minimal, so a droplet reads as one at a glance.
+ Backdrop::None => el.child(icon(&glyph, size * 0.86, if look.style.colored() || icon_name.starts_with("brand-") { tone } else { look.muted })),
}
}
@@ -197,6 +198,8 @@ pub mod tiles {
pub const LINUX: (u32, u32) = (0xffb35c, 0xf0703f);
pub const WINDOWS: (u32, u32) = (0x5ad2f4, 0x1f8fd6);
pub const OTHER: (u32, u32) = (0xa7aebb, 0x5f6673);
+ /// DigitalOcean's blue, for droplets.
+ pub const DIGITALOCEAN: (u32, u32) = (0x4d9bff, 0x0069ff);
}
/// An icon's colors, by what it stands for, so a thing looks the same in
diff --git a/src/ui/menu.rs b/src/ui/menu.rs
index 4759f81..89014de 100644
--- a/src/ui/menu.rs
+++ b/src/ui/menu.rs
@@ -63,6 +63,8 @@ enum Action {
enum Item {
Action { label: String, glyph: Glyph, action: Action, danger: bool },
+ /// An action that can't be done right now: shown dimmed, not clickable.
+ Off { label: String, glyph: Glyph },
/// Text that isn't clickable.
Note(String),
Separator,
@@ -91,19 +93,25 @@ impl Root {
let Some(m) = s.machines.iter().find(|m| &m.id == id) else { return Vec::new() };
let mut items = Vec::new();
if !m.host.is_empty() {
- items.push(act("New terminal", "square-terminal", Action::NewTerminal(id.clone())));
+ // These need the machine up: dimmed while it's off or unreachable.
+ let up = m.status != "offline";
+ let needs_up = |item: Item| match item {
+ Item::Action { label, glyph, .. } if !up => Item::Off { label, glyph },
+ other => other,
+ };
+ items.push(needs_up(act("New terminal", "square-terminal", Action::NewTerminal(id.clone()))));
for a in AGENTS.iter().filter(|a| a.id != "shell" && m.agents.iter().any(|i| i == a.id)) {
- items.push(Item::Action { label: format!("New {} session…", a.name), glyph: Glyph::Agent(a.id), action: Action::NewAgent(id.clone(), a.id), danger: false });
+ items.push(needs_up(Item::Action { label: format!("New {} session…", a.name), glyph: Glyph::Agent(a.id), action: Action::NewAgent(id.clone(), a.id), danger: false }));
}
if super::format::has_desktop(m) && !m.local {
- items.push(act("Show desktop", "monitor", Action::ShowDesktop(id.clone())));
+ items.push(needs_up(act("Show desktop", "monitor", Action::ShowDesktop(id.clone()))));
}
if !m.platform.starts_with("windows") {
- items.push(act("Copy files…", "folder", Action::CopyFiles(id.clone())));
+ items.push(needs_up(act("Copy files…", "folder", Action::CopyFiles(id.clone()))));
}
items.push(Item::Separator);
items.push(act("Check now", "refresh-cw", Action::Check(id.clone())));
- items.push(act("Install runner…", "plus", Action::InstallRunner(id.clone())));
+ items.push(needs_up(act("Install runner…", "plus", Action::InstallRunner(id.clone()))));
items.push(Item::Separator);
}
if Root::is_favorite(cx, id) {
@@ -115,7 +123,9 @@ impl Root {
// A cloud machine is powered and destroyed; removing it alone would leave it running (and billed).
if m.cloud.is_some() {
let off = m.status == "offline";
- items.push(act(if off { "Power on" } else { "Power off" }, "power", Action::CloudPower(id.clone(), off)));
+ let busy = s.operations.iter().any(|o| o.status == "running" && o.machine_id.as_deref() == Some(id.as_str()) && o.kind != "logs");
+ let label = if off { "Power on" } else { "Power off" };
+ items.push(if busy { Item::Off { label: label.into(), glyph: Glyph::Icon("power") } } else { act(label, "power", Action::CloudPower(id.clone(), off)) });
items.push(Item::Action { label: "Destroy…".into(), glyph: Glyph::Icon("trash-2"), action: Action::Remove(id.clone()), danger: true });
} else {
items.push(Item::Action { label: "Remove from fleet…".into(), glyph: Glyph::Icon("trash-2"), action: Action::Remove(id.clone()), danger: true });
@@ -368,7 +378,7 @@ impl Root {
let longest = items
.iter()
.map(|i| match i {
- Item::Action { label, .. } => label.chars().count() as f32 * 7.4 + 64.,
+ Item::Action { label, .. } | Item::Off { label, .. } => label.chars().count() as f32 * 7.4 + 64.,
Item::Note(text) => text.chars().count() as f32 * 6.8 + 32.,
Item::Separator => 0.,
})
@@ -384,17 +394,22 @@ impl Root {
.map(|(i, item)| match item {
Item::Separator => div().h(px(1.)).my(px(4.)).mx(px(8.)).bg(theme.border_variant).into_any_element(),
Item::Note(text) => div().px(px(12.)).py(px(5.)).text_size(px(12.)).text_color(theme.text_placeholder).child(text).into_any_element(),
+ Item::Off { label, glyph } => div()
+ .flex()
+ .items_center()
+ .gap(px(9.))
+ .h(px(28.))
+ .mx(px(4.))
+ .px(px(8.))
+ .opacity(0.4)
+ .text_size(px(13.))
+ .text_color(theme.text)
+ .child(div().w(px(18.)).flex().justify_center().child(menu_glyph(theme, glyph)))
+ .child(div().w(px(width - 56.)).truncate().child(label))
+ .into_any_element(),
Item::Action { label, glyph, action, danger } => {
let color = if danger { theme.error } else { theme.text };
- let glyph = match glyph {
- Glyph::Icon(name) => kit::color_tile(name, 18.).into_any_element(),
- Glyph::Agent(agent) => {
- let (name, (from, to)) = kit::agent_look(agent);
- kit::tile(name, from, to, 18.).into_any_element()
- }
- Glyph::Selected => icon("check", 14., theme.accent).into_any_element(),
- Glyph::None => div().into_any_element(),
- };
+ let glyph = menu_glyph(theme, glyph);
div()
.id(("menu-item", i))
.flex()
@@ -466,3 +481,15 @@ fn platform_label(label: &str) -> Option<&'static str> {
_ => None,
}
}
+
+fn menu_glyph(theme: &Theme, glyph: Glyph) -> AnyElement {
+ match glyph {
+ Glyph::Icon(name) => kit::color_tile(name, 18.).into_any_element(),
+ Glyph::Agent(agent) => {
+ let (name, (from, to)) = kit::agent_look(agent);
+ kit::tile(name, from, to, 18.).into_any_element()
+ }
+ Glyph::Selected => icon("check", 14., theme.accent).into_any_element(),
+ Glyph::None => div().into_any_element(),
+ }
+}
diff --git a/src/ui/overview.rs b/src/ui/overview.rs
index b0fe0a5..fb741e9 100644
--- a/src/ui/overview.rs
+++ b/src/ui/overview.rs
@@ -607,6 +607,7 @@ fn meter_row(theme: &Theme, label: &'static str, value: Option<String>, fraction
fn status_word(m: &Machine) -> &'static str {
match m.status.as_str() {
"online" => "online",
+ "offline" if format::is_powered_off(m) => "powered off",
"offline" if format::is_just_offline(m) => "offline",
"offline" => "can't connect",
"manual" => "no host",
diff --git a/src/ui/theme.rs b/src/ui/theme.rs
index 372fc3c..6fdd7a8 100644
--- a/src/ui/theme.rs
+++ b/src/ui/theme.rs
@@ -88,7 +88,7 @@ impl Theme {
pub fn machine_status(&self, m: &crate::fleet::model::Machine) -> Hsla {
match (m.status.as_str(), m.unreachable.as_ref().map(|u| u.kind.as_str())) {
("online", _) => self.success,
- ("offline", Some("offline")) => self.text_placeholder,
+ ("offline", Some("offline" | "powered-off")) => self.text_placeholder,
("offline", Some("refused" | "tailscale-off")) => self.warning,
("offline", _) => self.error,
_ => self.text_placeholder,
diff --git a/src/ui/workspaces.rs b/src/ui/workspaces.rs
index bde2632..5cd81cd 100644
--- a/src/ui/workspaces.rs
+++ b/src/ui/workspaces.rs
@@ -464,7 +464,7 @@ impl Root {
.child(
Button::new("ws-new-here", "New workspace")
.icon("plus")
- .disabled(!allowed)
+ .disabled(!allowed || m.status == "offline")
.on_click(cx.listener(move |this, _, window, cx| this.show_new_workspace(Some(new_on.clone()), window, cx))),
),
),