@peers-app/peers-ui 0.33.20 → 0.33.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/graph/ring-layout.d.ts +62 -0
  2. package/dist/graph/ring-layout.js +100 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
  6. package/dist/screens/network-viewer/graph/edge-route.js +133 -0
  7. package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
  8. package/dist/screens/network-viewer/graph/label-placement.js +134 -0
  9. package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
  10. package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
  11. package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
  12. package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
  13. package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
  14. package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
  15. package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
  16. package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
  17. package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
  18. package/dist/screens/network-viewer/graph/network-graph.js +419 -0
  19. package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
  20. package/dist/screens/network-viewer/network-viewer.js +65 -8
  21. package/dist/tabs-layout/linger.d.ts +75 -0
  22. package/dist/tabs-layout/linger.js +121 -0
  23. package/dist/tabs-layout/network-status-details.d.ts +27 -0
  24. package/dist/tabs-layout/network-status-details.js +203 -0
  25. package/dist/tabs-layout/network-status-format.d.ts +22 -0
  26. package/dist/tabs-layout/network-status-format.js +58 -0
  27. package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
  28. package/dist/tabs-layout/network-status-indicator.js +27 -133
  29. package/dist/tabs-layout/network-status-model.d.ts +71 -0
  30. package/dist/tabs-layout/network-status-model.js +155 -0
  31. package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
  32. package/dist/tabs-layout/use-network-details-data.js +90 -0
  33. package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
  34. package/dist/tabs-layout/use-syncing-look.js +50 -0
  35. package/dist/theme.css +635 -0
  36. package/package.json +3 -3
@@ -1,31 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SYNCED_STABLE_MS = exports.SYNCING_GREEN_MS = void 0;
3
+ exports.SYNCING_GREEN_MS = exports.SYNCED_STABLE_MS = void 0;
7
4
  exports.getNetworkStatusPresentation = getNetworkStatusPresentation;
8
5
  exports.withAppUpdate = withAppUpdate;
9
- exports.formatRelativeSyncTime = formatRelativeSyncTime;
10
- exports.connectionIdentityLabel = connectionIdentityLabel;
11
6
  exports.NetworkStatusIndicator = NetworkStatusIndicator;
12
7
  exports.TabsStripIndicators = TabsStripIndicators;
13
8
  const jsx_runtime_1 = require("react/jsx-runtime");
14
- const moment_1 = __importDefault(require("moment"));
15
9
  const react_1 = require("react");
16
10
  const app_update_controls_1 = require("../app-updates/app-update-controls");
17
11
  const app_updates_consumer_1 = require("../app-updates/app-updates-consumer");
18
12
  const use_app_update_status_1 = require("../app-updates/use-app-update-status");
19
13
  const notification_bell_1 = require("../notifications/notification-bell");
20
14
  const identity_routes_1 = require("../screens/identity/identity-routes");
21
- const network_viewer_ipc_1 = require("../screens/network-viewer/network-viewer-ipc");
22
15
  const network_viewer_section_1 = require("../screens/network-viewer/network-viewer-section");
16
+ const network_status_details_1 = require("./network-status-details");
23
17
  const tabs_state_1 = require("./tabs-state");
18
+ const use_network_details_data_1 = require("./use-network-details-data");
24
19
  const use_network_status_1 = require("./use-network-status");
25
- /** How long continuous raw syncing stays a green pulse before the indeterminate circle. */
26
- exports.SYNCING_GREEN_MS = 4_000;
27
- /** How long status must stay fully synced before leaving the syncing visual. */
28
- exports.SYNCED_STABLE_MS = 1_000;
20
+ const use_syncing_look_1 = require("./use-syncing-look");
21
+ var use_syncing_look_2 = require("./use-syncing-look");
22
+ Object.defineProperty(exports, "SYNCED_STABLE_MS", { enumerable: true, get: function () { return use_syncing_look_2.SYNCED_STABLE_MS; } });
23
+ Object.defineProperty(exports, "SYNCING_GREEN_MS", { enumerable: true, get: function () { return use_syncing_look_2.SYNCING_GREEN_MS; } });
29
24
  /**
30
25
  * Calm opacity pulse (same feel as kube-tools WatchButton) — not Bootstrap
31
26
  * spinner-grow, which scales the mark and reads as noisy in the tabs strip.
@@ -193,137 +188,36 @@ function StatusMark({ mode, colorClass }) {
193
188
  }
194
189
  return ((0, jsx_runtime_1.jsx)("span", { className: `rounded-circle ${bgClass}`, style: { width: DOT_SIZE, height: DOT_SIZE, display: "inline-block" }, "aria-hidden": "true" }));
195
190
  }
196
- /** Compact relative time for the status popover (always short enough for one line). */
197
- function formatRelativeSyncTime(timestampMs, nowMs = Date.now()) {
198
- const then = (0, moment_1.default)(timestampMs);
199
- const now = (0, moment_1.default)(nowMs);
200
- if (now.diff(then, "seconds") < 45) {
201
- return "now";
202
- }
203
- if (now.clone().subtract(1, "day").isSame(then, "day")) {
204
- return "yesterday";
205
- }
206
- return then.from(now);
207
- }
208
- function middleEllipsis(value, head = 4, tail = 4) {
209
- if (value.length <= head + tail + 1) {
210
- return value;
211
- }
212
- return `${value.slice(0, head)}…${value.slice(-tail)}`;
213
- }
214
- /** Prefer a friendly name; otherwise a compact middle-ellipsis of the id. */
215
- function connectionIdentityLabel(name, id) {
216
- const trimmed = name?.trim();
217
- if (trimmed) {
218
- return { text: trimmed, isId: false, title: trimmed };
219
- }
220
- return { text: middleEllipsis(id), isId: true, title: id };
221
- }
222
- function IdentityPart({ label }) {
223
- return ((0, jsx_runtime_1.jsx)("span", { className: `text-truncate ${label.isId ? "text-muted" : ""}`, style: {
224
- minWidth: 0,
225
- ...(label.isId ? { fontSize: "0.7rem" } : undefined),
226
- }, title: label.title, children: label.text }));
227
- }
228
- function ConnectedDeviceRow({ connection }) {
229
- const user = connectionIdentityLabel(connection.userName, connection.userId);
230
- const device = connectionIdentityLabel(connection.deviceName, connection.deviceId);
231
- const groupCount = connection.sharedGroups.length;
232
- return ((0, jsx_runtime_1.jsxs)("li", { className: "d-flex align-items-baseline gap-1 py-1", style: { listStyle: "none", minWidth: 0 }, children: [(0, jsx_runtime_1.jsx)(IdentityPart, { label: user }), (0, jsx_runtime_1.jsx)("span", { className: "text-muted flex-shrink-0", "aria-hidden": "true", children: "\u00B7" }), (0, jsx_runtime_1.jsx)(IdentityPart, { label: device }), groupCount > 0 && ((0, jsx_runtime_1.jsxs)("span", { className: "text-muted flex-shrink-0 ms-auto", style: { fontSize: "0.7rem" }, title: `${groupCount} ${groupCount === 1 ? "group" : "groups"}`, children: [groupCount, "g"] }))] }));
233
- }
234
- function ConnectedDevicesList({ loadState }) {
235
- if (loadState.status === "idle" || loadState.status === "loading") {
236
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "Loading\u2026" });
237
- }
238
- if (loadState.status === "error") {
239
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "Couldn't load devices" });
240
- }
241
- if (loadState.connections.length === 0) {
242
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "No connected devices" });
243
- }
244
- return ((0, jsx_runtime_1.jsx)("ul", { className: "small mb-0 ps-0", style: { maxHeight: "180px", overflowY: "auto" }, children: loadState.connections.map((connection) => ((0, jsx_runtime_1.jsx)(ConnectedDeviceRow, { connection: connection }, connection.deviceId))) }));
245
- }
246
- function StatusCountRow({ label, value, className, }) {
247
- const tone = className ? ` ${className}` : "";
248
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("dt", { className: `col-7${tone}`, children: label }), (0, jsx_runtime_1.jsx)("dd", { className: `col-5 text-end${tone}`, children: value })] }));
249
- }
250
- function NetworkStatusDetails({ detailsId, status, missingChangeCount, appUpdate, unavailable, connectionsLoadState, onUseInvite, onOpenIdentity, onOpenViewer, onOpenRecovery, }) {
251
- const needsRecovery = !!status && (status.stuckRecoveryCount > 0 || missingChangeCount > 0);
252
- return ((0, jsx_runtime_1.jsx)("div", { id: detailsId, role: "dialog", "aria-label": "Network status details", className: "card shadow position-absolute end-0 mt-1", style: { top: "100%", width: "320px", zIndex: 1100 }, children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2 mb-3", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-sm btn-outline-primary flex-fill", onClick: onUseInvite, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-qr-code me-1", "aria-hidden": "true" }), "Use Invite"] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-sm btn-outline-primary flex-fill", onClick: onOpenIdentity, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-person-badge me-1", "aria-hidden": "true" }), "Identity"] })] }), (0, jsx_runtime_1.jsx)(app_update_controls_1.AppUpdatePopoverSection, { status: appUpdate }), (0, jsx_runtime_1.jsx)("h6", { className: "card-title mb-2", children: "Network status" }), unavailable || !status ? ((0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-3", children: "Network diagnostics are temporarily unavailable. The local host may still be starting or reconnecting." })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("dl", { className: "row small mb-2", children: [(0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Connections", value: status.connectionCount }), (0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Groups connected", value: status.connectedContextCount }), status.syncingContextCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Syncing contexts", value: status.syncingContextCount })), status.disconnectedContextCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Groups offline", value: status.disconnectedContextCount, className: "text-warning" })), status.errorCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Sync errors", value: status.errorCount })), status.lastSuccessfulSyncAt != null && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("dt", { className: "col-7", children: "Last sync" }), (0, jsx_runtime_1.jsx)("dd", { className: "col-5 text-end text-truncate", title: new Date(status.lastSuccessfulSyncAt).toLocaleString(), children: formatRelativeSyncTime(status.lastSuccessfulSyncAt) })] }))] }), status.errors.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-2 small mb-2", children: [status.errors[0].message, status.errors.length > 1 && ` (+${status.errors.length - 1} more)`] })), status.stuckRecoveryCount > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning py-2 px-2 small mb-2", children: status.stuckRecoveryCount === 1
253
- ? "1 record needs attention"
254
- : `${status.stuckRecoveryCount} records need attention` })), missingChangeCount > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning py-2 px-2 small mb-2", children: missingChangesLabel(missingChangeCount) })), (0, jsx_runtime_1.jsxs)("div", { className: "border-top pt-2 mt-1 mb-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "small text-muted mb-1", children: "Connected Devices" }), (0, jsx_runtime_1.jsx)(ConnectedDevicesList, { loadState: connectionsLoadState })] })] })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm btn-outline-primary w-100${needsRecovery ? " mb-2" : ""}`, onClick: onOpenViewer, children: "Open Network Viewer" }), needsRecovery && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-warning w-100", onClick: onOpenRecovery, children: "Sync recovery" }))] }) }));
255
- }
256
191
  /** Accessible reactive network status button and details popover. */
257
192
  function NetworkStatusIndicator({ compact = false }) {
258
193
  const viewState = (0, use_network_status_1.useNetworkStatus)();
259
194
  const appUpdate = (0, use_app_update_status_1.useAppUpdateStatus)();
260
- const [displaySyncing, setDisplaySyncing] = (0, react_1.useState)(false);
261
- const [syncingLongerThanGreenMs, setSyncingLongerThanGreenMs] = (0, react_1.useState)(false);
262
195
  const [open, setOpen] = (0, react_1.useState)(false);
263
- const [connectionsLoadState, setConnectionsLoadState] = (0, react_1.useState)({
264
- status: "idle",
265
- });
266
196
  const containerRef = (0, react_1.useRef)(null);
267
197
  const detailsId = (0, react_1.useId)();
268
198
  const rawState = viewState.availability === "ready" ? viewState.status?.state : undefined;
269
199
  const rawIsSyncing = rawState === "syncing";
270
200
  const rawIsSynced = rawState === "synced";
271
- const connectionCount = viewState.status?.connectionCount;
272
201
  const diagnosticsReady = viewState.availability === "ready";
273
- (0, react_1.useEffect)(() => {
274
- if (rawIsSyncing) {
275
- setDisplaySyncing(true);
276
- return;
277
- }
278
- if (rawIsSynced) {
279
- if (!displaySyncing) {
280
- return;
281
- }
282
- const timer = window.setTimeout(() => {
283
- setDisplaySyncing(false);
284
- }, exports.SYNCED_STABLE_MS);
285
- return () => {
286
- window.clearTimeout(timer);
287
- };
288
- }
289
- setDisplaySyncing(false);
290
- }, [rawIsSyncing, rawIsSynced, displaySyncing]);
291
- (0, react_1.useEffect)(() => {
292
- if (!rawIsSyncing) {
293
- setSyncingLongerThanGreenMs(false);
294
- return;
295
- }
296
- const timer = window.setTimeout(() => {
297
- setSyncingLongerThanGreenMs(true);
298
- }, exports.SYNCING_GREEN_MS);
299
- return () => {
300
- window.clearTimeout(timer);
301
- };
302
- }, [rawIsSyncing]);
303
- (0, react_1.useEffect)(() => {
304
- if (!open || !diagnosticsReady) {
305
- setConnectionsLoadState({ status: "idle" });
306
- return;
307
- }
308
- let active = true;
309
- setConnectionsLoadState({ status: "loading" });
310
- void (0, network_viewer_ipc_1.getNetworkDiagnosticsConsumer)()
311
- .then((diagnostics) => diagnostics.tools.getConnections())
312
- .then((result) => {
313
- if (active) {
314
- setConnectionsLoadState({ status: "ready", connections: result.connections });
315
- }
316
- })
317
- .catch(() => {
318
- if (active) {
319
- setConnectionsLoadState({ status: "error" });
320
- }
321
- });
322
- return () => {
323
- active = false;
324
- };
325
- }, [open, diagnosticsReady, connectionCount]);
326
- const holdSyncingVisual = displaySyncing && !rawIsSyncing;
202
+ const syncingLook = (0, use_syncing_look_1.useSyncingLook)(rawIsSyncing, rawIsSynced);
203
+ const syncingLongerThanGreenMs = syncingLook === "spinner";
204
+ const status = viewState.status;
205
+ const detailsData = (0, use_network_details_data_1.useNetworkDetailsData)(open, diagnosticsReady, status
206
+ ? [
207
+ status.state,
208
+ status.connectionCount,
209
+ status.syncingContextCount,
210
+ status.errorCount,
211
+ status.connectedContextCount,
212
+ status.disconnectedContextCount,
213
+ ].join("|")
214
+ : "");
215
+ // While the syncing look is held after syncing stops, the headline keeps the last count.
216
+ const lastSyncingCount = (0, react_1.useRef)(0);
217
+ if (rawIsSyncing && status) {
218
+ lastSyncingCount.current = status.syncingContextCount;
219
+ }
220
+ const holdSyncingVisual = syncingLook !== undefined && !rawIsSyncing;
327
221
  const presentation = withAppUpdate(getNetworkStatusPresentation(viewState, {
328
222
  syncingLongerThanGreenMs,
329
223
  holdSyncingVisual,
@@ -378,7 +272,7 @@ function NetworkStatusIndicator({ compact = false }) {
378
272
  .network-status-update-badge.bi::before {
379
273
  vertical-align: 0;
380
274
  }
381
- ` })] }))] }), !compact && ((0, jsx_runtime_1.jsxs)("span", { className: "small", children: [viewState.status?.connectionCount ?? 0, (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " connections" })] }))] }), open && ((0, jsx_runtime_1.jsx)(NetworkStatusDetails, { detailsId: detailsId, status: viewState.status, missingChangeCount: viewState.missingChangeCount ?? 0, appUpdate: appUpdate, unavailable: viewState.availability !== "ready", connectionsLoadState: connectionsLoadState, onUseInvite: () => {
275
+ ` })] }))] }), !compact && ((0, jsx_runtime_1.jsxs)("span", { className: "small", children: [viewState.status?.connectionCount ?? 0, (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " connections" })] }))] }), open && ((0, jsx_runtime_1.jsx)(network_status_details_1.NetworkStatusDetails, { detailsId: detailsId, status: viewState.status, missingChangeCount: viewState.missingChangeCount ?? 0, appUpdate: appUpdate, unavailable: viewState.availability !== "ready", data: detailsData, syncingLook: syncingLook, syncingCount: rawIsSyncing ? (status?.syncingContextCount ?? 0) : lastSyncingCount.current, onUseInvite: () => {
382
276
  setOpen(false);
383
277
  (0, tabs_state_1.goToTabPath)(identity_routes_1.IDENTITY_ACCEPT_PATH);
384
278
  }, onOpenIdentity: () => {
@@ -0,0 +1,71 @@
1
+ import type { INetworkConnectionInfo, INetworkGroupSyncInfo, INetworkStatusSummary } from "@peers-app/peers-sdk";
2
+ /** How a group's or the whole network's state reads: its dot or icon color. */
3
+ export type NetworkTone = "ok" | "syncing" | "error" | "warning" | "quiet";
4
+ /** One group's line in the network status popover. */
5
+ export interface INetworkGroupRow {
6
+ groupId: string;
7
+ name: string;
8
+ tone: NetworkTone;
9
+ /** The right side: "4 devices", "syncing · 4 devices", "no connection" and the like. */
10
+ detail: string;
11
+ /** The group's sync error, shown under its name. */
12
+ error?: string;
13
+ }
14
+ /**
15
+ * One line per group for the network status popover: Personal first, then by name. A group's
16
+ * line stays while its state changes, so only its dot and text change in place.
17
+ *
18
+ * A group with no live connection is "no connection" (warning) when it has other members, or
19
+ * when the status counts more disconnected groups than those explain; otherwise it's "only this
20
+ * device" (quiet): a group with nobody else in it isn't missing anything.
21
+ *
22
+ * @param groups - From System Network Diagnostics' `getGroupSyncStatus`.
23
+ * @param status - The live status summary; its errors are what the indicator counts.
24
+ * @param personalId - The personal context's id (the user's id), listed first.
25
+ */
26
+ export declare function groupRows(groups: readonly INetworkGroupSyncInfo[], status: INetworkStatusSummary, personalId?: string): INetworkGroupRow[];
27
+ /** The popover's first line: how things are, in a few words. */
28
+ export interface INetworkHeadline {
29
+ tone: NetworkTone;
30
+ title: string;
31
+ /** Sync errors to show beside a title that's about something else. */
32
+ errorCount?: number;
33
+ }
34
+ /**
35
+ * The popover's headline. Syncing comes first (with any errors beside it), then errors, then
36
+ * groups without a connection, then "All synced".
37
+ *
38
+ * @param status - The live status summary.
39
+ * @param syncing - Show syncing: the status is syncing, or the indicator is holding its syncing
40
+ * look until synced is stable.
41
+ * @param syncingCount - Groups syncing; the last count while the look is held.
42
+ */
43
+ export declare function networkHeadline(status: INetworkStatusSummary, syncing: boolean, syncingCount: number): INetworkHeadline;
44
+ /**
45
+ * The line under the headline: devices connected, and groups connected out of all of them.
46
+ *
47
+ * @param status - The live status summary.
48
+ * @param groupCount - How many groups the popover lists, once they're loaded.
49
+ */
50
+ export declare function networkSummaryLine(status: INetworkStatusSummary, groupCount?: number): string;
51
+ /** One connected device as a chip in the popover. */
52
+ export interface INetworkDeviceChip {
53
+ deviceId: string;
54
+ label: string;
55
+ /** Who and what it is in full, for the tooltip. */
56
+ title: string;
57
+ /** One of the user's own devices. */
58
+ mine: boolean;
59
+ /** A Peers Services relay such as peers.app. */
60
+ service: boolean;
61
+ }
62
+ /**
63
+ * A connected device as a chip: its device name (or its owner's name, or a short id), the
64
+ * user's own devices marked, and a relay named by its host.
65
+ *
66
+ * @param connection - From `getConnections`.
67
+ * @param myUserId - The signed-in user, whose devices are "mine".
68
+ */
69
+ export declare function deviceChip(connection: INetworkConnectionInfo, myUserId: string | undefined): INetworkDeviceChip;
70
+ /** The chips' order: the user's own devices, then other people's, then relays; by name within. */
71
+ export declare function compareDeviceChips(a: INetworkDeviceChip, b: INetworkDeviceChip): number;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupRows = groupRows;
4
+ exports.networkHeadline = networkHeadline;
5
+ exports.networkSummaryLine = networkSummaryLine;
6
+ exports.deviceChip = deviceChip;
7
+ exports.compareDeviceChips = compareDeviceChips;
8
+ const network_graph_model_1 = require("../screens/network-viewer/graph/network-graph-model");
9
+ const network_status_format_1 = require("./network-status-format");
10
+ function devicesText(count) {
11
+ return `${count} ${count === 1 ? "device" : "devices"}`;
12
+ }
13
+ function groupsText(count) {
14
+ return `${count} ${count === 1 ? "group" : "groups"}`;
15
+ }
16
+ /**
17
+ * One line per group for the network status popover: Personal first, then by name. A group's
18
+ * line stays while its state changes, so only its dot and text change in place.
19
+ *
20
+ * A group with no live connection is "no connection" (warning) when it has other members, or
21
+ * when the status counts more disconnected groups than those explain; otherwise it's "only this
22
+ * device" (quiet): a group with nobody else in it isn't missing anything.
23
+ *
24
+ * @param groups - From System Network Diagnostics' `getGroupSyncStatus`.
25
+ * @param status - The live status summary; its errors are what the indicator counts.
26
+ * @param personalId - The personal context's id (the user's id), listed first.
27
+ */
28
+ function groupRows(groups, status, personalId) {
29
+ const sorted = [...groups].sort((a, b) => Number(b.groupId === personalId) - Number(a.groupId === personalId) ||
30
+ (0, network_status_format_1.compareNames)(a.groupName, b.groupName) ||
31
+ (0, network_status_format_1.compareNames)(a.groupId, b.groupId));
32
+ const offline = status.state === "offline";
33
+ const unconnected = sorted.filter((group) => group.connectedDevices.length === 0);
34
+ // Groups with other members explain part of the disconnected count; the rest goes, in order,
35
+ // to the groups that only have this user's own devices.
36
+ let unexplained = status.disconnectedContextCount - unconnected.filter((group) => group.totalMembers > 1).length;
37
+ return sorted.map((group) => {
38
+ const base = { groupId: group.groupId, name: group.groupName };
39
+ if (offline) {
40
+ return { ...base, tone: "quiet", detail: "offline" };
41
+ }
42
+ const error = status.errors.find((item) => item.dataContextId === group.groupId)?.message ??
43
+ (group.syncStatus.state === "error" ? group.syncStatus.lastError : undefined);
44
+ const count = group.connectedDevices.length;
45
+ if (group.syncStatus.state === "syncing") {
46
+ return { ...base, tone: "syncing", detail: `syncing · ${devicesText(count)}`, error };
47
+ }
48
+ if (error) {
49
+ return { ...base, tone: "error", detail: devicesText(count), error };
50
+ }
51
+ if (count > 0) {
52
+ return { ...base, tone: "ok", detail: devicesText(count) };
53
+ }
54
+ if (group.totalMembers > 1 || unexplained-- > 0) {
55
+ return { ...base, tone: "warning", detail: "no connection" };
56
+ }
57
+ return { ...base, tone: "quiet", detail: "only this device" };
58
+ });
59
+ }
60
+ /**
61
+ * The popover's headline. Syncing comes first (with any errors beside it), then errors, then
62
+ * groups without a connection, then "All synced".
63
+ *
64
+ * @param status - The live status summary.
65
+ * @param syncing - Show syncing: the status is syncing, or the indicator is holding its syncing
66
+ * look until synced is stable.
67
+ * @param syncingCount - Groups syncing; the last count while the look is held.
68
+ */
69
+ function networkHeadline(status, syncing, syncingCount) {
70
+ if (status.state === "offline") {
71
+ return { tone: "quiet", title: "Offline" };
72
+ }
73
+ if (syncing) {
74
+ return {
75
+ tone: "syncing",
76
+ title: syncingCount > 0 ? `Syncing ${groupsText(syncingCount)}` : "Syncing",
77
+ errorCount: status.errorCount > 0 ? status.errorCount : undefined,
78
+ };
79
+ }
80
+ if (status.errorCount > 0) {
81
+ return {
82
+ tone: "error",
83
+ title: status.errorCount === 1 ? "1 sync error" : `${status.errorCount} sync errors`,
84
+ };
85
+ }
86
+ if (status.disconnectedContextCount > 0) {
87
+ const count = status.disconnectedContextCount;
88
+ return {
89
+ tone: "warning",
90
+ title: `${groupsText(count)} without a connection`,
91
+ };
92
+ }
93
+ return { tone: "ok", title: "All synced" };
94
+ }
95
+ /**
96
+ * The line under the headline: devices connected, and groups connected out of all of them.
97
+ *
98
+ * @param status - The live status summary.
99
+ * @param groupCount - How many groups the popover lists, once they're loaded.
100
+ */
101
+ function networkSummaryLine(status, groupCount) {
102
+ if (status.state === "offline") {
103
+ return "No devices connected";
104
+ }
105
+ const connected = status.connectedContextCount;
106
+ const total = Math.max(groupCount ?? 0, connected + status.disconnectedContextCount);
107
+ const devices = devicesText(status.connectionCount);
108
+ if (total === 0) {
109
+ return devices;
110
+ }
111
+ return connected >= total
112
+ ? `${devices} · ${groupsText(total)}`
113
+ : `${devices} · ${connected} of ${groupsText(total)} connected`;
114
+ }
115
+ function hostOf(address) {
116
+ try {
117
+ return address ? new URL(address).host || undefined : undefined;
118
+ }
119
+ catch {
120
+ return undefined;
121
+ }
122
+ }
123
+ /**
124
+ * A connected device as a chip: its device name (or its owner's name, or a short id), the
125
+ * user's own devices marked, and a relay named by its host.
126
+ *
127
+ * @param connection - From `getConnections`.
128
+ * @param myUserId - The signed-in user, whose devices are "mine".
129
+ */
130
+ function deviceChip(connection, myUserId) {
131
+ const service = (0, network_graph_model_1.isServiceConnection)(connection);
132
+ const user = (0, network_status_format_1.connectionIdentityLabel)(connection.userName, connection.userId);
133
+ const device = (0, network_status_format_1.connectionIdentityLabel)(connection.deviceName, connection.deviceId);
134
+ const label = service
135
+ ? (hostOf(connection.connectionAddress) ?? user.text)
136
+ : connection.deviceName?.trim()
137
+ ? device.text
138
+ : user.text;
139
+ const groups = connection.sharedGroups.length;
140
+ const parts = service
141
+ ? [label, "Peers Services relay"]
142
+ : [user.title, device.title, groupsText(groups)];
143
+ return {
144
+ deviceId: connection.deviceId,
145
+ label,
146
+ title: [...parts, `${Math.round(connection.latencyMs)} ms`].join(" · "),
147
+ mine: !service && !!myUserId && connection.userId === myUserId,
148
+ service,
149
+ };
150
+ }
151
+ /** The chips' order: the user's own devices, then other people's, then relays; by name within. */
152
+ function compareDeviceChips(a, b) {
153
+ const rank = (chip) => (chip.service ? 2 : chip.mine ? 0 : 1);
154
+ return (rank(a) - rank(b) || (0, network_status_format_1.compareNames)(a.label, b.label) || (0, network_status_format_1.compareNames)(a.deviceId, b.deviceId));
155
+ }
@@ -0,0 +1,28 @@
1
+ import { type INetworkConnectionInfo, type INetworkGroupSyncInfo } from "@peers-app/peers-sdk";
2
+ /** How often the open popover refreshes its groups and devices, besides each status change. */
3
+ export declare const DETAILS_REFRESH_MS = 5000;
4
+ /** The least time between two refreshes, so a burst of status changes reads once. */
5
+ export declare const DETAILS_MIN_GAP_MS = 750;
6
+ /** The connected devices and groups the network status popover shows. */
7
+ export interface INetworkDetailsData {
8
+ /** Connected devices, sorted; undefined until the first read. */
9
+ connections?: INetworkConnectionInfo[];
10
+ /** Every group's sync state; undefined until the first read. */
11
+ groups?: INetworkGroupSyncInfo[];
12
+ /** The first read of the devices failed. */
13
+ failed: boolean;
14
+ /** The signed-in user, whose devices are theirs; read with the first list. */
15
+ myUserId?: string;
16
+ }
17
+ /**
18
+ * Read the devices and groups the network status popover shows, while it's open: at once, again
19
+ * whenever `refreshKey` changes (at most every {@link DETAILS_MIN_GAP_MS}), and every
20
+ * {@link DETAILS_REFRESH_MS}. What was read last stays until the next read lands, including
21
+ * across closing and reopening, so the popover never flashes "Loading…" once it has a list.
22
+ *
23
+ * @param open - The popover is open.
24
+ * @param diagnosticsReady - The host's diagnostics are reachable; when they go away, what was
25
+ * read is dropped.
26
+ * @param refreshKey - Changes when the status does in a way that could change the lists.
27
+ */
28
+ export declare function useNetworkDetailsData(open: boolean, diagnosticsReady: boolean, refreshKey: string): INetworkDetailsData;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DETAILS_MIN_GAP_MS = exports.DETAILS_REFRESH_MS = void 0;
4
+ exports.useNetworkDetailsData = useNetworkDetailsData;
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const react_1 = require("react");
7
+ const network_viewer_ipc_1 = require("../screens/network-viewer/network-viewer-ipc");
8
+ const network_status_format_1 = require("./network-status-format");
9
+ /** How often the open popover refreshes its groups and devices, besides each status change. */
10
+ exports.DETAILS_REFRESH_MS = 5_000;
11
+ /** The least time between two refreshes, so a burst of status changes reads once. */
12
+ exports.DETAILS_MIN_GAP_MS = 750;
13
+ /**
14
+ * Read the devices and groups the network status popover shows, while it's open: at once, again
15
+ * whenever `refreshKey` changes (at most every {@link DETAILS_MIN_GAP_MS}), and every
16
+ * {@link DETAILS_REFRESH_MS}. What was read last stays until the next read lands, including
17
+ * across closing and reopening, so the popover never flashes "Loading…" once it has a list.
18
+ *
19
+ * @param open - The popover is open.
20
+ * @param diagnosticsReady - The host's diagnostics are reachable; when they go away, what was
21
+ * read is dropped.
22
+ * @param refreshKey - Changes when the status does in a way that could change the lists.
23
+ */
24
+ function useNetworkDetailsData(open, diagnosticsReady, refreshKey) {
25
+ const [data, setData] = (0, react_1.useState)({ failed: false });
26
+ const [tick, setTick] = (0, react_1.useState)(0);
27
+ const lastReadAt = (0, react_1.useRef)(0);
28
+ const reading = (0, react_1.useRef)(false);
29
+ // Reads are numbered, and only one newer than the last applied lands. A status change doesn't
30
+ // cancel a read under way, so steady changes can't keep every read from landing.
31
+ const readCount = (0, react_1.useRef)(0);
32
+ const appliedRead = (0, react_1.useRef)(0);
33
+ (0, react_1.useEffect)(() => {
34
+ reading.current = open && diagnosticsReady;
35
+ if (!diagnosticsReady) {
36
+ setData({ failed: false });
37
+ }
38
+ return () => {
39
+ reading.current = false;
40
+ };
41
+ }, [open, diagnosticsReady]);
42
+ (0, react_1.useEffect)(() => {
43
+ if (!open || !diagnosticsReady) {
44
+ return;
45
+ }
46
+ const timer = window.setInterval(() => setTick((count) => count + 1), exports.DETAILS_REFRESH_MS);
47
+ return () => window.clearInterval(timer);
48
+ }, [open, diagnosticsReady]);
49
+ // refreshKey and tick only schedule a read.
50
+ (0, react_1.useEffect)(() => {
51
+ if (!open || !diagnosticsReady) {
52
+ return;
53
+ }
54
+ const read = async () => {
55
+ lastReadAt.current = Date.now();
56
+ const thisRead = ++readCount.current;
57
+ const landed = () => reading.current && thisRead > appliedRead.current;
58
+ try {
59
+ const diagnostics = await (0, network_viewer_ipc_1.getNetworkDiagnosticsConsumer)();
60
+ const [connections, groups, userContext] = await Promise.allSettled([
61
+ diagnostics.tools.getConnections(),
62
+ diagnostics.tools.getGroupSyncStatus({}),
63
+ (0, peers_sdk_1.getUserContext)(),
64
+ ]);
65
+ if (!landed()) {
66
+ return;
67
+ }
68
+ appliedRead.current = thisRead;
69
+ setData((current) => ({
70
+ connections: connections.status === "fulfilled"
71
+ ? (0, network_status_format_1.sortConnections)(connections.value.connections)
72
+ : current.connections,
73
+ groups: groups.status === "fulfilled" ? groups.value.groups : current.groups,
74
+ failed: connections.status === "rejected" && !current.connections,
75
+ myUserId: userContext.status === "fulfilled" ? userContext.value.userId : current.myUserId,
76
+ }));
77
+ }
78
+ catch {
79
+ if (landed()) {
80
+ appliedRead.current = thisRead;
81
+ setData((current) => ({ ...current, failed: !current.connections }));
82
+ }
83
+ }
84
+ };
85
+ const wait = Math.max(0, lastReadAt.current + exports.DETAILS_MIN_GAP_MS - Date.now());
86
+ const timer = window.setTimeout(() => void read(), wait);
87
+ return () => window.clearTimeout(timer);
88
+ }, [open, diagnosticsReady, refreshKey, tick]);
89
+ return data;
90
+ }
@@ -0,0 +1,18 @@
1
+ /** How long continuous syncing stays a green pulse before the blue spinner. */
2
+ export declare const SYNCING_GREEN_MS = 4000;
3
+ /** How long status must stay synced before leaving the syncing look. */
4
+ export declare const SYNCED_STABLE_MS = 1000;
5
+ /** How syncing looks: a calm green pulse at first, then a blue spinner while it goes on. */
6
+ export type SyncingLook = "pulse" | "spinner";
7
+ /**
8
+ * The syncing look of the shell's network indicator, for anything that syncs: the network as a
9
+ * whole, or one group. It's a green pulse for {@link SYNCING_GREEN_MS}, then the blue spinner
10
+ * for as long as syncing continues. When syncing stops and the thing is synced, the pulse stays
11
+ * until it has been synced for {@link SYNCED_STABLE_MS}, so brief flaps don't blink. Any other
12
+ * stop, such as an error or going offline, ends the look at once.
13
+ *
14
+ * @param syncing - Syncing now.
15
+ * @param synced - Synced now, with no error; only a stop into this state is held.
16
+ * @returns The look, or undefined when there's no syncing to show.
17
+ */
18
+ export declare function useSyncingLook(syncing: boolean, synced: boolean): SyncingLook | undefined;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SYNCED_STABLE_MS = exports.SYNCING_GREEN_MS = void 0;
4
+ exports.useSyncingLook = useSyncingLook;
5
+ const react_1 = require("react");
6
+ /** How long continuous syncing stays a green pulse before the blue spinner. */
7
+ exports.SYNCING_GREEN_MS = 4_000;
8
+ /** How long status must stay synced before leaving the syncing look. */
9
+ exports.SYNCED_STABLE_MS = 1_000;
10
+ /**
11
+ * The syncing look of the shell's network indicator, for anything that syncs: the network as a
12
+ * whole, or one group. It's a green pulse for {@link SYNCING_GREEN_MS}, then the blue spinner
13
+ * for as long as syncing continues. When syncing stops and the thing is synced, the pulse stays
14
+ * until it has been synced for {@link SYNCED_STABLE_MS}, so brief flaps don't blink. Any other
15
+ * stop, such as an error or going offline, ends the look at once.
16
+ *
17
+ * @param syncing - Syncing now.
18
+ * @param synced - Synced now, with no error; only a stop into this state is held.
19
+ * @returns The look, or undefined when there's no syncing to show.
20
+ */
21
+ function useSyncingLook(syncing, synced) {
22
+ const [held, setHeld] = (0, react_1.useState)(false);
23
+ const [long, setLong] = (0, react_1.useState)(false);
24
+ (0, react_1.useEffect)(() => {
25
+ if (syncing) {
26
+ setHeld(true);
27
+ return;
28
+ }
29
+ if (synced) {
30
+ if (!held) {
31
+ return;
32
+ }
33
+ const timer = window.setTimeout(() => setHeld(false), exports.SYNCED_STABLE_MS);
34
+ return () => window.clearTimeout(timer);
35
+ }
36
+ setHeld(false);
37
+ }, [syncing, synced, held]);
38
+ (0, react_1.useEffect)(() => {
39
+ if (!syncing) {
40
+ setLong(false);
41
+ return;
42
+ }
43
+ const timer = window.setTimeout(() => setLong(true), exports.SYNCING_GREEN_MS);
44
+ return () => window.clearTimeout(timer);
45
+ }, [syncing]);
46
+ if (syncing) {
47
+ return long ? "spinner" : "pulse";
48
+ }
49
+ return held && synced ? "pulse" : undefined;
50
+ }