@peers-app/peers-ui 0.34.10 → 0.34.12

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/components/markdown-editor/link-plugin.d.ts +9 -5
  2. package/dist/components/markdown-editor/link-plugin.js +47 -22
  3. package/dist/components/markdown-render.js +21 -8
  4. package/dist/components/markdown-with-mentions.d.ts +6 -4
  5. package/dist/components/markdown-with-mentions.js +6 -4
  6. package/dist/host-shell/host-shell-consumer.d.ts +13 -5
  7. package/dist/host-shell/host-shell-consumer.js +31 -16
  8. package/dist/isolated-screens/frame-runtime.js +14 -15
  9. package/dist/links/app-link-prompt.d.ts +29 -0
  10. package/dist/links/app-link-prompt.js +102 -0
  11. package/dist/links/link-schemes.d.ts +30 -0
  12. package/dist/links/link-schemes.js +46 -0
  13. package/dist/links/peers-links.d.ts +33 -0
  14. package/dist/links/peers-links.js +124 -0
  15. package/dist/mentions/mention-chooser.d.ts +12 -0
  16. package/dist/mentions/mention-chooser.js +48 -13
  17. package/dist/root-layout/root-layout-host.js +10 -1
  18. package/dist/screens/invites/accept-invite.js +3 -4
  19. package/dist/screens/invites/invite-capture.d.ts +2 -7
  20. package/dist/screens/invites/invite-capture.js +8 -25
  21. package/dist/screens/monitoring/device-picker.d.ts +9 -8
  22. package/dist/screens/monitoring/device-picker.js +5 -4
  23. package/dist/screens/monitoring/devices-tab.d.ts +6 -0
  24. package/dist/screens/monitoring/devices-tab.js +74 -0
  25. package/dist/screens/monitoring/monitored-devices.d.ts +84 -0
  26. package/dist/screens/monitoring/monitored-devices.js +193 -0
  27. package/dist/screens/monitoring/monitoring-routes.d.ts +1 -1
  28. package/dist/screens/monitoring/monitoring-routes.js +1 -0
  29. package/dist/screens/monitoring/monitoring-screen.d.ts +4 -3
  30. package/dist/screens/monitoring/monitoring-screen.js +15 -7
  31. package/dist/screens/monitoring/overview-tab.d.ts +18 -0
  32. package/dist/screens/monitoring/overview-tab.js +19 -4
  33. package/dist/screens/monitoring/use-telemetry.d.ts +8 -10
  34. package/dist/screens/monitoring/use-telemetry.js +26 -27
  35. package/dist/screens/settings/settings-page.js +3 -1
  36. package/package.json +3 -3
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Which links Peers opens, and how: the one rule the editor, rendered markdown, isolated screens
4
+ * and {@link openLink} share. It follows the host's own (`classifyHostOpenTarget` in the SDK), so
5
+ * a link the UI offers to open is one the host will open.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.linkScheme = linkScheme;
9
+ exports.linkKind = linkKind;
10
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
11
+ const SCHEME = /^([a-z][a-z\d+.-]*):/i;
12
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what it refuses
13
+ const CONTROL = /[\u0000-\u001f\u007f]/;
14
+ /**
15
+ * The scheme of a link, lowercased and without its colon (`obsidian` for `obsidian://open`), or
16
+ * undefined when the text doesn't start with one.
17
+ *
18
+ * @param url - The link.
19
+ */
20
+ function linkScheme(url) {
21
+ return SCHEME.exec(url.trim())?.[1]?.toLowerCase();
22
+ }
23
+ /**
24
+ * How Peers opens `url` (see {@link LinkKind}), or undefined when it doesn't: no scheme (a
25
+ * relative link or a path), a one-letter scheme (a Windows drive: `C:\…`, or `C:notes.txt`,
26
+ * which Windows opens as a file), a refused scheme (`javascript:`, `file:`, `data:`, and the
27
+ * others in the SDK's `HOST_OPEN_REFUSED_SCHEMES`), nothing after the scheme (except `mailto:`, a
28
+ * blank mail draft), or a control character.
29
+ *
30
+ * @param url - The link.
31
+ */
32
+ function linkKind(url) {
33
+ const value = url.trim();
34
+ const scheme = linkScheme(value);
35
+ if (!scheme || scheme.length === 1 || CONTROL.test(value))
36
+ return undefined;
37
+ if (value.length === scheme.length + 1 && scheme !== "mailto")
38
+ return undefined;
39
+ if (scheme === "peers")
40
+ return "peers";
41
+ if (peers_sdk_1.HOST_OPEN_URL_SCHEMES.includes(scheme))
42
+ return "web";
43
+ if (peers_sdk_1.HOST_OPEN_REFUSED_SCHEMES.includes(scheme))
44
+ return undefined;
45
+ return "app";
46
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `peers://` links: opening one inside Peers, and taking the ones the OS hands the desktop app (a
3
+ * link clicked in a browser, an email or another app such as Obsidian).
4
+ */
5
+ /**
6
+ * Open a `peers://` link inside Peers:
7
+ * - a record's link (`peers://note/<id>`, `peers://task/<id>`: anything a mention names) opens
8
+ * the record, as clicking its chip does, asking which when it's in more than one group;
9
+ * - an invite (`peers://i#<token>`) goes to the Accept screen.
10
+ *
11
+ * Any other `peers://` link is shown as one Peers can't open.
12
+ *
13
+ * @param url - The link.
14
+ */
15
+ export declare function openPeersLink(url: string): Promise<void>;
16
+ /**
17
+ * Take the `peers://` links the desktop app's main process hands this window: those it held
18
+ * while the window loaded, then each as it comes. An invite is kept for the Accept screen at
19
+ * once, signed in or not; any other link waits for {@link openIncomingLinksWith}. No-op outside
20
+ * the desktop app.
21
+ *
22
+ * @returns a function that stops listening
23
+ */
24
+ export declare function listenForIncomingLinks(): () => void;
25
+ /**
26
+ * Open incoming links with `open`: the ones waiting now (in this window, across reloads), and
27
+ * each one after. The signed-in app calls it once it has loaded, so a link that launched Peers,
28
+ * or came while signing in, opens then.
29
+ *
30
+ * @param open - Opens one link.
31
+ * @returns a function that stops; links wait again until the next call
32
+ */
33
+ export declare function openIncomingLinksWith(open: (url: string) => void): () => void;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * `peers://` links: opening one inside Peers, and taking the ones the OS hands the desktop app (a
4
+ * link clicked in a browser, an email or another app such as Obsidian).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.openPeersLink = openPeersLink;
8
+ exports.listenForIncomingLinks = listenForIncomingLinks;
9
+ exports.openIncomingLinksWith = openIncomingLinksWith;
10
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
11
+ const mentions_client_1 = require("../mentions/mentions-client");
12
+ const invite_capture_1 = require("../screens/invites/invite-capture");
13
+ /**
14
+ * Open a `peers://` link inside Peers:
15
+ * - a record's link (`peers://note/<id>`, `peers://task/<id>`: anything a mention names) opens
16
+ * the record, as clicking its chip does, asking which when it's in more than one group;
17
+ * - an invite (`peers://i#<token>`) goes to the Accept screen.
18
+ *
19
+ * Any other `peers://` link is shown as one Peers can't open.
20
+ *
21
+ * @param url - The link.
22
+ */
23
+ async function openPeersLink(url) {
24
+ const token = (0, invite_capture_1.inviteTokenFromUrl)(url);
25
+ if (token) {
26
+ (0, invite_capture_1.stashPendingInvite)(token);
27
+ return;
28
+ }
29
+ const ref = (0, peers_sdk_1.parseMentionUrl)(url.trim().replace(/^peers:/i, "peers:"));
30
+ if (ref) {
31
+ await (0, mentions_client_1.openMention)(ref);
32
+ return;
33
+ }
34
+ console.warn("Peers can't open this link:", url);
35
+ if (typeof window !== "undefined" && typeof window.alert === "function") {
36
+ window.alert(`Peers can't open this link: ${url}`);
37
+ }
38
+ }
39
+ /** The IPC channel the desktop app's main process sends `peers://` links on. */
40
+ const OPEN_URL_CHANNEL = "peers-open-url";
41
+ /** Sent once this window listens, so the main process sends the links it was holding. */
42
+ const OPEN_URL_READY_CHANNEL = "peers-open-url:ready";
43
+ /**
44
+ * Links that came before the signed-in app could open them, kept in sessionStorage as invites
45
+ * are, so the reload that signing in, creating an account or pairing does doesn't lose them.
46
+ */
47
+ const WAITING_LINKS_KEY = "peers.waitingLinks";
48
+ /** The most links kept waiting; older ones go first. */
49
+ const MAX_WAITING = 20;
50
+ let opener;
51
+ function readWaiting(consume) {
52
+ try {
53
+ const raw = sessionStorage.getItem(WAITING_LINKS_KEY);
54
+ if (raw === null)
55
+ return [];
56
+ if (consume)
57
+ sessionStorage.removeItem(WAITING_LINKS_KEY);
58
+ const stored = JSON.parse(raw);
59
+ if (!Array.isArray(stored))
60
+ return [];
61
+ const links = stored.filter((url) => typeof url === "string" && /^peers:\/\//i.test(url));
62
+ return links.length > MAX_WAITING ? links.slice(-MAX_WAITING) : links;
63
+ }
64
+ catch {
65
+ return [];
66
+ }
67
+ }
68
+ function queueLink(url) {
69
+ try {
70
+ const urls = readWaiting(false);
71
+ urls.push(url);
72
+ sessionStorage.setItem(WAITING_LINKS_KEY, JSON.stringify(urls.slice(-MAX_WAITING)));
73
+ }
74
+ catch {
75
+ // An unavailable store cannot hold a link across sign-in.
76
+ }
77
+ }
78
+ /**
79
+ * Take the `peers://` links the desktop app's main process hands this window: those it held
80
+ * while the window loaded, then each as it comes. An invite is kept for the Accept screen at
81
+ * once, signed in or not; any other link waits for {@link openIncomingLinksWith}. No-op outside
82
+ * the desktop app.
83
+ *
84
+ * @returns a function that stops listening
85
+ */
86
+ function listenForIncomingLinks() {
87
+ const ipc = window.ipcRenderer;
88
+ if (!ipc)
89
+ return () => { };
90
+ ipc.on(OPEN_URL_CHANNEL, (_event, url) => {
91
+ if (typeof url !== "string")
92
+ return;
93
+ const token = (0, invite_capture_1.inviteTokenFromUrl)(url);
94
+ if (token) {
95
+ (0, invite_capture_1.stashPendingInvite)(token);
96
+ return;
97
+ }
98
+ if (opener)
99
+ opener(url);
100
+ else
101
+ queueLink(url);
102
+ });
103
+ ipc.send(OPEN_URL_READY_CHANNEL);
104
+ return () => ipc.removeAllListeners(OPEN_URL_CHANNEL);
105
+ }
106
+ /**
107
+ * Open incoming links with `open`: the ones waiting now (in this window, across reloads), and
108
+ * each one after. The signed-in app calls it once it has loaded, so a link that launched Peers,
109
+ * or came while signing in, opens then.
110
+ *
111
+ * @param open - Opens one link.
112
+ * @returns a function that stops; links wait again until the next call
113
+ */
114
+ function openIncomingLinksWith(open) {
115
+ if (!("ipcRenderer" in window))
116
+ return () => { };
117
+ opener = open;
118
+ for (const url of readWaiting(true))
119
+ open(url);
120
+ return () => {
121
+ if (opener === open)
122
+ opener = undefined;
123
+ };
124
+ }
@@ -7,3 +7,15 @@ import type { IMentionPlace } from "@peers-app/peers-sdk";
7
7
  * @returns the place picked, or `undefined` when the user closed the chooser
8
8
  */
9
9
  export declare function chooseMentionPlace(places: IMentionPlace[]): Promise<IMentionPlace | undefined>;
10
+ /**
11
+ * Give Tab and Escape to the front one of the shell's small dialogs (this chooser, and the
12
+ * app-link prompt that shares its overlay), even after a click on its text has moved focus to
13
+ * the page. Tab and Shift+Tab go round its buttons and inputs, so they never reach a dialog it
14
+ * covers (whose button would act on a choice the person can't see) or the screen behind. Escape
15
+ * closes it alone.
16
+ *
17
+ * @param inside - An element of this dialog, so it can tell whether it is the front one.
18
+ * @param onEscape - Closes this dialog.
19
+ * @returns a function that stops listening
20
+ */
21
+ export declare function handleFrontDialogKeys(inside: () => Element | null, onEscape: () => void): () => void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chooseMentionPlace = chooseMentionPlace;
4
+ exports.handleFrontDialogKeys = handleFrontDialogKeys;
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
6
  const react_1 = require("react");
6
7
  const client_1 = require("react-dom/client");
@@ -25,28 +26,62 @@ function chooseMentionPlace(places) {
25
26
  root.render((0, jsx_runtime_1.jsx)(MentionChooser, { places: places, onClose: close }));
26
27
  });
27
28
  }
29
+ /** The overlay the chooser and the app-link prompt share; the newest open one is last. */
30
+ const DIALOG_CLASS = "peers-mention-chooser";
31
+ /**
32
+ * Give Tab and Escape to the front one of the shell's small dialogs (this chooser, and the
33
+ * app-link prompt that shares its overlay), even after a click on its text has moved focus to
34
+ * the page. Tab and Shift+Tab go round its buttons and inputs, so they never reach a dialog it
35
+ * covers (whose button would act on a choice the person can't see) or the screen behind. Escape
36
+ * closes it alone.
37
+ *
38
+ * @param inside - An element of this dialog, so it can tell whether it is the front one.
39
+ * @param onEscape - Closes this dialog.
40
+ * @returns a function that stops listening
41
+ */
42
+ function handleFrontDialogKeys(inside, onEscape) {
43
+ const onKey = (e) => {
44
+ if (e.defaultPrevented || (e.key !== "Tab" && e.key !== "Escape"))
45
+ return;
46
+ if (e.key === "Tab" && (e.ctrlKey || e.metaKey))
47
+ return;
48
+ // Every open dialog listens; only the front one acts.
49
+ const dialogs = document.getElementsByClassName(DIALOG_CLASS);
50
+ const front = dialogs[dialogs.length - 1];
51
+ if (!front?.contains(inside()))
52
+ return;
53
+ if (e.key === "Escape") {
54
+ e.stopImmediatePropagation();
55
+ onEscape();
56
+ return;
57
+ }
58
+ const controls = Array.from(front.querySelectorAll("button, input"));
59
+ const active = document.activeElement;
60
+ const index = active instanceof HTMLElement ? controls.indexOf(active) : -1;
61
+ const next = e.shiftKey
62
+ ? (controls[index - 1] ?? controls[controls.length - 1])
63
+ : (controls[index + 1] ?? controls[0]);
64
+ if (!next)
65
+ return;
66
+ e.preventDefault();
67
+ e.stopImmediatePropagation();
68
+ next.focus();
69
+ };
70
+ window.addEventListener("keydown", onKey, true);
71
+ return () => window.removeEventListener("keydown", onKey, true);
72
+ }
28
73
  function MentionChooser(props) {
29
74
  const { places, onClose } = props;
30
75
  const first = (0, react_1.useRef)(null);
31
76
  (0, react_1.useEffect)(() => {
32
77
  first.current?.focus();
33
- // For when focus has left the chooser (a click on its text); keys inside it stop below.
34
- const onKey = (e) => {
35
- if (e.key === "Escape")
36
- onClose();
37
- };
38
- window.addEventListener("keydown", onKey);
39
- return () => window.removeEventListener("keydown", onKey);
78
+ return handleFrontDialogKeys(() => first.current, () => onClose());
40
79
  }, [onClose]);
41
- return ((0, jsx_runtime_1.jsx)("div", { className: "peers-mention-chooser", role: "dialog", "aria-modal": "true", "aria-label": "Which one?", onMouseDown: (e) => {
80
+ return ((0, jsx_runtime_1.jsx)("div", { className: DIALOG_CLASS, role: "dialog", "aria-modal": "true", "aria-label": "Which one?", onMouseDown: (e) => {
42
81
  if (e.target === e.currentTarget)
43
82
  onClose();
44
83
  },
45
84
  // Keys pressed in the chooser stay in it, so the screen behind doesn't act on them too
46
85
  // (Tasks moves its selection on the arrow keys and closes the open task on Escape).
47
- onKeyDown: (e) => {
48
- e.stopPropagation();
49
- if (e.key === "Escape")
50
- onClose();
51
- }, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["This is in ", places.length, " places. Which one?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose() })] }), (0, jsx_runtime_1.jsx)("div", { className: "list-group list-group-flush", children: places.map((place, index) => ((0, jsx_runtime_1.jsxs)("button", { ref: index === 0 ? first : undefined, type: "button", className: "list-group-item list-group-item-action", onClick: () => onClose(place), children: [(0, jsx_runtime_1.jsxs)("div", { className: place.done ? "peers-mention-done" : undefined, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: place.iconClassName, fallback: "bi:link-45deg", className: "me-1" }), place.title || place.kindLabel] }), (0, jsx_runtime_1.jsx)("small", { className: "text-body-secondary", children: [place.groupName, place.packageName, place.status].filter(Boolean).join(" · ") })] }, `${place.groupId ?? ""}:${place.packageId ?? ""}`))) })] }) }));
86
+ onKeyDown: (e) => e.stopPropagation(), children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["This is in ", places.length, " places. Which one?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose() })] }), (0, jsx_runtime_1.jsx)("div", { className: "list-group list-group-flush", children: places.map((place, index) => ((0, jsx_runtime_1.jsxs)("button", { ref: index === 0 ? first : undefined, type: "button", className: "list-group-item list-group-item-action", onClick: () => onClose(place), children: [(0, jsx_runtime_1.jsxs)("div", { className: place.done ? "peers-mention-done" : undefined, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: place.iconClassName, fallback: "bi:link-45deg", className: "me-1" }), place.title || place.kindLabel] }), (0, jsx_runtime_1.jsx)("small", { className: "text-body-secondary", children: [place.groupName, place.packageName, place.status].filter(Boolean).join(" · ") })] }, `${place.groupId ?? ""}:${place.packageId ?? ""}`))) })] }) }));
52
87
  }
@@ -22,6 +22,7 @@ const globals_1 = require("../globals");
22
22
  const hooks_1 = require("../hooks");
23
23
  const config_1 = require("../isolated-screens/config");
24
24
  const global_widgets_1 = require("../isolated-screens/global-widgets");
25
+ const peers_links_1 = require("../links/peers-links");
25
26
  const identity_ipc_1 = require("../screens/device-pairing/identity-ipc");
26
27
  const identity_routes_1 = require("../screens/identity/identity-routes");
27
28
  const invite_capture_1 = require("../screens/invites/invite-capture");
@@ -56,7 +57,7 @@ function RootLayoutHost() {
56
57
  // finishes; signed-in captures route straight to the Accept screen.
57
58
  const onHashChange = () => (0, invite_capture_1.captureInviteFromLocation)();
58
59
  window.addEventListener("hashchange", onHashChange);
59
- const stopOpenUrl = (0, invite_capture_1.listenForOpenUrlInvites)();
60
+ const stopOpenUrl = (0, peers_links_1.listenForIncomingLinks)();
60
61
  const sub = invite_capture_1.inviteCaptured.subscribe(() => {
61
62
  if (userIdRef.current && (0, invite_capture_1.peekPendingInvite)()) {
62
63
  (0, globals_1.mainContentPath)(identity_routes_1.IDENTITY_ACCEPT_PATH);
@@ -107,6 +108,14 @@ function RootLayoutBootstrap(props) {
107
108
  const [_colorMode] = (0, hooks_1.useObservable)(color_mode_dropdown_1.colorMode);
108
109
  const [layoutId] = (0, hooks_1.useObservable)(root_layout_state_1.selectedRootLayoutId);
109
110
  const [overlays] = (0, hooks_1.useObservable)(global_overlays_1.globalOverlays);
111
+ // peers:// links the OS handed the desktop app (one that launched it, too) open once loaded.
112
+ (0, react_1.useEffect)(() => {
113
+ if (!loaded)
114
+ return;
115
+ return (0, peers_links_1.openIncomingLinksWith)((url) => {
116
+ (0, peers_links_1.openPeersLink)(url).catch((error) => console.warn("Could not open", url, error));
117
+ });
118
+ }, [loaded]);
110
119
  // Check if we should show the welcome modal after loading
111
120
  (0, react_1.useEffect)(() => {
112
121
  if (loaded && !(0, peers_sdk_1.hasShownWelcomeModal)()) {
@@ -51,11 +51,13 @@ function AcceptInvite(props) {
51
51
  const [busy, setBusy] = (0, react_1.useState)(false);
52
52
  const [error, setError] = (0, react_1.useState)("");
53
53
  const runPreview = (0, react_1.useCallback)(async (token) => {
54
+ setScanning(false);
54
55
  setError("");
55
56
  setBusy(true);
56
57
  try {
57
58
  const tools = await (0, invites_ipc_1.inviteTools)();
58
59
  const response = await tools.previewInvite({ token });
60
+ setResult(undefined);
59
61
  setTrustLevel(undefined);
60
62
  setPreview(response.preview);
61
63
  setText(token);
@@ -150,10 +152,7 @@ function AcceptInvite(props) {
150
152
  return (0, jsx_runtime_1.jsx)(ResultPanel, { result: result, preview: preview, onDone: done });
151
153
  }
152
154
  if (scanning) {
153
- return ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)(qr_scanner_1.QrScanner, { onScan: (scanned) => {
154
- setScanning(false);
155
- void runPreview(scanned);
156
- }, onError: (message) => {
155
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)(qr_scanner_1.QrScanner, { onScan: (scanned) => void runPreview(scanned), onError: (message) => {
157
156
  setScanning(false);
158
157
  setError(message);
159
158
  } }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary mt-3", onClick: () => setScanning(false), children: "Cancel" })] }));
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Captures an inbound invite token from the page URL or a desktop `peers://` open-url event
3
- * and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
2
+ * Captures an inbound invite token from the page URL or a desktop `peers://` link (taken by
3
+ * `links/peers-links.ts`) and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
4
4
  *
5
5
  * Tokens travel only in URL fragments and are stripped from the address bar immediately so
6
6
  * startup route restoration never persists them.
@@ -25,8 +25,3 @@ export declare function consumePendingInvite(storage?: Storage): string | undefi
25
25
  * Safe to call repeatedly; returns the captured token when one was present.
26
26
  */
27
27
  export declare function captureInviteFromLocation(locationLike?: Pick<Location, "href" | "pathname" | "search">, historyLike?: Pick<History, "replaceState" | "state">, storage?: Storage): string | undefined;
28
- /**
29
- * Listen for `peers://` links forwarded by the Electron main process (`peers-open-url`).
30
- * No-op outside Electron. Returns an unsubscribe function.
31
- */
32
- export declare function listenForOpenUrlInvites(): () => void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
- * Captures an inbound invite token from the page URL or a desktop `peers://` open-url event
4
- * and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
3
+ * Captures an inbound invite token from the page URL or a desktop `peers://` link (taken by
4
+ * `links/peers-links.ts`) and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
5
5
  *
6
6
  * Tokens travel only in URL fragments and are stripped from the address bar immediately so
7
7
  * startup route restoration never persists them.
@@ -13,7 +13,6 @@ exports.stashPendingInvite = stashPendingInvite;
13
13
  exports.peekPendingInvite = peekPendingInvite;
14
14
  exports.consumePendingInvite = consumePendingInvite;
15
15
  exports.captureInviteFromLocation = captureInviteFromLocation;
16
- exports.listenForOpenUrlInvites = listenForOpenUrlInvites;
17
16
  const peers_sdk_1 = require("@peers-app/peers-sdk");
18
17
  /** sessionStorage key for a captured token awaiting the Accept screen. */
19
18
  exports.PENDING_INVITE_STORAGE_KEY = "peers.pendingInviteToken";
@@ -31,7 +30,7 @@ function inviteTokenFromUrl(url) {
31
30
  const before = url.slice(0, hash);
32
31
  const fragment = url.slice(hash + 1);
33
32
  const isInviteFragment = fragment.startsWith("invite=");
34
- const isLandingPage = /^peers:\/\/i\/?$/.test(before) || /^https?:\/\/[^/]+\/i\/?$/.test(before);
33
+ const isLandingPage = /^\s*peers:\/\/i\/?$/i.test(before) || /^https?:\/\/[^/]+\/i\/?$/.test(before);
35
34
  if (!isInviteFragment && !isLandingPage) {
36
35
  return undefined;
37
36
  }
@@ -45,7 +44,11 @@ function inviteTokenFromUrl(url) {
45
44
  /** Store a token for the Accept screen and notify listeners. */
46
45
  function stashPendingInvite(token, storage = sessionStorage) {
47
46
  storage.setItem(exports.PENDING_INVITE_STORAGE_KEY, token);
48
- (0, exports.inviteCaptured)(token);
47
+ // Reopening the same invitation is another request to show Accept.
48
+ if ((0, exports.inviteCaptured)() === token)
49
+ exports.inviteCaptured.notifySubscribers();
50
+ else
51
+ (0, exports.inviteCaptured)(token);
49
52
  }
50
53
  /** Read the stored token without consuming it. */
51
54
  function peekPendingInvite(storage = sessionStorage) {
@@ -70,23 +73,3 @@ function captureInviteFromLocation(locationLike = window.location, historyLike =
70
73
  stashPendingInvite(token, storage);
71
74
  return token;
72
75
  }
73
- /**
74
- * Listen for `peers://` links forwarded by the Electron main process (`peers-open-url`).
75
- * No-op outside Electron. Returns an unsubscribe function.
76
- */
77
- function listenForOpenUrlInvites() {
78
- const ipc = window.ipcRenderer;
79
- if (!ipc) {
80
- return () => { };
81
- }
82
- ipc.on("peers-open-url", (_event, url) => {
83
- if (typeof url !== "string") {
84
- return;
85
- }
86
- const token = inviteTokenFromUrl(url);
87
- if (token) {
88
- stashPendingInvite(token);
89
- }
90
- });
91
- return () => ipc.removeAllListeners("peers-open-url");
92
- }
@@ -1,22 +1,23 @@
1
- import type { IMyDevice } from "./use-telemetry";
1
+ import type { IMonitoredDevice } from "./monitored-devices";
2
2
  /** Props for {@link DevicePicker}. */
3
3
  export interface DevicePickerProps {
4
- /** The user's devices, this one first; `undefined` while loading. */
5
- devices: IMyDevice[] | undefined;
4
+ /** The devices Monitoring can read, this one first; `undefined` while loading. */
5
+ devices: IMonitoredDevice[] | undefined;
6
6
  /** The device being looked at; omitted for this device. */
7
7
  deviceId: string | undefined;
8
8
  /** Called with the chosen device, or `undefined` for this device. */
9
9
  onChange: (deviceId: string | undefined) => void;
10
10
  }
11
11
  /**
12
- * Which of the user's devices Monitoring reads: this one, or another, through this device's host.
13
- * Every device is listed; one that can't be reached says so when a section reads it.
12
+ * Which device Monitoring reads: this one, or another through this device's host. Every one of
13
+ * the user's own devices is listed, and one that can't be reached says so when a section reads
14
+ * it; other users' devices are listed while they're connected and let the user read them.
14
15
  */
15
16
  export declare function DevicePicker(props: DevicePickerProps): import("react/jsx-runtime").JSX.Element;
16
17
  /**
17
18
  * A device's line in the picker: "Mac (this device)", "This device" when it has no name, and
18
- * another device's name (or id).
19
+ * another device's name ("Blair · Laptop" for another user's), or its id.
19
20
  *
20
- * @param device - One of the user's devices.
21
+ * @param device - A device Monitoring can read.
21
22
  */
22
- export declare function deviceLabel(device: IMyDevice): string;
23
+ export declare function deviceLabel(device: IMonitoredDevice): string;
@@ -4,8 +4,9 @@ exports.DevicePicker = DevicePicker;
4
4
  exports.deviceLabel = deviceLabel;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  /**
7
- * Which of the user's devices Monitoring reads: this one, or another, through this device's host.
8
- * Every device is listed; one that can't be reached says so when a section reads it.
7
+ * Which device Monitoring reads: this one, or another through this device's host. Every one of
8
+ * the user's own devices is listed, and one that can't be reached says so when a section reads
9
+ * it; other users' devices are listed while they're connected and let the user read them.
9
10
  */
10
11
  function DevicePicker(props) {
11
12
  const devices = props.devices ?? [];
@@ -18,9 +19,9 @@ function DevicePicker(props) {
18
19
  }
19
20
  /**
20
21
  * A device's line in the picker: "Mac (this device)", "This device" when it has no name, and
21
- * another device's name (or id).
22
+ * another device's name ("Blair · Laptop" for another user's), or its id.
22
23
  *
23
- * @param device - One of the user's devices.
24
+ * @param device - A device Monitoring can read.
24
25
  */
25
26
  function deviceLabel(device) {
26
27
  if (device.isThisDevice)
@@ -0,0 +1,6 @@
1
+ import type { MonitoringSectionProps } from "./monitoring-screen";
2
+ /**
3
+ * All devices: every device Monitoring can read, each with what's firing, its errors and call p95
4
+ * over the last 24 hours, and its telemetry database's size. A device's name opens its Overview.
5
+ */
6
+ export declare function DevicesTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DevicesTab = DevicesTab;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const device_picker_1 = require("./device-picker");
7
+ const form_fields_1 = require("./form-fields");
8
+ const format_1 = require("./format");
9
+ const monitored_devices_1 = require("./monitored-devices");
10
+ const overview_tab_1 = require("./overview-tab");
11
+ const telemetry_client_1 = require("./telemetry-client");
12
+ const use_telemetry_1 = require("./use-telemetry");
13
+ /** How long a device has to answer the All devices section before it shows as not reachable. */
14
+ const DEVICE_READ_TIMEOUT_MS = 15_000;
15
+ /**
16
+ * All devices: every device Monitoring can read, each with what's firing, its errors and call p95
17
+ * over the last 24 hours, and its telemetry database's size. A device's name opens its Overview.
18
+ */
19
+ function DevicesTab(props) {
20
+ // Each refresh reads every device again, and asks other users' devices again.
21
+ const [round, setRound] = (0, react_1.useState)(0);
22
+ const devices = (0, use_telemetry_1.useMonitoredDevices)(round);
23
+ const open = (device) => props.navigate({
24
+ section: "overview",
25
+ deviceId: device.isThisDevice ? undefined : device.deviceId,
26
+ });
27
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "d-flex justify-content-end mb-2", children: (0, jsx_runtime_1.jsx)(form_fields_1.RefreshButton, { onClick: () => setRound((r) => r + 1), loading: !devices }) }), !devices ? ((0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" })) : ((0, jsx_runtime_1.jsx)("div", { className: "table-responsive", children: (0, jsx_runtime_1.jsxs)("table", { className: "table table-sm align-middle", children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { scope: "col", children: "Device" }), (0, jsx_runtime_1.jsx)("th", { scope: "col", children: "Alerts" }), (0, jsx_runtime_1.jsx)("th", { scope: "col", className: "text-end text-nowrap", children: "Errors, 24 h" }), (0, jsx_runtime_1.jsx)("th", { scope: "col", className: "text-end text-nowrap", children: "Call p95, 24 h" }), (0, jsx_runtime_1.jsx)("th", { scope: "col", className: "text-end", children: "Telemetry" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: devices.map((device) => ((0, jsx_runtime_1.jsx)(DeviceRow, { device: device, onOpen: () => open(device) }, `${device.isThisDevice ? "this" : device.deviceId}:${round}`))) })] }) })), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary", children: "Other people's devices show here while they're connected to this one and let you read them." })] }));
28
+ }
29
+ /** One device's row: its name, and what it answered or why it didn't. */
30
+ function DeviceRow(props) {
31
+ const { device } = props;
32
+ const deviceId = device.isThisDevice ? undefined : device.deviceId;
33
+ const [{ summary, error }, setResult] = (0, react_1.useState)({});
34
+ (0, react_1.useEffect)(() => {
35
+ // A row reads once per mount. Its deadline includes reconnecting to the local host.
36
+ let active = true;
37
+ const read = (0, telemetry_client_1.getTelemetry)(deviceId).then((telemetry) => {
38
+ if (active)
39
+ return (0, overview_tab_1.readOverview)(telemetry);
40
+ });
41
+ void (0, monitored_devices_1.withTimeout)(read, DEVICE_READ_TIMEOUT_MS)
42
+ .then((data) => {
43
+ if (active && data)
44
+ setResult({ summary: (0, overview_tab_1.summarizeOverview)(data) });
45
+ })
46
+ .catch((error) => {
47
+ if (active)
48
+ setResult({ error });
49
+ active = false;
50
+ });
51
+ return () => {
52
+ active = false;
53
+ };
54
+ }, [deviceId]);
55
+ return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsxs)("td", { children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link p-0 text-start", onClick: props.onOpen, "aria-label": `Open ${(0, device_picker_1.deviceLabel)(device)}'s Overview`, children: (0, device_picker_1.deviceLabel)(device) }), device.lastSeen && !summary ? ((0, jsx_runtime_1.jsxs)("div", { className: "small text-body-secondary", children: ["Last seen ", (0, format_1.formatAgo)(new Date(device.lastSeen).getTime())] })) : null] }), summary ? ((0, jsx_runtime_1.jsx)(SummaryCells, { summary: summary })) : error ? ((0, jsx_runtime_1.jsx)("td", { colSpan: 4, className: "small text-body-secondary", children: (0, jsx_runtime_1.jsx)("span", { title: (0, telemetry_client_1.describeTelemetryError)(error), children: problem(error) }) })) : ((0, jsx_runtime_1.jsx)("td", { colSpan: 4, className: "small text-body-secondary", children: "Reading\u2026" }))] }));
56
+ }
57
+ function SummaryCells(props) {
58
+ const { summary } = props;
59
+ const firing = summary.active?.filter((alert) => alert.state === "firing").length;
60
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("td", { children: firing === undefined ? ((0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary", children: "\u2013" })) : firing > 0 ? ((0, jsx_runtime_1.jsxs)("span", { className: "badge text-bg-danger", children: [firing, " firing"] })) : ((0, jsx_runtime_1.jsxs)("span", { className: "small text-success", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-circle me-1", "aria-hidden": "true" }), "None"] })) }), (0, jsx_runtime_1.jsx)("td", { className: "text-end", children: summary.errors === undefined ? "–" : (0, format_1.formatNumber)(summary.errors) }), (0, jsx_runtime_1.jsx)("td", { className: "text-end", children: (0, format_1.formatDuration)(summary.p95) }), (0, jsx_runtime_1.jsx)("td", { className: "text-end text-nowrap", children: (0, format_1.formatBytes)(summary.databaseBytes) })] }));
61
+ }
62
+ /** A device's failed read, in a few words; the full sentence is its tooltip. */
63
+ function problem(error) {
64
+ switch ((0, telemetry_client_1.classifyTelemetryError)(error)) {
65
+ case "unavailable":
66
+ return "Runs a Peers version without telemetry";
67
+ case "unreachable":
68
+ return "Not reachable";
69
+ case "denied":
70
+ return "Doesn't let you read it";
71
+ default:
72
+ return "Couldn't read it";
73
+ }
74
+ }