@domicile-desktop/manganese-notifications 2.0.0 → 2.1.0
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/package.json +19 -17
- package/src/MailPicker.tsx +155 -0
- package/src/NotificationActions.tsx +2 -0
- package/src/NotificationCard.tsx +14 -2
- package/src/NotificationDrawer.tsx +3 -2
- package/src/inbox.ts +43 -2
- package/src/useMailLinks.ts +172 -0
- package/styled-system/styles.css +2021 -1899
- package/styled-system/tokens/index.mjs +7 -3
- package/styled-system/tokens/tokens.d.ts +2 -2
- package/styled-system/types/prop-type.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@domicile-desktop/component-library": "2.
|
|
4
|
-
"@domicile-desktop/manganese-bar": "1.1.
|
|
5
|
-
"@domicile-desktop/manganese-host": "2.0.
|
|
6
|
-
"@domicile-desktop/react": "0.
|
|
7
|
-
"@domicile-desktop/sdk": "
|
|
8
|
-
"@pandacss/dev": "^1.12.
|
|
3
|
+
"@domicile-desktop/component-library": "2.2.0",
|
|
4
|
+
"@domicile-desktop/manganese-bar": "1.1.3",
|
|
5
|
+
"@domicile-desktop/manganese-host": "2.0.3",
|
|
6
|
+
"@domicile-desktop/react": "0.2.0",
|
|
7
|
+
"@domicile-desktop/sdk": "3.0.0",
|
|
8
|
+
"@pandacss/dev": "^1.12.2",
|
|
9
9
|
"@phosphor-icons/react": "^2.1.10",
|
|
10
|
-
"react": "^19.
|
|
11
|
-
"react-dom": "^19.
|
|
12
|
-
"zod": "^4.
|
|
10
|
+
"react": "^19.3.1",
|
|
11
|
+
"react-dom": "^19.3.1",
|
|
12
|
+
"zod": "^4.6.7"
|
|
13
13
|
},
|
|
14
14
|
"description": "Manganese's notification toasts and drawer.",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@cprussin/tsconfig": "^5.0.0",
|
|
17
|
-
"@domicile-desktop/manganese-window-management": "
|
|
17
|
+
"@domicile-desktop/manganese-window-management": "2.0.0",
|
|
18
18
|
"@domicile-desktop/test-support": "0.0.2",
|
|
19
|
-
"@pandacss/preset-panda": "^1.12.
|
|
19
|
+
"@pandacss/preset-panda": "^1.12.2",
|
|
20
20
|
"@testing-library/react": "^16.3.3",
|
|
21
|
-
"@testing-library/user-event": "^14.6.
|
|
22
|
-
"@types/bun": "^1.4.
|
|
23
|
-
"@types/react": "^19.
|
|
24
|
-
"@types/react-dom": "^19.
|
|
25
|
-
"postcss": "^8.5.
|
|
21
|
+
"@testing-library/user-event": "^14.6.10",
|
|
22
|
+
"@types/bun": "^1.4.4",
|
|
23
|
+
"@types/react": "^19.3.0",
|
|
24
|
+
"@types/react-dom": "^19.3.0",
|
|
25
|
+
"postcss": "^8.5.32",
|
|
26
26
|
"typescript": "^7.0.2"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
"exports": {
|
|
32
32
|
"./ago": "./src/ago.ts",
|
|
33
33
|
"./inbox": "./src/inbox.ts",
|
|
34
|
+
"./MailPicker": "./src/MailPicker.tsx",
|
|
34
35
|
"./NotificationDrawer": "./src/NotificationDrawer.tsx",
|
|
35
36
|
"./NotificationToasts": "./src/NotificationToasts.tsx",
|
|
36
37
|
"./notifications-context": "./src/notifications-context.ts",
|
|
38
|
+
"./useMailLinks": "./src/useMailLinks.ts",
|
|
37
39
|
"./useNotifications": "./src/useNotifications.ts",
|
|
38
40
|
"./useNow": "./src/useNow.ts"
|
|
39
41
|
},
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"test:unit": "bun test"
|
|
61
63
|
},
|
|
62
64
|
"type": "module",
|
|
63
|
-
"version": "2.
|
|
65
|
+
"version": "2.1.0"
|
|
64
66
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Button } from "@domicile-desktop/component-library/Button";
|
|
2
|
+
import {
|
|
3
|
+
ChoiceList,
|
|
4
|
+
RadioRow,
|
|
5
|
+
} from "@domicile-desktop/component-library/ChoiceRow";
|
|
6
|
+
import { ModalDialog } from "@domicile-desktop/component-library/ModalDialog";
|
|
7
|
+
import type { Icon } from "@phosphor-icons/react";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
|
|
10
|
+
import { css } from "../styled-system/css";
|
|
11
|
+
|
|
12
|
+
/** One address an inbox writes email from. */
|
|
13
|
+
export type Sender = {
|
|
14
|
+
/** The address, such as `me@example.com` or an alias. */
|
|
15
|
+
address: string;
|
|
16
|
+
/** The inbox's icon. */
|
|
17
|
+
icon: Icon;
|
|
18
|
+
/** The inbox's name, such as `Work`. */
|
|
19
|
+
inbox: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type Props = {
|
|
23
|
+
/** The `mailto:` link, shown on one line at the bottom. */
|
|
24
|
+
link: string;
|
|
25
|
+
/** The name of the application that asked, if known. */
|
|
26
|
+
asker?: string | undefined;
|
|
27
|
+
/** Every address it may write from, in the order listed. */
|
|
28
|
+
senders: readonly Sender[];
|
|
29
|
+
/** The address picked last time, which starts picked. */
|
|
30
|
+
lastChoice?: string | undefined;
|
|
31
|
+
onChoose: (sender: Sender) => void;
|
|
32
|
+
onCancel: () => void;
|
|
33
|
+
/** Whether it is up. Turned off, it animates out. */
|
|
34
|
+
open?: boolean | undefined;
|
|
35
|
+
screen?: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Pick which inbox, and which of its addresses, to write a `mailto:` link's
|
|
40
|
+
* email from. The address picked last time, else the first, starts picked.
|
|
41
|
+
* Enter writes; dismissing it cancels.
|
|
42
|
+
*/
|
|
43
|
+
export const MailPicker = ({
|
|
44
|
+
asker,
|
|
45
|
+
lastChoice,
|
|
46
|
+
link,
|
|
47
|
+
onCancel,
|
|
48
|
+
onChoose,
|
|
49
|
+
open = true,
|
|
50
|
+
screen,
|
|
51
|
+
senders,
|
|
52
|
+
}: Props) => {
|
|
53
|
+
const [picked, setPicked] = useState<string | undefined>();
|
|
54
|
+
const chosen =
|
|
55
|
+
senders.find(({ address }) => address === picked) ??
|
|
56
|
+
senders.find(({ address }) => address === lastChoice) ??
|
|
57
|
+
senders[0];
|
|
58
|
+
const write = () => {
|
|
59
|
+
if (chosen !== undefined) {
|
|
60
|
+
onChoose(chosen);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const to = recipientsOf(link);
|
|
64
|
+
return (
|
|
65
|
+
<ModalDialog
|
|
66
|
+
closeButton={false}
|
|
67
|
+
footer={
|
|
68
|
+
<>
|
|
69
|
+
{asker !== undefined && (
|
|
70
|
+
<p className={askerStyles}>{`${asker} asks`}</p>
|
|
71
|
+
)}
|
|
72
|
+
<Button onClick={onCancel} variant="outline">
|
|
73
|
+
Cancel
|
|
74
|
+
</Button>
|
|
75
|
+
<Button
|
|
76
|
+
disabled={chosen === undefined}
|
|
77
|
+
onClick={write}
|
|
78
|
+
variant="accent"
|
|
79
|
+
>
|
|
80
|
+
Write email
|
|
81
|
+
</Button>
|
|
82
|
+
</>
|
|
83
|
+
}
|
|
84
|
+
onOpenChange={(opening) => {
|
|
85
|
+
if (!opening) {
|
|
86
|
+
onCancel();
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
open={open}
|
|
90
|
+
screen={screen}
|
|
91
|
+
title={to === "" ? "Write an email" : `Write to ${to}`}
|
|
92
|
+
>
|
|
93
|
+
<p className={textStyles}>Choose the inbox to send from.</p>
|
|
94
|
+
<div className={listStyles}>
|
|
95
|
+
<ChoiceList<string>
|
|
96
|
+
aria-label="Send from"
|
|
97
|
+
// Enter on a row writes, as the dialog's main button does.
|
|
98
|
+
onKeyDown={(event) => {
|
|
99
|
+
if (event.key === "Enter") {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
write();
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onValueChange={setPicked}
|
|
105
|
+
value={chosen?.address}
|
|
106
|
+
>
|
|
107
|
+
{senders.map(({ address, icon: SenderIcon, inbox }) => (
|
|
108
|
+
<RadioRow
|
|
109
|
+
detail={address}
|
|
110
|
+
icon={<SenderIcon weight="duotone" />}
|
|
111
|
+
key={address}
|
|
112
|
+
name={inbox}
|
|
113
|
+
value={address}
|
|
114
|
+
/>
|
|
115
|
+
))}
|
|
116
|
+
</ChoiceList>
|
|
117
|
+
</div>
|
|
118
|
+
<p className={addressStyles}>{link}</p>
|
|
119
|
+
</ModalDialog>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** The addresses a `mailto:` link writes to, as people read them. */
|
|
124
|
+
const recipientsOf = (link: string): string => {
|
|
125
|
+
const to = link.slice(link.indexOf(":") + 1).split("?")[0] ?? "";
|
|
126
|
+
return decodeURIComponent(to).split(",").join(", ");
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const textStyles = css({ color: "muted", margin: 0 });
|
|
130
|
+
|
|
131
|
+
// Who asks sits opposite the buttons, as in the app chooser.
|
|
132
|
+
const askerStyles = css({
|
|
133
|
+
color: "muted",
|
|
134
|
+
fontSize: "ui",
|
|
135
|
+
margin: 0,
|
|
136
|
+
marginInlineEnd: "auto",
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const listStyles = css({
|
|
140
|
+
marginBlockStart: 3,
|
|
141
|
+
maxBlockSize: 80,
|
|
142
|
+
overflowY: "auto",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// A link can be long, with no spaces, as the app chooser's address can.
|
|
146
|
+
const addressStyles = css({
|
|
147
|
+
color: "muted",
|
|
148
|
+
fontFamily: "mono",
|
|
149
|
+
fontSize: "xs",
|
|
150
|
+
marginBlockEnd: 0,
|
|
151
|
+
marginBlockStart: 3,
|
|
152
|
+
overflow: "hidden",
|
|
153
|
+
textOverflow: "ellipsis",
|
|
154
|
+
whiteSpace: "nowrap",
|
|
155
|
+
});
|
|
@@ -166,6 +166,8 @@ const stripStyles = cva({
|
|
|
166
166
|
display: "grid",
|
|
167
167
|
gridColumn: "1 / -1",
|
|
168
168
|
gridTemplateRows: "1fr 0fr",
|
|
169
|
+
// main-thread animation: swaps the actions for the reply field once, moving
|
|
170
|
+
// what is below.
|
|
169
171
|
transition: "grid-template-rows {durations.slow} {easings.outQuart}",
|
|
170
172
|
},
|
|
171
173
|
// Cancels the card's padding so the strip spans it edge to edge. Matches
|
package/src/NotificationCard.tsx
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Avatar } from "@domicile-desktop/component-library/Avatar";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Notification,
|
|
4
|
+
NotificationAction,
|
|
5
|
+
} from "@domicile-desktop/sdk/notification";
|
|
3
6
|
import {
|
|
4
7
|
DEFAULT_NOTIFICATION_ACTION,
|
|
5
8
|
INLINE_REPLY_NOTIFICATION_ACTION,
|
|
@@ -152,7 +155,7 @@ export const NotificationCard = ({
|
|
|
152
155
|
density={density}
|
|
153
156
|
onAction={onAction}
|
|
154
157
|
onReply={onReply}
|
|
155
|
-
replyLabel={reply
|
|
158
|
+
replyLabel={replyLabel(reply)}
|
|
156
159
|
/>
|
|
157
160
|
)}
|
|
158
161
|
<button
|
|
@@ -319,3 +322,12 @@ const closeStyles = css({
|
|
|
319
322
|
transition:
|
|
320
323
|
"opacity {durations.fast} {easings.out}, transform {durations.fast} {easings.outBack}, background-color {durations.fast} {easings.default}",
|
|
321
324
|
});
|
|
325
|
+
|
|
326
|
+
/** A reply's label: its own, or "Reply" when the app leaves it empty. */
|
|
327
|
+
const replyLabel = (reply: NotificationAction | undefined) => {
|
|
328
|
+
if (reply === undefined) {
|
|
329
|
+
return undefined;
|
|
330
|
+
} else {
|
|
331
|
+
return reply.label === "" ? "Reply" : reply.label;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
@@ -330,6 +330,8 @@ const listStyles = flex({
|
|
|
330
330
|
overflowX: "clip",
|
|
331
331
|
overflowY: "clip",
|
|
332
332
|
paddingInline: 0,
|
|
333
|
+
// main-thread animation: holds the drawer's height once, as its last row
|
|
334
|
+
// leaves.
|
|
333
335
|
transition: "min-block-size {durations.normal} {easings.in-out}",
|
|
334
336
|
});
|
|
335
337
|
|
|
@@ -347,8 +349,7 @@ const cardBoxStyles = css({
|
|
|
347
349
|
backgroundColor: "fill",
|
|
348
350
|
borderRadius: "lg",
|
|
349
351
|
minBlockSize: 0,
|
|
350
|
-
transition:
|
|
351
|
-
"background-color {durations.fast} {easings.default}, box-shadow {durations.fast} {easings.default}",
|
|
352
|
+
transition: "background-color {durations.fast} {easings.default}",
|
|
352
353
|
});
|
|
353
354
|
|
|
354
355
|
// Fades in as the last cleared row leaves.
|
package/src/inbox.ts
CHANGED
|
@@ -22,13 +22,16 @@ export type UnreadMessage = {
|
|
|
22
22
|
export const InboxReading = {
|
|
23
23
|
/**
|
|
24
24
|
* Every conversation, and the unread ones, with the newest message of each
|
|
25
|
-
* of the newest unread conversations, newest first
|
|
25
|
+
* of the newest unread conversations, newest first, and the addresses the
|
|
26
|
+
* account sends from, its own first, when known.
|
|
26
27
|
*/
|
|
27
28
|
Counted: (
|
|
28
29
|
total: number,
|
|
29
30
|
unread: number,
|
|
30
31
|
latest: readonly UnreadMessage[] = [],
|
|
32
|
+
addresses: readonly string[] = [],
|
|
31
33
|
) => ({
|
|
34
|
+
addresses,
|
|
32
35
|
kind: InboxReadingKind.Counted as const,
|
|
33
36
|
latest,
|
|
34
37
|
total,
|
|
@@ -105,12 +108,25 @@ export const Inbox = {
|
|
|
105
108
|
read: (domicile: Domicile) => SharedWatch<InboxReading>;
|
|
106
109
|
/** Opens it, or signs it in, for a press of its row. */
|
|
107
110
|
open: (domicile: Domicile, reading: InboxReading | undefined) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Writes email from its account, for `mailto:` links: opens a new
|
|
113
|
+
* message from address `from`, filled in from the link `link`. Without
|
|
114
|
+
* it, the inbox writes no email. See {@link sendersOf}.
|
|
115
|
+
*/
|
|
116
|
+
write?: (domicile: Domicile, link: string, from: string) => void;
|
|
108
117
|
/**
|
|
109
118
|
* The app window it opens in, if any, which the launcher lists: app
|
|
110
119
|
* `appId`'s, at `url`. With `pageNotifies`, its page notifies what the
|
|
111
120
|
* inbox notifies already, so the page's are cleared as they arrive.
|
|
121
|
+
* With `profile`, it opens in that browser profile rather than its
|
|
122
|
+
* site's.
|
|
112
123
|
*/
|
|
113
|
-
app?: {
|
|
124
|
+
app?: {
|
|
125
|
+
appId: string;
|
|
126
|
+
url: string;
|
|
127
|
+
pageNotifies?: boolean;
|
|
128
|
+
profile?: string;
|
|
129
|
+
};
|
|
114
130
|
},
|
|
115
131
|
) => ({ ...inbox, kind: InboxKind.Watched as const }),
|
|
116
132
|
/**
|
|
@@ -125,6 +141,11 @@ export const Inbox = {
|
|
|
125
141
|
appId: string;
|
|
126
142
|
/** The page's address. */
|
|
127
143
|
url: string;
|
|
144
|
+
/**
|
|
145
|
+
* The id of the browser profile its window opens in, such as `work`.
|
|
146
|
+
* By default, the one its site opens in.
|
|
147
|
+
*/
|
|
148
|
+
profile?: string;
|
|
128
149
|
/**
|
|
129
150
|
* Calls `onUnread` with the page's unread conversations, read with
|
|
130
151
|
* `countMatches`, which counts the window's elements matching a CSS
|
|
@@ -139,3 +160,23 @@ export const Inbox = {
|
|
|
139
160
|
};
|
|
140
161
|
|
|
141
162
|
export type Inbox = ReturnType<(typeof Inbox)[keyof typeof Inbox]>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The addresses `inbox` writes email from, given its `reading`: those the
|
|
166
|
+
* reading names, else its account's. None when it writes no email.
|
|
167
|
+
*/
|
|
168
|
+
export const sendersOf = (
|
|
169
|
+
inbox: Inbox,
|
|
170
|
+
reading: InboxReading | undefined,
|
|
171
|
+
): readonly string[] => {
|
|
172
|
+
if (inbox.kind !== InboxKind.Watched || inbox.write === undefined) {
|
|
173
|
+
return [];
|
|
174
|
+
} else if (
|
|
175
|
+
reading?.kind === InboxReadingKind.Counted &&
|
|
176
|
+
reading.addresses.length > 0
|
|
177
|
+
) {
|
|
178
|
+
return reading.addresses;
|
|
179
|
+
} else {
|
|
180
|
+
return inbox.account === undefined ? [] : [inbox.account];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
|
|
2
|
+
import type { Link } from "@domicile-desktop/sdk/shell-command";
|
|
3
|
+
import type { Listening } from "@domicile-desktop/sdk/system";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
import type { Inbox, InboxReading } from "./inbox";
|
|
7
|
+
import { InboxKind, sendersOf } from "./inbox";
|
|
8
|
+
import type { Sender } from "./MailPicker";
|
|
9
|
+
|
|
10
|
+
/** The scheme of email links. */
|
|
11
|
+
const MAILTO = "mailto";
|
|
12
|
+
|
|
13
|
+
/** A `mailto:` link waiting for the user to pick an address. */
|
|
14
|
+
export type MailAsk = {
|
|
15
|
+
link: string;
|
|
16
|
+
/** The desktop file id of the application that opened it, if known. */
|
|
17
|
+
appId: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** A {@link Sender}, with what writes from it. */
|
|
21
|
+
type Writer = Sender & { write: (link: string) => void };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `mailto:` links, written from the inboxes that write email: the desktop's
|
|
25
|
+
* (claimed from the compositor while any inbox writes) and those `open` is
|
|
26
|
+
* given, such as a page's, which `opens` says it takes. With one address to write from, a link is written
|
|
27
|
+
* at once; with several, it waits in `asking` until `choose` or `cancel`.
|
|
28
|
+
* `lastChoice` is the address picked last.
|
|
29
|
+
*/
|
|
30
|
+
export const useMailLinks = (
|
|
31
|
+
domicile: Domicile,
|
|
32
|
+
inboxes: readonly Inbox[],
|
|
33
|
+
readings: readonly (InboxReading | undefined)[],
|
|
34
|
+
) => {
|
|
35
|
+
const writers = useMemo(
|
|
36
|
+
() => writersOf(domicile, inboxes, readings),
|
|
37
|
+
[domicile, inboxes, readings],
|
|
38
|
+
);
|
|
39
|
+
const claims = useMemo(
|
|
40
|
+
() =>
|
|
41
|
+
inboxes.some(
|
|
42
|
+
(inbox) =>
|
|
43
|
+
inbox.kind === InboxKind.Watched && inbox.write !== undefined,
|
|
44
|
+
),
|
|
45
|
+
[inboxes],
|
|
46
|
+
);
|
|
47
|
+
const [asking, setAsking] = useState<MailAsk | undefined>();
|
|
48
|
+
const [lastChoice, setLastChoice] = useState<string | undefined>();
|
|
49
|
+
// Read when a link arrives, so the claim outlives a change of readings.
|
|
50
|
+
const current = useRef(writers);
|
|
51
|
+
current.current = writers;
|
|
52
|
+
|
|
53
|
+
const open = useCallback((link: string, appId?: string) => {
|
|
54
|
+
const [only, ...others] = current.current;
|
|
55
|
+
if (only !== undefined && others.length === 0) {
|
|
56
|
+
only.write(link);
|
|
57
|
+
} else {
|
|
58
|
+
setAsking({ appId, link });
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (claims) {
|
|
64
|
+
return claimLinks(domicile, [MAILTO], ({ appId, url }) => {
|
|
65
|
+
open(url, appId);
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}, [claims, domicile, open]);
|
|
71
|
+
|
|
72
|
+
const choose = useCallback(
|
|
73
|
+
(address: string) => {
|
|
74
|
+
const writer = writers.find((one) => one.address === address);
|
|
75
|
+
if (asking === undefined || writer === undefined) {
|
|
76
|
+
throw new Error(`nothing waits to be written from ${address}`);
|
|
77
|
+
} else {
|
|
78
|
+
writer.write(asking.link);
|
|
79
|
+
setLastChoice(address);
|
|
80
|
+
setAsking(undefined);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
[asking, writers],
|
|
84
|
+
);
|
|
85
|
+
const cancel = useCallback(() => {
|
|
86
|
+
setAsking(undefined);
|
|
87
|
+
}, []);
|
|
88
|
+
const opens = useCallback(
|
|
89
|
+
(link: string) => claims && link.toLowerCase().startsWith(`${MAILTO}:`),
|
|
90
|
+
[claims],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
asking,
|
|
95
|
+
cancel,
|
|
96
|
+
choose,
|
|
97
|
+
lastChoice,
|
|
98
|
+
open,
|
|
99
|
+
opens,
|
|
100
|
+
senders: writers as readonly Sender[],
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Every address the inboxes write from, inbox by inbox. */
|
|
105
|
+
const writersOf = (
|
|
106
|
+
domicile: Domicile,
|
|
107
|
+
inboxes: readonly Inbox[],
|
|
108
|
+
readings: readonly (InboxReading | undefined)[],
|
|
109
|
+
): Writer[] =>
|
|
110
|
+
inboxes.flatMap((inbox, index) =>
|
|
111
|
+
inbox.kind === InboxKind.Watched && inbox.write !== undefined
|
|
112
|
+
? sendersOf(inbox, readings[index]).map((address) => ({
|
|
113
|
+
address,
|
|
114
|
+
icon: inbox.icon,
|
|
115
|
+
inbox: inbox.name,
|
|
116
|
+
write: (link: string) => {
|
|
117
|
+
inbox.write?.(domicile, link, address);
|
|
118
|
+
},
|
|
119
|
+
}))
|
|
120
|
+
: [],
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Claims `schemes`' links from the compositor, calling `onLink` with each,
|
|
125
|
+
* until the returned function is called. A stop before the claim starts ends
|
|
126
|
+
* it once it does.
|
|
127
|
+
*/
|
|
128
|
+
const claimLinks = (
|
|
129
|
+
domicile: Domicile,
|
|
130
|
+
schemes: readonly string[],
|
|
131
|
+
onLink: (link: Link) => void,
|
|
132
|
+
): (() => void) => {
|
|
133
|
+
const state: { stopped: boolean; listening: Listening<Link> | undefined } = {
|
|
134
|
+
listening: undefined,
|
|
135
|
+
stopped: false,
|
|
136
|
+
};
|
|
137
|
+
domicile.shell
|
|
138
|
+
.links(schemes)
|
|
139
|
+
.then((result) => {
|
|
140
|
+
result.match({
|
|
141
|
+
Err: report,
|
|
142
|
+
Ok: (listening) => {
|
|
143
|
+
if (state.stopped) {
|
|
144
|
+
listening.stop();
|
|
145
|
+
} else {
|
|
146
|
+
state.listening = listening;
|
|
147
|
+
}
|
|
148
|
+
eachOf(listening.items, onLink).catch(report);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
})
|
|
152
|
+
.catch(report);
|
|
153
|
+
return () => {
|
|
154
|
+
state.stopped = true;
|
|
155
|
+
state.listening?.stop();
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** Call `each` with every item `items` brings, until it closes. */
|
|
160
|
+
const eachOf = async <T>(
|
|
161
|
+
items: ReadableStream<T>,
|
|
162
|
+
each: (item: T) => void,
|
|
163
|
+
): Promise<void> => {
|
|
164
|
+
for await (const item of items) {
|
|
165
|
+
each(item);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const report = (error: unknown): void => {
|
|
170
|
+
// biome-ignore lint/suspicious/noConsole: email links then open in the desk's mail app, if any
|
|
171
|
+
console.error("this page cannot claim email links", error);
|
|
172
|
+
};
|