@soffits/dsh-notify-inbox 0.1.2 → 0.2.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 +12 -0
- package/README.md +4 -0
- package/client.actions.js +36 -59
- package/client.js +25 -73
- package/index.js +4 -1
- package/locale/en.json +57 -1
- package/locale/fr.json +57 -0
- package/locale/zh.json +57 -1
- package/package.json +1 -1
- package/src/locales.js +40 -0
- package/src/push.js +4 -4
- package/src/routes.js +7 -2
- package/src/sw.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Every word on the page comes from `locale/<tag>.json`, one file per language, picked up by what files exist; a missing key falls back to the primary language, then English. French joins English and Chinese.
|
|
6
|
+
- The test push speaks the page's language; the push payload and service worker carry no built-in words.
|
|
7
|
+
- The buttons module is the card board's current one (words come from the page's own table).
|
|
8
|
+
|
|
9
|
+
## 0.1.3
|
|
10
|
+
|
|
11
|
+
- The buttons chunk keeps its names inside its own scope, so it loads next to another plugin's copy on the same page (DSH runs chunks as classic scripts in one global scope).
|
|
12
|
+
- Touch targets are at least 40 px on phones and touch screens.
|
|
13
|
+
- A notification you open under Unread stays on screen instead of vanishing as it turns read.
|
|
14
|
+
|
|
3
15
|
## 0.1.2
|
|
4
16
|
|
|
5
17
|
- The buttons chunk registers as a chunk of the package (`{ id, chunk }`), so a page that got the plugin while it was open loads the buttons instead of failing with "loaded without registering"; a failed load is retried next time and never hides the list.
|
package/README.md
CHANGED
|
@@ -84,6 +84,10 @@ Open the inbox on the device and press **Turn on**. The browser picks its own pu
|
|
|
84
84
|
|
|
85
85
|
Tapping a notification opens the inbox on it. A device whose subscription expired is dropped the first time its push service says so.
|
|
86
86
|
|
|
87
|
+
## Languages
|
|
88
|
+
|
|
89
|
+
The page follows DSH's language. Its words live in `locale/<tag>.json` (`ui` for the page, `meta` for the plugin list): English, French and Chinese ship. Another language is one more file with the same keys; anything it leaves out comes from its primary language (`pt` for `pt-BR`), then English. Notification text is shown as it was sent.
|
|
90
|
+
|
|
87
91
|
## Files the plugin writes
|
|
88
92
|
|
|
89
93
|
All under `dataDir`: `<person>/read.json` (read marks), `<person>/actions.jsonl` (presses), `.push/subscriptions.json` and `.push/cursor.json` (how far each inbox was pushed, so a restart doesn't push the backlog), and the VAPID key unless `vapidFile` says otherwise. It never rewrites `inbox.jsonl`.
|
package/client.actions.js
CHANGED
|
@@ -4,13 +4,23 @@
|
|
|
4
4
|
*
|
|
5
5
|
* A DSH client chunk: dsh-card-board's client loads it with
|
|
6
6
|
* `require.async('./client.actions.js')`. Another plugin can ship a copy as
|
|
7
|
-
* its own `client.actions.js`, changing OWNER below to its package name
|
|
8
|
-
*
|
|
7
|
+
* its own `client.actions.js`, changing OWNER below to its package name.
|
|
8
|
+
*
|
|
9
|
+
* DSH runs a chunk as a classic script, so everything sits inside one function
|
|
10
|
+
* (a top-level `const` would clash with another plugin's copy and the second
|
|
11
|
+
* chunk would never register).
|
|
9
12
|
*
|
|
10
13
|
* const { createActions } = await require.async('./client.actions.js')
|
|
11
|
-
* const ui = createActions({ React, ctx,
|
|
14
|
+
* const ui = createActions({ React, ctx, t, press })
|
|
12
15
|
* h(ui.ActionBar, { actions, states, chat, onPress })
|
|
13
16
|
*
|
|
17
|
+
* `t(key, params)` gives the words in the person's language; the host plugin
|
|
18
|
+
* keeps them in its one message table. The keys it must know are exported as
|
|
19
|
+
* `KEYS`: chat, chatAbout, done, snooze, event, link, in3h, tomorrow, pick,
|
|
20
|
+
* set, cancel, sending, pending, handled, unhandled, failed ({message}),
|
|
21
|
+
* noWorkspace. `t` is called while rendering, so a language switch shows up
|
|
22
|
+
* without building the buttons again.
|
|
23
|
+
*
|
|
14
24
|
* `press(action, extra)` is the plugin's own server call for done, snooze and
|
|
15
25
|
* event (extra carries `until` for a snooze); it should resolve once the
|
|
16
26
|
* server has accepted the press. `chat` and `link` never reach the server:
|
|
@@ -18,65 +28,37 @@
|
|
|
18
28
|
* UI's own workspace service (so the person sends it themselves, signed in as
|
|
19
29
|
* themselves), and link opens the URL.
|
|
20
30
|
*/
|
|
31
|
+
(() => {
|
|
21
32
|
const OWNER = '@soffits/dsh-notify-inbox'
|
|
22
33
|
|
|
23
|
-
const
|
|
24
|
-
en: {
|
|
25
|
-
chat: 'Ask',
|
|
26
|
-
chatAbout: 'Chat about this',
|
|
27
|
-
done: 'Done',
|
|
28
|
-
snooze: 'Snooze',
|
|
29
|
-
open: 'Open',
|
|
30
|
-
in3h: 'In 3 hours',
|
|
31
|
-
tomorrow: 'Tomorrow 9:00',
|
|
32
|
-
pick: 'Pick a time…',
|
|
33
|
-
set: 'Snooze',
|
|
34
|
-
cancel: 'Cancel',
|
|
35
|
-
sending: 'Sending…',
|
|
36
|
-
pending: 'Waiting for it to be picked up',
|
|
37
|
-
handled: 'Done',
|
|
38
|
-
unhandled: 'Nothing picked this up yet',
|
|
39
|
-
failed: 'Didn’t go through: {message}',
|
|
40
|
-
noWorkspace: 'Open a conversation once first, then try again.',
|
|
41
|
-
},
|
|
42
|
-
zh: {
|
|
43
|
-
chat: '问问',
|
|
44
|
-
chatAbout: '聊聊这个',
|
|
45
|
-
done: '完成',
|
|
46
|
-
snooze: '稍后提醒',
|
|
47
|
-
open: '打开',
|
|
48
|
-
in3h: '3 小时后',
|
|
49
|
-
tomorrow: '明天 9:00',
|
|
50
|
-
pick: '选个时间…',
|
|
51
|
-
set: '稍后提醒',
|
|
52
|
-
cancel: '取消',
|
|
53
|
-
sending: '发送中…',
|
|
54
|
-
pending: '等待处理',
|
|
55
|
-
handled: '已处理',
|
|
56
|
-
unhandled: '还没有被处理',
|
|
57
|
-
failed: '没有成功:{message}',
|
|
58
|
-
noWorkspace: '请先打开一次对话,再试一次。',
|
|
59
|
-
},
|
|
60
|
-
}
|
|
34
|
+
const KEYS = ['chat', 'chatAbout', 'done', 'snooze', 'event', 'link', 'in3h', 'tomorrow', 'pick', 'set', 'cancel', 'sending', 'pending', 'handled', 'unhandled', 'failed', 'noWorkspace']
|
|
61
35
|
|
|
62
36
|
const CSS = `
|
|
63
|
-
.ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
64
|
-
.ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;gap:
|
|
37
|
+
.ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center;min-width:0}
|
|
38
|
+
.ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;max-width:100%;padding:0 12px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;text-decoration:none;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3)}
|
|
39
|
+
.ua-btn span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
65
40
|
.ua-btn svg{flex:none;width:14px;height:14px}
|
|
66
41
|
.ua-btn:disabled{cursor:default;opacity:.7}
|
|
67
42
|
@media (hover:hover){.ua-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
68
|
-
.ua-icon{width:
|
|
43
|
+
.ua-icon{width:32px;padding:0;box-shadow:none;color:var(--dsw-alias-label-tertiary)}
|
|
69
44
|
.ua-btn[data-state=pending] svg,.ua-btn[data-state=sending] svg{animation:ua-pulse 1.2s ease-in-out infinite}
|
|
70
45
|
.ua-btn[data-state=done]{color:var(--dsw-alias-state-success-primary)}
|
|
71
46
|
.ua-btn[data-state=unhandled]{color:var(--dsw-alias-state-warn-label,var(--dsw-alias-state-warn-primary))}
|
|
72
47
|
@keyframes ua-pulse{50%{opacity:.35}}
|
|
73
|
-
.ua-wrap{position:relative;display:inline-flex}
|
|
48
|
+
.ua-wrap{position:relative;display:inline-flex;max-width:100%;flex-wrap:wrap;align-items:center;gap:4px 8px}
|
|
74
49
|
.ua-menu{position:absolute;z-index:20;top:calc(100% + 4px);right:0;min-width:168px;padding:4px;border-radius:12px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-base));box-shadow:0 6px 24px #0000001f,inset 0 0 0 .5px var(--dsw-alias-border-l2);display:flex;flex-direction:column}
|
|
75
|
-
.ua-menu button{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
50
|
+
.ua-menu button{display:flex;align-items:center;gap:8px;min-height:36px;padding:7px 10px;border:0;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
76
51
|
@media (hover:hover){.ua-menu button:hover{background:var(--dsw-alias-interactive-bg-hover)}}
|
|
77
|
-
.ua-menu input{margin:4px 6px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:
|
|
52
|
+
.ua-menu input{margin:4px 6px;min-height:36px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:16px}
|
|
78
53
|
.ua-menuRow{display:flex;justify-content:flex-end;gap:4px;padding:2px 4px}
|
|
79
|
-
.ua-error{color:var(--dsw-alias-state-error-primary);font-size:12px}
|
|
54
|
+
.ua-error{flex-basis:100%;color:var(--dsw-alias-state-error-primary);font-size:12px;overflow-wrap:anywhere}
|
|
55
|
+
@media (width<=768px),(pointer:coarse){
|
|
56
|
+
.ua-btn{min-height:40px}
|
|
57
|
+
.ua-icon{width:40px}
|
|
58
|
+
.ua-menu{position:fixed;z-index:1000;top:auto;left:12px;right:12px;bottom:12px;max-height:60vh;overflow:auto;padding:8px;box-shadow:0 8px 40px #00000040,inset 0 0 0 .5px var(--dsw-alias-border-l2)}
|
|
59
|
+
.ua-menu button{min-height:44px;font-size:15px}
|
|
60
|
+
.ua-menu input{min-height:44px}
|
|
61
|
+
}
|
|
80
62
|
`
|
|
81
63
|
|
|
82
64
|
const ICONS = {
|
|
@@ -89,10 +71,6 @@ const ICONS = {
|
|
|
89
71
|
unhandled: 'M8 3.5v5.5M8 12v.5',
|
|
90
72
|
}
|
|
91
73
|
|
|
92
|
-
function fill(text, params) {
|
|
93
|
-
return String(text).replace(/\{(\w+)\}/g, (match, key) => (key in params ? String(params[key]) : match))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
74
|
/** The next 09:00 after now, as an ISO string. */
|
|
97
75
|
function tomorrowMorning(now = new Date()) {
|
|
98
76
|
const date = new Date(now)
|
|
@@ -117,14 +95,12 @@ function chatText({ prompt = '', title, lines = [], context }) {
|
|
|
117
95
|
* @param {object} options
|
|
118
96
|
* @param {object} options.React - the page's React
|
|
119
97
|
* @param {object} options.ctx - the plugin's client context (ctx.get reaches the Web UI's services)
|
|
120
|
-
* @param {string}
|
|
98
|
+
* @param {(key: string, params?: object) => string} options.t - the words in the person's language, one of KEYS
|
|
121
99
|
* @param {(action: object, extra: object) => Promise<unknown>} [options.press] - the server call for done, snooze and event
|
|
122
100
|
*/
|
|
123
|
-
function createActions({ React, ctx,
|
|
101
|
+
function createActions({ React, ctx, t, press }) {
|
|
124
102
|
const h = React.createElement
|
|
125
103
|
const { useState, useEffect, useRef } = React
|
|
126
|
-
const words = WORDS[String(locale).toLowerCase().startsWith('zh') ? 'zh' : 'en']
|
|
127
|
-
const t = key => words[key] ?? WORDS.en[key] ?? key
|
|
128
104
|
|
|
129
105
|
if (typeof document !== 'undefined' && !document.getElementById('dsh-actions-ui-style')) {
|
|
130
106
|
const style = document.createElement('style')
|
|
@@ -197,7 +173,7 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
197
173
|
const [menu, setMenu] = useState(false)
|
|
198
174
|
useEffect(() => { if (state) setLocal(null) }, [state])
|
|
199
175
|
const shown = local ?? state
|
|
200
|
-
const label = action.label ?? t(action.kind
|
|
176
|
+
const label = action.label ?? t(action.kind)
|
|
201
177
|
const title = shown === 'sending' ? t('sending') : shown === 'pending' ? t('pending') : shown === 'done' ? t('handled') : shown === 'unhandled' ? t('unhandled') : error ?? label
|
|
202
178
|
const icon = shown === 'done' ? 'done' : shown === 'unhandled' ? 'unhandled' : action.kind
|
|
203
179
|
const className = `ua-btn${compact ? ' ua-icon' : ''}`
|
|
@@ -222,7 +198,7 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
222
198
|
}
|
|
223
199
|
} catch (reason) {
|
|
224
200
|
setLocal(null)
|
|
225
|
-
setError(
|
|
201
|
+
setError(t('failed', { message: reason?.message ?? String(reason) }))
|
|
226
202
|
}
|
|
227
203
|
}
|
|
228
204
|
const onClick = () => {
|
|
@@ -254,4 +230,5 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
254
230
|
return { ActionBar, ActionButton, Icon, startChat, chatText, t }
|
|
255
231
|
}
|
|
256
232
|
|
|
257
|
-
window.__ModuleLoader__.load({ id: OWNER, chunk: 'client.actions.js', factory: () => ({ createActions, chatText }) })
|
|
233
|
+
window.__ModuleLoader__.load({ id: OWNER, chunk: 'client.actions.js', factory: () => ({ createActions, chatText, KEYS }) })
|
|
234
|
+
})()
|
package/client.js
CHANGED
|
@@ -13,7 +13,7 @@ window.__ModuleLoader__.load({
|
|
|
13
13
|
factory(require) {
|
|
14
14
|
const React = require('react')
|
|
15
15
|
const h = React.createElement
|
|
16
|
-
const { useState, useEffect, useCallback, useSyncExternalStore } = React
|
|
16
|
+
const { useState, useEffect, useCallback, useRef, useSyncExternalStore } = React
|
|
17
17
|
|
|
18
18
|
const NS = 'dsh-notify-inbox'
|
|
19
19
|
const PANEL = 'dsh-notify-inbox'
|
|
@@ -22,71 +22,6 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
const PENDING_MS = 2 * 60 * 1000
|
|
23
23
|
const api = path => new URL(`api/notify-inbox/${path}`, document.baseURI).href
|
|
24
24
|
|
|
25
|
-
const en = {
|
|
26
|
-
panel: 'Inbox',
|
|
27
|
-
title: 'Inbox',
|
|
28
|
-
'filter.unread': 'Unread',
|
|
29
|
-
'filter.all': 'All',
|
|
30
|
-
'markAll': 'Mark all read',
|
|
31
|
-
'empty.unread': 'Nothing unread.',
|
|
32
|
-
'empty.all': 'No notifications yet.',
|
|
33
|
-
'loadMore': 'Show older',
|
|
34
|
-
'urgent': 'Urgent',
|
|
35
|
-
'test': 'Test',
|
|
36
|
-
'alsoSent': 'Also sent to',
|
|
37
|
-
'notSent': 'Not sent anywhere else',
|
|
38
|
-
'files': 'Attachments',
|
|
39
|
-
'notStored': 'not kept: {reason}',
|
|
40
|
-
'press.pending': 'Sent, waiting…',
|
|
41
|
-
'press.unhandled': 'Nobody picked this up yet',
|
|
42
|
-
'press.done': 'Marked done',
|
|
43
|
-
'press.snoozed': 'Will remind you {time}',
|
|
44
|
-
'push.title': 'Notifications on this device',
|
|
45
|
-
'push.on': 'On',
|
|
46
|
-
'push.off': 'Off',
|
|
47
|
-
'push.enable': 'Turn on',
|
|
48
|
-
'push.disable': 'Turn off',
|
|
49
|
-
'push.test': 'Send a test',
|
|
50
|
-
'push.testSent': 'Test sent to {n} device(s).',
|
|
51
|
-
'push.denied': 'Notifications are blocked for this site in the browser settings.',
|
|
52
|
-
'push.unsupported': 'This browser can’t receive push notifications here.',
|
|
53
|
-
'push.ios': 'On iPhone or iPad, add this site to the Home Screen and open it from there to turn notifications on.',
|
|
54
|
-
'error': 'Couldn’t load: {message}',
|
|
55
|
-
'time.locale': 'en-US',
|
|
56
|
-
}
|
|
57
|
-
const zh = {
|
|
58
|
-
panel: '收件箱',
|
|
59
|
-
title: '收件箱',
|
|
60
|
-
'filter.unread': '未读',
|
|
61
|
-
'filter.all': '全部',
|
|
62
|
-
'markAll': '全部已读',
|
|
63
|
-
'empty.unread': '没有未读通知。',
|
|
64
|
-
'empty.all': '还没有通知。',
|
|
65
|
-
'loadMore': '更早的',
|
|
66
|
-
'urgent': '紧急',
|
|
67
|
-
'test': '测试',
|
|
68
|
-
'alsoSent': '同时发到',
|
|
69
|
-
'notSent': '没有发到别处',
|
|
70
|
-
'files': '附件',
|
|
71
|
-
'notStored': '未保存:{reason}',
|
|
72
|
-
'press.pending': '已发出,等待处理…',
|
|
73
|
-
'press.unhandled': '暂时没有人处理',
|
|
74
|
-
'press.done': '已标为完成',
|
|
75
|
-
'press.snoozed': '会在{time}再提醒',
|
|
76
|
-
'push.title': '本设备的通知',
|
|
77
|
-
'push.on': '已开启',
|
|
78
|
-
'push.off': '未开启',
|
|
79
|
-
'push.enable': '开启',
|
|
80
|
-
'push.disable': '关闭',
|
|
81
|
-
'push.test': '发一条测试',
|
|
82
|
-
'push.testSent': '测试已发到 {n} 台设备。',
|
|
83
|
-
'push.denied': '浏览器设置里禁止了这个网站的通知。',
|
|
84
|
-
'push.unsupported': '这个浏览器在这里收不到推送通知。',
|
|
85
|
-
'push.ios': 'iPhone 或 iPad 上,先把这个网站添加到主屏幕,再从主屏幕打开,才能开启通知。',
|
|
86
|
-
'error': '加载失败:{message}',
|
|
87
|
-
'time.locale': 'zh-CN',
|
|
88
|
-
}
|
|
89
|
-
|
|
90
25
|
const CSS = `
|
|
91
26
|
.nib-page{width:100%;min-width:0;height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);font-size:14px;line-height:1.6}
|
|
92
27
|
.nib-scroll{flex:1;min-height:0;overflow:auto;scrollbar-gutter:stable}
|
|
@@ -137,6 +72,7 @@ window.__ModuleLoader__.load({
|
|
|
137
72
|
.nib-more{margin:12px auto 0;display:flex}
|
|
138
73
|
.nib-icon{position:relative;display:inline-flex}
|
|
139
74
|
.nib-badge{position:absolute;top:-5px;right:-8px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dsw-alias-state-error-primary);color:#fff;font-size:9px;font-weight:600;line-height:14px;text-align:center;pointer-events:none}
|
|
75
|
+
@media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
|
|
140
76
|
@media (width<=640px){.nib-content{padding-inline:12px}.nib-head{padding-top:16px}.nib-body{margin-left:0}.nib-item{padding:10px 8px}}
|
|
141
77
|
`
|
|
142
78
|
|
|
@@ -284,7 +220,7 @@ window.__ModuleLoader__.load({
|
|
|
284
220
|
const ua = navigator.userAgent
|
|
285
221
|
const os = /iPhone|iPad/.test(ua) ? 'iOS' : /Android/.test(ua) ? 'Android' : /Mac OS X/.test(ua) ? 'macOS' : /Windows/.test(ua) ? 'Windows' : /Linux/.test(ua) ? 'Linux' : ''
|
|
286
222
|
const browser = /Edg\//.test(ua) ? 'Edge' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Browser'
|
|
287
|
-
return [browser, os].filter(Boolean).join('
|
|
223
|
+
return [browser, os].filter(Boolean).join(' · ')
|
|
288
224
|
}
|
|
289
225
|
|
|
290
226
|
async function currentSubscription() {
|
|
@@ -346,7 +282,7 @@ window.__ModuleLoader__.load({
|
|
|
346
282
|
setState('off')
|
|
347
283
|
})
|
|
348
284
|
const test = run(async () => {
|
|
349
|
-
const result = await call('push/test', {})
|
|
285
|
+
const result = await call('push/test', { title: t('push.testTitle'), body: t('push.testBody') })
|
|
350
286
|
setNote(t('push.testSent', { n: result.sent }))
|
|
351
287
|
})
|
|
352
288
|
return h('div', { className: 'nib-push' },
|
|
@@ -368,10 +304,12 @@ window.__ModuleLoader__.load({
|
|
|
368
304
|
const [more, setMore] = useState(false)
|
|
369
305
|
const [error, setError] = useState(null)
|
|
370
306
|
const [open, setOpen] = useState(() => shared.linked)
|
|
307
|
+
const openRef = useRef(open)
|
|
308
|
+
openRef.current = open
|
|
371
309
|
const [ui, setUi] = useState(null)
|
|
372
310
|
useEffect(() => {
|
|
373
311
|
let live = true
|
|
374
|
-
makeActions(
|
|
312
|
+
makeActions().then(made => { if (live) setUi(made) }, reason => { console.warn('notify-inbox: buttons unavailable', reason) })
|
|
375
313
|
return () => { live = false }
|
|
376
314
|
}, [])
|
|
377
315
|
|
|
@@ -381,7 +319,15 @@ window.__ModuleLoader__.load({
|
|
|
381
319
|
if (filter === 'unread') params.set('unread', '1')
|
|
382
320
|
if (append && items?.length) params.set('before', items[items.length - 1].id)
|
|
383
321
|
const page = await call(`items?${params}`)
|
|
384
|
-
setItems(previous =>
|
|
322
|
+
setItems(previous => {
|
|
323
|
+
if (append && previous) return [...previous, ...page.items]
|
|
324
|
+
// The open item stays where it was even when it no longer matches the filter (opening marks it read).
|
|
325
|
+
const kept = previous?.findIndex(row => row.id === openRef.current) ?? -1
|
|
326
|
+
if (kept < 0 || page.items.some(row => row.id === openRef.current)) return page.items
|
|
327
|
+
const next = [...page.items]
|
|
328
|
+
next.splice(Math.min(kept, next.length), 0, { ...previous[kept], read: true })
|
|
329
|
+
return next
|
|
330
|
+
})
|
|
385
331
|
setMore(page.more)
|
|
386
332
|
setError(null)
|
|
387
333
|
} catch (reason) {
|
|
@@ -438,9 +384,15 @@ window.__ModuleLoader__.load({
|
|
|
438
384
|
return {
|
|
439
385
|
inject: ['slots', 'locale'],
|
|
440
386
|
apply(ctx) {
|
|
387
|
+
// The words come from the plugin's locale/<tag>.json files, served complete per tag.
|
|
441
388
|
ctx.effect(() => {
|
|
442
|
-
|
|
443
|
-
|
|
389
|
+
let disposers = []
|
|
390
|
+
let live = true
|
|
391
|
+
call('strings').then(({ tables }) => {
|
|
392
|
+
if (!live) return
|
|
393
|
+
disposers = Object.entries(tables).map(([tag, table]) => ctx.locale.register(NS, tag, table))
|
|
394
|
+
}, reason => console.warn('notify-inbox: words unavailable', reason))
|
|
395
|
+
return () => { live = false; for (const dispose of disposers) dispose() }
|
|
444
396
|
}, 'notify-inbox: dictionaries')
|
|
445
397
|
const t = ctx.locale.bind(NS)
|
|
446
398
|
|
|
@@ -453,7 +405,7 @@ window.__ModuleLoader__.load({
|
|
|
453
405
|
return () => tag.remove()
|
|
454
406
|
}, 'notify-inbox: styles')
|
|
455
407
|
|
|
456
|
-
const makeActions =
|
|
408
|
+
const makeActions = () => loadActions().then(module => module.createActions({ React, ctx, t: (key, params) => t(`action.${key}`, params) }))
|
|
457
409
|
|
|
458
410
|
ctx.slots.inject('main', () => ctx.slots.register({
|
|
459
411
|
name: 'main',
|
package/index.js
CHANGED
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
import { readFileSync } from 'node:fs'
|
|
12
12
|
import { homedir } from 'node:os'
|
|
13
13
|
import { isAbsolute, join, resolve } from 'node:path'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
14
15
|
import z from '@deepseek-ai/schemastery'
|
|
15
16
|
import { createPeople, expandHome } from './src/access.js'
|
|
16
17
|
import { createActions } from './src/actions.js'
|
|
17
18
|
import { createPush } from './src/push.js'
|
|
18
19
|
import { createRoutes } from './src/routes.js'
|
|
19
20
|
import { createStore } from './src/store.js'
|
|
21
|
+
import { readLocales, tables } from './src/locales.js'
|
|
20
22
|
|
|
21
23
|
export const name = 'dsh-notify-inbox'
|
|
22
24
|
export const inject = ['connection']
|
|
@@ -68,7 +70,8 @@ export function apply(ctx, config) {
|
|
|
68
70
|
})
|
|
69
71
|
const actions = createActions({ dataDir, events: () => ctx.get('cronJobs'), warn })
|
|
70
72
|
const pollSeconds = config.pollSeconds ?? 5
|
|
71
|
-
const
|
|
73
|
+
const strings = readLocales(fileURLToPath(new URL('./locale/', import.meta.url))).then(tables)
|
|
74
|
+
const routes = createRoutes({ store, people, push, actions, identity: () => ctx.get('requestIdentity'), serviceWorker, strings: () => strings, pollSeconds: Math.max(pollSeconds, 15) })
|
|
72
75
|
for (const route of routes) ctx.connection.fetch.register(route)
|
|
73
76
|
|
|
74
77
|
let stopped = false
|
package/locale/en.json
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Notification Inbox",
|
|
4
|
+
"description": "One inbox for the notifications your assistant and scripts send: read and unread per person, Web Push to phones and browsers, and buttons to act on each one."
|
|
5
|
+
},
|
|
6
|
+
"ui": {
|
|
7
|
+
"panel": "Inbox",
|
|
8
|
+
"title": "Inbox",
|
|
9
|
+
"filter.unread": "Unread",
|
|
10
|
+
"filter.all": "All",
|
|
11
|
+
"markAll": "Mark all read",
|
|
12
|
+
"empty.unread": "Nothing unread.",
|
|
13
|
+
"empty.all": "No notifications yet.",
|
|
14
|
+
"loadMore": "Show older",
|
|
15
|
+
"urgent": "Urgent",
|
|
16
|
+
"test": "Test",
|
|
17
|
+
"alsoSent": "Also sent to",
|
|
18
|
+
"notSent": "Not sent anywhere else",
|
|
19
|
+
"files": "Attachments",
|
|
20
|
+
"notStored": "not kept: {reason}",
|
|
21
|
+
"press.pending": "Sent, waiting…",
|
|
22
|
+
"press.unhandled": "Nobody picked this up yet",
|
|
23
|
+
"press.done": "Marked done",
|
|
24
|
+
"press.snoozed": "Will remind you {time}",
|
|
25
|
+
"push.title": "Notifications on this device",
|
|
26
|
+
"push.on": "On",
|
|
27
|
+
"push.off": "Off",
|
|
28
|
+
"push.enable": "Turn on",
|
|
29
|
+
"push.disable": "Turn off",
|
|
30
|
+
"push.test": "Send a test",
|
|
31
|
+
"push.testSent": "Test sent to {n} device(s).",
|
|
32
|
+
"push.denied": "Notifications are blocked for this site in the browser settings.",
|
|
33
|
+
"push.unsupported": "This browser can’t receive push notifications here.",
|
|
34
|
+
"push.ios": "On iPhone or iPad, add this site to the Home Screen and open it from there to turn notifications on.",
|
|
35
|
+
"error": "Couldn’t load: {message}",
|
|
36
|
+
"time.locale": "en-US",
|
|
37
|
+
"action.chat": "Ask",
|
|
38
|
+
"action.chatAbout": "Chat about this",
|
|
39
|
+
"action.done": "Done",
|
|
40
|
+
"action.snooze": "Snooze",
|
|
41
|
+
"action.event": "Go",
|
|
42
|
+
"action.link": "Open",
|
|
43
|
+
"action.in3h": "In 3 hours",
|
|
44
|
+
"action.tomorrow": "Tomorrow 9:00",
|
|
45
|
+
"action.pick": "Pick a time…",
|
|
46
|
+
"action.set": "Snooze",
|
|
47
|
+
"action.cancel": "Cancel",
|
|
48
|
+
"action.sending": "Sending…",
|
|
49
|
+
"action.pending": "Waiting for it to be picked up",
|
|
50
|
+
"action.handled": "Done",
|
|
51
|
+
"action.unhandled": "Nothing picked this up yet",
|
|
52
|
+
"action.failed": "Didn’t go through: {message}",
|
|
53
|
+
"action.noWorkspace": "Open a conversation once first, then try again.",
|
|
54
|
+
"push.testTitle": "Inbox",
|
|
55
|
+
"push.testBody": "Notifications reach this device."
|
|
56
|
+
}
|
|
57
|
+
}
|
package/locale/fr.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Boîte de notifications",
|
|
4
|
+
"description": "Toutes les notifications de votre assistant et de vos scripts au même endroit : lues et non lues par personne, notifications push sur téléphone et navigateur, et des boutons pour agir sur chacune."
|
|
5
|
+
},
|
|
6
|
+
"ui": {
|
|
7
|
+
"panel": "Notifications",
|
|
8
|
+
"title": "Notifications",
|
|
9
|
+
"filter.unread": "Non lues",
|
|
10
|
+
"filter.all": "Toutes",
|
|
11
|
+
"markAll": "Tout marquer comme lu",
|
|
12
|
+
"empty.unread": "Rien de non lu.",
|
|
13
|
+
"empty.all": "Pas encore de notifications.",
|
|
14
|
+
"loadMore": "Plus anciennes",
|
|
15
|
+
"urgent": "Urgent",
|
|
16
|
+
"test": "Test",
|
|
17
|
+
"alsoSent": "Aussi envoyé à",
|
|
18
|
+
"notSent": "Envoyé nulle part ailleurs",
|
|
19
|
+
"files": "Pièces jointes",
|
|
20
|
+
"notStored": "non conservé : {reason}",
|
|
21
|
+
"press.pending": "Envoyé, en attente…",
|
|
22
|
+
"press.unhandled": "Personne ne l’a encore pris en charge",
|
|
23
|
+
"press.done": "Marqué comme fait",
|
|
24
|
+
"press.snoozed": "Rappel {time}",
|
|
25
|
+
"push.title": "Notifications sur cet appareil",
|
|
26
|
+
"push.on": "Activées",
|
|
27
|
+
"push.off": "Désactivées",
|
|
28
|
+
"push.enable": "Activer",
|
|
29
|
+
"push.disable": "Désactiver",
|
|
30
|
+
"push.test": "Envoyer un test",
|
|
31
|
+
"push.testSent": "Test envoyé à {n} appareil(s).",
|
|
32
|
+
"push.denied": "Les notifications de ce site sont bloquées dans les réglages du navigateur.",
|
|
33
|
+
"push.unsupported": "Ce navigateur ne peut pas recevoir de notifications ici.",
|
|
34
|
+
"push.ios": "Sur iPhone ou iPad, ajoutez ce site à l’écran d’accueil et ouvrez-le depuis là pour activer les notifications.",
|
|
35
|
+
"error": "Chargement impossible : {message}",
|
|
36
|
+
"time.locale": "fr-FR",
|
|
37
|
+
"action.chat": "Demander",
|
|
38
|
+
"action.chatAbout": "En discuter",
|
|
39
|
+
"action.done": "Fait",
|
|
40
|
+
"action.snooze": "Plus tard",
|
|
41
|
+
"action.event": "Lancer",
|
|
42
|
+
"action.link": "Ouvrir",
|
|
43
|
+
"action.in3h": "Dans 3 heures",
|
|
44
|
+
"action.tomorrow": "Demain 9:00",
|
|
45
|
+
"action.pick": "Choisir une heure…",
|
|
46
|
+
"action.set": "Rappeler",
|
|
47
|
+
"action.cancel": "Annuler",
|
|
48
|
+
"action.sending": "Envoi…",
|
|
49
|
+
"action.pending": "En attente de traitement",
|
|
50
|
+
"action.handled": "Fait",
|
|
51
|
+
"action.unhandled": "Personne ne l’a encore pris en charge",
|
|
52
|
+
"action.failed": "Échec : {message}",
|
|
53
|
+
"action.noWorkspace": "Ouvrez d’abord une conversation, puis réessayez.",
|
|
54
|
+
"push.testTitle": "Notifications",
|
|
55
|
+
"push.testBody": "Les notifications arrivent sur cet appareil."
|
|
56
|
+
}
|
|
57
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "通知收件箱",
|
|
4
|
+
"description": "助手和脚本发出的通知都收在这里:每个人各看各的、分已读未读,推送到手机和浏览器,每条通知都能直接操作。"
|
|
5
|
+
},
|
|
6
|
+
"ui": {
|
|
7
|
+
"panel": "收件箱",
|
|
8
|
+
"title": "收件箱",
|
|
9
|
+
"filter.unread": "未读",
|
|
10
|
+
"filter.all": "全部",
|
|
11
|
+
"markAll": "全部已读",
|
|
12
|
+
"empty.unread": "没有未读通知。",
|
|
13
|
+
"empty.all": "还没有通知。",
|
|
14
|
+
"loadMore": "更早的",
|
|
15
|
+
"urgent": "紧急",
|
|
16
|
+
"test": "测试",
|
|
17
|
+
"alsoSent": "同时发到",
|
|
18
|
+
"notSent": "没有发到别处",
|
|
19
|
+
"files": "附件",
|
|
20
|
+
"notStored": "未保存:{reason}",
|
|
21
|
+
"press.pending": "已发出,等待处理…",
|
|
22
|
+
"press.unhandled": "暂时没有人处理",
|
|
23
|
+
"press.done": "已标为完成",
|
|
24
|
+
"press.snoozed": "会在{time}再提醒",
|
|
25
|
+
"push.title": "本设备的通知",
|
|
26
|
+
"push.on": "已开启",
|
|
27
|
+
"push.off": "未开启",
|
|
28
|
+
"push.enable": "开启",
|
|
29
|
+
"push.disable": "关闭",
|
|
30
|
+
"push.test": "发一条测试",
|
|
31
|
+
"push.testSent": "测试已发到 {n} 台设备。",
|
|
32
|
+
"push.denied": "浏览器设置里禁止了这个网站的通知。",
|
|
33
|
+
"push.unsupported": "这个浏览器在这里收不到推送通知。",
|
|
34
|
+
"push.ios": "iPhone 或 iPad 上,先把这个网站添加到主屏幕,再从主屏幕打开,才能开启通知。",
|
|
35
|
+
"error": "加载失败:{message}",
|
|
36
|
+
"time.locale": "zh-CN",
|
|
37
|
+
"action.chat": "问问",
|
|
38
|
+
"action.chatAbout": "聊聊这个",
|
|
39
|
+
"action.done": "完成",
|
|
40
|
+
"action.snooze": "稍后提醒",
|
|
41
|
+
"action.event": "执行",
|
|
42
|
+
"action.link": "打开",
|
|
43
|
+
"action.in3h": "3 小时后",
|
|
44
|
+
"action.tomorrow": "明天 9:00",
|
|
45
|
+
"action.pick": "选个时间…",
|
|
46
|
+
"action.set": "稍后提醒",
|
|
47
|
+
"action.cancel": "取消",
|
|
48
|
+
"action.sending": "发送中…",
|
|
49
|
+
"action.pending": "等待处理",
|
|
50
|
+
"action.handled": "已处理",
|
|
51
|
+
"action.unhandled": "还没有被处理",
|
|
52
|
+
"action.failed": "没有成功:{message}",
|
|
53
|
+
"action.noWorkspace": "请先打开一次对话,再试一次。",
|
|
54
|
+
"push.testTitle": "收件箱",
|
|
55
|
+
"push.testBody": "这台设备能收到通知了。"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-notify-inbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|
package/src/locales.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's words: one `locale/<tag>.json` per language, `{ meta, ui }`.
|
|
3
|
+
* Which languages exist is whatever files are there; adding one needs no code.
|
|
4
|
+
* Each table the page gets is complete: a key missing from `zh-CN` comes from
|
|
5
|
+
* `zh`, then from `en`.
|
|
6
|
+
*/
|
|
7
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
|
|
10
|
+
export const BASE = 'en'
|
|
11
|
+
const TAG = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/
|
|
12
|
+
|
|
13
|
+
/** `{ tag: ui }` for every `<tag>.json` in the folder with a `ui` object. */
|
|
14
|
+
export async function readLocales(dir) {
|
|
15
|
+
const out = {}
|
|
16
|
+
for (const name of (await readdir(dir)).sort()) {
|
|
17
|
+
const tag = name.replace(/\.json$/, '')
|
|
18
|
+
if (tag === name || !TAG.test(tag)) continue
|
|
19
|
+
const value = JSON.parse(await readFile(join(dir, name), 'utf8'))
|
|
20
|
+
if (typeof value?.ui === 'object' && value.ui !== null) out[tag] = value.ui
|
|
21
|
+
}
|
|
22
|
+
return out
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const primary = tag => tag.split('-')[0]
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Complete tables by tag: exact tag, then its primary subtag, then the base
|
|
29
|
+
* language. A regional file without its primary one also answers for the
|
|
30
|
+
* primary tag, so `zh-CN.json` alone serves a page set to `zh`.
|
|
31
|
+
*/
|
|
32
|
+
export function tables(locales) {
|
|
33
|
+
const base = locales[BASE] ?? {}
|
|
34
|
+
const out = {}
|
|
35
|
+
for (const tag of Object.keys(locales)) {
|
|
36
|
+
out[tag] = { ...base, ...(locales[primary(tag)] ?? {}), ...locales[tag] }
|
|
37
|
+
if (out[primary(tag)] === undefined && locales[primary(tag)] === undefined) out[primary(tag)] = out[tag]
|
|
38
|
+
}
|
|
39
|
+
return out
|
|
40
|
+
}
|
package/src/push.js
CHANGED
|
@@ -83,7 +83,7 @@ export function checkSubscription(value) {
|
|
|
83
83
|
|
|
84
84
|
/** The notification a record becomes: what the push service carries (encrypted) and the service worker shows. */
|
|
85
85
|
export function payloadOf(record) {
|
|
86
|
-
const title = record.title || record.spoken.slice(0, 60) ||
|
|
86
|
+
const title = record.title || record.spoken.slice(0, 60) || record.text.slice(0, 60) || record.domain
|
|
87
87
|
const body = record.spoken && record.spoken !== record.title ? record.spoken : record.text
|
|
88
88
|
return {
|
|
89
89
|
title: record.test ? `[test] ${title}` : title,
|
|
@@ -167,11 +167,11 @@ export function createPush({ dataDir, vapidFile, subject, perPerson, warn, fetch
|
|
|
167
167
|
return { sent, removed: gone.length }
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
/** Push a test to the asking person's devices. */
|
|
171
|
-
function test(person) {
|
|
170
|
+
/** Push a test, in the words the asking page sends, to the asking person's devices. */
|
|
171
|
+
function test(person, { title, body }) {
|
|
172
172
|
return serial(async () => {
|
|
173
173
|
const subs = (await subscriptions()).filter(sub => (sub.person ?? null) === (person ?? null))
|
|
174
|
-
return deliver(subs, { title: '
|
|
174
|
+
return deliver(subs, { title: String(title ?? '').slice(0, 80), body: String(body ?? '').slice(0, BODY_LIMIT), tag: 'notify-inbox-test', url: './?notify-inbox=', urgent: false }, false)
|
|
175
175
|
})
|
|
176
176
|
}
|
|
177
177
|
|
package/src/routes.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* POST /api/notify-inbox/push/subscribe { subscription, label }
|
|
14
14
|
* POST /api/notify-inbox/push/unsubscribe { endpoint }
|
|
15
15
|
* POST /api/notify-inbox/push/test
|
|
16
|
+
* GET /api/notify-inbox/strings the page's words by language tag (src/locales.js)
|
|
16
17
|
* GET /api/notify-inbox/sw.js the service worker (scope /api/notify-inbox/)
|
|
17
18
|
*/
|
|
18
19
|
import { readFile } from 'node:fs/promises'
|
|
@@ -58,9 +59,10 @@ async function body(request) {
|
|
|
58
59
|
* @param {ReturnType<import('./actions.js').createActions>} options.actions
|
|
59
60
|
* @param {() => object | undefined} options.identity - the requestIdentity service right now, if any
|
|
60
61
|
* @param {string} options.serviceWorker - the service worker's source
|
|
62
|
+
* @param {() => Promise<Record<string, Record<string, string>>>} [options.strings] - the page's words, complete per tag
|
|
61
63
|
* @param {number} options.pollSeconds
|
|
62
64
|
*/
|
|
63
|
-
export function createRoutes({ store, people, push, actions, identity, serviceWorker, pollSeconds }) {
|
|
65
|
+
export function createRoutes({ store, people, push, actions, identity, serviceWorker, strings = async () => ({}), pollSeconds }) {
|
|
64
66
|
/** Who is asking, as the inbox folders they may read; undefined with the response to send instead. */
|
|
65
67
|
async function caller() {
|
|
66
68
|
const viewer = await viewerOf(people, identity())
|
|
@@ -181,7 +183,9 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
181
183
|
await push.unsubscribe(who.person, value.endpoint)
|
|
182
184
|
return json(200, { ok: true })
|
|
183
185
|
})
|
|
184
|
-
const pushTest = handle(async (
|
|
186
|
+
const pushTest = handle(async (request, who) => json(200, await push.test(who.person, await body(request))))
|
|
187
|
+
|
|
188
|
+
const words = async () => json(200, { tables: await strings() }, { 'cache-control': 'private, max-age=300' })
|
|
185
189
|
|
|
186
190
|
const worker = async () => new Response(serviceWorker, {
|
|
187
191
|
status: 200,
|
|
@@ -201,6 +205,7 @@ export function createRoutes({ store, people, push, actions, identity, serviceWo
|
|
|
201
205
|
post('/push/subscribe', subscribe),
|
|
202
206
|
post('/push/unsubscribe', unsubscribe),
|
|
203
207
|
post('/push/test', pushTest),
|
|
208
|
+
get('/strings', words),
|
|
204
209
|
get('/sw.js', worker),
|
|
205
210
|
]
|
|
206
211
|
}
|
package/src/sw.js
CHANGED
|
@@ -15,7 +15,7 @@ function payloadOf(event) {
|
|
|
15
15
|
} catch {
|
|
16
16
|
// An unreadable payload still shows something.
|
|
17
17
|
}
|
|
18
|
-
return { title:
|
|
18
|
+
return { title: self.location.host, body: '' }
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
self.addEventListener('push', event => {
|
|
@@ -31,7 +31,7 @@ self.addEventListener('push', event => {
|
|
|
31
31
|
options.tag = value.tag
|
|
32
32
|
options.renotify = true
|
|
33
33
|
}
|
|
34
|
-
event.waitUntil(self.registration.showNotification(typeof value.title === 'string' && value.title ? value.title :
|
|
34
|
+
event.waitUntil(self.registration.showNotification(typeof value.title === 'string' && value.title ? value.title : self.location.host, options))
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
self.addEventListener('notificationclick', event => {
|