Skip to content

Commit b7f83ea

Browse files
committed
🐛 番茄钟双击编辑时长后,统计时长有误
1 parent 21ae54f commit b7f83ea

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

src/components/PomodoroTimer.ts

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export class PomodoroTimer {
4747
private isExpanded: boolean = true;
4848
private isMinimized: boolean = false;
4949
private startTime: number = 0; // 记录开始时间
50+
51+
// 新增:当前阶段的原始设定时长(用于统计)
52+
private currentPhaseOriginalDuration: number = 0; // 当前阶段的原始设定时长(分钟)
5053
// 新增:自动模式相关属性
5154
private autoMode: boolean = false; // 自动模式状态
5255
private longBreakInterval: number = 4; // 长休息间隔
@@ -82,6 +85,9 @@ export class PomodoroTimer {
8285
this.totalTime = this.timeLeft;
8386
this.recordManager = PomodoroRecordManager.getInstance();
8487

88+
// 初始化当前阶段的原始时长(分钟)
89+
this.currentPhaseOriginalDuration = settings.workDuration;
90+
8591
// 初始化声音设置
8692
this.isBackgroundAudioMuted = settings.backgroundAudioMuted || false;
8793
this.backgroundVolume = Math.max(0, Math.min(1, settings.backgroundVolume || 0.5));
@@ -302,7 +308,7 @@ export class PomodoroTimer {
302308
if (this.randomNotificationSystemNotificationEnabled) {
303309
this.showSystemNotification(
304310
t('randomNotificationSettings'),
305-
t('randomRest')
311+
t('randomRest', { duration: this.settings.randomNotificationBreakDuration })
306312
);
307313
}
308314

@@ -1963,6 +1969,9 @@ export class PomodoroTimer {
19631969
this.isRunning = false;
19641970
this.isPaused = false;
19651971

1972+
// 设置当前阶段的原始时长
1973+
this.currentPhaseOriginalDuration = this.settings.workDuration;
1974+
19661975
if (this.isCountUp) {
19671976
this.timeElapsed = 0;
19681977
// 不重置番茄计数,保持累计
@@ -1994,6 +2003,9 @@ export class PomodoroTimer {
19942003
this.isRunning = false;
19952004
this.isPaused = false;
19962005

2006+
// 设置当前阶段的原始时长
2007+
this.currentPhaseOriginalDuration = this.settings.breakDuration;
2008+
19972009
if (this.isCountUp) {
19982010
this.timeElapsed = 0;
19992011
this.breakTimeLeft = this.settings.breakDuration * 60;
@@ -2024,6 +2036,9 @@ export class PomodoroTimer {
20242036
this.isRunning = false;
20252037
this.isPaused = false;
20262038

2039+
// 设置当前阶段的原始时长
2040+
this.currentPhaseOriginalDuration = this.settings.longBreakDuration;
2041+
20272042
if (this.isCountUp) {
20282043
this.timeElapsed = 0;
20292044
this.breakTimeLeft = this.settings.longBreakDuration * 60;
@@ -2047,6 +2062,9 @@ export class PomodoroTimer {
20472062
// this.completedPomodoros = 0;
20482063
this.statusDisplay.textContent = '工作时间';
20492064

2065+
// 重置当前阶段的原始时长为工作时长
2066+
this.currentPhaseOriginalDuration = this.settings.workDuration;
2067+
20502068
if (this.timer) {
20512069
clearInterval(this.timer);
20522070
this.timer = null;
@@ -2164,17 +2182,16 @@ export class PomodoroTimer {
21642182
} else {
21652183
// 正计时模式完成番茄后也要停止随机提示音
21662184
this.stopRandomNotificationTimer();
2167-
}
2168-
2169-
// 无论哪种模式都记录完成的工作番茄
2185+
} // 无论哪种模式都记录完成的工作番茄
21702186
const eventId = this.reminder.isRepeatInstance ? this.reminder.originalId : this.reminder.id;
21712187
const eventTitle = this.reminder.title || '番茄专注';
21722188

2189+
// 使用当前阶段的实际设定时长进行记录
21732190
await this.recordManager.recordWorkSession(
2174-
this.settings.workDuration,
2191+
this.currentPhaseOriginalDuration,
21752192
eventId,
21762193
eventTitle,
2177-
this.settings.workDuration,
2194+
this.currentPhaseOriginalDuration,
21782195
true
21792196
);
21802197

@@ -2218,15 +2235,14 @@ export class PomodoroTimer {
22182235
}
22192236

22202237
// 记录完成的休息时间
2221-
const breakDuration = this.isLongBreak ? this.settings.longBreakDuration : this.settings.breakDuration;
22222238
const eventId = this.reminder.isRepeatInstance ? this.reminder.originalId : this.reminder.id;
22232239
const eventTitle = this.reminder.title || '番茄专注';
22242240

22252241
await this.recordManager.recordBreakSession(
2226-
breakDuration,
2242+
this.currentPhaseOriginalDuration,
22272243
eventId,
22282244
eventTitle,
2229-
breakDuration,
2245+
this.currentPhaseOriginalDuration,
22302246
this.isLongBreak,
22312247
true
22322248
);
@@ -2283,16 +2299,15 @@ export class PomodoroTimer {
22832299

22842300
if (this.workEndAudio) {
22852301
await this.safePlayAudio(this.workEndAudio);
2286-
}
2287-
// 记录完成的工作番茄
2302+
} // 记录完成的工作番茄
22882303
const eventId = this.reminder.isRepeatInstance ? this.reminder.originalId : this.reminder.id;
22892304
const eventTitle = this.reminder.title || '番茄专注';
22902305

22912306
await this.recordManager.recordWorkSession(
2292-
this.settings.workDuration,
2307+
this.currentPhaseOriginalDuration,
22932308
eventId,
22942309
eventTitle,
2295-
this.settings.workDuration,
2310+
this.currentPhaseOriginalDuration,
22962311
true
22972312
);
22982313

@@ -2312,22 +2327,25 @@ export class PomodoroTimer {
23122327
setTimeout(() => {
23132328
this.autoSwitchToBreak(shouldTakeLongBreak);
23142329
}, 1000);
2315-
} else {
2316-
// 非自动模式下,也要根据番茄钟数量判断休息类型
2330+
} else { // 非自动模式下,也要根据番茄钟数量判断休息类型
23172331
if (shouldTakeLongBreak) {
23182332
showMessage(`🍅 工作时间结束!已完成${this.completedPomodoros}个番茄,开始长时休息`, 3000);
23192333
this.isWorkPhase = false;
23202334
this.isLongBreak = true;
23212335
this.statusDisplay.textContent = '长时休息';
23222336
this.timeLeft = this.settings.longBreakDuration * 60;
23232337
this.totalTime = this.timeLeft;
2338+
// 设置当前阶段的原始时长
2339+
this.currentPhaseOriginalDuration = this.settings.longBreakDuration;
23242340
} else {
23252341
showMessage('🍅 工作时间结束!开始短时休息', 3000);
23262342
this.isWorkPhase = false;
23272343
this.isLongBreak = false;
23282344
this.statusDisplay.textContent = '短时休息';
23292345
this.timeLeft = this.settings.breakDuration * 60;
23302346
this.totalTime = this.timeLeft;
2347+
// 设置当前阶段的原始时长
2348+
this.currentPhaseOriginalDuration = this.settings.breakDuration;
23312349
}
23322350
this.isRunning = false;
23332351
this.isPaused = false;
@@ -2340,15 +2358,14 @@ export class PomodoroTimer {
23402358
}
23412359

23422360
// 记录完成的休息时间
2343-
const breakDuration = this.isLongBreak ? this.settings.longBreakDuration : this.settings.breakDuration;
23442361
const eventId = this.reminder.isRepeatInstance ? this.reminder.originalId : this.reminder.id;
23452362
const eventTitle = this.reminder.title || '番茄专注';
23462363

23472364
await this.recordManager.recordBreakSession(
2348-
breakDuration,
2365+
this.currentPhaseOriginalDuration,
23492366
eventId,
23502367
eventTitle,
2351-
breakDuration,
2368+
this.currentPhaseOriginalDuration,
23522369
this.isLongBreak,
23532370
true
23542371
);
@@ -2380,6 +2397,8 @@ export class PomodoroTimer {
23802397
this.statusDisplay.textContent = '工作时间';
23812398
this.timeLeft = this.settings.workDuration * 60;
23822399
this.totalTime = this.timeLeft;
2400+
// 设置当前阶段的原始时长
2401+
this.currentPhaseOriginalDuration = this.settings.workDuration;
23832402
this.isRunning = false;
23842403
this.isPaused = false;
23852404
this.updateDisplay();
@@ -2408,16 +2427,17 @@ export class PomodoroTimer {
24082427
if (this.autoTransitionTimer) {
24092428
clearTimeout(this.autoTransitionTimer);
24102429
this.autoTransitionTimer = null;
2411-
}
2412-
2413-
// 设置休息阶段
2430+
} // 设置休息阶段
24142431
this.isWorkPhase = false;
24152432
this.isLongBreak = isLongBreak;
24162433
this.isRunning = true;
24172434
this.isPaused = false;
24182435

24192436
const breakDuration = isLongBreak ? this.settings.longBreakDuration : this.settings.breakDuration;
24202437

2438+
// 设置当前阶段的原始时长
2439+
this.currentPhaseOriginalDuration = breakDuration;
2440+
24212441
if (this.isCountUp) {
24222442
this.timeElapsed = 0;
24232443
this.breakTimeLeft = breakDuration * 60;
@@ -2471,14 +2491,15 @@ export class PomodoroTimer {
24712491
if (this.autoTransitionTimer) {
24722492
clearTimeout(this.autoTransitionTimer);
24732493
this.autoTransitionTimer = null;
2474-
}
2475-
2476-
// 设置工作阶段
2494+
} // 设置工作阶段
24772495
this.isWorkPhase = true;
24782496
this.isLongBreak = false;
24792497
this.isRunning = true;
24802498
this.isPaused = false;
24812499

2500+
// 设置当前阶段的原始时长
2501+
this.currentPhaseOriginalDuration = this.settings.workDuration;
2502+
24822503
if (this.isCountUp) {
24832504
this.timeElapsed = 0;
24842505
this.breakTimeLeft = 0;
@@ -2667,16 +2688,18 @@ export class PomodoroTimer {
26672688
showMessage(t('timeRangeLimit') || '时间必须在 00:01 到 999:59 之间', 3000);
26682689
parent.replaceChild(this.timeDisplay, input);
26692690
return;
2670-
}
2671-
2672-
// 更新对应的时间
2691+
} // 更新对应的时间
26732692
if (this.isCountUp && !this.isWorkPhase) {
26742693
// 正计时休息模式
26752694
this.breakTimeLeft = newTimeInSeconds;
2695+
// 更新当前休息阶段的原始时长
2696+
this.currentPhaseOriginalDuration = Math.floor(newTimeInSeconds / 60);
26762697
} else if (!this.isCountUp) {
26772698
// 倒计时模式
26782699
this.timeLeft = newTimeInSeconds;
26792700
this.totalTime = newTimeInSeconds;
2701+
// 更新当前阶段的原始时长
2702+
this.currentPhaseOriginalDuration = Math.floor(newTimeInSeconds / 60);
26802703
}
26812704

26822705
// 恢复时间显示

0 commit comments

Comments
 (0)