跳到主要内容

github/tai

公开

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

提交记录
修改Core/Servicers/Instances/Main.cs+22 −14看文件
@@ -43,7 +43,7 @@ namespace Core.Servicers.Instances
4343 /// <summary>
4444 /// 当前聚焦进程
4545 /// </summary>
46删除: private string activeProcess, activeProcessDescription, activeProcessFile = null;
46新增: private string activeProcess = null;
4747
4848 /// <summary>
4949 /// 焦点开始时间
@@ -61,6 +61,7 @@ namespace Core.Servicers.Instances
6161 private ConfigModel config;
6262
6363 public event EventHandler OnUpdateTime;
64新增: public event EventHandler OnStarted;
6465
6566 /// <summary>
6667 /// 忽略进程缓存列表
@@ -104,8 +105,14 @@ namespace Core.Servicers.Instances
104105 private void DateTimeObserver_OnDateTimeChanging(object sender, DateTime time)
105106 {
106107 Logger.Info("[time changed] status:" + sleepStatus + ",process:" + activeProcess + ",start:" + activeStartTime.ToString() + ",end:" + DateTime.Now.ToString() + ",time:" + time.ToString());
107删除:
108删除: UpdateTime(time);
108新增: if (sleepStatus == SleepStatus.Wake)
109新增: {
110新增: UpdateTime();
111新增: }
112新增: else
113新增: {
114新增: activeStartTime = DateTime.Now;
115新增: }
109116 }
110117
111118 private void AppConfig_ConfigChanged(ConfigModel oldConfig, ConfigModel newConfig)
@@ -157,6 +164,7 @@ namespace Core.Servicers.Instances
157164 // 启动睡眠监测
158165 sleepdiscover.Start();
159166
167新增: OnStarted?.Invoke(this, EventArgs.Empty);
160168 }
161169
162170 public void Exit()
@@ -188,14 +196,11 @@ namespace Core.Servicers.Instances
188196 {
189197 this.sleepStatus = sleepStatus;
190198
191删除: Debug.WriteLine("睡眠状态:" + sleepStatus);
192删除: Logger.Info("【" + sleepStatus + "】当前进程:" + activeProcess);
199新增: Logger.Info($"[{sleepStatus}] process:{activeProcess},start:{activeStartTime}");
193200 if (sleepStatus == SleepStatus.Sleep)
194201 {
195202 // 更新时间
196203 UpdateTime();
197删除:
198删除: activeProcess = null;
199204 }
200205 else if (sleepStatus == SleepStatus.Wake)
201206 {
@@ -258,22 +263,25 @@ namespace Core.Servicers.Instances
258263
259264 private void Observer_OnAppActive(string processName, string description, string file)
260265 {
266新增: if (sleepStatus == SleepStatus.Sleep)
267新增: {
268新增: return;
269新增: }
270新增:
261271 bool isCheck = IsCheckApp(processName, description, file);
262272
263删除: if (activeProcess != processName && activeProcessFile != file)
273新增: if (activeProcess != processName)
264274 {
265275 UpdateTime();
266276 }
267277
268删除: if (isCheck && sleepStatus != SleepStatus.Sleep)
278新增: if (isCheck)
269279 {
270280 if (activeProcess == null)
271281 {
272282 activeStartTime = DateTime.Now;
273283 }
274284 activeProcess = processName;
275删除: activeProcessDescription = description;
276删除: activeProcessFile = file;
277285 }
278286 else
279287 {
@@ -329,10 +337,12 @@ namespace Core.Servicers.Instances
329337 }
330338 #endregion
331339
332删除: private void UpdateTime(DateTime? time = null)
340新增: private void UpdateTime()
333341 {
334342 if (!string.IsNullOrEmpty(activeProcess))
335343 {
344新增: var time = activeStartTime;
345新增:
336346 // 更新计时
337347 TimeSpan timeSpan = DateTime.Now - activeStartTime;
338348
@@ -357,8 +367,6 @@ namespace Core.Servicers.Instances
357367 activeStartTime = DateTime.Now;
358368
359369 OnUpdateTime?.Invoke(this, null);
360删除:
361删除:
362370 }
363371 }
364372
修改Core/Servicers/Interfaces/IMain.cs+4 −0看文件
@@ -24,5 +24,9 @@ namespace Core.Servicers.Interfaces
2424 /// 更新某个进程时间时发生
2525 /// </summary>
2626 event EventHandler OnUpdateTime;
27新增: /// <summary>
28新增: /// 初始化完成时发生
29新增: /// </summary>
30新增: event EventHandler OnStarted;
2731 }
2832}