creditdaddy 1.8.1 → 1.8.2

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.
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Windows 托盘(PowerShell NotifyIcon)— 移植自 10Router cli/src/cli/tray/trayWin.js(AGPL-3.0 同族,10R ← CD 双向移植免记账)。
3
+ *
4
+ * 为什么不用 systray 的 Go 二进制:杀软误报(Kaspersky 等 flag tray_windows.exe),
5
+ * PowerShell 方案零二进制依赖、免签名。IPC:stdin JSON 命令 / stdout JSON 事件。
6
+ */
7
+ import { spawn, execSync } from 'node:child_process';
8
+ import path from 'node:path';
9
+ import fs from 'node:fs';
10
+ import readline from 'node:readline';
11
+
12
+ let psProcess = null;
13
+ let clickHandler = null;
14
+
15
+ /**
16
+ * Windows 托盘背景主题:true = 浅色,false = 深色(默认)。
17
+ * 任务栏颜色跟随「Windows 模式」(SystemUsesLightTheme),不是「应用模式」
18
+ * (AppsUseLightTheme)——自定义主题下两者可不同,优先读任务栏自己的值。
19
+ */
20
+ function isWindowsLightTheme() {
21
+ const key = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize';
22
+ try {
23
+ const out = execSync(`reg query "${key}" /v SystemUsesLightTheme`, {
24
+ encoding: 'utf8', timeout: 2000, windowsHide: true,
25
+ });
26
+ return /0x1\b/.test(out);
27
+ } catch (e) { /* fall through to app mode */ }
28
+ try {
29
+ const out = execSync(`reg query "${key}" /v AppsUseLightTheme`, {
30
+ encoding: 'utf8', timeout: 2000, windowsHide: true,
31
+ });
32
+ return /0x1\b/.test(out);
33
+ } catch (e) {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /** 单色托盘图标跟随系统主题(深任务栏白色 / 浅任务栏黑色),缺资源回落品牌彩图标 */
39
+ function winTrayIconPath() {
40
+ const mono = path.join(__dirname, isWindowsLightTheme() ? 'icon-mono-black.ico' : 'icon-mono-white.ico');
41
+ try {
42
+ if (fs.existsSync(mono)) return mono;
43
+ } catch (e) {}
44
+ return path.join(__dirname, 'icon.ico');
45
+ }
46
+
47
+ function sendCommand(cmd) {
48
+ if (psProcess && psProcess.stdin.writable) {
49
+ psProcess.stdin.write(`${JSON.stringify(cmd)}\n`, 'utf8');
50
+ }
51
+ }
52
+
53
+ /**
54
+ * 初始化 Windows 托盘
55
+ * @param {Object} options - { iconPath, tooltip, items, onClick }
56
+ * @returns {Object|null} controller with updateItem/setTooltip/kill
57
+ */
58
+ function initWinTray(options) {
59
+ const { iconPath, tooltip, items, onClick } = options;
60
+ clickHandler = onClick;
61
+
62
+ const scriptPath = path.join(__dirname, 'tray.ps1');
63
+
64
+ try {
65
+ psProcess = spawn(
66
+ 'powershell.exe',
67
+ [
68
+ '-NoProfile',
69
+ '-ExecutionPolicy', 'Bypass',
70
+ '-WindowStyle', 'Hidden',
71
+ '-InputFormat', 'Text',
72
+ '-OutputFormat', 'Text',
73
+ '-File', scriptPath,
74
+ '-IconPath', iconPath,
75
+ '-Tooltip', tooltip,
76
+ ],
77
+ { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] },
78
+ );
79
+ } catch (err) {
80
+ return null;
81
+ }
82
+
83
+ const rl = readline.createInterface({ input: psProcess.stdout });
84
+ rl.on('line', (line) => {
85
+ try {
86
+ const evt = JSON.parse(line);
87
+ if (evt.type === 'click' && clickHandler) {
88
+ clickHandler(evt.index);
89
+ }
90
+ } catch (e) {}
91
+ });
92
+
93
+ psProcess.on('error', () => {});
94
+ psProcess.stderr.on('data', () => {});
95
+
96
+ items.forEach((item, index) => {
97
+ sendCommand({ action: 'add-item', index, title: item.title, enabled: item.enabled });
98
+ });
99
+
100
+ return {
101
+ updateItem(index, title, enabled) {
102
+ sendCommand({ action: 'update-item', index, title, enabled });
103
+ },
104
+ setTooltip(text) {
105
+ sendCommand({ action: 'set-tooltip', text });
106
+ },
107
+ kill() {
108
+ try {
109
+ sendCommand({ action: 'kill' });
110
+ } catch (e) {}
111
+ setTimeout(() => {
112
+ if (psProcess && !psProcess.killed) {
113
+ try { psProcess.kill(); } catch (e) {}
114
+ }
115
+ psProcess = null;
116
+ }, 300);
117
+ },
118
+ };
119
+ }
120
+
121
+ export { initWinTray, isWindowsLightTheme, winTrayIconPath };
@@ -755,7 +755,18 @@ export function normalizeBalance(balanceResp) {
755
755
  const d = balanceResp?.data || {};
756
756
  const epochMs = (v) => iso(Number(v) * (Number(v) < 1e12 ? 1000 : 1));
757
757
  const plans = Array.isArray(d.plans) ? d.plans.filter((p) => String(p.status || '').toLowerCase() === 'active') : [];
758
- const balanceParts = (Array.isArray(d.balances) ? d.balances : []).map((b) => {
758
+ // 过期包过滤(2026-11-19 用户实测:已过期的资源包还挂在卡上,有时还配着「已领取」徽章):
759
+ // 服务端的 balances 不清理过期行(expire_at 已过仍返 remaining=3亿),直接全量映射会让
760
+ // 面板展示已失效的额度。expire_at 已过的行丢弃——one_time 包过期即无意义;周期包
761
+ // (recurring)的 expire_at 是下一轮重置点,不算过期(period_end 语义),不过滤。
762
+ // 注意 epochMs 返回 ISO 字符串(经 iso() 包装),比较前转数字
763
+ const expired = (ms) => { if (!ms) return false; const t = new Date(ms).getTime(); return Number.isFinite(t) && t <= Date.now(); };
764
+ const balanceParts = (Array.isArray(d.balances) ? d.balances : [])
765
+ .filter((b) => {
766
+ const exp = epochMs(b.expire_at || 0);
767
+ return !(expired(exp) && String(b.period || 'one_time').toLowerCase() === 'one_time');
768
+ })
769
+ .map((b) => {
759
770
  const total = Number(b.total_units);
760
771
  const used = Number(b.used_units);
761
772
  const remaining = Number(b.remaining_units ?? b.available_units);
@@ -775,6 +786,11 @@ export function normalizeBalance(balanceResp) {
775
786
  const entitlementParts = plans.flatMap((p) =>
776
787
  (Array.isArray(p.entitlements) ? p.entitlements : [])
777
788
  .filter((e) => e.unit_type === 'token' && Number(e.grant_units) > 0)
789
+ // 同款过期过滤:one_time 包的 plan.ends_at 已过 = 该活动额度已失效,不再派生展示
790
+ .filter((e) => {
791
+ const endsAt = epochMs(p.ends_at);
792
+ return !(expired(endsAt) && String(e.period || 'one_time').toLowerCase() === 'one_time');
793
+ })
778
794
  .map((e) => {
779
795
  const grant = Number(e.grant_units);
780
796
  const startsAt = epochMs(e.effective_at || p.starts_at);