Skip to content

Commit 635b6f6

Browse files
committed
添加深度专注功能
1 parent 19a546e commit 635b6f6

File tree

5 files changed

+132
-49
lines changed

5 files changed

+132
-49
lines changed

TimeControl/Data/TimeData.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ namespace TimeControl.Data
88
{
99
public class TimeData
1010
{
11-
public TimeSpan Time { get; set; }=new TimeSpan();
11+
public TimeSpan LockTime { get; set; }=new TimeSpan();
12+
public TimeSpan DeepLockTime { get; set; } = new TimeSpan();
1213
public void AddTime(TimeSpan time)
1314
{
14-
Time += time;
15+
LockTime += time;
16+
}public void AddDeepTime(TimeSpan time)
17+
{
18+
DeepLockTime += time;
1519
}
1620
}
1721
}

TimeControl/Tools/TimeControlFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public static class TimeControlFile
2424
public static readonly string WhiteAppLocation = BaseLocation + "\\WhiteApp.txt";//应用白名单保存
2525
public static readonly string TempTimeFile = BaseLocation + "\\Temp.txt";
2626
public static readonly string NoteFile = BaseLocation + "\\Notes.txt";
27+
//深度屏保
28+
public static readonly string DeepTempTimeFile = BaseLocation + "DeepTemp.txt";
2729
//自动关机
2830
public static readonly string ShutdownSpan = BaseLocation + "\\Shutdown.txt";
2931
//数据显示

TimeControl/Windows/ControlPanel.Designer.cs

Lines changed: 78 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/Windows/ControlPanel.cs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public ControlPanel(bool hide)
2323
{
2424
InitializeComponent();
2525
this.hide = hide;
26+
//数据记录
27+
if (File.Exists(TimeControlFile.SavedData))
28+
{
29+
timeData = TimeControlFile.ReadTimeData();
30+
RefreshAndSaveData();
31+
}
32+
else
33+
{
34+
timeData = new();
35+
RefreshAndSaveData();
36+
}
2637
//屏保
2738
if (File.Exists(TimeControlFile.WhiteAppLocation))
2839
whiteProcessBox.Text = File.ReadAllText(TimeControlFile.WhiteAppLocation);
@@ -31,6 +42,24 @@ public ControlPanel(bool hide)
3142
MessageBox.Show("恢复屏保");
3243
StartLock(unlockPasswordHash);
3344
}
45+
//深度专注
46+
if (File.Exists(TimeControlFile.DeepTempTimeFile))
47+
{
48+
string[] deepTimeFileStr=File.ReadAllLines(TimeControlFile.DeepTempTimeFile);
49+
TimeSpan deepFocusTime = DateTime.Now -
50+
DateTime.Parse(deepTimeFileStr[0]);
51+
if (deepFocusTime < TimeSpan.Parse(deepTimeFileStr[1]))
52+
{
53+
SystemControl.Shutdown();
54+
Application.Exit();
55+
}
56+
else
57+
{
58+
File.Delete(TimeControlFile.DeepTempTimeFile);
59+
timeData.AddDeepTime(deepFocusTime);
60+
RefreshAndSaveData();
61+
}
62+
}
3463
//程序计时
3564
if (!Directory.Exists(TimeControlFile.BaseLocation))
3665
{
@@ -51,17 +80,6 @@ public ControlPanel(bool hide)
5180
}
5281
Application.Exit();
5382
}
54-
//数据记录
55-
if(File.Exists(TimeControlFile.SavedData))
56-
{
57-
timeData = TimeControlFile.ReadTimeData();
58-
RefreshAndSaveData();
59-
}
60-
else
61-
{
62-
timeData = new();
63-
RefreshAndSaveData();
64-
}
6583
//密码
6684
if (File.Exists(TimeControlFile.PassLocation))//加载密码哈希值
6785
{
@@ -164,6 +182,16 @@ private void WhiteProcessBox_TextChanged(object sender, EventArgs e)
164182

165183
#endregion
166184

185+
#region DeepLockPage
186+
private void deepStartButton_Click(object sender, EventArgs e)
187+
{
188+
TimeSpan deepTime =new(0, (int)deepTimeInput.Value,0);
189+
File.WriteAllText(TimeControlFile.DeepTempTimeFile, DateTime.Now + Environment.NewLine + deepTime);
190+
SystemControl.Shutdown();
191+
Application.Exit();
192+
}
193+
#endregion
194+
167195
#region ProcessPage
168196

169197
private void FileSaveTimer_Tick(object sender, EventArgs e)
@@ -313,13 +341,11 @@ private void RemoveBootButton_Click(object sender, EventArgs e)
313341
private void RefreshAndSaveData()
314342
{
315343
//刷新列表
316-
//屏保合计
344+
//普通屏保
317345
dataGridView.Rows.Clear();
318-
dataGridView.Rows.Add();
319-
dataGridView.Rows[0].Cells[0].Value = timeData.Time.Hours;
320-
dataGridView.Rows[0].Cells[1].Value = timeData.Time.Minutes;
321-
dataGridView.Rows[0].Cells[2].Value = timeData.Time.Seconds;
322-
dataGridView.Rows[0].Cells[3].Value = "屏保合计";
346+
dataGridView.Rows.Add(timeData.LockTime, "普通屏保");
347+
//深度专注屏保
348+
dataGridView.Rows.Add(timeData.DeepLockTime, "深度专注屏保");
323349
//保存
324350
TimeControlFile.SaveTimeData(timeData);
325351
}

TimeControl/Windows/ControlPanel.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
<resheader name="writer">
5858
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
5959
</resheader>
60-
<metadata name="hourColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
60+
<metadata name="timeColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6161
<value>True</value>
6262
</metadata>
63-
<metadata name="minuteColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
63+
<metadata name="nameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6464
<value>True</value>
6565
</metadata>
66-
<metadata name="secondColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
66+
<metadata name="timeColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6767
<value>True</value>
6868
</metadata>
6969
<metadata name="nameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

0 commit comments

Comments
 (0)