@peers-app/peers-ui 0.33.19 → 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.
- package/dist/command-palette/command-palette.d.ts +47 -0
- package/dist/command-palette/command-palette.js +42 -9
- package/dist/components/group-switcher.d.ts +3 -2
- package/dist/components/group-switcher.js +16 -3
- package/dist/graph/ring-layout.d.ts +62 -0
- package/dist/graph/ring-layout.js +100 -0
- package/dist/groups/group-appearance-dialog.d.ts +27 -7
- package/dist/groups/group-appearance-dialog.js +49 -16
- package/dist/groups/index.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/screens/groups/group-details.js +1 -1
- package/dist/screens/groups/group-list.js +1 -1
- package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
- package/dist/screens/network-viewer/graph/edge-route.js +133 -0
- package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
- package/dist/screens/network-viewer/graph/label-placement.js +134 -0
- package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
- package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
- package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
- package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
- package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
- package/dist/screens/network-viewer/graph/network-graph.js +419 -0
- package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
- package/dist/screens/network-viewer/network-viewer.js +65 -8
- package/dist/tabs-layout/linger.d.ts +75 -0
- package/dist/tabs-layout/linger.js +121 -0
- package/dist/tabs-layout/network-status-details.d.ts +27 -0
- package/dist/tabs-layout/network-status-details.js +203 -0
- package/dist/tabs-layout/network-status-format.d.ts +22 -0
- package/dist/tabs-layout/network-status-format.js +58 -0
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
- package/dist/tabs-layout/network-status-indicator.js +27 -133
- package/dist/tabs-layout/network-status-model.d.ts +71 -0
- package/dist/tabs-layout/network-status-model.js +155 -0
- package/dist/tabs-layout/tab-color.d.ts +9 -2
- package/dist/tabs-layout/tab-color.js +14 -4
- package/dist/tabs-layout/tab-order.d.ts +51 -0
- package/dist/tabs-layout/tab-order.js +70 -0
- package/dist/tabs-layout/tab-switcher-overlay.d.ts +16 -0
- package/dist/tabs-layout/tab-switcher-overlay.js +68 -0
- package/dist/tabs-layout/tab-switcher.d.ts +64 -0
- package/dist/tabs-layout/tab-switcher.js +150 -0
- package/dist/tabs-layout/tabs-layout.d.ts +3 -1
- package/dist/tabs-layout/tabs-layout.js +90 -46
- package/dist/tabs-layout/tabs-state.d.ts +34 -13
- package/dist/tabs-layout/tabs-state.js +104 -31
- package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
- package/dist/tabs-layout/use-network-details-data.js +90 -0
- package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
- package/dist/tabs-layout/use-syncing-look.js +50 -0
- package/dist/theme.css +741 -0
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.switchToPreviousTab = exports.switchToNextTab = exports.closeCurrentTab = exports.openNewTab = exports.setSingleTabMode = exports.updateActiveTabTitle = exports.handleMainPathChanged = exports.initializedTabs = exports.activeTabId = exports.activeTabs = exports.launcherApp = void 0;
|
|
3
|
+
exports.switchToPreviousTab = exports.switchToNextTab = exports.switchToPreviousApp = exports.moveTab = exports.closeCurrentTab = exports.closeTab = exports.openNewTab = exports.setSingleTabMode = exports.updateActiveTabTitle = exports.handleMainPathChanged = exports.initializedTabs = exports.tabHistory = exports.activeTabId = exports.activeTabs = exports.tabsByRecentUse = exports.previousAppTabId = exports.normalizeTabHistory = exports.launcherApp = void 0;
|
|
4
4
|
exports.navigateTo = navigateTo;
|
|
5
5
|
exports.goToTabPath = goToTabPath;
|
|
6
6
|
exports.isRemovedAppRoute = isRemovedAppRoute;
|
|
@@ -11,21 +11,22 @@ const globals_1 = require("../globals");
|
|
|
11
11
|
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
12
12
|
const system_apps_1 = require("../system-apps");
|
|
13
13
|
const routes_loader_1 = require("../ui-router/routes-loader");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
iconClassName: "bi-grid-3x3-gap",
|
|
21
|
-
};
|
|
14
|
+
const tab_order_1 = require("./tab-order");
|
|
15
|
+
var tab_order_2 = require("./tab-order");
|
|
16
|
+
Object.defineProperty(exports, "launcherApp", { enumerable: true, get: function () { return tab_order_2.launcherApp; } });
|
|
17
|
+
Object.defineProperty(exports, "normalizeTabHistory", { enumerable: true, get: function () { return tab_order_2.normalizeTabHistory; } });
|
|
18
|
+
Object.defineProperty(exports, "previousAppTabId", { enumerable: true, get: function () { return tab_order_2.previousAppTabId; } });
|
|
19
|
+
Object.defineProperty(exports, "tabsByRecentUse", { enumerable: true, get: function () { return tab_order_2.tabsByRecentUse; } });
|
|
22
20
|
// Persistent vars for storage (write-only, no subscription to avoid oscillation)
|
|
23
21
|
const _persistentActiveTabs = (0, peers_sdk_1.groupDeviceVar)("activeTabs", {
|
|
24
|
-
defaultValue: [
|
|
22
|
+
defaultValue: [tab_order_1.launcherApp],
|
|
25
23
|
});
|
|
26
24
|
const _persistentActiveTabId = (0, peers_sdk_1.groupDeviceVar)("activeTabId", {
|
|
27
25
|
defaultValue: "launcher",
|
|
28
26
|
});
|
|
27
|
+
const _persistentTabHistory = (0, peers_sdk_1.groupDeviceVar)("tabHistory", {
|
|
28
|
+
defaultValue: [],
|
|
29
|
+
});
|
|
29
30
|
let finishNavigationRestore = () => { };
|
|
30
31
|
const navigationReady = new Promise((resolve) => {
|
|
31
32
|
finishNavigationRestore = resolve;
|
|
@@ -33,7 +34,7 @@ const navigationReady = new Promise((resolve) => {
|
|
|
33
34
|
// In-memory observables for UI state (loaded once, then write-through to persistent vars)
|
|
34
35
|
/** Open tabs. Writes through to device storage after the initial restore. */
|
|
35
36
|
exports.activeTabs = (() => {
|
|
36
|
-
const obs = (0, peers_sdk_1.observable)([
|
|
37
|
+
const obs = (0, peers_sdk_1.observable)([tab_order_1.launcherApp]);
|
|
37
38
|
// Write-through to persistent var on change
|
|
38
39
|
obs.subscribe((value) => {
|
|
39
40
|
_persistentActiveTabs(value);
|
|
@@ -49,17 +50,48 @@ exports.activeTabId = (() => {
|
|
|
49
50
|
});
|
|
50
51
|
return Object.assign(obs, { loadingPromise: navigationReady });
|
|
51
52
|
})();
|
|
53
|
+
// Stored history is only written after it has been restored, so nothing that runs before the
|
|
54
|
+
// restore can overwrite it.
|
|
55
|
+
let tabHistoryRestored = false;
|
|
56
|
+
/**
|
|
57
|
+
* Ids of the open tabs, the most recently active first, the launcher included. It is
|
|
58
|
+
* separate from {@link activeTabs}: recent use orders the switchers (the phone's tab menu,
|
|
59
|
+
* Ctrl+Tab), never the tab strip. Kept per device.
|
|
60
|
+
*/
|
|
61
|
+
exports.tabHistory = (() => {
|
|
62
|
+
const obs = (0, peers_sdk_1.observable)([]);
|
|
63
|
+
obs.subscribe((value) => {
|
|
64
|
+
if (tabHistoryRestored) {
|
|
65
|
+
_persistentTabHistory(value);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(obs, { loadingPromise: navigationReady });
|
|
69
|
+
})();
|
|
52
70
|
void Promise.all([
|
|
53
71
|
_persistentActiveTabs.loadingPromise,
|
|
54
72
|
_persistentActiveTabId.loadingPromise,
|
|
73
|
+
_persistentTabHistory.loadingPromise,
|
|
55
74
|
]).then(() => {
|
|
56
75
|
const restored = restoreNavigationState(_persistentActiveTabs(), _persistentActiveTabId());
|
|
57
76
|
(0, exports.activeTabs)(restored.tabs);
|
|
58
77
|
if ((0, exports.activeTabId)() !== restored.activeId) {
|
|
59
78
|
(0, exports.activeTabId)(restored.activeId);
|
|
60
79
|
}
|
|
80
|
+
tabHistoryRestored = true;
|
|
81
|
+
(0, exports.tabHistory)((0, tab_order_1.normalizeTabHistory)(_persistentTabHistory() ?? [], (0, exports.activeTabs)(), (0, exports.activeTabId)()));
|
|
61
82
|
finishNavigationRestore();
|
|
62
83
|
});
|
|
84
|
+
function sameIds(left, right) {
|
|
85
|
+
return left.length === right.length && left.every((id, index) => id === right[index]);
|
|
86
|
+
}
|
|
87
|
+
function refreshTabHistory() {
|
|
88
|
+
const next = (0, tab_order_1.normalizeTabHistory)((0, exports.tabHistory)(), (0, exports.activeTabs)(), (0, exports.activeTabId)());
|
|
89
|
+
if (!sameIds(next, (0, exports.tabHistory)())) {
|
|
90
|
+
(0, exports.tabHistory)(next);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.activeTabs.subscribe(refreshTabHistory);
|
|
94
|
+
exports.activeTabId.subscribe(refreshTabHistory);
|
|
63
95
|
/** Tab ids whose bodies have been mounted at least once. */
|
|
64
96
|
exports.initializedTabs = new Set();
|
|
65
97
|
/**
|
|
@@ -158,7 +190,7 @@ function isRemovedAppRoute(path) {
|
|
|
158
190
|
*/
|
|
159
191
|
function restoreNavigationState(tabs, activeId) {
|
|
160
192
|
const kept = tabs.filter((tab) => tab.tabId === "launcher" || !isRemovedAppRoute(tab.path));
|
|
161
|
-
const migrated = (kept.length > 0 ? kept : [
|
|
193
|
+
const migrated = (kept.length > 0 ? kept : [tab_order_1.launcherApp]).map(migrateStoredTab);
|
|
162
194
|
const merged = mergeIdentityTabs(migrated, activeId);
|
|
163
195
|
const activeExists = merged.tabs.some((tab) => tab.tabId === merged.activeId);
|
|
164
196
|
return {
|
|
@@ -177,7 +209,7 @@ function determineAppFromPath(path) {
|
|
|
177
209
|
navItem: {
|
|
178
210
|
name: "Apps",
|
|
179
211
|
navigationPath: "",
|
|
180
|
-
iconClassName:
|
|
212
|
+
iconClassName: tab_order_1.launcherApp.iconClassName || "bi-grid-3x3-gap",
|
|
181
213
|
},
|
|
182
214
|
package: system_apps_1.systemPackage,
|
|
183
215
|
};
|
|
@@ -392,29 +424,70 @@ const openNewTab = (tab, forceNew = false) => {
|
|
|
392
424
|
}
|
|
393
425
|
};
|
|
394
426
|
exports.openNewTab = openNewTab;
|
|
427
|
+
/**
|
|
428
|
+
* Close a tab. The launcher tab stays open. Closing the active tab activates the tab used
|
|
429
|
+
* most recently before it (see {@link tabHistory}), which may be the launcher.
|
|
430
|
+
*
|
|
431
|
+
* @param tabId - The tab to close.
|
|
432
|
+
*/
|
|
433
|
+
const closeTab = (tabId) => {
|
|
434
|
+
const currentTabs = (0, exports.activeTabs)();
|
|
435
|
+
if (tabId === tab_order_1.launcherApp.tabId || !currentTabs.some((t) => t.tabId === tabId))
|
|
436
|
+
return;
|
|
437
|
+
const history = (0, exports.tabHistory)();
|
|
438
|
+
const newTabs = currentTabs.filter((t) => t.tabId !== tabId);
|
|
439
|
+
(0, exports.activeTabs)(newTabs);
|
|
440
|
+
exports.initializedTabs.delete(tabId);
|
|
441
|
+
if ((0, exports.activeTabId)() !== tabId)
|
|
442
|
+
return;
|
|
443
|
+
const open = new Set(newTabs.map((t) => t.tabId));
|
|
444
|
+
const next = history.find((id) => id !== tabId && open.has(id));
|
|
445
|
+
(0, exports.activeTabId)(next ?? newTabs[0]?.tabId ?? tab_order_1.launcherApp.tabId);
|
|
446
|
+
};
|
|
447
|
+
exports.closeTab = closeTab;
|
|
395
448
|
/** Close the active tab. The launcher tab stays open. */
|
|
396
449
|
const closeCurrentTab = () => {
|
|
450
|
+
(0, exports.closeTab)((0, exports.activeTabId)());
|
|
451
|
+
};
|
|
452
|
+
exports.closeCurrentTab = closeCurrentTab;
|
|
453
|
+
/**
|
|
454
|
+
* Move a tab to another place in the strip. The launcher keeps its place, and no tab moves
|
|
455
|
+
* in front of it.
|
|
456
|
+
*
|
|
457
|
+
* @param tabId - The tab to move.
|
|
458
|
+
* @param toIndex - Its new index in {@link activeTabs}.
|
|
459
|
+
*/
|
|
460
|
+
const moveTab = (tabId, toIndex) => {
|
|
397
461
|
const currentTabs = (0, exports.activeTabs)();
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
if (!tabToClose || tabToClose.tabId === "launcher")
|
|
462
|
+
const fromIndex = currentTabs.findIndex((t) => t.tabId === tabId);
|
|
463
|
+
if (fromIndex < 0 || tabId === tab_order_1.launcherApp.tabId)
|
|
401
464
|
return;
|
|
402
|
-
const
|
|
403
|
-
const
|
|
465
|
+
const launcherIndex = currentTabs.findIndex((t) => t.tabId === tab_order_1.launcherApp.tabId);
|
|
466
|
+
const minIndex = launcherIndex === 0 ? 1 : 0;
|
|
467
|
+
const target = Math.max(minIndex, Math.min(toIndex, currentTabs.length - 1));
|
|
468
|
+
if (target === fromIndex)
|
|
469
|
+
return;
|
|
470
|
+
const newTabs = [...currentTabs];
|
|
471
|
+
const [moved] = newTabs.splice(fromIndex, 1);
|
|
472
|
+
newTabs.splice(target, 0, moved);
|
|
404
473
|
(0, exports.activeTabs)(newTabs);
|
|
405
|
-
exports.initializedTabs.delete(_activeTabId);
|
|
406
|
-
if (newTabs.length === 0) {
|
|
407
|
-
(0, exports.activeTabId)("launcher");
|
|
408
|
-
}
|
|
409
|
-
else if (closedIndex < newTabs.length) {
|
|
410
|
-
(0, exports.activeTabId)(newTabs[closedIndex].tabId);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
(0, exports.activeTabId)(newTabs[newTabs.length - 1].tabId);
|
|
414
|
-
}
|
|
415
474
|
};
|
|
416
|
-
exports.
|
|
417
|
-
/**
|
|
475
|
+
exports.moveTab = moveTab;
|
|
476
|
+
/**
|
|
477
|
+
* Activate the app tab used before the active one (see {@link previousAppTabId}). From the
|
|
478
|
+
* launcher, that is the most recently used app. Doing it again goes back.
|
|
479
|
+
*
|
|
480
|
+
* @returns Whether a tab was activated; `false` when no other app is open.
|
|
481
|
+
*/
|
|
482
|
+
const switchToPreviousApp = () => {
|
|
483
|
+
const previous = (0, tab_order_1.previousAppTabId)((0, exports.tabHistory)(), (0, exports.activeTabId)());
|
|
484
|
+
if (!previous)
|
|
485
|
+
return false;
|
|
486
|
+
(0, exports.activeTabId)(previous);
|
|
487
|
+
return true;
|
|
488
|
+
};
|
|
489
|
+
exports.switchToPreviousApp = switchToPreviousApp;
|
|
490
|
+
/** Activate the next open tab in strip order, wrapping around. */
|
|
418
491
|
const switchToNextTab = () => {
|
|
419
492
|
const currentTabs = (0, exports.activeTabs)();
|
|
420
493
|
const activeTab = (0, exports.activeTabId)();
|
|
@@ -425,7 +498,7 @@ const switchToNextTab = () => {
|
|
|
425
498
|
(0, exports.activeTabId)(currentTabs[nextIndex].tabId);
|
|
426
499
|
};
|
|
427
500
|
exports.switchToNextTab = switchToNextTab;
|
|
428
|
-
/** Activate the previous open tab, wrapping around. */
|
|
501
|
+
/** Activate the previous open tab in strip order, wrapping around. */
|
|
429
502
|
const switchToPreviousTab = () => {
|
|
430
503
|
const currentTabs = (0, exports.activeTabs)();
|
|
431
504
|
const activeTab = (0, exports.activeTabId)();
|
|
@@ -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
|
+
}
|