Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

Size the combine diagram and network table to their content, not guesses

Anmol Kapil87531b0c7edf
diff --git a/src/renderer/src/components/CombineDiagram.tsx b/src/renderer/src/components/CombineDiagram.tsx
index 67a06ac..eb8a780 100644
--- a/src/renderer/src/components/CombineDiagram.tsx
+++ b/src/renderer/src/components/CombineDiagram.tsx
@@ -2,12 +2,21 @@ import { FONT_MONO } from '../theme'
import { formatSpeed } from '../utils/format'
const ROW_HEIGHT = 36
-const LABEL_X = 58
-const DOT_X = 64
-const CURVE_START_X = 70
-const COMBINE_X = 122
-const STREAM_END_X = 158
-const WIDTH = 166
+// Gaps between the label column and the rest of the diagram stay fixed — only the label
+// column's own width flexes with the longest network name, so a long custom label (the dev
+// tool lets you type anything) grows the diagram instead of getting cut off.
+const DOT_GAP = 8
+const CURVE_GAP = 6
+const CURVE_LEN = 64
+const STREAM_LEN = 42
+const END_PAD = 8
+const MIN_LABEL_X = 68
+const MAX_LABEL_CHARS = 18
+// Rough advance width (px) of one uppercase glyph in the label's 8.5px mono font plus its
+// 0.08em letter-spacing — an overestimate is safer here than an underestimate, since this
+// sizes an SVG column rather than flowing text a browser could wrap or ellipsize for us.
+const CHAR_WIDTH = 6.4
+const LABEL_EDGE_PAD = 4
export interface CombineDiagramNetwork {
solid: string
@@ -35,6 +44,17 @@ export function CombineDiagram({
const height = Math.max(78, networks.length * ROW_HEIGHT + 10)
const midY = height / 2
+ const longestLabelChars = Math.min(
+ MAX_LABEL_CHARS,
+ networks.reduce((max, network) => Math.max(max, network.label.trim().length), 0)
+ )
+ const LABEL_X = Math.max(MIN_LABEL_X, longestLabelChars * CHAR_WIDTH + LABEL_EDGE_PAD)
+ const DOT_X = LABEL_X + DOT_GAP
+ const CURVE_START_X = DOT_X + CURVE_GAP
+ const COMBINE_X = CURVE_START_X + CURVE_LEN
+ const STREAM_END_X = COMBINE_X + STREAM_LEN
+ const WIDTH = STREAM_END_X + END_PAD
+
return (
<svg
viewBox={`0 0 ${WIDTH} ${height}`}
@@ -101,8 +121,11 @@ export function CombineDiagram({
{networks.map((network, index) => {
const y = (index + 0.5) * (height / networks.length)
const label =
- network.label.trim().length > 10
- ? `${network.label.trim().slice(0, 9).toUpperCase()}…`
+ network.label.trim().length > MAX_LABEL_CHARS
+ ? `${network.label
+ .trim()
+ .slice(0, MAX_LABEL_CHARS - 1)
+ .toUpperCase()}…`
: network.label.trim().toUpperCase()
const hasSpeed = network.speedBytesPerSec != null && network.speedBytesPerSec > 0
const speedText = hasSpeed ? formatSpeed(network.speedBytesPerSec!) : '—'
diff --git a/src/renderer/src/components/NetworkRow.tsx b/src/renderer/src/components/NetworkRow.tsx
index f8a82ff..a153b40 100644
--- a/src/renderer/src/components/NetworkRow.tsx
+++ b/src/renderer/src/components/NetworkRow.tsx
@@ -71,11 +71,6 @@ export function NetworkRow({
<div style={{ minWidth: 0, display: 'flex', alignItems: 'center', gap: 6 }}>
<span
style={{
- // A fixed basis rather than letting the name take its natural width — otherwise
- // the streams pill and "⋯" button (and everything after them, all the way out to
- // the Progress column) shift left or right by however long each network's name
- // happens to be, so the gap before the progress bar looks different on every row.
- flex: '0 0 100px',
font: `600 12.5px/1.2 ${FONT_UI}`,
whiteSpace: 'nowrap',
overflow: 'hidden',
diff --git a/src/renderer/src/screens/DownloadingScreen.tsx b/src/renderer/src/screens/DownloadingScreen.tsx
index 8a4bfec..76a4f68 100644
--- a/src/renderer/src/screens/DownloadingScreen.tsx
+++ b/src/renderer/src/screens/DownloadingScreen.tsx
@@ -480,7 +480,7 @@ export function DownloadingScreen({ download }: { download: DownloadState }): Re
/>
</div>
- <div style={{ flex: 1, overflowY: 'auto' }}>
+ <div style={{ flex: 1, overflowY: 'auto', overflowX: 'hidden' }}>
<div
style={{
display: 'flex',
diff --git a/src/renderer/src/theme.ts b/src/renderer/src/theme.ts
index 868e955..6a9a9ac 100644
--- a/src/renderer/src/theme.ts
+++ b/src/renderer/src/theme.ts
@@ -199,14 +199,15 @@ export const statValueStyle: React.CSSProperties = {
fontVariantNumeric: 'tabular-nums'
}
-// Network is a fixed width, sized to what its content (name + streams pill + "⋯" button) needs
-// and nothing more — giving it a share of `fr` growth (an earlier version of this did, in a 1:2
-// ratio with Progress) just accumulated dead trailing space inside it on a wide window, since
-// nothing in that cell actually gets wider. Progress is the one column that should visually
-// scale with the window (the bar already fills 100% of its track), so it alone takes the rest
-// of the space; that also keeps the gap after the bar, into Share, the same fixed 12px as every
-// other column boundary — instead of Network's gap growing while Progress's stays put.
-export const NETWORK_ROW_GRID_COLUMNS = '10px 220px 1fr 48px 78px 90px'
+// Network sizes to its content (name + streams pill + "⋯" button) instead of a guessed fixed
+// px — `minmax(0, max-content)` grows it to fit whatever's actually in that cell (no dead
+// trailing space before Progress) and, just as importantly, lets it shrink below that on a
+// narrow window instead of holding a fixed width the row can't fit in. Progress is the one
+// column that should visually scale with the window (the bar already fills 100% of its track),
+// so it alone takes the leftover space; that also keeps the gap after the bar, into Share, the
+// same fixed 12px as every other column boundary — instead of Network's gap growing while
+// Progress's stays put.
+export const NETWORK_ROW_GRID_COLUMNS = '10px minmax(0, max-content) 1fr 48px 78px 90px'
// The header and every NetworkRow used to each be their own independent CSS grid with this same
// column template — which happened to compute matching track widths most of the time, but wasn't