dsh-galatea 0.4.0 → 0.4.1
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/index.js +23 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -114,7 +114,28 @@ function liveConfig(raw) {
|
|
|
114
114
|
*/
|
|
115
115
|
export function apply(ctx, config) {
|
|
116
116
|
const raw = config ?? {};
|
|
117
|
-
|
|
117
|
+
// volatile 字段在 apply 里拿到的是引用(`{ get() }`),不是值。
|
|
118
|
+
//
|
|
119
|
+
// 直接读 `raw.x` 会拿到对象 —— `Number(对象)` 是 NaN,`if (NaN > 0)` 不成立,
|
|
120
|
+
// 于是那个开关永远不会生效,而且**没有任何地方会报错**。
|
|
121
|
+
//
|
|
122
|
+
// 0.4.0 的自动心跳就是这么死的:同一个文件里六个字段走了 pick(),
|
|
123
|
+
// 第七个(autoBeatMinutes)忘了,于是它从来没有被打开过。
|
|
124
|
+
//
|
|
125
|
+
// 与其要求每个调用点都记得 pick(),不如在这里一次性解引用:
|
|
126
|
+
// 之后所有地方只看普通值,「忘了 pick」这种错误就不可能再发生。
|
|
127
|
+
const cfg = {};
|
|
128
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
129
|
+
cfg[k] = v && typeof v.get === 'function' ? v.get() : v;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 解引用之后再自检一次:还有对象就说明这个字段的形状跟以为的不一样。
|
|
133
|
+
// 不能说"大概没配"就把它当默认值用掉 —— 那正是 0.4.0 的死法。
|
|
134
|
+
for (const [k, v] of Object.entries(cfg)) {
|
|
135
|
+
if (v !== null && typeof v === 'object' && !Array.isArray(v)) {
|
|
136
|
+
console.warn(`[galatea] 设置项 ${k} 解引用后仍然是对象,这项配置可能没生效`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
118
139
|
|
|
119
140
|
// ── 正控:这一段真的跑过吗 ────────────────────────────────
|
|
120
141
|
// marker 不是日志。它只回答一个问题:apply() 到底有没有被执行。
|
|
@@ -198,7 +219,7 @@ export function apply(ctx, config) {
|
|
|
198
219
|
// 想确认它在动,看心跳账本里有没有新记录就够了。
|
|
199
220
|
//
|
|
200
221
|
// 默认关(autoBeatMinutes = 0):一个会自己转的东西,不该在装上的那一刻就开始转。
|
|
201
|
-
const everyMin = Number(
|
|
222
|
+
const everyMin = Number(cfg.autoBeatMinutes ?? 0);
|
|
202
223
|
if (Number.isFinite(everyMin) && everyMin > 0) {
|
|
203
224
|
if (ctx && typeof ctx.setInterval === 'function') {
|
|
204
225
|
const ms = Math.max(60_000, everyMin * 60_000);
|