@lls-a1/dsh-balance-float 1.1.52 → 1.1.53
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/client.js +38 -229
- package/index.js +8 -15
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -27,12 +27,10 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
const h = React.createElement;
|
|
28
28
|
|
|
29
29
|
const NS = 'balance-float';
|
|
30
|
+
/** The published name DSH's plugin manager lists this bundle under. */
|
|
31
|
+
const PACKAGE_NAME = '@lls-a1/dsh-balance-float';
|
|
30
32
|
const ROUTE = '/balance-float/snapshot';
|
|
31
33
|
const ROUTE_UPDATE = '/balance-float/update';
|
|
32
|
-
const NPM_SPEC = '@lls-a1/dsh-balance-float';
|
|
33
|
-
// Native modal support decides whether the mask lives in the top layer.
|
|
34
|
-
const DIALOG_OK =
|
|
35
|
-
typeof document !== 'undefined' && typeof document.createElement('dialog').showModal === 'function';
|
|
36
34
|
const REPO_URL = 'https://github.com/ming-a1/dsh-balance-float';
|
|
37
35
|
const POS_KEY = 'dsh.balance-float.position';
|
|
38
36
|
// Official top-up page; the balance endpoint has no recharge API, so the
|
|
@@ -112,20 +110,8 @@ window.__ModuleLoader__.load({
|
|
|
112
110
|
history: '近 7 天',
|
|
113
111
|
'history.total': '合计 {total}',
|
|
114
112
|
version: '版本',
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'update.checking': '正在检查…',
|
|
118
|
-
'update.failed': '检查失败',
|
|
119
|
-
'update.found': '发现新版本 v{latest}(当前 v{current})',
|
|
120
|
-
'update.latest': '最新版本 v{current}',
|
|
121
|
-
'update.label.current': '当前',
|
|
122
|
-
'update.label.latest': '最新',
|
|
123
|
-
'update.now': '更新',
|
|
124
|
-
'update.copy': '复制安装链接',
|
|
125
|
-
'update.copied': '已复制 ✓',
|
|
126
|
-
'update.installHint': '复制后到插件管理器里粘贴安装(npm 包名,安装源可选用国内镜像)。',
|
|
127
|
-
'update.later': '稍后',
|
|
128
|
-
'update.retry': '点击重试',
|
|
113
|
+
'version.open': '打开插件页(更新在这里)',
|
|
114
|
+
'version.new': '发现新版本 v{latest},点击打开插件页更新',
|
|
129
115
|
source: '本地账本',
|
|
130
116
|
updated: '更新于 {time}',
|
|
131
117
|
refreshing: '正在刷新',
|
|
@@ -211,20 +197,8 @@ window.__ModuleLoader__.load({
|
|
|
211
197
|
history: 'Last 7 days',
|
|
212
198
|
'history.total': 'Total {total}',
|
|
213
199
|
version: 'Version',
|
|
214
|
-
'
|
|
215
|
-
'
|
|
216
|
-
'update.checking': 'Checking…',
|
|
217
|
-
'update.failed': 'Update check failed',
|
|
218
|
-
'update.found': 'v{latest} is available (you have v{current})',
|
|
219
|
-
'update.latest': 'Latest version v{current}',
|
|
220
|
-
'update.label.current': 'Current',
|
|
221
|
-
'update.label.latest': 'Latest',
|
|
222
|
-
'update.now': 'Update',
|
|
223
|
-
'update.copy': 'Copy install spec',
|
|
224
|
-
'update.copied': 'Copied ✓',
|
|
225
|
-
'update.installHint': 'Paste this npm package name into the plugin manager to upgrade.',
|
|
226
|
-
'update.later': 'Later',
|
|
227
|
-
'update.retry': 'click to retry',
|
|
200
|
+
'version.open': 'Open the plugin page (updates live there)',
|
|
201
|
+
'version.new': 'v{latest} is available — click to open the plugin page',
|
|
228
202
|
source: 'Local ledger',
|
|
229
203
|
updated: 'Updated {time}',
|
|
230
204
|
refreshing: 'Refreshing',
|
|
@@ -316,27 +290,6 @@ window.__ModuleLoader__.load({
|
|
|
316
290
|
'.dbf-version-glyph{font-size:10px;opacity:.75}',
|
|
317
291
|
'.dbf-version.has-update{color:var(--dsw-alias-state-error-primary)}',
|
|
318
292
|
'.dbf-version.has-update .dbf-version-glyph{opacity:1}',
|
|
319
|
-
'.dbf-modal{position:fixed;top:0;right:0;bottom:0;left:0;height:100dvh;z-index:10;display:flex;align-items:center;justify-content:center;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));background:rgba(0,0,0,.45);overscroll-behavior:contain;touch-action:none}',
|
|
320
|
-
'.dbf-dialog{position:fixed;top:0;left:0;width:100vw;height:100dvh;min-width:100vw;min-height:100dvh;max-width:none;max-height:none;margin:0;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));border:0;box-sizing:border-box;background:transparent;color:inherit;display:flex;align-items:center;justify-content:center;overflow:hidden;overscroll-behavior:contain;outline:none}',
|
|
321
|
-
'.dbf-dialog:focus,.dbf-dialog:focus-visible{outline:none}',
|
|
322
|
-
'.dbf-modal-open{scrollbar-width:none}',
|
|
323
|
-
'.dbf-modal-open ::-webkit-scrollbar{width:0;height:0;display:none}',
|
|
324
|
-
'.dbf-dialog::backdrop{background:rgba(0,0,0,.45)}',
|
|
325
|
-
'.dbf-modal-card{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:min(308px,calc(100vw - 24px));margin:0;max-height:calc(100dvh - 24px);overflow:auto;touch-action:auto;overscroll-behavior:contain;padding:16px;border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,calc(.34 * var(--dbf-shadow,1)));background:var(--dsw-alias-bg-layer-1,Canvas);color:var(--dsw-alias-label-primary,CanvasText)}',
|
|
326
|
-
'.dbf-modal-head{display:flex;align-items:center;gap:8px;margin-bottom:10px}',
|
|
327
|
-
'.dbf-modal-icon{width:22px;height:22px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay));color:var(--dsw-alias-brand-primary,#4d6bfe);font-size:12px;line-height:1}',
|
|
328
|
-
'.dbf-modal-title{font-size:13px;font-weight:600}',
|
|
329
|
-
'.dbf-modal-body{font-size:12px;line-height:18px}',
|
|
330
|
-
'.dbf-modal-note{margin-top:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.85}',
|
|
331
|
-
'.dbf-modal-versions{display:flex;align-items:center;gap:8px;margin-top:8px}',
|
|
332
|
-
'.dbf-modal-version{display:flex;flex-direction:column;gap:1px;padding:4px 8px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay))}',
|
|
333
|
-
'.dbf-modal-version.is-new{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4d6bfe) 14%,transparent)}',
|
|
334
|
-
'.dbf-modal-version-label{font-size:10px;line-height:13px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.8}',
|
|
335
|
-
'.dbf-modal-version-value{font-size:12px;line-height:17px;font-weight:600;font-variant-numeric:tabular-nums}',
|
|
336
|
-
'.dbf-modal-arrow{color:var(--dsw-alias-label-tertiary)}',
|
|
337
|
-
'.dbf-btn-primary{padding:4px 12px;border:0;border-radius:8px;background:var(--dsw-alias-label-primary,CanvasText);color:var(--dsw-alias-bg-base,Canvas);font:inherit;font-size:12px;font-weight:600;line-height:18px;cursor:pointer}',
|
|
338
|
-
'.dbf-btn-primary:hover{filter:brightness(1.06)}',
|
|
339
|
-
'.dbf-modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:12px}',
|
|
340
293
|
'.dbf-fold-head{cursor:pointer;user-select:none}',
|
|
341
294
|
'.dbf-fold-arrow{display:inline-block;width:10px;margin-right:3px;color:var(--dsw-alias-label-tertiary);font-size:9px}',
|
|
342
295
|
'.dbf-fold-head:hover .dbf-row-title{color:var(--dsw-alias-label-primary)}',
|
|
@@ -581,11 +534,12 @@ window.__ModuleLoader__.load({
|
|
|
581
534
|
// The shell can re-mount the overlay when a run starts or stops. Component
|
|
582
535
|
// state is lost then, so the live position lives at module scope too: a
|
|
583
536
|
// remount must not snap the widget back to the stored default.
|
|
584
|
-
const shared = { frame: null, dir: 'up', dock: ''
|
|
537
|
+
const shared = { frame: null, dir: 'up', dock: '' };
|
|
585
538
|
|
|
586
539
|
/** The floating pill and its expanded card. */
|
|
587
540
|
function BalanceFloat(props) {
|
|
588
541
|
const t = props.t;
|
|
542
|
+
const openPluginPage = typeof props.openPluginPage === 'function' ? props.openPluginPage : () => {};
|
|
589
543
|
const [snapshot, setSnapshot] = useState(null);
|
|
590
544
|
const [failure, setFailure] = useState('');
|
|
591
545
|
const [busy, setBusy] = useState(false);
|
|
@@ -612,34 +566,9 @@ window.__ModuleLoader__.load({
|
|
|
612
566
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
613
567
|
// Token buckets are collapsed until asked for.
|
|
614
568
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
615
|
-
//
|
|
616
|
-
const [update, setUpdate] = useState(
|
|
617
|
-
const [updateOpen, setUpdateOpen] = useState(shared.updateOpen);
|
|
569
|
+
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
570
|
+
const [update, setUpdate] = useState(null);
|
|
618
571
|
const updateCheckedAt = useRef(0);
|
|
619
|
-
const [copied, setCopied] = useState(false);
|
|
620
|
-
const modalRef = useRef(null);
|
|
621
|
-
|
|
622
|
-
// A plain fixed <div> stays inside the shell's stacking context, so the
|
|
623
|
-
// page header kept painting above the mask. showModal() moves the element
|
|
624
|
-
// into the browser top layer, where the ::backdrop always covers the
|
|
625
|
-
// whole viewport — no z-index can beat it.
|
|
626
|
-
useEffect(() => {
|
|
627
|
-
if (update === null || !updateOpen) return undefined;
|
|
628
|
-
const root = document.documentElement;
|
|
629
|
-
root.classList.add('dbf-modal-open');
|
|
630
|
-
return () => root.classList.remove('dbf-modal-open');
|
|
631
|
-
}, [update, updateOpen]);
|
|
632
|
-
|
|
633
|
-
useEffect(() => {
|
|
634
|
-
const element = modalRef.current;
|
|
635
|
-
if (element === null || typeof element.showModal !== 'function' || element.open) return;
|
|
636
|
-
try {
|
|
637
|
-
element.showModal();
|
|
638
|
-
} catch {
|
|
639
|
-
// already open or detached — nothing to do
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
|
|
643
572
|
const flashAtRef = useRef(null);
|
|
644
573
|
const flashTimerRef = useRef(null);
|
|
645
574
|
const leaveTimerRef = useRef(null);
|
|
@@ -653,11 +582,6 @@ window.__ModuleLoader__.load({
|
|
|
653
582
|
useEffect(() => {
|
|
654
583
|
shared.dock = dock;
|
|
655
584
|
}, [dock]);
|
|
656
|
-
useEffect(() => {
|
|
657
|
-
shared.update = update;
|
|
658
|
-
shared.updateOpen = updateOpen;
|
|
659
|
-
}, [update, updateOpen]);
|
|
660
|
-
|
|
661
585
|
// Forces a re-render so the countdown text follows the clock.
|
|
662
586
|
const [, setTick] = useState(0);
|
|
663
587
|
// Host/browser clock offset, so the switch countdown follows the Host.
|
|
@@ -766,43 +690,30 @@ window.__ModuleLoader__.load({
|
|
|
766
690
|
}, 200);
|
|
767
691
|
}, []);
|
|
768
692
|
|
|
769
|
-
/**
|
|
770
|
-
const checkUpdate = useCallback(async (
|
|
771
|
-
|
|
772
|
-
if (showModal) setUpdateOpen(true);
|
|
773
|
-
setUpdate({ phase: 'checking', latest: '', current: '', hasUpdate: false, error: '' });
|
|
774
|
-
updateCheckedAt.current = Date.now();
|
|
693
|
+
/** Silent check so the footer can flag a newer release before you click. */
|
|
694
|
+
const checkUpdate = useCallback(async () => {
|
|
695
|
+
updateCheckedAt.current = Date.now()
|
|
775
696
|
try {
|
|
776
|
-
const response = await fetch(ROUTE_UPDATE
|
|
697
|
+
const response = await fetch(ROUTE_UPDATE, { headers: { accept: 'application/json' }, cache: 'no-store' });
|
|
777
698
|
const body = await response.json();
|
|
778
699
|
if (!aliveRef.current) return;
|
|
779
|
-
if (!response.ok || body?.ok === false)
|
|
780
|
-
setUpdate({ phase: 'error', latest: '', current: body?.current ?? '', hasUpdate: false, error: body?.error ?? 'HTTP ' + response.status });
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
700
|
+
if (!response.ok || body?.ok === false) return;
|
|
783
701
|
setUpdate({
|
|
784
702
|
phase: 'done',
|
|
785
703
|
latest: typeof body.latest === 'string' ? body.latest : '',
|
|
786
704
|
current: typeof body.current === 'string' ? body.current : '',
|
|
787
705
|
hasUpdate: body.hasUpdate === true,
|
|
788
|
-
error: '',
|
|
789
706
|
});
|
|
790
|
-
} catch
|
|
791
|
-
|
|
792
|
-
setUpdate({ phase: 'error', latest: '', current: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) });
|
|
707
|
+
} catch {
|
|
708
|
+
// Silent: a failed check must not disturb the widget.
|
|
793
709
|
}
|
|
794
710
|
}, []);
|
|
795
711
|
|
|
796
|
-
// Check quietly when the card opens so the hover text already knows, and
|
|
797
|
-
// re-check whenever the local version changed since the last answer.
|
|
798
712
|
useEffect(() => {
|
|
799
713
|
if (!open) return;
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (answered && Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
|
|
804
|
-
void checkUpdate(false);
|
|
805
|
-
}, [open, update, snapshot?.version, checkUpdate]);
|
|
714
|
+
if (Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
|
|
715
|
+
void checkUpdate();
|
|
716
|
+
}, [open, snapshot?.version, checkUpdate]);
|
|
806
717
|
|
|
807
718
|
const load = useCallback(async (manual) => {
|
|
808
719
|
// Hold the spinner for at least one full turn: a local read returns in
|
|
@@ -1120,18 +1031,6 @@ window.__ModuleLoader__.load({
|
|
|
1120
1031
|
|
|
1121
1032
|
const dot = h('span', { className: 'dbf-dot ' + (peakActive ? 'is-peak' : 'is-valley'), 'aria-hidden': true });
|
|
1122
1033
|
|
|
1123
|
-
// The version control's hover text reports the last check's outcome.
|
|
1124
|
-
const updateTitle =
|
|
1125
|
-
update === null
|
|
1126
|
-
? t('update.check')
|
|
1127
|
-
: update.phase === 'checking'
|
|
1128
|
-
? t('update.checking')
|
|
1129
|
-
: update.phase === 'error'
|
|
1130
|
-
? t('update.failed') + ' · ' + t('update.retry')
|
|
1131
|
-
: update.hasUpdate
|
|
1132
|
-
? t('update.found', { latest: update.latest, current: update.current }) + ' · ' + t('update.now')
|
|
1133
|
-
: t('update.latest', { current: update.current || snapshot?.version || '—' });
|
|
1134
|
-
|
|
1135
1034
|
// Docked to a side edge: a square ball that only shows the balance.
|
|
1136
1035
|
const docked = appearance.dockBall && dock !== '';
|
|
1137
1036
|
const balanceText = '¥' + money(snapshot?.balance);
|
|
@@ -1543,12 +1442,15 @@ window.__ModuleLoader__.load({
|
|
|
1543
1442
|
'button',
|
|
1544
1443
|
{
|
|
1545
1444
|
type: 'button',
|
|
1546
|
-
className: 'dbf-version' + (update !== null && update.
|
|
1547
|
-
title:
|
|
1548
|
-
|
|
1445
|
+
className: 'dbf-version' + (update !== null && update.hasUpdate ? ' has-update' : ''),
|
|
1446
|
+
title:
|
|
1447
|
+
update !== null && update.hasUpdate
|
|
1448
|
+
? t('version.new', { latest: update.latest })
|
|
1449
|
+
: t('version.open'),
|
|
1450
|
+
onClick: () => openPluginPage(),
|
|
1549
1451
|
},
|
|
1550
1452
|
t('version') + ' v' + (snapshot?.version || '—'),
|
|
1551
|
-
h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '
|
|
1453
|
+
h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '↗'),
|
|
1552
1454
|
),
|
|
1553
1455
|
h(
|
|
1554
1456
|
'span',
|
|
@@ -1709,106 +1611,6 @@ window.__ModuleLoader__.load({
|
|
|
1709
1611
|
)
|
|
1710
1612
|
: null;
|
|
1711
1613
|
|
|
1712
|
-
const updateModal =
|
|
1713
|
-
update === null || !updateOpen
|
|
1714
|
-
? null
|
|
1715
|
-
: h(
|
|
1716
|
-
DIALOG_OK ? 'dialog' : 'div',
|
|
1717
|
-
{
|
|
1718
|
-
ref: DIALOG_OK ? modalRef : undefined,
|
|
1719
|
-
className: DIALOG_OK ? 'dbf-dialog' : 'dbf-modal',
|
|
1720
|
-
role: 'dialog',
|
|
1721
|
-
'aria-modal': 'true',
|
|
1722
|
-
'aria-label': t('update.title'),
|
|
1723
|
-
onCancel: (event) => {
|
|
1724
|
-
event.preventDefault();
|
|
1725
|
-
setUpdateOpen(false);
|
|
1726
|
-
},
|
|
1727
|
-
onClick: (event) => {
|
|
1728
|
-
if (event.target === event.currentTarget) setUpdateOpen(false);
|
|
1729
|
-
},
|
|
1730
|
-
},
|
|
1731
|
-
h(
|
|
1732
|
-
'div',
|
|
1733
|
-
{ className: 'dbf-modal-card dbf-surface' },
|
|
1734
|
-
h(
|
|
1735
|
-
'div',
|
|
1736
|
-
{ className: 'dbf-modal-head' },
|
|
1737
|
-
h('span', { className: 'dbf-modal-icon', 'aria-hidden': true }, '⟳'),
|
|
1738
|
-
h('span', { className: 'dbf-modal-title' }, t('update.title')),
|
|
1739
|
-
),
|
|
1740
|
-
update.phase === 'checking'
|
|
1741
|
-
? h('div', { className: 'dbf-modal-body' }, t('update.checking'))
|
|
1742
|
-
: update.phase === 'error'
|
|
1743
|
-
? h(
|
|
1744
|
-
'div',
|
|
1745
|
-
null,
|
|
1746
|
-
h('div', { className: 'dbf-modal-body dbf-error' }, t('update.failed') + ': ' + update.error),
|
|
1747
|
-
h(
|
|
1748
|
-
'div',
|
|
1749
|
-
{ className: 'dbf-modal-actions' },
|
|
1750
|
-
h(
|
|
1751
|
-
'button',
|
|
1752
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => void checkUpdate(true) },
|
|
1753
|
-
t('update.retry'),
|
|
1754
|
-
),
|
|
1755
|
-
),
|
|
1756
|
-
)
|
|
1757
|
-
: update.hasUpdate
|
|
1758
|
-
? h(
|
|
1759
|
-
'div',
|
|
1760
|
-
null,
|
|
1761
|
-
h('div', { className: 'dbf-modal-body' }, t('update.found', { latest: update.latest, current: update.current })),
|
|
1762
|
-
h(
|
|
1763
|
-
'div',
|
|
1764
|
-
{ className: 'dbf-modal-versions' },
|
|
1765
|
-
h(
|
|
1766
|
-
'span',
|
|
1767
|
-
{ className: 'dbf-modal-version' },
|
|
1768
|
-
h('span', { className: 'dbf-modal-version-label' }, t('update.label.current')),
|
|
1769
|
-
h('span', { className: 'dbf-modal-version-value' }, 'v' + (update.current || '—')),
|
|
1770
|
-
),
|
|
1771
|
-
h('span', { className: 'dbf-modal-arrow', 'aria-hidden': true }, '→'),
|
|
1772
|
-
h(
|
|
1773
|
-
'span',
|
|
1774
|
-
{ className: 'dbf-modal-version is-new' },
|
|
1775
|
-
h('span', { className: 'dbf-modal-version-label' }, t('update.label.latest')),
|
|
1776
|
-
h('span', { className: 'dbf-modal-version-value' }, 'v' + update.latest),
|
|
1777
|
-
),
|
|
1778
|
-
),
|
|
1779
|
-
h('div', { className: 'dbf-modal-note' }, t('update.installHint')),
|
|
1780
|
-
h(
|
|
1781
|
-
'div',
|
|
1782
|
-
{ className: 'dbf-modal-actions' },
|
|
1783
|
-
h(
|
|
1784
|
-
'button',
|
|
1785
|
-
{ type: 'button', className: 'dbf-textbtn', onClick: () => setUpdateOpen(false) },
|
|
1786
|
-
t('update.later'),
|
|
1787
|
-
),
|
|
1788
|
-
h(
|
|
1789
|
-
'button',
|
|
1790
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => void copyInstallSpec() },
|
|
1791
|
-
copied ? t('update.copied') : t('update.copy'),
|
|
1792
|
-
),
|
|
1793
|
-
),
|
|
1794
|
-
)
|
|
1795
|
-
: h(
|
|
1796
|
-
'div',
|
|
1797
|
-
null,
|
|
1798
|
-
h('div', { className: 'dbf-modal-body' }, t('update.latest', { current: update.current || snapshot?.version || '—' })),
|
|
1799
|
-
h(
|
|
1800
|
-
'div',
|
|
1801
|
-
{ className: 'dbf-modal-actions' },
|
|
1802
|
-
h(
|
|
1803
|
-
'button',
|
|
1804
|
-
{ type: 'button', className: 'dbf-btn-primary', onClick: () => setUpdateOpen(false) },
|
|
1805
|
-
t('settings.done'),
|
|
1806
|
-
),
|
|
1807
|
-
),
|
|
1808
|
-
),
|
|
1809
|
-
),
|
|
1810
|
-
);
|
|
1811
|
-
|
|
1812
1614
|
const surface = settingsOpen ? settingsPanel : open ? card : pill;
|
|
1813
1615
|
|
|
1814
1616
|
const tree = h(
|
|
@@ -1817,9 +1619,6 @@ window.__ModuleLoader__.load({
|
|
|
1817
1619
|
h('style', { key: 'css' }, STYLE),
|
|
1818
1620
|
surface,
|
|
1819
1621
|
bubble,
|
|
1820
|
-
createPortal !== null && typeof document !== 'undefined' && updateModal !== null
|
|
1821
|
-
? createPortal(updateModal, document.body)
|
|
1822
|
-
: updateModal,
|
|
1823
1622
|
);
|
|
1824
1623
|
return createPortal !== null && typeof document !== 'undefined' ? createPortal(tree, document.body) : tree;
|
|
1825
1624
|
}
|
|
@@ -1831,9 +1630,19 @@ window.__ModuleLoader__.load({
|
|
|
1831
1630
|
function apply(ctx) {
|
|
1832
1631
|
ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'balance-float: dictionaries');
|
|
1833
1632
|
const t = ctx.locale.bind(NS);
|
|
1633
|
+
// The plugin page ships its own update button, so the footer version just
|
|
1634
|
+
// jumps there instead of running a second update flow.
|
|
1635
|
+
const openPluginPage = () => {
|
|
1636
|
+
try {
|
|
1637
|
+
const navigation = ctx.get('pluginNavigation');
|
|
1638
|
+
navigation?.openBundle?.(PACKAGE_NAME);
|
|
1639
|
+
} catch {
|
|
1640
|
+
// plugin manager UI not installed: nothing to open
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1834
1643
|
ctx.slots.inject('shell.overlay', () =>
|
|
1835
1644
|
ctx.slots.register({ name: 'shell.overlay', id: 'balance-float', order: 60, locale: NS }, (props) =>
|
|
1836
|
-
h(MemoBalanceFloat, { ...props, t }),
|
|
1645
|
+
h(MemoBalanceFloat, { ...props, t, openPluginPage }),
|
|
1837
1646
|
),
|
|
1838
1647
|
);
|
|
1839
1648
|
}
|
package/index.js
CHANGED
|
@@ -57,39 +57,32 @@ function isNewer(a, b) {
|
|
|
57
57
|
return false
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
/** Cached check against the published
|
|
60
|
+
/** Cached check against the version published on npm. */
|
|
61
61
|
const UPDATE_TTL_MS = 5 * 60 * 1000
|
|
62
|
-
// Only the
|
|
63
|
-
// locally bumped version
|
|
62
|
+
// Only the published version is cached; `current` is re-read every call so a
|
|
63
|
+
// locally bumped version is compared against the fresh one.
|
|
64
64
|
let updateCache = { at: 0, latest: null }
|
|
65
65
|
|
|
66
66
|
async function checkUpdate({ fresh = false } = {}) {
|
|
67
67
|
const now = Date.now()
|
|
68
68
|
const current = packageVersion()
|
|
69
|
-
// A manual click must never be answered from the cache: the published version
|
|
70
|
-
// can change right after a silent check.
|
|
71
69
|
if (!fresh && updateCache.latest !== null && now - updateCache.at < UPDATE_TTL_MS) {
|
|
72
70
|
return { ok: true, current, latest: updateCache.latest, hasUpdate: isNewer(updateCache.latest, current) }
|
|
73
71
|
}
|
|
74
72
|
const controller = new AbortController()
|
|
75
73
|
const timer = setTimeout(() => controller.abort(), 10000)
|
|
76
74
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
signal: controller.signal,
|
|
83
|
-
headers: { accept: 'application/vnd.github.raw', 'user-agent': 'dsh-balance-float' },
|
|
84
|
-
},
|
|
85
|
-
)
|
|
75
|
+
const response = await fetch('https://registry.npmjs.org/@lls-a1/dsh-balance-float/latest', {
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
headers: { accept: 'application/json', 'user-agent': 'dsh-balance-float' },
|
|
78
|
+
})
|
|
86
79
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
87
80
|
const pkg = JSON.parse(await response.text())
|
|
88
81
|
const latest = typeof pkg?.version === 'string' ? pkg.version : ''
|
|
89
82
|
if (latest !== '') updateCache = { at: now, latest }
|
|
90
83
|
return { ok: true, current, latest, hasUpdate: latest !== '' && isNewer(latest, current) }
|
|
91
84
|
} catch (error) {
|
|
92
|
-
// Do not cache failures: the next
|
|
85
|
+
// Do not cache failures: the next check retries.
|
|
93
86
|
return { ok: false, current, latest: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) }
|
|
94
87
|
} finally {
|
|
95
88
|
clearTimeout(timer)
|