跳到主要内容

github/tai

公开

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

提交记录
修改Core/Servicers/Instances/Main.cs+56 −39看文件
@@ -31,7 +31,16 @@ namespace Core.Servicers.Instances
3131 "ApplicationFrameHost",
3232 "StartMenuExperienceHost",
3333 "ShellExperienceHost",
34删除: "OpenWith"
34新增: "OpenWith",
35新增: "Updater",
36新增: "LockApp",
37新增: "",
38新增: "",
39新增: "",
40新增: "",
41新增: "",
42新增: "",
43新增:
3544 };
3645
3746 /// <summary>
@@ -39,12 +48,15 @@ namespace Core.Servicers.Instances
3948 /// </summary>
4049 private string activeProcess, activeProcessDescription, activeProcessFile = null;
4150
42删除: //private DateTime activeStartTime = DateTime.Now;
43删除:
4451 /// <summary>
45删除: /// 活动计时器
52新增: /// 焦点开始时间
4653 /// </summary>
47删除: private Timer activeTimer;
54新增: private DateTime activeStartTime = DateTime.Now;
55新增:
56新增: ///// <summary>
57新增: ///// 活动计时器
58新增: ///// </summary>
59新增: //private Timer activeTimer;
4860 /// <summary>
4961 /// 睡眠状态
5062 /// </summary>
@@ -56,10 +68,10 @@ namespace Core.Servicers.Instances
5668 private ConfigModel config;
5769
5870 public event EventHandler OnUpdateTime;
59删除: /// <summary>
60删除: /// 当前焦点使用时长(秒)
61删除: /// </summary>
62删除: private int activeSeconds = 0;
71新增: ///// <summary>
72新增: ///// 当前焦点使用时长(秒)
73新增: ///// </summary>
74新增: //private int activeSeconds = 0;
6375 public Main(
6476 IObserver observer,
6577 IData data,
@@ -74,30 +86,25 @@ namespace Core.Servicers.Instances
7486
7587 observer.OnAppActive += Observer_OnAppActive;
7688 sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged;
77删除: activeTimer = new Timer();
78删除: activeTimer.Interval = 1000;
79删除: activeTimer.Elapsed += ActiveTimer_Elapsed;
80删除: activeTimer.Disposed += ActiveTimer_Disposed;
89新增: //activeTimer = new Timer();
90新增: //activeTimer.Interval = 1000;
91新增: //activeTimer.Elapsed += ActiveTimer_Elapsed;
8192 appConfig.ConfigChanged += AppConfig_ConfigChanged;
8293 dateObserver.OnDateChanging += DateObserver_OnDateChanging;
83删除:
8494 }
8595
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新增: //private void ActiveTimer_Elapsed(object sender, ElapsedEventArgs e)
97新增: //{
98新增: // activeSeconds++;
99新增: //}
96100
97101 private void DateObserver_OnDateChanging(object sender, EventArgs e)
98102 {
99删除: Debug.WriteLine("日期变更前:" + DateTime.Now.ToString());
100删除: UpdateTime();
103新增: if (sleepStatus == SleepStatus.Wake)
104新增: {
105新增: Debug.WriteLine("日期变更前:" + DateTime.Now.ToString());
106新增: UpdateTime();
107新增: }
101108 }
102109
103110 private void AppConfig_ConfigChanged(ConfigModel oldConfig, ConfigModel newConfig)
@@ -144,14 +151,13 @@ namespace Core.Servicers.Instances
144151 UpdateTime();
145152
146153 activeProcess = null;
147删除:
148删除: activeTimer.Stop();
154新增: //activeSeconds = 0;
155新增: //activeTimer.Stop();
149156 }
150157 }
151158
152159 private void Observer_OnAppActive(string processName, string description, string file)
153160 {
154删除:
155161 if (activeProcess != processName && activeProcessFile != file)
156162 {
157163 UpdateTime();
@@ -166,13 +172,13 @@ namespace Core.Servicers.Instances
166172 activeProcessDescription = description;
167173 activeProcessFile = file;
168174
169删除: //activeStartTime = DateTime.Now;
175新增: activeStartTime = DateTime.Now;
170176
171删除: activeSeconds = 0;
172删除: if (!activeTimer.Enabled)
173删除: {
174删除: activeTimer.Start();
175删除: }
177新增: //activeSeconds = 0;
178新增: //if (!activeTimer.Enabled)
179新增: //{
180新增: // activeTimer.Start();
181新增: //}
176182
177183 // 提取icon
178184 Iconer.ExtractFromFile(file, processName, description);
@@ -180,8 +186,8 @@ namespace Core.Servicers.Instances
180186 else
181187 {
182188 activeProcess = null;
183删除: activeSeconds = 0;
184删除: activeTimer.Stop();
189新增: //activeSeconds = 0;
190新增: //activeTimer.Stop();
185191 }
186192 }
187193
@@ -238,15 +244,26 @@ namespace Core.Servicers.Instances
238244 if (!string.IsNullOrEmpty(activeProcess))
239245 {
240246 // 更新计时
247新增: TimeSpan timeSpan = DateTime.Now - activeStartTime;
248新增:
249新增: int seconds = (int)timeSpan.TotalSeconds;
241250
242删除: int seconds = activeSeconds;
251新增: // 如果是休眠状态要减去5分钟
252新增: if (sleepStatus == SleepStatus.Sleep)
253新增: {
254新增: seconds -= 300;
255新增: }
243256
244删除: Debug.WriteLine(sleepStatus + " 进程:" + activeProcess + " 更新时间:" + seconds);
245257 if (seconds <= 0)
246258 {
247259 return;
248260 }
249261
262新增:
263新增:
264新增: Logger.Info(sleepStatus + " 进程:" + activeProcess + " 更新时间:" + seconds);
265新增:
266新增:
250267 data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds);
251268
252269 // 关联进程更新