@soffits/dsh-notify-inbox 0.4.0 → 0.6.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/CHANGELOG.md +16 -0
- package/README.md +42 -4
- package/client.js +334 -213
- package/docs/ui.md +38 -0
- package/index.js +41 -19
- package/locale/en.json +24 -6
- package/locale/fr.json +25 -7
- package/locale/zh.json +23 -5
- package/package.json +24 -4
- package/src/changes.js +104 -0
- package/src/domains.js +49 -0
- package/src/routes.js +77 -18
- package/src/store.js +156 -15
- package/src/view.js +117 -0
package/docs/ui.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# What the page is made of
|
|
2
|
+
|
|
3
|
+
The inbox page should look like it always was part of DSH, so it is built from DSH's own pieces first, then the shared kit, and only a little of its own.
|
|
4
|
+
|
|
5
|
+
## DSH's own
|
|
6
|
+
|
|
7
|
+
From `@deepseek-ai/dsh-client-ui-primitives`, which DSH puts in every plugin's module table (`require` at runtime, no copy):
|
|
8
|
+
|
|
9
|
+
| Piece | Where |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `Button` (outline, small) | Mark all read, Mark unread, Show older, the ⋯ trigger |
|
|
12
|
+
| `Pill` | The Needs you / All filters, as on the Automation page |
|
|
13
|
+
| `Menu`, `Tooltip` | The ⋯ menu: notifications on this device, a test push |
|
|
14
|
+
| `StateDot` | The green dot on a live item |
|
|
15
|
+
| `IconCheckCircleOutlineRegular`, `IconEllipsisOutlineRegular`, `IconSendOutlineRegular` | The handled check, the ⋯ trigger, the reply's Send |
|
|
16
|
+
| Theme tokens (`--dsw-alias-*`) | Every colour, so light and dark follow the Web UI |
|
|
17
|
+
|
|
18
|
+
The page's layout copies the numbers of DSH's own pages, since their CSS modules aren't shared: the frame (960 px column, 28 px top inset, `clamp(24px, 4vw, 48px)` sides) and rows (12 px radius, 8 px padding, 12 px gap, 13 px tertiary summary) of the Automation page, and the group headings (14 px medium title, count beside it) of the plugin manager.
|
|
19
|
+
|
|
20
|
+
`test/client-names.test.js` checks every primitive the page takes against the export list of the oldest DSH it supports (`test/fixtures/`), so a wrong name fails a test instead of the page.
|
|
21
|
+
|
|
22
|
+
## The shared kit
|
|
23
|
+
|
|
24
|
+
From [@soffits/dsh-ui-kit](https://github.com/soffits/dsh-ui-kit) (`ctx.uiKit`), for what DSH has no piece for and other plugin pages need too: `Tile` and `Icon` (a domain's Lucide icon on a tinted tile), `TimeAgo` and `TimeUntil` (times that tick, full date on hover), `LiveStatus` and `useEventStream` (the live line and the events stream), `useWash` and `NewDot` (the two-second cue on an item that just changed, the unread dot), `History` (a thread's earlier entries), `Progress` (a live item's bar through time) and `Suggested` (the suggested steps). The buttons themselves come from [@soffits/dsh-ui-actions](https://github.com/soffits/dsh-ui-actions).
|
|
25
|
+
|
|
26
|
+
## Ours
|
|
27
|
+
|
|
28
|
+
About fifty lines of CSS in `client.js`, only for layout DSH doesn't expose:
|
|
29
|
+
|
|
30
|
+
- **The page frame, rows and group headings**, with the values above. A row is a disclosure (the header is a button, the details open below it), which no DSH primitive draws.
|
|
31
|
+
- **Two-line titles and summaries** (`line-clamp`), so a phone shows the whole of a short title instead of cutting it.
|
|
32
|
+
- **The counts line** (`Urgent 1 · Needs you 2 · Live 1 · …`), joined the way DSH joins row metadata.
|
|
33
|
+
- **An ask's points** (`+3`): a small tinted label beside the title in the accent colour; DSH has no badge primitive for a row.
|
|
34
|
+
- **The reply box** under an opened ask: a native `textarea` with DSH's border, radius and background tokens, since DSH exports no multi-line input.
|
|
35
|
+
- **The unread badge on the sidebar bell**: DSH's sidebar has no count badge for an entry.
|
|
36
|
+
- **Phone sizes**: at 640 px and below, or with a touch pointer, every control is at least 40 px tall, as DSH's own controls are only on desktop.
|
|
37
|
+
|
|
38
|
+
Nothing else: no colours, fonts or shadows of its own.
|
package/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import { fileURLToPath } from 'node:url'
|
|
|
15
15
|
import z from '@deepseek-ai/schemastery'
|
|
16
16
|
import { createPeople, expandHome } from './src/access.js'
|
|
17
17
|
import { createActions } from './src/actions.js'
|
|
18
|
+
import { createChanges } from './src/changes.js'
|
|
19
|
+
import { TONES, domainMap } from './src/domains.js'
|
|
18
20
|
import { createPush } from './src/push.js'
|
|
19
21
|
import { createRoutes } from './src/routes.js'
|
|
20
22
|
import { createStore } from './src/store.js'
|
|
@@ -38,13 +40,18 @@ export const Config = z.object({
|
|
|
38
40
|
.description('Where the Web Push (VAPID) key pair is kept; made on first start, mode 600. Default: .push/vapid.json in dataDir.'),
|
|
39
41
|
vapidSubject: z.string().default('mailto:admin@example.invalid')
|
|
40
42
|
.description('A mailto: or https: contact that push services can reach about this server.'),
|
|
41
|
-
|
|
42
|
-
.description('
|
|
43
|
+
domains: z.dict(z.object({
|
|
44
|
+
icon: z.string().description('A Lucide icon name, such as plane or heart-pulse.'),
|
|
45
|
+
tone: z.union([...TONES]).description('A colour this domain keeps wherever it shows. Usually left out: the group gives the colour.'),
|
|
46
|
+
})).default({})
|
|
47
|
+
.description('How each domain (the record\'s domain field) is drawn, on top of the built-in defaults (mail, money, health, travel, home...).'),
|
|
48
|
+
summaryHours: z.natural().min(1).max(168).default(12)
|
|
49
|
+
.description('How long the summary line (<dataDir>/<person>/summary.json) is shown after it was written.'),
|
|
43
50
|
})
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
47
|
-
* @param {{ dataDir: string, people: Record<string, string>, peopleFile: string, peopleKey: string, vapidFile: string, vapidSubject: string,
|
|
54
|
+
* @param {{ dataDir: string, people: Record<string, string>, peopleFile: string, peopleKey: string, vapidFile: string, vapidSubject: string, domains: Record<string, { icon: string, tone?: string }>, summaryHours: number }} config
|
|
48
55
|
*/
|
|
49
56
|
export function apply(ctx, config) {
|
|
50
57
|
const logger = ctx.logger('notify-inbox')
|
|
@@ -69,25 +76,40 @@ export function apply(ctx, config) {
|
|
|
69
76
|
warn,
|
|
70
77
|
})
|
|
71
78
|
const actions = createActions({ dataDir, events: () => ctx.get('cronJobs'), warn })
|
|
72
|
-
const pollSeconds = config.pollSeconds ?? 5
|
|
73
79
|
const strings = readLocales(fileURLToPath(new URL('./locale/', import.meta.url))).then(tables)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let stopped = false
|
|
78
|
-
let timer
|
|
80
|
+
// New records are pushed when the inbox file changes; one scan at a time, and one more if a change came meanwhile.
|
|
81
|
+
let scanning = null
|
|
82
|
+
let again = false
|
|
79
83
|
const scan = async () => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
if (scanning !== null) { again = true; return }
|
|
85
|
+
scanning = (async () => {
|
|
86
|
+
do {
|
|
87
|
+
again = false
|
|
88
|
+
try {
|
|
89
|
+
await push.scan(await store.persons())
|
|
90
|
+
} catch (error) {
|
|
91
|
+
warn(`push scan failed: ${error.message}`)
|
|
92
|
+
}
|
|
93
|
+
} while (again)
|
|
94
|
+
})()
|
|
95
|
+
await scanning
|
|
96
|
+
scanning = null
|
|
86
97
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
const changes = createChanges({ dataDir, persons: () => store.persons(), warn, onChange: (_person, file) => { if (file === 'inbox.jsonl') scan() } })
|
|
99
|
+
const routes = createRoutes({
|
|
100
|
+
store, people, push, actions, changes,
|
|
101
|
+
identity: () => ctx.get('requestIdentity'),
|
|
102
|
+
serviceWorker,
|
|
103
|
+
strings: () => strings,
|
|
104
|
+
domains: domainMap(config.domains ?? {}),
|
|
105
|
+
summaryHours: config.summaryHours ?? 12,
|
|
106
|
+
})
|
|
107
|
+
for (const route of routes) ctx.connection.fetch.register(route)
|
|
108
|
+
|
|
109
|
+
push.vapid().then(() => changes.start().then(scan), error => {
|
|
110
|
+
logger.error(`Web Push keys unusable, push is off: ${error.message}`)
|
|
111
|
+
return changes.start()
|
|
91
112
|
})
|
|
113
|
+
ctx.on('dispose', () => changes.stop())
|
|
92
114
|
logger.info(`inbox at ${dataDir} (${people.enabled ? 'per person' : 'single owner'})`)
|
|
93
115
|
}
|
package/locale/en.json
CHANGED
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
"ui": {
|
|
7
7
|
"panel": "Inbox",
|
|
8
8
|
"title": "Inbox",
|
|
9
|
-
"filter.unread": "Unread",
|
|
10
9
|
"filter.all": "All",
|
|
11
10
|
"markAll": "Mark all read",
|
|
12
11
|
"markUnread": "Mark unread",
|
|
13
|
-
"empty.unread": "Nothing unread.",
|
|
14
12
|
"empty.all": "No notifications yet.",
|
|
15
13
|
"loadMore": "Show older",
|
|
16
|
-
"urgent": "Urgent",
|
|
17
14
|
"test": "Test",
|
|
18
15
|
"alsoSent": "Also sent to",
|
|
19
16
|
"notSent": "Not sent anywhere else",
|
|
@@ -25,8 +22,7 @@
|
|
|
25
22
|
"press.snoozed": "Will remind you {time}",
|
|
26
23
|
"press.started": "Started",
|
|
27
24
|
"push.title": "Notifications on this device",
|
|
28
|
-
"push.on": "
|
|
29
|
-
"push.off": "Off",
|
|
25
|
+
"push.on": "on",
|
|
30
26
|
"push.enable": "Turn on",
|
|
31
27
|
"push.disable": "Turn off",
|
|
32
28
|
"push.test": "Send a test",
|
|
@@ -37,6 +33,28 @@
|
|
|
37
33
|
"error": "Couldn’t load: {message}",
|
|
38
34
|
"time.locale": "en-US",
|
|
39
35
|
"push.testTitle": "Inbox",
|
|
40
|
-
"push.testBody": "Notifications reach this device."
|
|
36
|
+
"push.testBody": "Notifications reach this device.",
|
|
37
|
+
"filter.label": "Show",
|
|
38
|
+
"group.needs-you": "Needs you",
|
|
39
|
+
"group.live": "Live",
|
|
40
|
+
"group.handled": "Handled",
|
|
41
|
+
"group.info": "To know",
|
|
42
|
+
"empty.needs-you": "Nothing needs you right now.",
|
|
43
|
+
"moved.done": "You marked it done.",
|
|
44
|
+
"moved.ended": "Ended",
|
|
45
|
+
"more": "More",
|
|
46
|
+
"push.off": "off",
|
|
47
|
+
"push.unavailable": "not available here",
|
|
48
|
+
"kitMissing": "This page needs the @soffits/dsh-ui-kit plugin.",
|
|
49
|
+
"group.urgent": "Urgent",
|
|
50
|
+
"points": "+{n} pts",
|
|
51
|
+
"reply.label": "Reply",
|
|
52
|
+
"reply.placeholder": "Your answer goes to the conversation that asked",
|
|
53
|
+
"reply.send": "Send",
|
|
54
|
+
"reply.sending": "Sending…",
|
|
55
|
+
"reply.sent": "Sent to the conversation.",
|
|
56
|
+
"reply.open": "Open it",
|
|
57
|
+
"reply.failed": "Couldn’t send: {message}",
|
|
58
|
+
"moved.closed": "Settled."
|
|
41
59
|
}
|
|
42
60
|
}
|
package/locale/fr.json
CHANGED
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
"ui": {
|
|
7
7
|
"panel": "Notifications",
|
|
8
8
|
"title": "Notifications",
|
|
9
|
-
"filter.unread": "Non lues",
|
|
10
9
|
"filter.all": "Toutes",
|
|
11
10
|
"markAll": "Tout marquer comme lu",
|
|
12
11
|
"markUnread": "Marquer comme non lu",
|
|
13
|
-
"empty.
|
|
14
|
-
"empty.all": "Pas encore de notifications.",
|
|
12
|
+
"empty.all": "Aucune notification pour l’instant.",
|
|
15
13
|
"loadMore": "Plus anciennes",
|
|
16
|
-
"urgent": "Urgent",
|
|
17
14
|
"test": "Test",
|
|
18
15
|
"alsoSent": "Aussi envoyé à",
|
|
19
16
|
"notSent": "Envoyé nulle part ailleurs",
|
|
@@ -25,8 +22,7 @@
|
|
|
25
22
|
"press.snoozed": "Rappel {time}",
|
|
26
23
|
"press.started": "Lancé",
|
|
27
24
|
"push.title": "Notifications sur cet appareil",
|
|
28
|
-
"push.on": "
|
|
29
|
-
"push.off": "Désactivées",
|
|
25
|
+
"push.on": "activées",
|
|
30
26
|
"push.enable": "Activer",
|
|
31
27
|
"push.disable": "Désactiver",
|
|
32
28
|
"push.test": "Envoyer un test",
|
|
@@ -37,6 +33,28 @@
|
|
|
37
33
|
"error": "Chargement impossible : {message}",
|
|
38
34
|
"time.locale": "fr-FR",
|
|
39
35
|
"push.testTitle": "Notifications",
|
|
40
|
-
"push.testBody": "Les notifications arrivent sur cet appareil."
|
|
36
|
+
"push.testBody": "Les notifications arrivent sur cet appareil.",
|
|
37
|
+
"filter.label": "Afficher",
|
|
38
|
+
"group.needs-you": "Pour vous",
|
|
39
|
+
"group.live": "En cours",
|
|
40
|
+
"group.handled": "Réglé",
|
|
41
|
+
"group.info": "À savoir",
|
|
42
|
+
"empty.needs-you": "Rien ne vous attend pour l’instant.",
|
|
43
|
+
"moved.done": "Vous l’avez marqué comme fait.",
|
|
44
|
+
"moved.ended": "Terminé",
|
|
45
|
+
"more": "Plus",
|
|
46
|
+
"push.off": "désactivées",
|
|
47
|
+
"push.unavailable": "indisponibles ici",
|
|
48
|
+
"kitMissing": "Cette page a besoin du plugin @soffits/dsh-ui-kit.",
|
|
49
|
+
"group.urgent": "Urgent",
|
|
50
|
+
"points": "+{n} pts",
|
|
51
|
+
"reply.label": "Répondre",
|
|
52
|
+
"reply.placeholder": "Votre réponse va dans la conversation qui a posé la question",
|
|
53
|
+
"reply.send": "Envoyer",
|
|
54
|
+
"reply.sending": "Envoi…",
|
|
55
|
+
"reply.sent": "Envoyé dans la conversation.",
|
|
56
|
+
"reply.open": "L’ouvrir",
|
|
57
|
+
"reply.failed": "Envoi impossible : {message}",
|
|
58
|
+
"moved.closed": "Réglé."
|
|
41
59
|
}
|
|
42
60
|
}
|
package/locale/zh.json
CHANGED
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
"ui": {
|
|
7
7
|
"panel": "收件箱",
|
|
8
8
|
"title": "收件箱",
|
|
9
|
-
"filter.unread": "未读",
|
|
10
9
|
"filter.all": "全部",
|
|
11
10
|
"markAll": "全部已读",
|
|
12
11
|
"markUnread": "标为未读",
|
|
13
|
-
"empty.unread": "没有未读通知。",
|
|
14
12
|
"empty.all": "还没有通知。",
|
|
15
13
|
"loadMore": "更早的",
|
|
16
|
-
"urgent": "紧急",
|
|
17
14
|
"test": "测试",
|
|
18
15
|
"alsoSent": "同时发到",
|
|
19
16
|
"notSent": "没有发到别处",
|
|
@@ -26,7 +23,6 @@
|
|
|
26
23
|
"press.started": "已开始",
|
|
27
24
|
"push.title": "本设备的通知",
|
|
28
25
|
"push.on": "已开启",
|
|
29
|
-
"push.off": "未开启",
|
|
30
26
|
"push.enable": "开启",
|
|
31
27
|
"push.disable": "关闭",
|
|
32
28
|
"push.test": "发一条测试",
|
|
@@ -37,6 +33,28 @@
|
|
|
37
33
|
"error": "加载失败:{message}",
|
|
38
34
|
"time.locale": "zh-CN",
|
|
39
35
|
"push.testTitle": "收件箱",
|
|
40
|
-
"push.testBody": "这台设备能收到通知了。"
|
|
36
|
+
"push.testBody": "这台设备能收到通知了。",
|
|
37
|
+
"filter.label": "显示",
|
|
38
|
+
"group.needs-you": "待你处理",
|
|
39
|
+
"group.live": "进行中",
|
|
40
|
+
"group.handled": "已处理",
|
|
41
|
+
"group.info": "知道就好",
|
|
42
|
+
"empty.needs-you": "现在没有要你处理的事。",
|
|
43
|
+
"moved.done": "你已标记为完成。",
|
|
44
|
+
"moved.ended": "已结束",
|
|
45
|
+
"more": "更多",
|
|
46
|
+
"push.off": "已关闭",
|
|
47
|
+
"push.unavailable": "这里不可用",
|
|
48
|
+
"kitMissing": "这个页面需要 @soffits/dsh-ui-kit 插件。",
|
|
49
|
+
"group.urgent": "紧急",
|
|
50
|
+
"points": "+{n} 分",
|
|
51
|
+
"reply.label": "回复",
|
|
52
|
+
"reply.placeholder": "回复会发到提问的那个对话里",
|
|
53
|
+
"reply.send": "发送",
|
|
54
|
+
"reply.sending": "正在发送…",
|
|
55
|
+
"reply.sent": "已经发到那个对话里了。",
|
|
56
|
+
"reply.open": "打开对话",
|
|
57
|
+
"reply.failed": "没发出去:{message}",
|
|
58
|
+
"moved.closed": "已经处理好了。"
|
|
41
59
|
}
|
|
42
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-notify-inbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A notification inbox for DeepSeek Harness: each person sees their own notifications with read and unread, gets Web Push on their phone or browser, and can act on them.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,15 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/soffits/dsh-notify-inbox/issues"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"dsh",
|
|
18
|
+
"dsh-plugin",
|
|
19
|
+
"deepseek-harness",
|
|
20
|
+
"notifications",
|
|
21
|
+
"inbox",
|
|
22
|
+
"web-push",
|
|
23
|
+
"pwa"
|
|
24
|
+
],
|
|
17
25
|
"main": "./index.js",
|
|
18
26
|
"exports": {
|
|
19
27
|
".": "./index.js",
|
|
@@ -22,7 +30,18 @@
|
|
|
22
30
|
"./icon": "./icon.svg",
|
|
23
31
|
"./package.json": "./package.json"
|
|
24
32
|
},
|
|
25
|
-
"files": [
|
|
33
|
+
"files": [
|
|
34
|
+
"src",
|
|
35
|
+
"client.js",
|
|
36
|
+
"index.js",
|
|
37
|
+
"cordis.patch.yml",
|
|
38
|
+
"locale/*.json",
|
|
39
|
+
"icon.svg",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"docs/*.md"
|
|
44
|
+
],
|
|
26
45
|
"dsh": {
|
|
27
46
|
"bundle": {
|
|
28
47
|
"patch": "./cordis.patch.yml"
|
|
@@ -32,6 +51,7 @@
|
|
|
32
51
|
"immediately": true,
|
|
33
52
|
"inject": [
|
|
34
53
|
"@deepseek-ai/dsh-client-locale",
|
|
54
|
+
"@soffits/dsh-ui-kit",
|
|
35
55
|
"@soffits/dsh-ui-actions",
|
|
36
56
|
"@deepseek-ai/dsh-client-ui-layout",
|
|
37
57
|
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
@@ -47,6 +67,6 @@
|
|
|
47
67
|
},
|
|
48
68
|
"engines": {
|
|
49
69
|
"node": ">=22",
|
|
50
|
-
"dsh": ">=0.2.
|
|
70
|
+
"dsh": ">=0.2.2-rc.1 <0.3.0-0"
|
|
51
71
|
}
|
|
52
72
|
}
|
package/src/changes.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Change notices. The data folder and each person's folder are watched
|
|
3
|
+
* (`fs.watch` on the directories, so a file replaced by a rename is seen as
|
|
4
|
+
* well as one appended to); when one of the files that make up a person's
|
|
5
|
+
* inbox (records, read marks, presses, the summary line, the asks) changes,
|
|
6
|
+
* every listener allowed to see that person hears a short notice and the page
|
|
7
|
+
* fetches again, and `onChange` runs (push looks for new records). No timer:
|
|
8
|
+
* the files' own changes are the signal. A folder that appears later is
|
|
9
|
+
* picked up when the data folder reports it.
|
|
10
|
+
*/
|
|
11
|
+
import { watch } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
|
|
14
|
+
export const FILES = ['inbox.jsonl', 'read.json', 'actions.jsonl', 'summary.json', 'asks.json']
|
|
15
|
+
const SETTLE_MS = 50
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} options
|
|
19
|
+
* @param {string} options.dataDir
|
|
20
|
+
* @param {() => Promise<string[]>} options.persons - every inbox folder there is
|
|
21
|
+
* @param {(person: string, file: string) => void} [options.onChange] - also called for each change
|
|
22
|
+
* @param {(message: string) => void} [options.warn]
|
|
23
|
+
*/
|
|
24
|
+
export function createChanges({ dataDir, persons, onChange = () => {}, warn = () => {} }) {
|
|
25
|
+
const listeners = new Set()
|
|
26
|
+
const watchers = new Map() // folder name ('' for the data folder) -> FSWatcher
|
|
27
|
+
const pending = new Map() // person -> { timer, files }
|
|
28
|
+
let stopped = false
|
|
29
|
+
|
|
30
|
+
function notify(person, file) {
|
|
31
|
+
const due = pending.get(person) ?? { timer: undefined, files: new Set() }
|
|
32
|
+
due.files.add(file)
|
|
33
|
+
clearTimeout(due.timer)
|
|
34
|
+
// Several writes in one go (an append and its status line, a rename) become one notice.
|
|
35
|
+
due.timer = setTimeout(() => {
|
|
36
|
+
pending.delete(person)
|
|
37
|
+
for (const listener of listeners) if (listener.folders === null || listener.folders.includes(person)) listener.send(person)
|
|
38
|
+
for (const name of due.files) onChange(person, name)
|
|
39
|
+
}, SETTLE_MS)
|
|
40
|
+
pending.set(person, due)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function watchFolder(person) {
|
|
44
|
+
if (stopped || watchers.has(person)) return
|
|
45
|
+
try {
|
|
46
|
+
const watcher = watch(join(dataDir, person), (_event, name) => {
|
|
47
|
+
const file = name === null ? null : String(name)
|
|
48
|
+
if (file === null || FILES.includes(file)) notify(person, file ?? 'inbox.jsonl')
|
|
49
|
+
})
|
|
50
|
+
watcher.on('error', error => {
|
|
51
|
+
warn(`stopped watching ${person}: ${error.message}`)
|
|
52
|
+
watcher.close()
|
|
53
|
+
watchers.delete(person)
|
|
54
|
+
})
|
|
55
|
+
watchers.set(person, watcher)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code !== 'ENOENT') warn(`cannot watch ${person}: ${error.message}`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function sync() {
|
|
62
|
+
for (const person of await persons()) {
|
|
63
|
+
if (!watchers.has(person)) {
|
|
64
|
+
watchFolder(person)
|
|
65
|
+
notify(person, 'inbox.jsonl')
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Start watching: the data folder for new people, and every person's folder. */
|
|
71
|
+
async function start() {
|
|
72
|
+
if (stopped || watchers.has('')) return
|
|
73
|
+
try {
|
|
74
|
+
const top = watch(dataDir, () => { sync().catch(error => warn(`inbox folders not read: ${error.message}`)) })
|
|
75
|
+
top.on('error', error => warn(`stopped watching the inbox folder: ${error.message}`))
|
|
76
|
+
watchers.set('', top)
|
|
77
|
+
} catch (error) {
|
|
78
|
+
warn(`cannot watch ${dataDir}: ${error.message}`)
|
|
79
|
+
}
|
|
80
|
+
for (const person of await persons()) watchFolder(person)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Hear about changes to these folders (null: every folder, for an owner who sees them all).
|
|
85
|
+
* @returns {() => void} stop listening
|
|
86
|
+
*/
|
|
87
|
+
function listen(folders, send) {
|
|
88
|
+
const listener = { folders, send }
|
|
89
|
+
listeners.add(listener)
|
|
90
|
+
return () => listeners.delete(listener)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Stop at once (the plugin is going away). */
|
|
94
|
+
function stop() {
|
|
95
|
+
stopped = true
|
|
96
|
+
listeners.clear()
|
|
97
|
+
for (const watcher of watchers.values()) watcher.close()
|
|
98
|
+
watchers.clear()
|
|
99
|
+
for (const { timer } of pending.values()) clearTimeout(timer)
|
|
100
|
+
pending.clear()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return { start, listen, stop }
|
|
104
|
+
}
|
package/src/domains.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icon (and optionally the colour) each domain is drawn with. Records
|
|
3
|
+
* already carry a `domain` (mail, money, home...); these defaults cover the
|
|
4
|
+
* common ones and the `domains` setting adds or replaces entries. Icons are
|
|
5
|
+
* Lucide names drawn by @soffits/dsh-ui-kit. A domain names no colour by
|
|
6
|
+
* default: an item's colour says what it needs (its group), so a page of
|
|
7
|
+
* notifications isn't a rainbow; set `tone` only for a domain that should
|
|
8
|
+
* stand out wherever it shows.
|
|
9
|
+
*/
|
|
10
|
+
export const TONES = ['ok', 'warn', 'bad', 'accent', 'violet', 'muted']
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_DOMAINS = {
|
|
13
|
+
general: { icon: 'bell' },
|
|
14
|
+
mail: { icon: 'mail' },
|
|
15
|
+
calendar: { icon: 'calendar' },
|
|
16
|
+
money: { icon: 'wallet' },
|
|
17
|
+
bills: { icon: 'receipt' },
|
|
18
|
+
orders: { icon: 'package' },
|
|
19
|
+
shopping: { icon: 'shopping-cart' },
|
|
20
|
+
health: { icon: 'heart-pulse' },
|
|
21
|
+
medication: { icon: 'pill' },
|
|
22
|
+
food: { icon: 'utensils' },
|
|
23
|
+
travel: { icon: 'plane' },
|
|
24
|
+
weather: { icon: 'cloud-sun' },
|
|
25
|
+
home: { icon: 'house' },
|
|
26
|
+
people: { icon: 'users' },
|
|
27
|
+
work: { icon: 'briefcase' },
|
|
28
|
+
legal: { icon: 'scale' },
|
|
29
|
+
learning: { icon: 'graduation-cap' },
|
|
30
|
+
media: { icon: 'clapperboard' },
|
|
31
|
+
games: { icon: 'gamepad-2' },
|
|
32
|
+
news: { icon: 'newspaper' },
|
|
33
|
+
safety: { icon: 'shield-alert' },
|
|
34
|
+
upkeep: { icon: 'wrench' },
|
|
35
|
+
system: { icon: 'server' },
|
|
36
|
+
jobs: { icon: 'timer' },
|
|
37
|
+
test: { icon: 'terminal' },
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The defaults with the configured entries on top; entries with an unknown tone keep only their icon. */
|
|
41
|
+
export function domainMap(configured = {}) {
|
|
42
|
+
const out = { ...DEFAULT_DOMAINS }
|
|
43
|
+
for (const [name, entry] of Object.entries(configured)) {
|
|
44
|
+
const icon = typeof entry?.icon === 'string' && entry.icon !== '' ? entry.icon : out[name]?.icon
|
|
45
|
+
const tone = TONES.includes(entry?.tone) ? entry.tone : undefined
|
|
46
|
+
out[name] = tone === undefined ? { icon } : { icon, tone }
|
|
47
|
+
}
|
|
48
|
+
return out
|
|
49
|
+
}
|