Files
paseo/packages/app/src/hosts/host-badge.tsx
T
Mohamed BoudraandTaras Kornichuk e06bfbb94c Redesign host picker with configurable auto-detected icons, connection type, and latency (#10702)
Supersedes #5787.

- Add best-effort daemon hardware detection (macOS ioreg/sysctl, Linux containers, WSL, device-tree boards, cloud/VM DMI, SMBIOS chassis) exposed as optional `machineKind` on `server_info` and `/api/status`.
- Add configurable per-host icons in Host Settings -> Appearance (`Auto` plus 9 icons across all 9 locales), keeping `icon` omitted while untouched for rollback compatibility and preserving unknown future icons on disk.
- Redesign `HostPicker` and `HostChooserModal` with resolved host icons, connection type (`Local`, `Tailscale`, `Relay`, `SSH`, `Direct`, `Via`) + endpoint, on-demand round-trip latency, aligned leading and content rails, and full keyboard navigation.
- Update the website host mockup to match.

Co-authored-by: Taras Kornichuk <dread9ko@gmail.com>
2026-11-24 21:52:39 +07:00

106 lines
3.7 KiB
TypeScript

import { Text, View } from "react-native";
import { StyleSheet } from "react-native-unistyles";
import { type HostBadgeModel, type HostColor } from "@/hosts/appearance";
import { HostIconGlyph } from "@/hosts/host-icon-glyph";
import { identityForeground } from "@/styles/identity-colors";
/**
* The glyph size the badge draws at. Rows that place the badge alongside their own glyphs
* match this so the line reads as one rank of peers.
*/
export const HOST_BADGE_ICON_SIZE = 12;
/**
* Which machine something lives on, drawn the same way everywhere it appears: the host's device
* glyph and, when the host is configured to show one, its name — both in the host's identity color.
*
* A hostname is the least interesting thing on any line that carries it and the only one whose
* length nobody chose, so the badge yields space before its neighbours rather than alongside
* them — see `flexShrink` below.
*/
export function HostBadge({ badge }: { badge: HostBadgeModel }) {
return (
<View
style={styles.badge}
testID={`host-badge-${badge.serverId}`}
accessibilityLabel={badge.label}
>
<HostIconGlyph
icon={badge.icon}
color={badge.color}
size={HOST_BADGE_ICON_SIZE}
style={styles.icon}
/>
{badge.showLabel ? (
<Text style={[styles.label, labelColorStyle(badge.color)]} numberOfLines={1}>
{badge.label}
</Text>
) : null}
</View>
);
}
// Text has no `color` prop, so the label cannot ride the icon's uniProps mapping — its color
// has to come from a registered style. One entry per host color, picked at render time; a
// module-level lookup table would read the style proxies before the persisted theme lands.
function labelColorStyle(color: HostColor) {
switch (color) {
case "none":
return null;
case "violet":
return styles.labelViolet;
case "sky":
return styles.labelSky;
case "emerald":
return styles.labelEmerald;
case "orange":
return styles.labelOrange;
case "pink":
return styles.labelPink;
case "indigo":
return styles.labelIndigo;
case "teal":
return styles.labelTeal;
case "red":
return styles.labelRed;
case "amber":
return styles.labelAmber;
case "blue":
return styles.labelBlue;
}
}
const styles = StyleSheet.create((theme) => ({
badge: {
flexDirection: "row",
alignItems: "center",
gap: 3,
minWidth: HOST_BADGE_ICON_SIZE,
// Outweighs a sibling's `flexShrink: 1` by enough that the badge is effectively fully
// squeezed before that sibling gives up its first pixel. An equal factor would split the
// loss in proportion to length, which hands the most space to the longest hostname —
// exactly backwards. The icon has a fixed width, so the badge never disappears outright.
flexShrink: 100,
},
icon: {
flexShrink: 0,
},
label: {
color: theme.colors.foregroundMuted,
fontSize: theme.fontSize.sm,
lineHeight: 16,
flexShrink: 1,
minWidth: 0,
},
labelViolet: { color: identityForeground("violet", theme.colorScheme) },
labelSky: { color: identityForeground("sky", theme.colorScheme) },
labelEmerald: { color: identityForeground("emerald", theme.colorScheme) },
labelOrange: { color: identityForeground("orange", theme.colorScheme) },
labelPink: { color: identityForeground("pink", theme.colorScheme) },
labelIndigo: { color: identityForeground("indigo", theme.colorScheme) },
labelTeal: { color: identityForeground("teal", theme.colorScheme) },
labelRed: { color: identityForeground("red", theme.colorScheme) },
labelAmber: { color: identityForeground("amber", theme.colorScheme) },
labelBlue: { color: identityForeground("blue", theme.colorScheme) },
}));