Skip to content

A high-performance Android storage analyzer that bypasses MTP using a native C++ daemon, a Rust TCP bridge, and a React Treemap UI.

Rust

Add a keyboard-accessible storage map toggle (#215)

Vishnu Srivatsava67771063f332
diff --git a/src/ResultScreen.tsx b/src/ResultScreen.tsx
index 88dc99c..268d352 100644
--- a/src/ResultScreen.tsx
+++ b/src/ResultScreen.tsx
@@ -1,5 +1,5 @@
import type { SearchFolder } from "./searchResults";
-import { useEffect, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { StorageMap } from "./StorageMap";
import { formatBytes } from "./formatBytes";
import type { ScanResponse } from "./scanView";
@@ -43,6 +43,8 @@ export function ResultScreen({
const [expanded, setExpanded] = useState(() => new Set([data.root.id]));
const [mode, setMode] = useState<"map" | "largest" | "types" | "search" | "apps">("map");
const [searchFolder, setSearchFolder] = useState<SearchFolder | null>(null);
+ const [mapVisible, setMapVisible] = useState(true);
+ const mapPanel = useRef<HTMLDivElement>(null);
const view = useScanView(data, zoomId, mode === "map");
const page = view.page;
const onZoom = (id: number) => {
@@ -130,21 +132,42 @@ export function ResultScreen({
<StatCard label="Scan Time" value={`${data.scan_time_ms}ms`} />
</div>
- <div className="flex gap-2 px-4 pb-2 shrink-0 overflow-x-auto" role="group" aria-label="Scan view">
- <button aria-pressed={mode === "map"} disabled={busy} onClick={() => setMode("map")}
- className={`px-3 py-2 rounded-lg text-xs ${mode === "map" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Storage map</button>
- <button aria-pressed={mode === "largest"} disabled={busy} onClick={() => setMode("largest")}
- className={`px-3 py-2 rounded-lg text-xs ${mode === "largest" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Largest files</button>
- <button aria-pressed={mode === "types"} disabled={busy} onClick={() => setMode("types")}
- className={`px-3 py-2 rounded-lg text-xs ${mode === "types" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>File types</button>
- <button aria-pressed={mode === "search"} disabled={busy} onClick={() => { setSearchFolder(null); setMode("search"); }}
- className={`px-3 py-2 rounded-lg text-xs ${mode === "search" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Search</button>
- <button aria-pressed={mode === "apps"} disabled={busy} onClick={() => setMode("apps")}
- className={`px-3 py-2 rounded-lg text-xs whitespace-nowrap ${mode === "apps" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Package folders</button>
+ <div className="flex items-start gap-2 px-4 pb-2 shrink-0">
+ <div className="flex flex-1 gap-2 min-w-0 overflow-x-auto [&>button]:shrink-0 [&>button]:whitespace-nowrap" role="group" aria-label="Scan view">
+ <button aria-pressed={mode === "map"} disabled={busy} onClick={() => setMode("map")}
+ className={`px-3 py-2 rounded-lg text-xs ${mode === "map" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Storage map</button>
+ <button aria-pressed={mode === "largest"} disabled={busy} onClick={() => setMode("largest")}
+ className={`px-3 py-2 rounded-lg text-xs ${mode === "largest" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Largest files</button>
+ <button aria-pressed={mode === "types"} disabled={busy} onClick={() => setMode("types")}
+ className={`px-3 py-2 rounded-lg text-xs ${mode === "types" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>File types</button>
+ <button aria-pressed={mode === "search"} disabled={busy} onClick={() => { setSearchFolder(null); setMode("search"); }}
+ className={`px-3 py-2 rounded-lg text-xs ${mode === "search" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Search</button>
+ <button aria-pressed={mode === "apps"} disabled={busy} onClick={() => setMode("apps")}
+ className={`px-3 py-2 rounded-lg text-xs ${mode === "apps" ? "bg-zinc-700 text-white" : "bg-zinc-900 text-zinc-400"}`}>Package folders</button>
+ </div>
+ {mode === "map" && (
+ <button
+ type="button"
+ aria-controls="storage-map-panel"
+ aria-expanded={mapVisible}
+ onClick={event => {
+ if (mapVisible && mapPanel.current?.contains(document.activeElement)) {
+ event.currentTarget.focus({ preventScroll: true });
+ }
+ setMapVisible(visible => !visible);
+ }}
+ className="shrink-0 whitespace-nowrap rounded-lg px-3 py-2 text-xs bg-zinc-900 text-zinc-300
+ hover:bg-zinc-800 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-accent-400"
+ >
+ {mapVisible ? "Hide map" : "Show map"}
+ </button>
+ )}
</div>
- {mode === "apps" ? <AppUsage key={data.revision} scope={data} busy={busy} /> : mode === "types" ? <FileTypes scope={data} busy={busy} /> : mode === "largest" ? <LargestFiles scope={data} busy={busy} onZoom={onZoom} onNuke={onNuke} /> : mode === "search" ? <SearchFiles key={searchFolder?.id ?? "all"} scope={data} folder={searchFolder} busy={busy} onZoom={onZoom} onNuke={onNuke} /> : <div className="flex-1 min-h-0 grid grid-rows-[7rem_minmax(0,1fr)] md:grid-rows-1 md:grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3 px-4 pb-3">
- <div className="min-h-0 min-w-0">
- <StorageMap page={page} busy={busy} onZoom={onZoom} />
+ {mode === "apps" ? <AppUsage key={data.revision} scope={data} busy={busy} /> : mode === "types" ? <FileTypes scope={data} busy={busy} /> : mode === "largest" ? <LargestFiles scope={data} busy={busy} onZoom={onZoom} onNuke={onNuke} /> : mode === "search" ? <SearchFiles key={searchFolder?.id ?? "all"} scope={data} folder={searchFolder} busy={busy} onZoom={onZoom} onNuke={onNuke} /> : <div className={`flex-1 min-h-0 grid gap-3 px-4 pb-3 ${mapVisible
+ ? "grid-rows-[7rem_minmax(0,1fr)] md:grid-rows-1 md:grid-cols-[minmax(0,1fr)_minmax(0,2fr)]"
+ : "grid-cols-1 grid-rows-1"}`}>
+ <div id="storage-map-panel" ref={mapPanel} hidden={!mapVisible} className="min-h-0 min-w-0">
+ {mapVisible && <StorageMap page={page} busy={busy} onZoom={onZoom} />}
</div>
{/* File tree */}
diff --git a/tests/scan_ui_fixture.js b/tests/scan_ui_fixture.js
index 6291330..bce39e4 100644
--- a/tests/scan_ui_fixture.js
+++ b/tests/scan_ui_fixture.js
@@ -300,7 +300,7 @@
const report = (passed, error) => {
const output = document.createElement("pre");
output.id = "scan-test-report";
- output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });
+ output.textContent = JSON.stringify({ fixture: "scan-ui", passed, error, ipc_calls: calls.length, wide_paging: widePaging, expanded_tree: expandedTree, checks: passed ? ["offline fonts under CSP", "bounded collapsed discovery diagnostics", "discovery retry recovery", "setup alignment", "result fonts", "file label semantics", "usable file workspace", "keyboard storage map visibility", "collapsible diagnostics", "complete paging", "directory paging focus and retries", "expanded-tree row growth and keyboard focus", "first-scan comparison", "unchanged comparison after rescan", "deletion delta comparison", "cross-device comparison isolation", "bounded package-folder paging and coverage", "package query retries and stale replies", "bounded file-type totals", "file-type retry and malformed response", "file-type generation and deletion revision", "file-type coverage and empty scan", "bounded largest files", "late largest response", "largest query retry", "malformed largest response recovery", "largest ID-only deletion", "largest read-only guards", "largest folder navigation without rescanning", "bounded search results", "late search response", "search retry and malformed response", "search ID-only deletion", "read-only search deletion disabled", "late zoom", "Other tile", "stale confirmation", "exact confirmation whitespace", "reachable long-path confirmation", "native modal keyboard focus and cancellation", "ID-only deletion", "revision refresh", "partial failure", "read-only", "acknowledged shutdown", "unconfirmed shutdown", "reconnect", "stop action ordering", "duplicate rescan guard", "rescan failure recovery", "rescan cancellation recovery", "toast dismissal integration", "bounded diagnostic integration"] : undefined });
document.body.append(output);
void fetch("/report", { method: "POST", body: output.textContent }).then(() => {
if (passed) location.replace("/tests/toast_lifecycle_fixture.html");
@@ -820,6 +820,34 @@
check(document.activeElement === mapFolder, "Storage map folder did not receive focus");
await pressKey("Enter");
await waitFor(() => button("← Back to Root") && rows().length === 129, "Keyboard map zoom failed");
+ await waitFor(() => document.querySelector('svg [role="button"]'), "Zoomed map did not render");
+ const mapToggle = button("Hide map");
+ const mapPanel = document.getElementById(mapToggle.getAttribute("aria-controls"));
+ check(mapPanel && !mapPanel.hidden && mapToggle.getAttribute("aria-expanded") === "true",
+ "Toggle does not announce the visible map");
+ const zoomedViewport = document.querySelector('[aria-label="Files and folders"]');
+ const shownBounds = zoomedViewport.getBoundingClientRect();
+ const zoomedRoot = zoomedViewport.querySelector('[role="treeitem"][aria-level="1"]');
+ const zoomQueries = calls.filter(call => call.command === "get_scan_view").length;
+ button("Package folders").focus();
+ await pressKey("Tab");
+ check(document.activeElement === mapToggle, "Map toggle is missing from the keyboard tab order");
+ await pressKey("Enter");
+ await waitFor(() => mapPanel.hidden && button("Show map") === mapToggle, "Keyboard did not hide the map");
+ const hiddenBounds = zoomedViewport.getBoundingClientRect();
+ check(mapToggle.getAttribute("aria-expanded") === "false" && !mapPanel.querySelector("svg"),
+ "Hidden map did not clear its tiles or announce its state");
+ check(document.activeElement === mapToggle, "Hiding the map lost toggle focus");
+ check(hiddenBounds.width > shownBounds.width || hiddenBounds.height > shownBounds.height,
+ `Hiding the map did not grow the file pane: ${shownBounds.width}×${shownBounds.height} to ${hiddenBounds.width}×${hiddenBounds.height}`);
+ await pressKey("Enter");
+ await waitFor(() => !mapPanel.hidden && mapPanel.querySelector('svg [role="button"]'), "Keyboard did not restore the map");
+ check(document.activeElement === mapToggle && mapToggle.getAttribute("aria-expanded") === "true",
+ "Restoring the map lost focus or did not announce the visible state");
+ check(zoomedViewport.querySelector('[role="treeitem"][aria-level="1"]') === zoomedRoot
+ && zoomedRoot.getAttribute("aria-expanded") === "true" && rows().length === 129
+ && calls.filter(call => call.command === "get_scan_view").length === zoomQueries,
+ "Toggling the map reset the current folder or its expanded rows");
button("← Back to Root").click();
await waitFor(() => !button("← Back to Root") && rows().some(row => row.textContent.includes("large-folder")), "Map zoom did not return to root");
@@ -1093,6 +1121,19 @@
const viewportBounds = viewport.getBoundingClientRect();
check(finalRowBounds.top >= viewportBounds.top && finalRowBounds.bottom <= viewportBounds.bottom,
"Final expanded entry could not be scrolled into view");
+ const wideMapToggle = button("Hide map");
+ wideMapToggle.focus({ preventScroll: true });
+ for (const visible of [false, true]) {
+ await pressKey("Enter");
+ await viewportSettled();
+ check(document.activeElement === wideMapToggle && wideMapToggle.getAttribute("aria-expanded") === String(visible),
+ "Toggling the map beside a virtualized tree lost toggle focus");
+ check(logicalRows() === 1 + 128 + 128 * 128 && rows().length < 100,
+ "Toggling the map reset expansion or broke the virtual row bound");
+ check(viewport.querySelector('[data-tree-node="17383"][tabindex="0"] button[aria-label="Delete entry-128-127"]') === last,
+ "Toggling the map discarded the active virtual row");
+ }
+ last.focus({ preventScroll: true });
await pressKey("Home");
await waitFor(() => document.activeElement?.dataset.treeNode === "0", "Home did not focus the first tree entry");
await pressKey("ArrowDown");