feat: Bark 增加开始运行与获得学分提醒
收尾通知去掉重复的积分台账与完成门数;学习统计在无 TTY 时照常累计,保证 Docker 里也能推送学分提醒。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
18c5e5a3be
commit
6b508a0b1a
15 files changed
+188
-51
No files matched your search
+13
-5
@@ -35,9 +35,10 @@ export function createStudyTracker(opts = {}) {
|
||||
* 传进来的快照字段可能缺失(页面刚跳转时就是半空的),所以全部按可选处理。
|
||||
*/
|
||||
function update(snap) {
|
||||
if (!snap || snap.noApi) return get();
|
||||
if (!snap || snap.noApi) return { ...get(), earned: [] };
|
||||
const at = now();
|
||||
const course = snap.course || '';
|
||||
const earned = [];
|
||||
|
||||
// ---- 学习时长:只算视频真的在播的时间 ----
|
||||
// 用「两次快照的真实间隔」而不是写死的轮询周期:CDP 往返偶尔会慢,
|
||||
@@ -70,13 +71,15 @@ export function createStudyTracker(opts = {}) {
|
||||
const justDone = lastCourse || course;
|
||||
if (justDone && creditOf.has(justDone) && !credited.has(justDone)) {
|
||||
credited.add(justDone);
|
||||
creditEarned += creditOf.get(justDone);
|
||||
const amount = creditOf.get(justDone);
|
||||
creditEarned += amount;
|
||||
earned.push({ course: justDone, credit: amount });
|
||||
}
|
||||
lastCompleted = completed;
|
||||
}
|
||||
if (course) lastCourse = course;
|
||||
|
||||
return get();
|
||||
return { ...get(), earned };
|
||||
}
|
||||
|
||||
/** 当前统计值(不会被外部改到内部状态) */
|
||||
@@ -93,13 +96,18 @@ export function createStudyTracker(opts = {}) {
|
||||
|
||||
/** 学分文本:整数不带小数点,小数保留最多两位并去掉尾随 0 */
|
||||
function creditText(value) {
|
||||
const v = value === undefined ? creditEarned : value;
|
||||
return String(Number(v.toFixed(2)));
|
||||
return formatCredit(value === undefined ? creditEarned : value);
|
||||
}
|
||||
|
||||
return { update, get, summary, creditText, reset() { studySeconds = 0; creditEarned = 0; credit = null; lastAt = 0; lastPlaying = false; lastCompleted = 0; lastCourse = ''; creditOf.clear(); credited.clear(); } };
|
||||
}
|
||||
|
||||
/** 学分文本:整数不带小数点,小数保留最多两位并去掉尾随 0 */
|
||||
export function formatCredit(value) {
|
||||
const v = Number(value) || 0;
|
||||
return String(Number(v.toFixed(2)));
|
||||
}
|
||||
|
||||
/** 秒 → 1:23:45 / 23:45(与面板显示保持一致,面板自己那份在 tui.mjs) */
|
||||
function fmt(sec) {
|
||||
const s = Math.max(0, Math.round(Number(sec) || 0));
|
||||
|
||||
Reference in new issue
Block a user