dsh-whale-widget 0.3.12 → 0.3.13
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/lib/index.js +53 -20
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -582,10 +582,50 @@ function loadWidgetJs() {
|
|
|
582
582
|
return widgetJsCache ? widgetJsCache.text : ''
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
+
// —— 桌面端(Electron)结构化注入行:**内联 script 行**,不是 script-src 行(issue #154)——
|
|
586
|
+
// 桌面壳的 index.html 从安装包静态 dist 直出,`tapIndex`(函数变换)永远过不去;唯一通道是
|
|
587
|
+
// `webserver/index-inject` 推的结构化行,经 IPC 交给页面侧解释器逐行应用。
|
|
588
|
+
// 但解释器对两种 script 行的处理**不对称**(desktop 前端 `web-boot`):
|
|
589
|
+
// case "script": createElement + textContent + append —— 没有 await,**不可能"加载失败"**
|
|
590
|
+
// case "script-src": await loadScript(src) —— 失败即 reject,而那个 reject 会
|
|
591
|
+
// reject 掉 __DSH_BOOT_READY__ ⇒ **应用起不来**
|
|
592
|
+
// 再加一层:外壳把这张表在**宿主启动时收集一次**后缓存,**没有任何刷新路径** ⇒ 插件在运行期被关掉时,
|
|
593
|
+
// 表里仍留着这一行,而 `/dsh-whale/*` 路由已注销 ⇒ 加载 404 ⇒ 就是 issue #154 那个
|
|
594
|
+
// "desktop web: failed to load /dsh-whale/widget.js" 致命错误。
|
|
595
|
+
// 所以改成内联行:由**我们自己**建 `<script src=…>` 并**吞掉** onerror —— 路由在就正常加载,
|
|
596
|
+
// 路由不在就静默失败,宿主永远不会因为我们起不来。
|
|
597
|
+
const DESKTOP_WIDGET_ROW_TEXT =
|
|
598
|
+
'(function(){try{var d=document.body||document.head||document.documentElement;if(!d)return;' +
|
|
599
|
+
'var s=document.createElement("script");s.src="/dsh-whale/widget.js";' +
|
|
600
|
+
's.onerror=function(){};d.appendChild(s)}catch(e){}})()'
|
|
601
|
+
|
|
585
602
|
export default {
|
|
586
603
|
name: 'whale-balance-widget',
|
|
587
|
-
inject: ['webServer',
|
|
588
|
-
apply(
|
|
604
|
+
// v758:**有意去掉对象级 `inject: ['webServer','credentials','connection']`**(issue #154 的隐患面)。
|
|
605
|
+
// 对象级 inject 会把整个 apply() 推迟到三个服务就绪之后;而桌面端的注入表是**宿主启动时一次性
|
|
606
|
+
// 收集**的(`dsh-desktop-host`:`collectIndexInjections()` → IPC → 渲染层),订阅一旦晚于那次收集,
|
|
607
|
+
// 这一行就永远进不了表 = 桌面端挂件完全不出现(#152/#153 那位报告人无法稳定复现的正是这个竞态)。
|
|
608
|
+
// 现在 apply() 立刻执行、**第一件事就是注册注入行**(它不依赖任何服务),其余逻辑原样放进
|
|
609
|
+
// `root.inject([...], cb)` 局部等待 —— 语义与原来的对象级 inject 等价,但行的注册不再被推迟。
|
|
610
|
+
apply(root) {
|
|
611
|
+
const rowDisposers = []
|
|
612
|
+
root.effect(() => () => { for (const d of rowDisposers) { try { d() } catch (err) {} } })
|
|
613
|
+
// ① 结构化注入行:桌面端唯一能生效的通道(web 形态另有 tapIndex,两条并存、各自去重)
|
|
614
|
+
rowDisposers.push(root.on('webserver/index-inject', (table) => {
|
|
615
|
+
try {
|
|
616
|
+
if (!Array.isArray(table)) return
|
|
617
|
+
for (const row of table) {
|
|
618
|
+
if (!row) continue
|
|
619
|
+
if (row.kind === 'script-src' && row.src === '/dsh-whale/widget.js') return // 旧版本推过 → 不重复
|
|
620
|
+
if (row.kind === 'script' && typeof row.text === 'string'
|
|
621
|
+
&& row.text.indexOf('/dsh-whale/widget.js') >= 0) return
|
|
622
|
+
}
|
|
623
|
+
table.push({ kind: 'script', placement: 'body', text: DESKTOP_WIDGET_ROW_TEXT })
|
|
624
|
+
} catch (err) {}
|
|
625
|
+
}))
|
|
626
|
+
|
|
627
|
+
// ② 其余逻辑:等齐三个服务后再跑(等价于原来的对象级 inject,但不再挡住 ①)
|
|
628
|
+
root.inject(['webServer', 'credentials', 'connection'], (ctx) => {
|
|
589
629
|
// —— 浏览器信任栅栏(issue #92 建立,issue #136 补 fail-closed)——
|
|
590
630
|
// dsh 的 connection 服务提供 requestRejection(req):Host/Origin 被伪造(DNS 重绑定)或未认证的
|
|
591
631
|
// 请求必须被拒。**但这个方法在较老的 dsh 上不存在**(#136 实测:0.1.5-rc.2/rc.3 有、0.1.0-rc.3 没有),
|
|
@@ -1052,7 +1092,7 @@ export default {
|
|
|
1052
1092
|
const days = new Set([today, ...Object.keys(led.history || {}), ...accountingDays(led)])
|
|
1053
1093
|
for (const e of events) if (/^\d{4}-\d{2}-\d{2}$/.test(e.day)) days.add(e.day)
|
|
1054
1094
|
return {
|
|
1055
|
-
ok: true, version: '0.3.
|
|
1095
|
+
ok: true, version: '0.3.13', today: todayData, days7,
|
|
1056
1096
|
total7: total7ByCurrency[todayData.currency] || 0, total7Currency: todayData.currency, total7ByCurrency,
|
|
1057
1097
|
all: {
|
|
1058
1098
|
days: Array.from(days).filter(d => /^\d{4}-\d{2}-\d{2}$/.test(d)).sort().reverse().map(forDay),
|
|
@@ -2252,7 +2292,7 @@ export default {
|
|
|
2252
2292
|
const summary = daySummary(led, todayKey())
|
|
2253
2293
|
const nowSec = Math.floor(Date.now() / 1000)
|
|
2254
2294
|
return {
|
|
2255
|
-
...visible, version: '0.3.
|
|
2295
|
+
...visible, version: '0.3.13', isPeak: isPeakTime(nowSec),
|
|
2256
2296
|
// 峰谷切换点与节假日清单:前端倒计时要与宿主同源(否则法定节假日会算错切换点)
|
|
2257
2297
|
peakNextChangeAt: nextPeakChangeAt(nowSec),
|
|
2258
2298
|
peakHolidays: HOLIDAY_VALLEY_LIST,
|
|
@@ -3531,27 +3571,20 @@ export default {
|
|
|
3531
3571
|
return html + tag
|
|
3532
3572
|
}))
|
|
3533
3573
|
|
|
3534
|
-
// —— 官方 DSH 桌面端(Electron)适配(issue #152 / #153)——
|
|
3535
|
-
// 桌面壳的 index.html 是**从安装包静态 dist 直接读盘**的(`dsh-app://app
|
|
3536
|
-
//
|
|
3537
|
-
//
|
|
3538
|
-
// 经 IPC
|
|
3539
|
-
//
|
|
3540
|
-
//
|
|
3541
|
-
|
|
3542
|
-
try {
|
|
3543
|
-
if (!Array.isArray(table)) return
|
|
3544
|
-
for (const row of table) {
|
|
3545
|
-
if (row && row.kind === 'script-src' && row.src === '/dsh-whale/widget.js') return
|
|
3546
|
-
}
|
|
3547
|
-
table.push({ kind: 'script-src', placement: 'body', src: '/dsh-whale/widget.js' })
|
|
3548
|
-
} catch (err) {}
|
|
3549
|
-
}))
|
|
3574
|
+
// —— 官方 DSH 桌面端(Electron)适配(issue #152 / #153 / #154)——
|
|
3575
|
+
// 桌面壳的 index.html 是**从安装包静态 dist 直接读盘**的(`dsh-app://app/`),永远不经过宿主的
|
|
3576
|
+
// renderIndex(),所以上面的 tapIndex 在桌面端不生效 —— 于是"宿主半区活着、客户端半区从未被请求"。
|
|
3577
|
+
// 桌面端唯一的注入通道是 `webserver/index-inject` 的结构化行(宿主启动时 collectIndexInjections()
|
|
3578
|
+
// 经 IPC 交给渲染层,渲染层按 kind 逐行应用)。
|
|
3579
|
+
// **该行的注册已上移到 apply() 开头**(见 `DESKTOP_WIDGET_ROW_TEXT` 上方那段注释):两个原因 ——
|
|
3580
|
+
// ① 桌面端的注入表是**一次性收集**的,行必须尽早进表;② 行本身改成了**内联 script 行**,
|
|
3581
|
+
// 因为页面侧解释器对 `script-src` 是"加载失败即 reject 整个 boot"(issue #154 的致命启动错误)。
|
|
3550
3582
|
|
|
3551
3583
|
ctx.effect(() => () => {
|
|
3552
3584
|
for (const d of disposers) {
|
|
3553
3585
|
try { d() } catch (err) {}
|
|
3554
3586
|
}
|
|
3555
3587
|
})
|
|
3588
|
+
}) // ← 结束 root.inject(['webServer','credentials','connection'], cb)
|
|
3556
3589
|
},
|
|
3557
3590
|
}
|
package/package.json
CHANGED