跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
修改Core/Servicers/Instances/Main.cs+32 −7看文件
@@ -11,6 +11,8 @@ using System.Diagnostics;
1111using System.Linq;
1212using System.Text;
1313using System.Threading.Tasks;
14新增:using System.Timers;
15新增:using System.Windows.Threading;
1416
1517namespace Core.Servicers.Instances
1618{
@@ -42,7 +44,7 @@ namespace Core.Servicers.Instances
4244 /// <summary>
4345 /// 活动计时器
4446 /// </summary>
45删除: private Stopwatch activeWatcher;
47新增: private Timer activeTimer;
4648 /// <summary>
4749 /// 睡眠状态
4850 /// </summary>
@@ -54,7 +56,10 @@ namespace Core.Servicers.Instances
5456 private ConfigModel config;
5557
5658 public event EventHandler OnUpdateTime;
57删除:
59新增: /// <summary>
60新增: /// 当前焦点使用时长(秒)
61新增: /// </summary>
62新增: private int activeSeconds = 0;
5863 public Main(
5964 IObserver observer,
6065 IData data,
@@ -69,12 +74,26 @@ namespace Core.Servicers.Instances
6974
7075 observer.OnAppActive += Observer_OnAppActive;
7176 sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged;
72删除: activeWatcher = new Stopwatch();
77新增: activeTimer = new Timer();
78新增: activeTimer.Interval = 1000;
79新增: activeTimer.Elapsed += ActiveTimer_Elapsed;
80新增: activeTimer.Disposed += ActiveTimer_Disposed;
7381 appConfig.ConfigChanged += AppConfig_ConfigChanged;
7482 dateObserver.OnDateChanging += DateObserver_OnDateChanging;
7583
7684 }
7785
86新增: private void ActiveTimer_Disposed(object sender, EventArgs e)
87新增: {
88新增: Debug.WriteLine("disposed!timer");
89新增: }
90新增:
91新增: private void ActiveTimer_Elapsed(object sender, ElapsedEventArgs e)
92新增: {
93新增: activeSeconds++;
94新增: Debug.WriteLine(activeSeconds.ToString());
95新增: }
96新增:
7897 private void DateObserver_OnDateChanging(object sender, EventArgs e)
7998 {
8099 Debug.WriteLine("日期变更前:" + DateTime.Now.ToString());
@@ -126,7 +145,7 @@ namespace Core.Servicers.Instances
126145
127146 activeProcess = null;
128147
129删除: activeWatcher.Stop();
148新增: activeTimer.Stop();
130149 }
131150 }
132151
@@ -148,7 +167,12 @@ namespace Core.Servicers.Instances
148167 activeProcessFile = file;
149168
150169 //activeStartTime = DateTime.Now;
151删除: activeWatcher.Restart();
170新增:
171新增: activeSeconds = 0;
172新增: if (!activeTimer.Enabled)
173新增: {
174新增: activeTimer.Start();
175新增: }
152176
153177 // 提取icon
154178 Iconer.ExtractFromFile(file, processName, description);
@@ -156,7 +180,8 @@ namespace Core.Servicers.Instances
156180 else
157181 {
158182 activeProcess = null;
159删除: activeWatcher.Stop();
183新增: activeSeconds = 0;
184新增: activeTimer.Stop();
160185 }
161186 }
162187
@@ -214,7 +239,7 @@ namespace Core.Servicers.Instances
214239 {
215240 // 更新计时
216241
217删除: int seconds = (int)activeWatcher.Elapsed.TotalSeconds;
242新增: int seconds = activeSeconds;
218243
219244 Debug.WriteLine(sleepStatus + " 进程:" + activeProcess + " 更新时间:" + seconds);
220245 if (seconds <= 0)