fix(ssh,ui): read /proc/self/exe, open Tailscale SSH approval links, soften freshness fades, remove Apparent size checkbox, tidy selection icons

This commit is contained in:
Tobi Lutke
2026-11-25 18:09:58 -05:00
parent cc22df95f7
commit 8df1c08f7d
7 changed files with 214 additions and 146 deletions
-9
View File
@@ -130,15 +130,6 @@ pub const fn highlight(theme: &Theme) -> Hsla {
theme.warning
}
/// Text on a filled highlight.
pub const fn on_highlight(theme: &Theme) -> Hsla {
if dark(theme) {
theme.background
} else {
theme.bright
}
}
/// The diagonal hatch over reclaimable space: quiet enough to leave the hue
/// readable, visible on every fill.
pub fn hatch(theme: &Theme) -> Hsla {
+34 -5
View File
@@ -949,6 +949,8 @@ pub struct Disktree {
pub remote: Option<String>,
remote_disk: bool,
pub remote_progress: disktree_core::remote_progress::Progress,
/// Tailscale SSH check URL opened in the browser while waiting for approval.
pub auth_url: Option<String>,
pub scan_preview: Option<Arc<disktree_core::scan_preview::Preview>>,
preview_updated: Option<Instant>,
remote_platform: String,
@@ -1139,6 +1141,7 @@ impl Disktree {
preview_updated: None,
remote_progress: disktree_core::remote_progress::Progress::default(
),
auth_url: None,
remote_platform: String::new(),
remote_identity: None,
home,
@@ -1376,6 +1379,7 @@ impl Disktree {
self.volumes.clear();
self.volume_highlight = 0;
self.picker_error = None;
self.auth_url = None;
let event = match host {
Some(host) => discovery_machine::Event::StartRemote { host },
None => discovery_machine::Event::StartLocal,
@@ -1516,9 +1520,13 @@ impl Disktree {
else {
return false;
};
let Some(result) = job.poll() else {
let auth_url = job.progress().auth_url;
let polled = job.poll();
self.handle_auth_url(auth_url, cx);
let Some(result) = polled else {
return true;
};
self.auth_url = None;
self.finish_volume_listing_for(
epoch,
result.map(|roots| (roots.volumes, roots.home)),
@@ -1527,6 +1535,22 @@ impl Disktree {
false
}
fn handle_auth_url(
&mut self,
url: Option<String>,
cx: &mut Context<'_, Self>,
) {
if let Some(url) = url {
if self.auth_url.as_deref() != Some(url.as_str()) {
self.auth_url = Some(url.clone());
cx.open_url(&url);
cx.notify();
}
} else if self.auth_url.take().is_some() {
cx.notify();
}
}
#[cfg(test)]
pub(crate) fn finish_volume_listing(
&mut self,
@@ -1791,6 +1815,7 @@ impl Disktree {
/// Closing cancels discovery, not the scan already on screen.
pub fn close_volumes(&mut self, cx: &mut Context<'_, Self>) {
self.step_discovery(discovery_machine::Event::Reset, cx);
self.auth_url = None;
self.volumes_open = false;
self.focus_request = Some(FocusTarget::Root);
cx.notify();
@@ -1899,6 +1924,7 @@ impl Disktree {
/// and a widening scan leaves the tree it started from on screen.
pub fn cancel_scan(&mut self, cx: &mut Context<'_, Self>) {
self.scan_preview = None;
self.auth_url = None;
self.updating_paths.clear();
self.refreshed_paths.clear();
self.active_scan_path = None;
@@ -2138,16 +2164,18 @@ impl Disktree {
match active {
ActiveScan::Remote { handle, intent } => {
let outcome = handle.poll();
let refresh_metric = match intent {
ScanIntent::Refresh { metric, .. } => Some(*metric),
ScanIntent::Initial | ScanIntent::Widening { .. } => None,
};
self.remote_progress = handle.progress();
let auth_url = self.remote_progress.auth_url.clone();
self.handle_auth_url(auth_url, cx);
self.scan_preview.clone_from(&self.remote_progress.preview);
self.progress.files = self.remote_progress.files;
self.progress.dirs = self.remote_progress.dirs;
self.progress.bytes = self.remote_progress.bytes;
self.progress.errors = self.remote_progress.errors;
let refresh_metric = match intent {
ScanIntent::Refresh { metric, .. } => Some(*metric),
ScanIntent::Initial | ScanIntent::Widening { .. } => None,
};
let Some(outcome) = outcome else {
cx.notify();
return true;
@@ -2198,6 +2226,7 @@ impl Disktree {
}
}
self.active_scan = None;
self.auth_url = None;
self.scan_preview = None;
self.progress.finished = true;
cx.notify();
+30 -72
View File
@@ -27,21 +27,20 @@ use crate::appearance;
use crate::palette;
use crate::state::{Disktree, Filtered, Label, View};
/// Freshness & refresh-queue state of a tile, painted independently of
/// category colour and reclaimable hatching.
/// Freshness & refresh-queue state of a tile, communicated through subtle
/// fades toward the inset surface so category hues stay calm and intact.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum TileFreshness {
/// Freshly scanned or within the cache TTL.
#[default]
Fresh,
/// Cached older than TTL and not currently scheduled for refresh:
/// gently washed toward the inset surface with a muted corner dot.
/// Cached older than TTL and idle: gently faded toward `inset`.
Stale,
/// Queued in an active background refresh / SWR pass: lightly veiled
/// with a dashed accent border.
/// Queued for refresh in an active pass: stepped back slightly further
/// until it refreshes back into full colour.
Scheduled,
/// Actively being scanned right now (current worker or prioritized):
/// subtle accent wash with a solid accent border.
/// Actively being scanned right now: nearly full colour with a subtle
/// neutral hairline outline.
Updating,
}
@@ -239,8 +238,7 @@ struct Colors {
selected_border: Hsla,
marked_border: Hsla,
marked_label: Hsla,
accent: Hsla,
stale_pip: Hsla,
updating_border: Hsla,
warning: Hsla,
hatch: Hsla,
/// Fills per category, then per depth.
@@ -292,8 +290,7 @@ impl Colors {
selected_border: palette::highlight(theme),
marked_border: theme.danger,
marked_label: theme.danger,
accent: theme.accent,
stale_pip: theme.secondary.opacity(0.65),
updating_border: theme.foreground.opacity(0.24),
warning: theme.warning,
hatch: palette::hatch(theme),
fill: CATEGORIES
@@ -328,14 +325,14 @@ impl Colors {
Some(bucket) => self.age[bucket.min(self.age.len() - 1)][depth],
None => self.fill[category_index(tile.category)][depth],
};
// Freshness shading sits beneath find-filtering so stale folders read
// as softly washed out, queued folders lightly veiled, and actively
// refreshing folders softly tinted with the accent.
// Freshness uses subtle fades toward `inset` so category hues stay
// calm: queued folders step back slightly, stale folders soften a bit,
// and actively updating folders lift back toward full colour.
let fill = match tile.freshness {
TileFreshness::Fresh => fill,
TileFreshness::Stale => palette::mix(fill, self.inset, 0.44),
TileFreshness::Scheduled => palette::mix(fill, self.inset, 0.22),
TileFreshness::Updating => palette::mix(fill, self.accent, 0.14),
TileFreshness::Updating => palette::mix(fill, self.inset, 0.14),
TileFreshness::Stale => palette::mix(fill, self.inset, 0.28),
TileFreshness::Scheduled => palette::mix(fill, self.inset, 0.42),
};
// Only what matches keeps its colour; a directory holding matches
// steps back less, so the way to them stays readable.
@@ -360,18 +357,11 @@ fn paint_tiles(
) {
let none = Edges::all(px(0.));
let solid = gpui_kit::BorderStyle::Solid;
let dashed = gpui_kit::BorderStyle::Dashed;
let scale = window.scale_factor();
// Outlines are drawn after every fill: a directory's children paint over
// its body, and would otherwise cover its selection ring, leaving only
// slivers of it showing in the gaps between them.
let mut outlines: Vec<(
u8,
Bounds<Pixels>,
f32,
Hsla,
gpui_kit::BorderStyle,
)> = Vec::new();
let mut outlines: Vec<(u8, Bounds<Pixels>, f32, Hsla)> = Vec::new();
for tile in tiles {
let rect = view.project(tile.rect);
if rect.w <= 0.5 || rect.h <= 0.5 {
@@ -410,9 +400,8 @@ fn paint_tiles(
}
// A top-level directory carries a thin strip of its colour, so the
// first level of structure reads before any detail. Freshness modulates
// the strip: stale dims it, scheduled tints it softly with the accent,
// and actively updating lights it up in the accent.
// first level of structure reads before any detail. Stale and queued
// directories dim their strip softly without changing hue.
if tile.depth == 0
&& tile.age_bucket.is_none()
&& tile.filtered != Filtered::Out
@@ -426,10 +415,9 @@ fn paint_tiles(
);
let base = colors.strip[category_index(tile.category)];
let strip_color = match tile.freshness {
TileFreshness::Fresh => base,
TileFreshness::Stale => base.opacity(0.32),
TileFreshness::Scheduled => colors.accent.opacity(0.50),
TileFreshness::Updating => colors.accent,
TileFreshness::Fresh | TileFreshness::Updating => base,
TileFreshness::Stale => base.opacity(0.55),
TileFreshness::Scheduled => base.opacity(0.38),
};
window.paint_quad(quad(
strip,
@@ -458,67 +446,37 @@ fn paint_tiles(
colors.warning,
solid,
));
} else if tile.freshness == TileFreshness::Stale
&& tile.depth <= 1
&& rect.w > 18.0
&& rect.h > 14.0
{
// A quiet muted corner dot on stale cached directories so even
// low-chroma categories visibly read as stale.
let mark = Bounds::new(
Point::new(
quad_bounds.origin.x + quad_bounds.size.width - px(6.),
quad_bounds.origin.y + px(4.),
),
Size::new(px(3.), px(3.)),
);
window.paint_quad(quad(
mark,
Corners::default(),
colors.stale_pip,
none,
colors.stale_pip,
solid,
));
}
// Ranked so the most important ring is painted last, on top.
// Scheduled refresh tiles get a dashed accent border (rank 0) and
// actively updating tiles get a solid accent border (rank 1), always
// yielding to marked/hover/selected rings.
let outline = if tile.selected {
Some((4, 2.0, colors.selected_border, solid))
Some((3, 2.0, colors.selected_border))
} else if tile.hovered {
Some((3, 1.0, colors.hover_border, solid))
Some((2, 1.0, colors.hover_border))
} else if tile.marked {
Some((2, 2.0, colors.marked_border, solid))
Some((1, 2.0, colors.marked_border))
} else if tile.freshness == TileFreshness::Updating
&& tile.depth <= 1
&& rect.w > 14.0
&& rect.h > 12.0
{
Some((1, 2.0, colors.accent, solid))
} else if tile.freshness == TileFreshness::Scheduled
&& tile.depth <= 1
&& rect.w > 18.0
&& rect.h > 14.0
{
Some((0, 1.0, colors.accent.opacity(0.70), dashed))
Some((0, 1.0, colors.updating_border))
} else {
None
};
if let Some((rank, width, color, style)) = outline {
outlines.push((rank, quad_bounds, width, color, style));
if let Some((rank, width, color)) = outline {
outlines.push((rank, quad_bounds, width, color));
}
}
outlines.sort_by_key(|(rank, ..)| *rank);
for (_, ring, width, color, style) in outlines {
for (_, ring, width, color) in outlines {
window.paint_quad(quad(
ring,
Corners::default(),
gpui_kit::transparent_black(),
Edges::all(px(width)),
color,
style,
solid,
));
}
}
+61 -55
View File
@@ -193,11 +193,38 @@ fn volumes_dialog(
.border_color(theme.divider());
match &app.discovery.phase {
crate::state::discovery_machine::Phase::Loading { .. } => {
rows = rows.child(
div()
.p(space::MD)
.child(dialog_description("Listing mounts…", cx)),
);
if let Some(url) = app.auth_url.clone() {
rows = rows.child(
div()
.flex()
.flex_col()
.gap(space::SM)
.p(space::MD)
.child(dialog_description(
"Waiting for Tailscale SSH approval in your browser…",
cx,
))
.child(
div().flex().flex_row().child(
button(
"source-auth-link",
"Open login link",
ButtonVariant::Outline,
cx,
)
.on_click(move |_, _, cx| {
cx.open_url(&url);
}),
),
),
);
} else {
rows = rows.child(
div()
.p(space::MD)
.child(dialog_description("Listing mounts…", cx)),
);
}
}
crate::state::discovery_machine::Phase::Installing { host } => {
rows = rows.child(div().p(space::MD).child(dialog_description(
@@ -1425,8 +1452,6 @@ fn view_settings(
}
};
let hidden = {
let entity = entity.clone();
let focus = focus.clone();
checkbox(
"hidden",
"Hidden files",
@@ -1441,21 +1466,6 @@ fn view_settings(
window.focus(&focus, cx);
})
};
let apparent = {
checkbox(
"apparent",
"Apparent size",
check(app.options.apparent_size),
cx,
)
.tab_stop(false)
.on_change(move |_, _, window, cx| {
let _ = entity.update(cx, |this, cx| {
this.toggle_apparent_size(cx);
});
window.focus(&focus, cx);
})
};
let theme = cx.omarchy().clone();
// Back and forward through the directories visited, beside the choices
@@ -1578,7 +1588,6 @@ fn view_settings(
.child(history)
.child(mode)
.child(hidden)
.child(apparent)
.child(depth_control)
}
@@ -1700,25 +1709,15 @@ fn legend(app: &Disktree, theme: &Theme, cx: &App) -> Div {
Some(disktree_scanner::Freshness::Stale { .. })
);
let stale_swatch = div()
.relative()
.flex_shrink_0()
.size(size::SWATCH)
.bg(palette::mix(ground, theme.inset, 0.44))
.child(
div()
.absolute()
.top(px(1.))
.right(px(1.))
.size(px(3.))
.bg(theme.secondary.opacity(0.75)),
);
.bg(palette::mix(ground, theme.inset, 0.28));
let queued_swatch = div()
.flex_shrink_0()
.size(size::SWATCH)
.bg(palette::mix(ground, theme.inset, 0.22))
.bg(palette::mix(ground, theme.inset, 0.42))
.border_1()
.border_dashed()
.border_color(theme.accent.opacity(0.8));
.border_color(theme.control_border());
div()
.flex()
.flex_row()
@@ -1856,21 +1855,18 @@ fn selection_section(
} else {
gpui_omarchy::IconName::Delete
};
let mark_filled = can_mark && !unmark_mode;
let mark_icon_color = if !can_mark {
theme.secondary
} else if unmark_mode {
theme.danger
} else {
palette::on_highlight(theme)
theme.foreground
};
let mark_btn_inner = button(
"mark",
"",
if unmark_mode {
if unmark_mode && can_mark {
ButtonVariant::Danger
} else if mark_filled {
ButtonVariant::Primary
} else {
ButtonVariant::Outline
},
@@ -1895,13 +1891,7 @@ fn selection_section(
}
window.focus(&this.focus, cx);
}));
let mark_btn_inner = if mark_filled {
mark_btn_inner.bg(highlight).border_color(highlight).hover(
move |style| {
style.bg(highlight.opacity(0.85)).border_color(highlight)
},
)
} else if unmark_mode && can_mark {
let mark_btn_inner = if unmark_mode && can_mark {
mark_btn_inner.border_color(theme.danger)
} else {
mark_btn_inner
@@ -1941,9 +1931,9 @@ fn selection_section(
.flex_row()
.items_center()
.gap(space::XS)
.child(refresh_btn)
.child(open_btn)
.child(mark_btn)
.child(refresh_btn),
.child(mark_btn),
);
let section = div()
@@ -2015,10 +2005,10 @@ fn selection_section(
chips.push(widgets::chip("Stale", theme.secondary, cx));
}
treemap_view::TileFreshness::Scheduled => {
chips.push(widgets::chip("Queued", theme.accent, cx));
chips.push(widgets::chip("Queued", theme.secondary, cx));
}
treemap_view::TileFreshness::Updating => {
chips.push(widgets::chip("Refreshing…", theme.accent, cx));
chips.push(widgets::chip("Refreshing…", theme.foreground, cx));
}
}
if marked {
@@ -2985,6 +2975,19 @@ fn indexing_progress(
"Reading this computer"
},
))
.when_some(app.auth_url.clone(), |panel, url| {
panel.child(
button(
"indexing-auth-link",
"Open login link",
ButtonVariant::Outline,
cx,
)
.on_click(move |_, _, cx| {
cx.open_url(&url);
}),
)
})
.child(row(
"Files",
widgets::human_count(app.progress.files),
@@ -4139,13 +4142,16 @@ fn node_card(
treemap_view::TileFreshness::Scheduled => {
badges = badges.child(widgets::chip(
"Queued for refresh",
theme.accent,
theme.secondary,
cx,
));
}
treemap_view::TileFreshness::Updating => {
badges =
badges.child(widgets::chip("Refreshing…", theme.accent, cx));
badges = badges.child(widgets::chip(
"Refreshing…",
theme.foreground,
cx,
));
}
}
if hidden {
+12 -1
View File
@@ -43,7 +43,18 @@ pub fn digest(bytes: &[u8]) -> String {
impl Archive {
pub fn current() -> io::Result<Option<Self>> {
Self::open(&std::env::current_exe()?)
// On Linux, `current_exe()` returns `... (deleted)` after an in-place
// upgrade (`make install` or package update) while the app is open,
// causing `File::open` to fail with ENOENT. Opening `/proc/self/exe`
// directly resolves the live running inode instead.
#[cfg(target_os = "linux")]
{
Self::open(Path::new("/proc/self/exe"))
}
#[cfg(not(target_os = "linux"))]
{
Self::open(&std::env::current_exe()?)
}
}
pub fn open(path: &Path) -> io::Result<Option<Self>> {
+43 -4
View File
@@ -579,9 +579,17 @@ pub fn validate_host(host: &str) -> io::Result<()> {
Ok(())
}
fn read_diagnostics(mut input: impl io::Read) -> String {
fn read_diagnostics(input: impl io::Read) -> String {
read_diagnostics_watching(input, None)
}
fn read_diagnostics_watching(
mut input: impl io::Read,
progress: Option<&Shared>,
) -> String {
let mut tail = Vec::new();
let mut chunk = [0_u8; 4096];
let mut auth_seen = false;
while let Ok(length) = input.read(&mut chunk) {
if length == 0 {
break;
@@ -590,6 +598,16 @@ fn read_diagnostics(mut input: impl io::Read) -> String {
if tail.len() > MAX_DIAGNOSTICS {
tail.drain(..tail.len() - MAX_DIAGNOSTICS);
}
if !auth_seen
&& let Some(shared) = progress
&& let Some(url) =
crate::remote_progress::extract_tailscale_auth_url(
&String::from_utf8_lossy(&tail),
)
{
crate::remote_progress::auth_required(shared, url);
auth_seen = true;
}
}
// Diagnostics are remote-controlled too; keep text, not terminal escapes.
String::from_utf8_lossy(&tail)
@@ -739,15 +757,19 @@ impl<T: Send + 'static> RemoteJob<T> {
.stderr(Stdio::piped())
.spawn()?;
let stderr = child.stderr.take().expect("piped stderr");
// Drain concurrently so noisy login scripts cannot block discovery.
let diagnostics = std::thread::spawn(move || read_diagnostics(stderr));
let progress = Shared::default();
let stderr_progress = progress.clone();
// Drain concurrently so noisy login scripts cannot block discovery,
// and surface Tailscale SSH approval links immediately while waiting.
let diagnostics = std::thread::spawn(move || {
read_diagnostics_watching(stderr, Some(&stderr_progress))
});
let mut stdin = child.stdin.take().expect("piped stdin");
let stdout = child.stdout.take().expect("piped stdout");
let child = Arc::new(Mutex::new(child));
let worker = child.clone();
let host = host.to_owned();
let (tx, result) = mpsc::channel();
let progress = Shared::default();
let live = progress.clone();
std::thread::spawn(move || {
let mut input = BufReader::new(stdout);
@@ -925,6 +947,23 @@ mod tests {
assert!(install_cli_command("Permission denied").is_none());
}
#[test]
fn tailscale_ssh_auth_url_is_extracted_and_restricted_to_tailscale() {
let stderr = "# Tailscale SSH requires an additional check.\n\
# To authenticate, visit: https://login.tailscale.com/a/l10f3362d3b2b77\n";
assert_eq!(
crate::remote_progress::extract_tailscale_auth_url(stderr)
.as_deref(),
Some("https://login.tailscale.com/a/l10f3362d3b2b77")
);
assert_eq!(
crate::remote_progress::extract_tailscale_auth_url(
"visit https://evil.example/a/123"
),
None
);
}
#[cfg(unix)]
#[test]
fn banner_and_truncated_output_are_reported_without_a_hang() {
@@ -7,6 +7,7 @@ use std::time::{Duration, Instant};
pub enum Stage {
#[default]
Connecting,
Authenticating,
CheckingHelper,
UploadingHelper,
Starting,
@@ -18,6 +19,7 @@ impl Stage {
pub const fn label(self) -> &'static str {
match self {
Self::Connecting => "Connecting over SSH",
Self::Authenticating => "Waiting for Tailscale SSH approval",
Self::CheckingHelper => "Checking remote scanner",
Self::UploadingHelper => "Uploading remote scanner",
Self::Starting => "Starting remote scanner",
@@ -35,10 +37,39 @@ pub struct Progress {
pub bytes: u64,
pub errors: u64,
pub directory: Option<PathBuf>,
pub auth_url: Option<String>,
pub updated: Option<Instant>,
pub preview: Option<Arc<crate::scan_preview::Preview>>,
}
/// Extract a Tailscale SSH check/login URL from SSH stderr diagnostics.
///
/// Strictly bounded to `https://login.tailscale.com/` and safe URL characters
/// so untrusted remote stderr can never direct the browser elsewhere.
#[must_use]
pub fn extract_tailscale_auth_url(text: &str) -> Option<String> {
const PREFIX: &str = "https://login.tailscale.com/";
let start = text.find(PREFIX)?;
let tail = &text[start..];
let len = tail
.bytes()
.take_while(|b| {
b.is_ascii_alphanumeric() || b"-._~:/?#[]@!$&'()*+,;=%".contains(b)
})
.count();
let url = tail[..len].trim_end_matches(['.', ',', ')', ']']);
(url.len() > PREFIX.len()).then(|| url.to_owned())
}
pub(crate) fn auth_required(shared: &Shared, url: String) {
let mut progress = shared.lock().expect("remote progress lock");
if progress.auth_url.as_deref() != Some(url.as_str()) {
progress.auth_url = Some(url);
progress.stage = Stage::Authenticating;
progress.updated = Some(Instant::now());
}
}
/// Cap both wire heartbeats and UI publications at five per second.
pub(crate) const INTERVAL: Duration = Duration::from_millis(200);
pub(crate) type Shared = Arc<Mutex<Progress>>;
@@ -46,5 +77,8 @@ pub(crate) type Shared = Arc<Mutex<Progress>>;
pub(crate) fn stage(shared: &Shared, value: Stage) {
let mut progress = shared.lock().expect("remote progress lock");
progress.stage = value;
if value != Stage::Authenticating {
progress.auth_url = None;
}
progress.updated = Some(Instant::now());
}