Compare commits
2 Commits
aa8467ccce
...
e26c015e09
| Author | SHA1 | Date | |
|---|---|---|---|
| e26c015e09 | |||
| ff8c7f032d |
@@ -16,6 +16,7 @@ namespace TimerApp
|
||||
private DateTime _lastWorkStartTime;
|
||||
private TimeSpan _accumulatedWorkTime;
|
||||
private DateTime _restStartTime;
|
||||
private int _restElapsedSeconds; // 休息已过秒数(用于避免时间计算导致的跳变)
|
||||
|
||||
// 配置 (默认值)
|
||||
public TimeSpan WorkDuration { get; set; } = TimeSpan.FromMinutes(20);
|
||||
@@ -73,10 +74,12 @@ namespace TimerApp
|
||||
if (CurrentState == MonitorState.Resting)
|
||||
{
|
||||
// 休息模式逻辑
|
||||
TimeSpan timeInRest = DateTime.Now - _restStartTime;
|
||||
TimeSpan remainingRest = RestDuration - timeInRest;
|
||||
// 使用计数器而不是时间差,避免秒数跳变
|
||||
_restElapsedSeconds++;
|
||||
int totalRestSeconds = (int)RestDuration.TotalSeconds;
|
||||
int remainingSeconds = totalRestSeconds - _restElapsedSeconds;
|
||||
|
||||
if (remainingRest <= TimeSpan.Zero)
|
||||
if (remainingSeconds <= 0)
|
||||
{
|
||||
// 休息结束
|
||||
RestEnded?.Invoke(this, EventArgs.Empty);
|
||||
@@ -84,6 +87,7 @@ namespace TimerApp
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan remainingRest = TimeSpan.FromSeconds(remainingSeconds);
|
||||
RestProgressChanged?.Invoke(this, remainingRest);
|
||||
}
|
||||
}
|
||||
@@ -130,6 +134,7 @@ namespace TimerApp
|
||||
{
|
||||
// 触发休息
|
||||
_restStartTime = DateTime.Now;
|
||||
_restElapsedSeconds = 0; // 重置休息计数器
|
||||
ChangeState(MonitorState.Resting);
|
||||
RestStarted?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
@@ -145,6 +150,7 @@ namespace TimerApp
|
||||
public void ForceRest()
|
||||
{
|
||||
_restStartTime = DateTime.Now;
|
||||
_restElapsedSeconds = 0; // 重置休息计数器
|
||||
ChangeState(MonitorState.Resting);
|
||||
RestStarted?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
@@ -158,8 +164,11 @@ namespace TimerApp
|
||||
}
|
||||
else if (CurrentState == MonitorState.Resting)
|
||||
{
|
||||
TimeSpan timeInRest = DateTime.Now - _restStartTime;
|
||||
TimeSpan remaining = RestDuration - timeInRest;
|
||||
// 使用计数器计算剩余时间,保持一致性
|
||||
int totalRestSeconds = (int)RestDuration.TotalSeconds;
|
||||
int remainingSeconds = totalRestSeconds - _restElapsedSeconds;
|
||||
if (remainingSeconds < 0) remainingSeconds = 0;
|
||||
TimeSpan remaining = TimeSpan.FromSeconds(remainingSeconds);
|
||||
RestProgressChanged?.Invoke(this, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
8
MainForm.Designer.cs
generated
8
MainForm.Designer.cs
generated
@@ -190,9 +190,9 @@ namespace TimerApp
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
|
||||
this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label1.ForeColor = System.Drawing.Color.LightGray;
|
||||
this.label1.Location = new System.Drawing.Point(40, 20);
|
||||
this.label1.Location = new System.Drawing.Point(40, 22);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(100, 23);
|
||||
this.label1.TabIndex = 0;
|
||||
@@ -246,9 +246,9 @@ namespace TimerApp
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
|
||||
this.label2.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label2.Font = new System.Drawing.Font("Microsoft YaHei UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label2.ForeColor = System.Drawing.Color.LightGray;
|
||||
this.label2.Location = new System.Drawing.Point(40, 60);
|
||||
this.label2.Location = new System.Drawing.Point(40, 62);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(100, 23);
|
||||
this.label2.TabIndex = 4;
|
||||
|
||||
Reference in New Issue
Block a user