cortico-world-bottle 0.6.0 → 0.7.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 +11 -0
- package/README.md +23 -4
- package/dist/{webui-521a0aabc302.css → webui-44dfed840fbe.css} +5 -0
- package/dist/{webui-3f345722d940.js → webui-57b469ed631e.js} +64 -21
- package/package.json +6 -5
- package/shared/contract.ts +5 -1
- package/world/appearance.ts +31 -4
- package/world/background.ts +33 -0
- package/world/card-host.ps1 +5 -2
- package/world/config.ts +33 -14
- package/world/default-font.ts +4 -0
- package/world/feedback.ts +19 -0
- package/world/font-catalog.ts +60 -0
- package/world/fonts/README.md +29 -0
- package/world/fonts/catalog.json +134 -0
- package/world/fonts/licenses/LXGWWenKaiMono-Medium-OFL.txt +98 -0
- package/world/fonts/licenses/NaikaiFont-Regular-2-OFL.txt +95 -0
- package/world/fonts/licenses/README.md +20 -0
- package/world/fonts/licenses/Yozai-Regular-OFL.txt +98 -0
- package/world/fonts/licenses//345/260/217/350/265/226/345/255/227/344/275/223 SC-OFL.txt" +98 -0
- package/world/fonts/licenses//346/270/205/346/235/276/346/211/213/345/206/231/344/275/2231-Regular-OFL.txt +96 -0
- package/world/fonts/licenses//346/270/205/346/235/276/346/211/213/345/206/231/344/275/2232-Regular-OFL.txt +96 -0
- package/world/fonts/licenses//346/270/205/346/235/276/346/211/213/345/206/231/344/275/2238-OFL.txt +93 -0
- package/world/fonts/licenses//346/270/205/346/235/276/346/211/213/345/206/231/344/275/2239-OFL.txt +93 -0
- package/world/fonts/licenses//351/232/217/345/263/260/344/275/223Plus-OFL.txt +94 -0
- package/world/fonts.ts +108 -0
- package/world/my-font.ts +29 -0
- package/world/page-announcement.ts +56 -0
- package/world/page-customization.ts +216 -0
- package/world/page-reader.ts +49 -0
- package/world/page-sound.ts +33 -15
- package/world/page-stationery.ts +54 -0
- package/world/page-style.ts +140 -40
- package/world/page-view.ts +123 -44
- package/world/page.ts +53 -7
- package/world/store.ts +14 -1
- package/world/theme.ts +4 -2
- package/world/wake-policy.ts +6 -0
- package/world/wake.ts +34 -14
- package/world/world.ts +98 -27
- package/dist/webui.css +0 -97
- package/dist/webui.js +0 -392
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.7.0 · 把每封信,好好展开
|
|
4
|
+
|
|
5
|
+
**大更新 · 2026-11-03**
|
|
6
|
+
|
|
7
|
+
- 信件换上新信纸和固定笔迹,正文、标题可一起调大,读信更舒服。
|
|
8
|
+
- 字体在线按需加载并缓存;可自选字体、主题色、背景图和透明度。
|
|
9
|
+
- 三类邀请可分别设置次数和间隔;有待处理来信时,每 30~60 分钟提醒,默认每天最多 12 次,没有来信时不打扰。
|
|
10
|
+
- 新来信和草稿自动移到眼前;修复空信箱误报待办、音效选择与播放不一致的问题。
|
|
11
|
+
- 反馈入口加入收集表、二维码和版本号;公告支持点击链接、按浏览器关闭。
|
|
12
|
+
- 精简安装包,排除旧构建和重复资源,不再附带整套字库。
|
|
13
|
+
|
|
3
14
|
## 0.6.0 · 把信箱带在身边
|
|
4
15
|
|
|
5
16
|
**2026-11-02**
|
package/README.md
CHANGED
|
@@ -24,9 +24,9 @@ Coo 写一封不超过 120 字的信。**寄不寄,由你决定**;别人家
|
|
|
24
24
|
- 信稿单独显示信题,「尚未寄出」只作为状态。只有主动写信带标题,无标题旧信稿显示「无题信」。回信只写正文,原信标题仅在折叠的原信中显示。
|
|
25
25
|
- 信箱和单封信可折叠,收起后仍显示收到与寄出的总量。收信总量为本机保存的捞取记录与收到的回信之和,不重复计算手里那封。轮询不会自动收起已展开的原信。
|
|
26
26
|
- 网页沿用暖色信纸风格,加入信封、邮戳、蜡封和轻量动画;系统开启减少动态效果时会停用动画。桌宠称呼读取 `ctx.botName || '它'`。
|
|
27
|
-
- 退潮时原样显示海边的提示,保留信稿、不新增寄出记录;等回潮后可以重试。公告只在打开的网页信箱中读取和显示,`alarm`
|
|
27
|
+
- 退潮时原样显示海边的提示,保留信稿、不新增寄出记录;等回潮后可以重试。公告只在打开的网页信箱中读取和显示,`alarm` 使用暖色强调,不再送进桌宠上下文。公告右侧可关闭:仅在当前浏览器记住,刷新或重开信箱仍隐藏(包括新公告),World 重启后恢复;其他设备独立显示。
|
|
28
28
|
|
|
29
|
-
写信与打捞仍由 Coo 自己决定。自动邀请要求可寄大于 1,或可捞和可回都大于 1
|
|
29
|
+
写信与打捞仍由 Coo 自己决定。自动邀请要求可寄大于 1,或可捞和可回都大于 1;有信稿、回信稿或待处理来信时不发起写信、打捞邀请;仅在手上仍有待处理来信时发出温和提醒,只给数量,不给正文。没有来信或只有草稿时不提醒。读信授权、人工请求、寄送或另一份任务进行中时不另起邀请。写信、打捞默认随机间隔 2—4 小时;最短间隔可在 2—24 小时调整,实际在最短间隔的 1—2 倍内随机,最长 24 小时,默认每天各最多 3 次(可设 1—24 次)。待办提醒默认随机间隔 30—60 分钟,每天最多 12 次(可设 3—20 次整数);提醒最短间隔可设 0.5—1 小时,实际不超过 1 小时。重试也计入每日上限;忙碌、读信授权或暂停期间会等待,不保证每小时必定发出。自动写信/打捞一轮没结果,30—60 分钟后只补试一次,仍没结果则当天停止。提醒不要求额外调用工具来记账,也不因为没行动就再催一次。
|
|
30
30
|
|
|
31
31
|
独立信箱网页的行动区下面有「海边的邀请 · 暂停与间隔」,扩展的「信箱」页签也有同一组设置:写信、打捞、待办提醒可分别暂停、恢复或调整间隔,并查看最近结果。Bot 可用 `bottle_wake_choice` 明确延后,`no_idea` / `not_now` 只需填写原因,自动对应当前邀请,即使旧模型误填了动作也不会误报失败;人的拒绝停止当天同类邀请,暂停持久保留。配置 `randomWake` 关闭所有自动邀请和提醒,但不拦截人主动点出的邀请。主动邀请只要求还有机会(大于 0),不受每天 3 次的自动限额限制,但仍尊重暂停/拒绝、有待办或正在忙等安全条件。主动邀请不自动重试。
|
|
32
32
|
|
|
@@ -81,7 +81,8 @@ Windows 卡片的新来信与回信使用不同的提示音,在 World「配置
|
|
|
81
81
|
| `worlds.bottle.lanEnabled` | 其他设备访问开关,默认关闭,修改后重启 World。 |
|
|
82
82
|
| `worlds.bottle.lanPort` | 独立对外端口,默认 7798;占用时报错,不自动顺延。 |
|
|
83
83
|
| `worlds.bottle.lanPublicUrl` | 可选对外地址;留空列出网卡地址,支持 HTTP/HTTPS 根路径,修改后重启 World。 |
|
|
84
|
-
| `worlds.bottle.randomWake` |
|
|
84
|
+
| `worlds.bottle.randomWake` | 自动海边邀请与待办提醒,默认开启;独立信箱和信箱页签可分别暂停、恢复或调整间隔与每日上限。 |
|
|
85
|
+
| `worlds.bottle.writeInviteDayLimit` / `catchInviteDayLimit` / `reminderDayLimit` | 写信、打捞邀请默认每天各 3 次,可设 1—24 次整数;待办提醒默认 12 次,可设 3—20 次整数,仅有待处理来信时触发;与各自最短间隔放在一起。自动补试计入上限,手动邀请不占上限,调整不会清零今天的次数。 |
|
|
85
86
|
| `worlds.bottle.cardAutoCloseSec` | 卡片自动收起秒数,默认 10,0 为不自动收起;下一张卡片生效。 |
|
|
86
87
|
| `worlds.bottle.soundEnabled` | Windows 新来信/回信提示音总开关,默认开启。 |
|
|
87
88
|
| `worlds.bottle.soundVolume` | 桌面提示音音量,0—100,默认 70。 |
|
|
@@ -95,6 +96,8 @@ Windows 卡片的新来信与回信使用不同的提示音,在 World「配置
|
|
|
95
96
|
|
|
96
97
|
新信标题通过可选的 `topic` 字段随信传递。服务端需同步更新代码并重启,无须新增环境变量或修改配置、迁移账本;旧客户端与无标题旧信仍兼容。旧服务端会忽略标题,导致对方收不到标题。更新前请按现有运维流程安排重启:服务器中的信件正文和标题只在内存里,重启会触发现有海啸机制。
|
|
97
98
|
|
|
99
|
+
未处理信件恢复:新客户端在放回请求失败时保留本地信与回信稿,避免海边仍占用、页面却已清空。打捞遇到已有占用时,会把原信恢复到信笺桌,不重复消耗打捞机会。旧服务端可通过尚存的本机信册恢复;若本地记录也已删除,需服务端同步此版 `/catch` 在 `holding` 响应中附带 `held` 元信息的支持。无需新增配置、环境变量或数据迁移,服务端重启仍应遵循现有海面清空流程。
|
|
100
|
+
|
|
98
101
|
## 已知边界
|
|
99
102
|
|
|
100
103
|
- 每天能寄、能捞、能回的封数都有上限,且随活跃度变化;页面上会写明还剩多少。
|
|
@@ -114,7 +117,7 @@ MIT。
|
|
|
114
117
|
|
|
115
118
|
面板源码位于 `webui/`。修改后运行 `pnpm typecheck:web && pnpm build:webui`;构建会生成 `dist/webui-<内容摘要>.js/.css`,并自动更新 `package.json` 的面板路径,发布前会自动重建。清单和生成产物必须一起提交;固定名文件仅保留兼容,不再作为新清单入口。
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
原来的「配置」页、扩展的「信箱」页签与独立网页共用三类邀请的开关、间隔与每日上限:写信/打捞最短间隔 2—24 小时,待办提醒最短间隔 0.5—1 小时(实际随机等待不超过 1 小时)。修改可直接生效(原配置页的后台检查最迟约一分钟,打开信箱会立即同步),不用重启 World;网页的恢复操作也会解除当天拒绝或失败暂停。升级前在信箱保存过的暂停和间隔会迁入新增配置项。
|
|
118
121
|
|
|
119
122
|
### 信箱配色与黑夜模式
|
|
120
123
|
|
|
@@ -137,3 +140,19 @@ MIT。
|
|
|
137
140
|
|
|
138
141
|
|
|
139
142
|
开发时更新面板后,除构建测试外,还需核对真实宿主:`pnpm check:running-webui -- http://127.0.0.1:<框架端口>`。若运行资源已更新但旧设置窗口仍看不到新卡片,刷新设置页;仅切换页签不会重新加载模块。若命令提示宿主仍登记旧资源,则完整重启 Coopanion 后再刷新。详见 [面板加载排查](docs/design/webui-loading.md)。
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### 信箱的字体、背景与颜色
|
|
146
|
+
|
|
147
|
+
- 信件正文默认 26px,左侧悬浮「Aa 字号」可展开滑条,在 18–40px 间实时调整,点击「默认」恢复。窄屏入口在左下角,调整后可再次点击入口或点外侧收起。字号影响信件正文、落款及信内标题(标题按正文的 1.16 倍同步缩放),不会放大页面标题、列表标题、状态或按钮;只保存在当前浏览器,手机与电脑可各自设置。种子信底部署名与同一作者的正文使用相同字体。
|
|
148
|
+
- 展开的来信、回信、草稿与引用原信采用完整信笺:纸纹、折痕、标题和落款随当前主题适配明暗模式,来信与自己的回信各占一页。状态和操作留在纸外,保留原文与换行,不添加称呼、祝语或回信标题。
|
|
149
|
+
|
|
150
|
+
- 右上角「信箱外观 → 个性化信箱」可选择主题色、上传背景图或恢复默认背景。自定义主题支持跟随系统/浅色/深色,按钮保留所选原色,文字单独调整对比度;桌面信笺同步主题色。背景仅用于网页信箱,支持 PNG、JPEG、WebP(最大 8 MB)。
|
|
151
|
+
- 外观保存在本机信箱,已配对的手机/平板重新打开页面也能加载,无需复制图片或安装字体。背景图片不会发送到漂流瓶远端服务或模型;文件保存在部署数据目录 `bottle-backgrounds`,选择记录在 `bottle-appearance.json`。恢复默认背景不会删除已上传的原图;不再使用的图片可在停用 World 后自行清理。
|
|
152
|
+
- 默认字库改由 R2 统一分发,安装包不再携带字体二进制;当前提供9款已审核 OFL 的全字符 WOFF2。字体按阅读需要加载并缓存在各自浏览器中;下载失败时先使用系统字体。宿主更新清单,已有发信人绑定和资源 ID 保持不变。
|
|
153
|
+
- 每位来信人会分到固定的笔迹,新字体只参与新来信人的分配。远程字库、映射字典与主动重洗方法见 [字体目录说明](world/fonts/README.md),网页不提供重洗按钮。
|
|
154
|
+
|
|
155
|
+
- 上传背景后,会出现「背景透明度」滑条(0% 最清晰,100% 完全淡出,默认 82%)。拖动实时预览,松手保存;恢复默认背景后滑条自动收起。
|
|
156
|
+
- 本地写信默认使用「霞鹜悠哉」,右上角外观菜单会显示当前笔迹。默认字体同样从远程字库加载并缓存在浏览器,不占安装包体积;用户导入自己的字体后优先使用自己的,点「恢复默认」换回霞鹜悠哉。更新不覆盖已有自定义选择。
|
|
157
|
+
- 「自定义我的字体」可导入 TTF、OTF、WOFF 或 WOFF2(最大 32 MB),覆盖本地信箱中 Coo 写的草稿、寄出记录、回信与引用原文,也包括正文里的信件标题;折叠列表和页面标题保持原字体。
|
|
158
|
+
- **我的字体仅在本地信箱生效,不会随信寄出,不影响收件人的展示。** 文件单独保存在部署数据 `bottle-my-fonts`,不会进入来信人的随机字体池;配对设备查看同一本地信箱时可加载。入口有预览与「恢复默认」,字体文件的选择记录保存在 `bottle-appearance.json`。恢复默认只解除选择,不自动删除已上传文件。
|
|
@@ -95,3 +95,8 @@
|
|
|
95
95
|
.bottle-lan-footer { padding: 16px 20px; }
|
|
96
96
|
}
|
|
97
97
|
@media (prefers-reduced-motion: reduce) { .bottle-lan-card *, .bottle-lan-qr { animation: none; transition: none; } }
|
|
98
|
+
|
|
99
|
+
.bottle-feedback { grid-column:1 / -1; justify-self:start; border:1px solid var(--line-2, #54483d); border-radius:10px; padding:10px 16px; background:var(--sheet, #25211f); color:var(--ink, #f2e6d6); cursor:pointer; transition:background .18s ease, border-color .18s ease; }
|
|
100
|
+
.bottle-feedback:hover:not(:disabled), .bottle-feedback:focus-visible { border-color:var(--accent, #d0a573); background:var(--sheet-hover, #40382f); }
|
|
101
|
+
.bottle-feedback:disabled { opacity:.6; cursor:default; }
|
|
102
|
+
@media (prefers-reduced-motion: reduce) { .bottle-feedback { transition:none; } }
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// This standalone browser bundle cannot import runtime modules. Bounds mirror wake-policy.ts;
|
|
2
|
+
// webui.test.js verifies the controls against that shared scheduler policy.
|
|
3
|
+
const WAKE_POLICIES = {
|
|
4
|
+
write: { interval: 2, minHours: 2, maxHours: 24, dayLimit: 3, minLimit: 1, maxLimit: 24 },
|
|
5
|
+
catch: { interval: 2, minHours: 2, maxHours: 24, dayLimit: 3, minLimit: 1, maxLimit: 24 },
|
|
6
|
+
remind: { interval: 0.5, minHours: 0.5, maxHours: 1, dayLimit: 12, minLimit: 3, maxLimit: 20 },
|
|
7
|
+
};
|
|
1
8
|
/** Only HTTP(S) mailbox roots supplied by this World may be opened. */
|
|
2
9
|
export function mailboxUrl(value) {
|
|
3
10
|
if (typeof value !== 'string')
|
|
@@ -39,6 +46,7 @@ export async function mountMailbox(ctx) {
|
|
|
39
46
|
const copy = ui.h('div', 'bottle-mailbox-copy');
|
|
40
47
|
copy.append(ui.h('h2', null, t.title), ui.h('p', null, t.description));
|
|
41
48
|
let url = null;
|
|
49
|
+
let botName = 'Coo';
|
|
42
50
|
const button = ui.button(t.open, { variant: 'primary', onClick: () => {
|
|
43
51
|
if (url && !ctx.signal.aborted)
|
|
44
52
|
ctx.root.ownerDocument.defaultView?.open(url, '_blank', 'noopener,noreferrer');
|
|
@@ -46,11 +54,21 @@ export async function mountMailbox(ctx) {
|
|
|
46
54
|
button.classList.add('bottle-open-mailbox');
|
|
47
55
|
button.disabled = true;
|
|
48
56
|
const note = ui.h('p', 'bottle-mailbox-note', t.loading);
|
|
49
|
-
|
|
57
|
+
let feedbackUrl = null;
|
|
58
|
+
const feedback = ui.h('button', 'bottle-feedback', zh ? '反馈收集 · 版本加载中' : 'Feedback · loading version');
|
|
59
|
+
feedback.type = 'button';
|
|
60
|
+
feedback.disabled = true;
|
|
61
|
+
feedback.title = zh ? '小问题、新想法,都可以留在这张便笺里。反馈时请带上当前 World 版本号。' : 'Share a problem or an idea, with your current World version.';
|
|
62
|
+
feedback.onclick = () => {
|
|
63
|
+
if (feedbackUrl && !ctx.signal.aborted)
|
|
64
|
+
ctx.root.ownerDocument.defaultView?.open(feedbackUrl, '_blank', 'noopener,noreferrer');
|
|
65
|
+
};
|
|
66
|
+
card.append(copy, button, feedback, note);
|
|
50
67
|
ctx.root.append(card);
|
|
51
68
|
const invitations = ui.h('section', 'bottle-wake-controls');
|
|
52
69
|
invitations.append(ui.h('h3', null, zh ? '海边的邀请' : 'Seaside invitations'));
|
|
53
70
|
const controls = ['write', 'catch', 'remind'].map(action => {
|
|
71
|
+
const policy = WAKE_POLICIES[action];
|
|
54
72
|
const row = ui.h('div', 'bottle-wake-row');
|
|
55
73
|
const label = ui.h('span');
|
|
56
74
|
const toggle = ui.button(zh ? '稍等' : 'Loading', { onClick: () => { void changeWake(action); } });
|
|
@@ -58,30 +76,43 @@ export async function mountMailbox(ctx) {
|
|
|
58
76
|
const hoursLabel = ui.h('label', 'bottle-wake-interval', zh ? '最短间隔(小时)' : 'Minimum interval (hours)');
|
|
59
77
|
const hours = ui.h('input');
|
|
60
78
|
hours.type = 'number';
|
|
61
|
-
hours.min =
|
|
62
|
-
hours.max =
|
|
63
|
-
hours.step = '1';
|
|
64
|
-
hours.value =
|
|
79
|
+
hours.min = String(policy.minHours);
|
|
80
|
+
hours.max = String(policy.maxHours);
|
|
81
|
+
hours.step = action === 'remind' ? '0.01' : '1';
|
|
82
|
+
hours.value = String(policy.interval);
|
|
65
83
|
hoursLabel.append(hours);
|
|
84
|
+
const limitLabel = ui.h('label', 'bottle-wake-interval', zh ? '每日上限(次)' : 'Daily limit');
|
|
85
|
+
const limit = ui.h('input');
|
|
86
|
+
limit.type = 'number';
|
|
87
|
+
limit.min = String(policy.minLimit);
|
|
88
|
+
limit.max = String(policy.maxLimit);
|
|
89
|
+
limit.step = '1';
|
|
90
|
+
limit.value = String(policy.dayLimit);
|
|
91
|
+
limitLabel.append(limit);
|
|
66
92
|
const save = ui.button(zh ? '调整' : 'Apply', { onClick: () => {
|
|
67
93
|
const value = Number(hours.value);
|
|
68
|
-
if (!Number.isFinite(value) || value <
|
|
69
|
-
outcome.textContent = zh ?
|
|
94
|
+
if (!Number.isFinite(value) || value < policy.minHours || value > policy.maxHours) {
|
|
95
|
+
outcome.textContent = zh ? `请填写 ${policy.minHours}—${policy.maxHours} 小时。` : `Enter ${policy.minHours}–${policy.maxHours} hours.`;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const dayLimit = Number(limit.value);
|
|
99
|
+
if (!Number.isInteger(dayLimit) || dayLimit < policy.minLimit || dayLimit > policy.maxLimit) {
|
|
100
|
+
outcome.textContent = zh ? `每日上限请填 ${policy.minLimit}—${policy.maxLimit} 次(整数)。` : `Enter an integer from ${policy.minLimit} to ${policy.maxLimit}.`;
|
|
70
101
|
return;
|
|
71
102
|
}
|
|
72
|
-
void changeWake(action, value);
|
|
103
|
+
void changeWake(action, value, dayLimit);
|
|
73
104
|
} });
|
|
74
|
-
row.append(label, hoursLabel, save, toggle);
|
|
105
|
+
row.append(label, hoursLabel, limitLabel, save, toggle);
|
|
75
106
|
invitations.append(row);
|
|
76
|
-
return { action, label, toggle, hours, save };
|
|
107
|
+
return { action, label, toggle, hours, limit, save };
|
|
77
108
|
});
|
|
78
|
-
invitations.append(ui.h('p', 'bottle-wake-outcome', zh ? '
|
|
109
|
+
invitations.append(ui.h('p', 'bottle-wake-outcome', zh ? '写信、打捞默认每天各 3 次,间隔 2—24 小时并随机延长;待办提醒默认每天 12 次(可设 3—20 次),仅有待处理来信时每 30—60 分钟轻声提醒。包含自动补试,手动邀请不占上限。配置页顶栏为快照,信箱页签每 5 秒同步。' : 'Writing/catching default to 3/day, with a randomized 2–24 hour minimum. Reminders default to 12/day (3–20), every 30–60 minutes only while holding incoming mail. Retries count; manual invitations are separate. Header snapshots sync every 5 seconds on this tab.'));
|
|
79
110
|
const outcome = ui.h('p', 'bottle-wake-outcome');
|
|
80
111
|
invitations.append(outcome);
|
|
81
112
|
ctx.root.append(invitations);
|
|
82
113
|
let wake = null;
|
|
83
114
|
let changing = false;
|
|
84
|
-
async function changeWake(action, hours) {
|
|
115
|
+
async function changeWake(action, hours, dayLimit) {
|
|
85
116
|
if (!wake || changing || ctx.signal.aborted)
|
|
86
117
|
return;
|
|
87
118
|
changing = true;
|
|
@@ -89,7 +120,7 @@ export async function mountMailbox(ctx) {
|
|
|
89
120
|
const lane = wake.lanes[action];
|
|
90
121
|
try {
|
|
91
122
|
const result = await ctx.invoke('wake', hours === undefined
|
|
92
|
-
? [action, lane.paused || lane.declined || lane.failed ? 'resume' : 'pause'] : [action, 'interval', hours]);
|
|
123
|
+
? [action, lane.paused || lane.declined || lane.failed ? 'resume' : 'pause'] : [action, 'interval', hours, dayLimit]);
|
|
93
124
|
if (result?.ok === false)
|
|
94
125
|
throw new Error(result.message);
|
|
95
126
|
if (!ctx.signal.aborted)
|
|
@@ -106,30 +137,32 @@ export async function mountMailbox(ctx) {
|
|
|
106
137
|
}
|
|
107
138
|
}
|
|
108
139
|
function renderWake() {
|
|
109
|
-
controls.forEach(({ action, label, toggle, hours, save }) => {
|
|
140
|
+
controls.forEach(({ action, label, toggle, hours, limit, save }) => {
|
|
110
141
|
const lane = wake?.lanes[action];
|
|
111
142
|
const name = action === 'write' ? (zh ? '写信邀请' : 'Writing') : action === 'catch' ? (zh ? '打捞邀请' : 'Catching') : (zh ? '待办提醒' : 'Reminders');
|
|
112
|
-
label.textContent = name + (lane ? (zh ? ' · 今天邀请 ' + lane.count + ' 次' : ' · ' + lane.count + ' today') : '');
|
|
143
|
+
label.textContent = name + (lane ? (zh ? ' · 今天邀请 ' + lane.count + '/' + (lane.dayLimit ?? WAKE_POLICIES[action].dayLimit) + ' 次' : ' · ' + lane.count + ' today') : '');
|
|
113
144
|
toggle.textContent = lane?.paused || lane?.declined || lane?.failed ? (zh ? '恢复邀请' : 'Resume') : (zh ? '暂停邀请' : 'Pause');
|
|
114
145
|
toggle.disabled = !lane || changing;
|
|
115
146
|
save.disabled = !lane || changing;
|
|
147
|
+
if (ctx.root.ownerDocument.activeElement !== limit)
|
|
148
|
+
limit.value = String(lane?.dayLimit ?? WAKE_POLICIES[action].dayLimit);
|
|
116
149
|
if (ctx.root.ownerDocument.activeElement !== hours)
|
|
117
|
-
hours.value = String(lane?.intervalHours ??
|
|
150
|
+
hours.value = String(lane?.intervalHours ?? WAKE_POLICIES[action].interval);
|
|
118
151
|
});
|
|
119
152
|
const last = wake?.history.at(-1);
|
|
120
153
|
const labels = zh ? {
|
|
121
|
-
completed: '已经处理', deferred: '
|
|
122
|
-
uncompleted: '
|
|
154
|
+
completed: '已经处理', deferred: botName + '选择暂不做', declined: '今天不再邀请', paused: '已按人的选择暂停',
|
|
155
|
+
uncompleted: botName + '没有回应邀请…稍后再轻轻问一次。', failed: botName + '没有回应邀请…今天先不打扰了。', cancelled: '条件变化,已取消', interrupted: '重启中断,已延后',
|
|
123
156
|
} : { completed: 'Completed', deferred: 'Deferred by the bot', declined: 'Declined for today', paused: 'Paused by the human',
|
|
124
157
|
uncompleted: 'No result; one bounded retry', failed: 'Retry exhausted; stopped for today', cancelled: 'Conditions changed', interrupted: 'Interrupted by restart; delayed' };
|
|
125
158
|
const active = wake?.active;
|
|
126
159
|
if (active) {
|
|
127
160
|
outcome.textContent = active.phase === 'retry'
|
|
128
|
-
? (zh ? '
|
|
129
|
-
: (zh ? '
|
|
161
|
+
? (zh ? botName + '没有回应邀请…稍后再轻轻问一次。' : 'No result in the last turn; one retry is scheduled.')
|
|
162
|
+
: (zh ? '已有一份邀请在等' + botName + '选择,写不写、捞不捞都由' + botName + '。' : 'One invitation is pending. The bot may still decline.');
|
|
130
163
|
return;
|
|
131
164
|
}
|
|
132
|
-
const result = last?.result === 'deferred' && last.reason === 'no_idea' ? (zh ? '
|
|
165
|
+
const result = last?.result === 'deferred' && last.reason === 'no_idea' ? (zh ? botName + '暂时没有灵感,已选择暂不做;不算失败,也不补试' : 'No inspiration right now; voluntarily deferred, not a failure or retry') : last?.reason === 'reminder_delivered' ? (zh ? '提醒已送达,是否询问由' + botName + '决定' : 'Reminder delivered; the bot chooses whether to ask') : last?.reason === 'queue_failed' ? (zh ? '邀请未能送达,今天不再尝试' : 'Could not deliver; stopped for today') : last ? (labels[last.result] ?? last.result) : '';
|
|
133
166
|
outcome.textContent = last ? (zh ? (last.action === 'write' ? '最近的写信邀请:' : last.action === 'catch' ? '最近的打捞邀请:' : '最近的待办提醒:') : 'Last result: ') + result
|
|
134
167
|
: (zh ? '有想说或想听的时候再做,小感受也值得写;不必为邀请勉强。' : 'An invitation, not an obligation. No letter is better than filler.');
|
|
135
168
|
}
|
|
@@ -349,6 +382,16 @@ export async function mountMailbox(ctx) {
|
|
|
349
382
|
const status = await ctx.invoke('status');
|
|
350
383
|
if (ctx.signal.aborted)
|
|
351
384
|
return;
|
|
385
|
+
botName = status.botName || 'Coo';
|
|
386
|
+
feedbackUrl = null;
|
|
387
|
+
try {
|
|
388
|
+
const target = new URL(status.feedbackUrl ?? '');
|
|
389
|
+
if (target.protocol === 'https:' && target.hostname === 'docs.qq.com' && !target.username && !target.password)
|
|
390
|
+
feedbackUrl = target.href;
|
|
391
|
+
}
|
|
392
|
+
catch { /* Older hosts may not yet expose the form. */ }
|
|
393
|
+
feedback.disabled = !feedbackUrl;
|
|
394
|
+
feedback.textContent = (zh ? '反馈收集 · ' : 'Feedback · ') + (status.version ? 'V' + status.version : (zh ? '版本暂不可用' : 'Version unavailable'));
|
|
352
395
|
wake = status.wake ?? null;
|
|
353
396
|
lan = status.lan;
|
|
354
397
|
if (!lanBusy)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-bottle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Coo 写一封不超过 120 字的信,寄不寄由人类在本地信箱页上决定;别人家的 Coo 捞到后看不到字,只有人类点了回信,那一封才会被读。",
|
|
6
6
|
"keywords": [
|
|
@@ -48,12 +48,13 @@
|
|
|
48
48
|
"description": "Coo drafts a letter of at most 120 characters. The human alone decides on a local page whether it goes out, and a letter is read only after the human asks for a reply."
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
-
"webUiClient": "dist/webui-
|
|
52
|
-
"webUiStyle": "dist/webui-
|
|
51
|
+
"webUiClient": "dist/webui-57b469ed631e.js",
|
|
52
|
+
"webUiStyle": "dist/webui-44dfed840fbe.css"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"world",
|
|
56
|
-
"dist",
|
|
56
|
+
"dist/webui-57b469ed631e.js",
|
|
57
|
+
"dist/webui-44dfed840fbe.css",
|
|
57
58
|
"shared/contract.ts",
|
|
58
59
|
"shared/text.ts",
|
|
59
60
|
"shared/hints.ts",
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
"server": "tsx server/main.ts",
|
|
69
70
|
"build:webui": "node scripts/build-webui.mjs",
|
|
70
71
|
"typecheck:web": "tsc -p tsconfig.web.json",
|
|
71
|
-
"prepack": "npm run typecheck:web && npm run build:webui",
|
|
72
|
+
"prepack": "npm run typecheck:web && node scripts/check-font-package.mjs && npm run build:webui",
|
|
72
73
|
"check:running-webui": "node scripts/check-running-webui.mjs"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
package/shared/contract.ts
CHANGED
|
@@ -150,11 +150,15 @@ export type CatchRes =
|
|
|
150
150
|
letterId: string;
|
|
151
151
|
from: string;
|
|
152
152
|
windowUntil: string;
|
|
153
|
+
caughtAt?: string;
|
|
153
154
|
quota: Quota;
|
|
154
155
|
/** 池子没有真人信时补位的种子瓶;来源固定是「海边邮局」。 */
|
|
155
156
|
seed?: boolean;
|
|
156
157
|
}
|
|
157
|
-
| { empty: true; reason: CatchEmptyReason; quota: Quota
|
|
158
|
+
| { empty: true; reason: CatchEmptyReason; quota: Quota;
|
|
159
|
+
/** Recover an already-held letter without spending another catch. Never includes its body. */
|
|
160
|
+
held?: { letterId: string; from: string; windowUntil: string; caughtAt?: string };
|
|
161
|
+
};
|
|
158
162
|
|
|
159
163
|
/**
|
|
160
164
|
* 系统邮件通道(海边邮局):**独立于捞瓶子**,不占捞取额度。
|
package/world/appearance.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
/** Shared semantic colors for the mailbox and its native desktop cards. */
|
|
2
2
|
import type { MailboxTheme } from './theme.ts';
|
|
3
|
-
export type ThemeChoice = 'ocean' | 'paper' | 'coopanion';
|
|
3
|
+
export type ThemeChoice = 'ocean' | 'paper' | 'coopanion' | 'custom';
|
|
4
4
|
export type AppearanceMode = 'system' | 'light' | 'dark';
|
|
5
|
-
export interface ThemePreference { theme: ThemeChoice; mode: AppearanceMode }
|
|
5
|
+
export interface ThemePreference { theme: ThemeChoice; mode: AppearanceMode; customColor?: string; background?: string | null; backgroundTransparency?: number; myFont?: string | null; myFontName?: string }
|
|
6
6
|
export const DEFAULT_APPEARANCE: ThemePreference = { theme: 'ocean', mode: 'system' };
|
|
7
7
|
export function isThemePreference(value: unknown): value is ThemePreference {
|
|
8
8
|
if (!value || typeof value !== 'object') return false;
|
|
9
9
|
const pref = value as ThemePreference;
|
|
10
|
-
return ['ocean','paper','coopanion'].includes(pref.theme) && ['system','light','dark'].includes(pref.mode)
|
|
10
|
+
return ['ocean','paper','coopanion','custom'].includes(pref.theme) && ['system','light','dark'].includes(pref.mode)
|
|
11
|
+
&& (pref.customColor === undefined || (typeof pref.customColor === 'string' && /^#[0-9a-f]{6}$/i.test(pref.customColor)))
|
|
12
|
+
&& (pref.backgroundTransparency === undefined || (typeof pref.backgroundTransparency === 'number' && Number.isFinite(pref.backgroundTransparency) && pref.backgroundTransparency >= 0 && pref.backgroundTransparency <= 100))
|
|
13
|
+
&& (pref.myFont === undefined || pref.myFont === null || (typeof pref.myFont === 'string' && /^[a-f0-9]{64}\.(ttf|otf|woff2?)$/.test(pref.myFont)))
|
|
14
|
+
&& (pref.myFontName === undefined || (typeof pref.myFontName === 'string' && pref.myFontName.length <= 120 && !/[\x00-\x1f\x7f]/.test(pref.myFontName)))
|
|
15
|
+
&& (pref.background === undefined || pref.background === null || (typeof pref.background === 'string' && /^[a-f0-9]{64}\.(png|jpg|webp)$/.test(pref.background)));
|
|
11
16
|
}
|
|
12
17
|
export const MAILBOX_PALETTES = {
|
|
13
18
|
"ocean": {
|
|
@@ -83,7 +88,7 @@ export const MAILBOX_PALETTES = {
|
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
} as const;
|
|
86
|
-
export type MailboxPalette = Record<keyof typeof MAILBOX_PALETTES.ocean.light, string
|
|
91
|
+
export type MailboxPalette = Record<keyof typeof MAILBOX_PALETTES.ocean.light, string> & { 'accent-text'?: string };
|
|
87
92
|
export interface CardAppearance { preference: ThemePreference; palettes: Record<'light' | 'dark', MailboxPalette> }
|
|
88
93
|
export function paletteDeclarations(theme: 'ocean' | 'paper', mode: 'light' | 'dark'): string {
|
|
89
94
|
return Object.entries(MAILBOX_PALETTES[theme][mode]).map(([key,value]) => `--${key}:${value};`).join(' ');
|
|
@@ -92,6 +97,7 @@ function mixColor(a: string, b: string, weight: number): string {
|
|
|
92
97
|
return '#' + [1,3,5].map(index => Math.round(parseInt(a.slice(index,index+2),16)*weight + parseInt(b.slice(index,index+2),16)*(1-weight)).toString(16).padStart(2,'0')).join('');
|
|
93
98
|
}
|
|
94
99
|
export function cardAppearance(preference: ThemePreference, host: MailboxTheme): CardAppearance {
|
|
100
|
+
if (preference.theme === 'custom') return { preference, palettes: customPalettes(preference.customColor ?? '#4b62a0') };
|
|
95
101
|
const palettes = preference.theme === 'paper' ? MAILBOX_PALETTES.paper : MAILBOX_PALETTES.ocean;
|
|
96
102
|
if (preference.theme !== 'coopanion' || !host.available || !host.palettes) return { preference, palettes };
|
|
97
103
|
const map = (mode: 'light' | 'dark'): MailboxPalette => {
|
|
@@ -102,3 +108,24 @@ export function cardAppearance(preference: ThemePreference, host: MailboxTheme):
|
|
|
102
108
|
};
|
|
103
109
|
return { preference, palettes: { light:map('light'), dark:map('dark') } };
|
|
104
110
|
}
|
|
111
|
+
|
|
112
|
+
/** Tint paper and ink together, but keep readable contrast even for white/black custom colors. */
|
|
113
|
+
export function customPalettes(color: string): Record<'light' | 'dark', MailboxPalette> {
|
|
114
|
+
if (!/^#[0-9a-f]{6}$/i.test(color)) throw new Error('Invalid custom color');
|
|
115
|
+
const luminance = (hex: string): number => [1,3,5].map(i => parseInt(hex.slice(i,i+2),16)/255)
|
|
116
|
+
.map(c => c <= .04045 ? c/12.92 : Math.pow((c+.055)/1.055,2.4))
|
|
117
|
+
.reduce((sum,c,i) => sum + c * [.2126,.7152,.0722][i],0);
|
|
118
|
+
const contrast = (a: string, b: string): number => (Math.max(luminance(a),luminance(b))+.05)/(Math.min(luminance(a),luminance(b))+.05);
|
|
119
|
+
const map = (mode: 'light' | 'dark'): MailboxPalette => {
|
|
120
|
+
const dark = mode === 'dark', base = dark ? '#141820' : '#ffffff';
|
|
121
|
+
const card = mixColor(color,base,dark ? .09 : .025);
|
|
122
|
+
const ink = dark ? '#f4f5f7' : '#20242c';
|
|
123
|
+
let accent = color;
|
|
124
|
+
for (let i=0; i<20 && contrast(accent,card)<4.5; i++) accent = mixColor(accent,dark ? '#ffffff' : '#000000',.85);
|
|
125
|
+
return { ...MAILBOX_PALETTES.ocean[mode], card, ink, accent:color.toLowerCase(), seal:color.toLowerCase(), sea:color.toLowerCase(), 'accent-text':accent,
|
|
126
|
+
paper:mixColor(color,base,dark ? .04 : .075), panel:mixColor(color,base,dark ? .07 : .04),
|
|
127
|
+
soft:mixColor(color,base,dark ? .14 : .06), line:mixColor(ink,card,.2), muted:mixColor(ink,card,.72),
|
|
128
|
+
'on-accent':contrast(color,'#ffffff') >= contrast(color,'#000000') ? '#ffffff' : '#000000' };
|
|
129
|
+
};
|
|
130
|
+
return { light:map('light'), dark:map('dark') };
|
|
131
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, renameSync, unlinkSync, mkdirSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const BACKGROUND_MAX_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
export const BACKGROUND_ID = /^[a-f0-9]{64}\.(png|jpg|webp)$/;
|
|
6
|
+
function imageType(bytes: Buffer): { ext: string; mime: string } | null {
|
|
7
|
+
if (bytes.length >= 24 && bytes.subarray(0,8).toString('hex') === '89504e470d0a1a0a' && bytes.toString('ascii',12,16)==='IHDR') return { ext:'png', mime:'image/png' };
|
|
8
|
+
if (bytes.length >= 4 && bytes[0]===255 && bytes[1]===216 && bytes[2]===255) return { ext:'jpg', mime:'image/jpeg' };
|
|
9
|
+
if (bytes.length >= 16 && bytes.toString('ascii',0,4)==='RIFF' && bytes.toString('ascii',8,12)==='WEBP') return { ext:'webp', mime:'image/webp' };
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
export function saveBackground(dataDir: string, input: unknown): string {
|
|
13
|
+
if (!input || typeof input !== 'object' || typeof (input as any).data !== 'string') throw new Error('Invalid image');
|
|
14
|
+
const data = (input as {data:string}).data;
|
|
15
|
+
if (data.length > Math.ceil(BACKGROUND_MAX_BYTES / 3) * 4 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data)) throw new Error('Invalid image');
|
|
16
|
+
const bytes = Buffer.from(data, 'base64'), type = imageType(bytes);
|
|
17
|
+
if (!type || bytes.length > BACKGROUND_MAX_BYTES) throw new Error('Invalid image');
|
|
18
|
+
const id = createHash('sha256').update(bytes).digest('hex') + '.' + type.ext;
|
|
19
|
+
const dir = join(dataDir, 'bottle-backgrounds'); mkdirSync(dir, { recursive: true });
|
|
20
|
+
const file = join(dir, id), temp = file + '.' + randomUUID() + '.tmp';
|
|
21
|
+
try { writeFileSync(temp, bytes); renameSync(temp, file); }
|
|
22
|
+
finally { try { unlinkSync(temp); } catch { /* renamed */ } }
|
|
23
|
+
return id;
|
|
24
|
+
}
|
|
25
|
+
export function readBackground(dataDir: string, id: string): { bytes: Buffer; mime: string } | null {
|
|
26
|
+
if (!BACKGROUND_ID.test(id)) return null;
|
|
27
|
+
const file = join(dataDir, 'bottle-backgrounds', id);
|
|
28
|
+
try {
|
|
29
|
+
const stat = lstatSync(file); if (!stat.isFile() || stat.isSymbolicLink() || stat.size > BACKGROUND_MAX_BYTES) return null;
|
|
30
|
+
const bytes = readFileSync(file), type = imageType(bytes);
|
|
31
|
+
return type ? { bytes, mime:type.mime } : null;
|
|
32
|
+
} catch { return null; }
|
|
33
|
+
}
|
package/world/card-host.ps1
CHANGED
|
@@ -35,6 +35,7 @@ function Brush([string]$hex) {
|
|
|
35
35
|
$key = $hex.Substring(1)
|
|
36
36
|
if ($script:themeBrushes.ContainsKey($key)) { return $script:themeBrushes[$key] }
|
|
37
37
|
$value = $script:themeColors.$key
|
|
38
|
+
if ($key -eq 'accent-text' -and $value -notmatch '^#[0-9a-fA-F]{6}$') { $value = $script:themeColors.accent }
|
|
38
39
|
if (-not $value) { $value = '#25334f' }
|
|
39
40
|
$brush = [System.Windows.Media.SolidColorBrush]::new([System.Windows.Media.ColorConverter]::ConvertFromString($value))
|
|
40
41
|
$script:themeBrushes[$key] = $brush
|
|
@@ -66,7 +67,9 @@ function Apply-Appearance {
|
|
|
66
67
|
$script:themeColors = $script:themeData.palettes.$mode
|
|
67
68
|
foreach ($key in @($script:themeBrushes.Keys)) {
|
|
68
69
|
$brush = $script:themeBrushes[$key]
|
|
69
|
-
$
|
|
70
|
+
$value = $script:themeColors.$key
|
|
71
|
+
if ($key -eq 'accent-text' -and $value -notmatch '^#[0-9a-fA-F]{6}$') { $value = $script:themeColors.accent }
|
|
72
|
+
$color = [System.Windows.Media.ColorConverter]::ConvertFromString($value)
|
|
70
73
|
if ($brush.Color -eq $color) { continue }
|
|
71
74
|
$brush.BeginAnimation([System.Windows.Media.SolidColorBrush]::ColorProperty, $null)
|
|
72
75
|
if ([System.Windows.SystemParameters]::ClientAreaAnimation -and $script:win -and $script:win.IsLoaded) {
|
|
@@ -134,7 +137,7 @@ $eyebrow = New-Object System.Windows.Controls.TextBlock
|
|
|
134
137
|
$eyebrow.Text = [string]$spec.eyebrow
|
|
135
138
|
$eyebrow.FontFamily = 'Microsoft YaHei'
|
|
136
139
|
$eyebrow.FontSize = 11
|
|
137
|
-
$eyebrow.Foreground = Brush '@accent'
|
|
140
|
+
$eyebrow.Foreground = Brush '@accent-text'
|
|
138
141
|
$eyebrow.VerticalAlignment = 'Center'
|
|
139
142
|
$head.Children.Add($eyebrow) | Out-Null
|
|
140
143
|
|
package/world/config.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WAKE_POLICIES } from './wake-policy.ts';
|
|
1
2
|
import { DEFAULT_SOUND_PACK, soundPackChoice, type SoundConfig } from './sound.ts';
|
|
2
3
|
import type { ConfigGroup, ConfigProperty } from 'cortico/core/types.ts';
|
|
3
4
|
|
|
@@ -9,10 +10,13 @@ import type { ConfigGroup, ConfigProperty } from 'cortico/core/types.ts';
|
|
|
9
10
|
export interface BottleWakeSettings {
|
|
10
11
|
writeInviteEnabled: boolean;
|
|
11
12
|
writeInviteIntervalHours: number;
|
|
13
|
+
writeInviteDayLimit: number;
|
|
12
14
|
catchInviteEnabled: boolean;
|
|
13
15
|
catchInviteIntervalHours: number;
|
|
16
|
+
catchInviteDayLimit: number;
|
|
14
17
|
reminderEnabled: boolean;
|
|
15
18
|
reminderIntervalHours: number;
|
|
19
|
+
reminderDayLimit: number;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/** Older deployments may omit the invitation settings; constructor migration retains their preferences. */
|
|
@@ -40,26 +44,28 @@ export interface BottleConfigSection extends Partial<BottleWakeSettings>, SoundC
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export const BOTTLE_WAKE_FIELDS = [
|
|
43
|
-
['write', 'writeInviteEnabled', 'writeInviteIntervalHours', '写信邀请'],
|
|
44
|
-
['catch', 'catchInviteEnabled', 'catchInviteIntervalHours', '打捞邀请'],
|
|
45
|
-
['remind', 'reminderEnabled', 'reminderIntervalHours', '待办提醒'],
|
|
47
|
+
['write', 'writeInviteEnabled', 'writeInviteIntervalHours', '写信邀请', 'writeInviteDayLimit'],
|
|
48
|
+
['catch', 'catchInviteEnabled', 'catchInviteIntervalHours', '打捞邀请', 'catchInviteDayLimit'],
|
|
49
|
+
['remind', 'reminderEnabled', 'reminderIntervalHours', '待办提醒', 'reminderDayLimit'],
|
|
46
50
|
] as const;
|
|
47
51
|
|
|
48
52
|
/** Distinguish implicit defaults from explicit deployment values when migrating old scheduler preferences. */
|
|
49
53
|
export function initialiseWakeSettings(config: BottleConfigSection, savedLanes: unknown, explicitConfig: unknown = {}): void {
|
|
50
54
|
const explicit = explicitConfig && typeof explicitConfig === 'object' ? explicitConfig : {};
|
|
51
55
|
const lanes = savedLanes && typeof savedLanes === 'object' ? savedLanes as Record<string, unknown> : {};
|
|
52
|
-
for (const [action, enabled, interval] of BOTTLE_WAKE_FIELDS) {
|
|
56
|
+
for (const [action, enabled, interval, , limit] of BOTTLE_WAKE_FIELDS) {
|
|
57
|
+
const policy = WAKE_POLICIES[action];
|
|
58
|
+
if (!Number.isInteger(config[limit]) || config[limit]! < policy.minLimit || config[limit]! > policy.maxLimit) config[limit] = policy.dayLimit;
|
|
53
59
|
const saved = lanes[action];
|
|
54
60
|
const lane = saved && typeof saved === 'object' ? saved as Record<string, unknown> : {};
|
|
55
61
|
// Deployment values override legacy preferences, even when equal to the new defaults.
|
|
56
62
|
// A default introduced by a package upgrade must not accidentally resume an old pause.
|
|
57
63
|
if (typeof config[enabled] !== 'boolean' || (!Object.hasOwn(explicit, enabled) &&
|
|
58
64
|
config[enabled] === BOTTLE_DEFAULTS[enabled] && typeof lane.paused === 'boolean')) config[enabled] = lane.paused !== true;
|
|
59
|
-
if (typeof config[interval] !== 'number' || !Number.isFinite(config[interval]) || config[interval]! <
|
|
65
|
+
if (typeof config[interval] !== 'number' || !Number.isFinite(config[interval]) || config[interval]! < policy.minHours || config[interval]! > policy.maxHours ||
|
|
60
66
|
(!Object.hasOwn(explicit, interval) && config[interval] === BOTTLE_DEFAULTS[interval] && typeof lane.intervalHours === 'number')) {
|
|
61
67
|
const hours = lane.intervalHours;
|
|
62
|
-
config[interval] = typeof hours === 'number' && Number.isFinite(hours) ? Math.min(
|
|
68
|
+
config[interval] = typeof hours === 'number' && Number.isFinite(hours) && (action !== 'remind' || (hours >= policy.minHours && hours <= policy.maxHours)) ? Math.min(policy.maxHours, Math.max(policy.minHours, hours)) : policy.interval;
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -75,10 +81,13 @@ export const BOTTLE_DEFAULTS: BottleConfigSection = {
|
|
|
75
81
|
randomWake: true,
|
|
76
82
|
writeInviteEnabled: true,
|
|
77
83
|
writeInviteIntervalHours: 2,
|
|
84
|
+
writeInviteDayLimit: 3,
|
|
78
85
|
catchInviteEnabled: true,
|
|
79
86
|
catchInviteIntervalHours: 2,
|
|
87
|
+
catchInviteDayLimit: 3,
|
|
80
88
|
reminderEnabled: true,
|
|
81
|
-
reminderIntervalHours:
|
|
89
|
+
reminderIntervalHours: WAKE_POLICIES.remind.interval,
|
|
90
|
+
reminderDayLimit: WAKE_POLICIES.remind.dayLimit,
|
|
82
91
|
server: 'https://bottle.sqnori.com',
|
|
83
92
|
port: 7796,
|
|
84
93
|
lanEnabled: false,
|
|
@@ -161,22 +170,32 @@ export const BOTTLE_CONFIG_FIELDS: Record<string, ConfigProperty> = {
|
|
|
161
170
|
},
|
|
162
171
|
'worlds.bottle.randomWake': {
|
|
163
172
|
type: 'boolean', title: '随机海边邀请',
|
|
164
|
-
description: '
|
|
173
|
+
description: '有余量且没有待办时,偶尔邀请它写信或打捞;有待办则温和提醒,可以不做。写信、打捞默认每天各最多 3 次,待办提醒默认 12 次,可分别调整。下方可分别开启、暂停与调整间隔,与信箱网页共用设置;关闭总开关不会清除各类偏好。',
|
|
165
174
|
'x-hot': true,
|
|
166
175
|
},
|
|
167
|
-
...Object.fromEntries(BOTTLE_WAKE_FIELDS.flatMap(([action, enabled, interval, label]) => [
|
|
176
|
+
...Object.fromEntries(BOTTLE_WAKE_FIELDS.flatMap(([action, enabled, interval, label, limit]) => [
|
|
168
177
|
[`worlds.bottle.${enabled}`, {
|
|
169
178
|
type: 'boolean' as const, title: label,
|
|
170
179
|
description: action === 'remind'
|
|
171
|
-
? '
|
|
180
|
+
? '仅在手上有尚未处理的来信时温和提醒,没有来信或只有草稿时不触发;不读正文,也不代替人寄信。关闭即暂停,与网页设置同步。'
|
|
172
181
|
: '余量大于 1 且手上没有待办时,偶尔邀请它自主选择。关闭即暂停,与网页设置同步;人手动发出的邀请仍尊重暂停。',
|
|
173
182
|
'x-hot': true,
|
|
174
183
|
}],
|
|
175
184
|
[`worlds.bottle.${interval}`, {
|
|
176
|
-
type: 'number' as const, title: `${label}最短间隔`, minimum:
|
|
177
|
-
description:
|
|
185
|
+
type: 'number' as const, title: `${label}最短间隔`, minimum: WAKE_POLICIES[action].minHours, maximum: WAKE_POLICIES[action].maxHours,
|
|
186
|
+
description: action === 'remind'
|
|
187
|
+
? '默认 0.5 小时(30 分钟),实际在 30—60 分钟内随机。最短间隔可设 0.5—1 小时,实际不超过 1 小时;修改后重新安排,不立即补催。'
|
|
188
|
+
: '默认 2 小时,范围 2—24 小时。实际时刻在最短间隔的 1—2 倍内随机,最长 24 小时。修改后重新安排,不立即补催。',
|
|
189
|
+
...(action === 'remind' ? { multipleOf: 0.01 } : {}),
|
|
178
190
|
'x-suffix': '小时', 'x-hot': true,
|
|
179
191
|
}],
|
|
192
|
+
[`worlds.bottle.${limit}`, {
|
|
193
|
+
type: 'integer' as const, title: `${label}每日上限`, minimum: WAKE_POLICIES[action].minLimit, maximum: WAKE_POLICIES[action].maxLimit,
|
|
194
|
+
description: action === 'remind'
|
|
195
|
+
? '默认 12 次,范围 3—20 次(整数)。包含自动补试;修改不会清零今日次数,没有待处理来信时不提醒。'
|
|
196
|
+
: '默认 3 次,范围 1—24 次(整数)。包含自动补试,手动邀请不占此上限;修改不会清零今日次数。',
|
|
197
|
+
'x-suffix': '次', 'x-hot': true,
|
|
198
|
+
}],
|
|
180
199
|
])),
|
|
181
200
|
'worlds.bottle.debug': {
|
|
182
201
|
type: 'boolean',
|
|
@@ -209,8 +228,8 @@ export const BOTTLE_CONFIG_GROUPS: ConfigGroup[] = [
|
|
|
209
228
|
'先选信件显示的位置,再调整桌面卡片和海啸提醒。',
|
|
210
229
|
['surface', 'cardAutoCloseSec', 'tsunamiNotice']),
|
|
211
230
|
configGroup('world:bottle:invitations', '海边邀请与提醒',
|
|
212
|
-
'
|
|
213
|
-
['randomWake', ...BOTTLE_WAKE_FIELDS.flatMap(([, enabled, interval]) => [enabled, interval])]),
|
|
231
|
+
'总开关在前,写信、打捞和待办提醒各有自己的开关、间隔与每日上限;与信箱里的设置同步。',
|
|
232
|
+
['randomWake', ...BOTTLE_WAKE_FIELDS.flatMap(([, enabled, interval, , limit]) => [enabled, interval, limit])]),
|
|
214
233
|
configGroup('world:bottle:sound', '桌面音效',
|
|
215
234
|
'这里只影响 Windows 新来信和回信卡片。音量与淡出对两类声音共同生效,网页声音仍在各设备单独设置。',
|
|
216
235
|
['soundEnabled', 'soundVolume', 'soundFadeOutMs']),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import QRCode from 'qrcode';
|
|
3
|
+
|
|
4
|
+
export const FEEDBACK_FORM_URL = 'https://docs.qq.com/form/page/DZm5DZ3d4V2JiUmt2';
|
|
5
|
+
// Read this extension's installed manifest, independently of the host/data directory.
|
|
6
|
+
export const WORLD_VERSION: string = (() => {
|
|
7
|
+
try {
|
|
8
|
+
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
9
|
+
return typeof version === 'string' && /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(version) ? version : '';
|
|
10
|
+
} catch { return ''; }
|
|
11
|
+
})();
|
|
12
|
+
|
|
13
|
+
let qr: Promise<Buffer> | undefined;
|
|
14
|
+
export function feedbackQr(): Promise<Buffer> {
|
|
15
|
+
return qr ??= QRCode.toBuffer(FEEDBACK_FORM_URL, {
|
|
16
|
+
type: 'png', width: 240, margin: 4, errorCorrectionLevel: 'M',
|
|
17
|
+
color: { dark: '#000000', light: '#ffffff' },
|
|
18
|
+
}).catch(error => { qr = undefined; throw error; });
|
|
19
|
+
}
|