跳到主要内容

github/tai

公开

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

提交记录
修改Core/Core.csproj+2 −2看文件
@@ -134,7 +134,7 @@
134134 <Compile Include="Servicers\Instances\Categorys.cs" />
135135 <Compile Include="Servicers\Instances\Data.cs" />
136136 <Compile Include="Librarys\Logger.cs" />
137删除: <Compile Include="Servicers\Instances\DateObserver.cs" />
137新增: <Compile Include="Servicers\Instances\DateTimeObserver.cs" />
138138 <Compile Include="Servicers\Instances\Main.cs" />
139139 <Compile Include="Servicers\Instances\Observer.cs" />
140140 <Compile Include="Servicers\Instances\Sleepdiscover.cs" />
@@ -142,7 +142,7 @@
142142 <Compile Include="Servicers\Interfaces\ICategorys.cs" />
143143 <Compile Include="Servicers\Interfaces\IAppData.cs" />
144144 <Compile Include="Servicers\Interfaces\IData.cs" />
145删除: <Compile Include="Servicers\Interfaces\IDateObserver.cs" />
145新增: <Compile Include="Servicers\Interfaces\IDateTimeObserver.cs" />
146146 <Compile Include="Servicers\Interfaces\IMain.cs" />
147147 <Compile Include="Servicers\Interfaces\IObserver.cs" />
148148 <Compile Include="Servicers\Interfaces\ISleepdiscover.cs" />
修改Core/Event/EventHandler.cs+1 −1看文件
@@ -9,6 +9,6 @@ using System.Threading.Tasks;
99namespace Core.Event
1010{
1111 public delegate void SleepdiscoverEventHandler(SleepStatus sleepStatus);
12删除:
1312 public delegate void AppConfigEventHandler(ConfigModel oldConfig, ConfigModel newConfig);
13新增: public delegate void DateTimeObserverEventHandler(object sender, DateTime e);
1414}
修改Core/Servicers/Instances/Data.cs+15 −8看文件
@@ -19,8 +19,14 @@ namespace Core.Servicers.Instances
1919 {
2020 this.appData = appData;
2121 }
22删除: public void Set(string processName, string processDescription, string file, int seconds)
22新增: public void Set(string processName, string processDescription, string file, int seconds, DateTime? time_ = null)
2323 {
24新增: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value;
25新增: var today = time.Date;
26新增:
27新增: // 当前时段
28新增: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0);
29新增:
2430 if (string.IsNullOrEmpty(processName) || seconds <= 0)
2531 {
2632 return;
@@ -35,7 +41,7 @@ namespace Core.Servicers.Instances
3541 }
3642
3743
38删除: var today = DateTime.Now.Date;
44新增:
3945 using (var db = new TaiDbContext())
4046 {
4147 var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID);
@@ -56,8 +62,6 @@ namespace Core.Servicers.Instances
5662
5763 // 分时段记录数据
5864
59删除: // 当前时段
60删除: var nowtime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0);
6165 var hourslog = db.HoursLog.SingleOrDefault(
6266 m =>
6367 m.DataTime == nowtime
@@ -185,8 +189,14 @@ namespace Core.Servicers.Instances
185189 return GetDateRangelogList(weekStartDate, weekEndDate);
186190 }
187191
188删除: public void Set(string processName, int seconds)
192新增: public void Set(string processName, int seconds, DateTime? time_ = null)
189193 {
194新增: DateTime time = !time_.HasValue ? DateTime.Now : time_.Value;
195新增: var today = time.Date;
196新增:
197新增: // 当前时段
198新增: var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0);
199新增:
190200 if (string.IsNullOrEmpty(processName) || seconds <= 0)
191201 {
192202 return;
@@ -200,7 +210,6 @@ namespace Core.Servicers.Instances
200210
201211 using (var db = new TaiDbContext())
202212 {
203删除: var today = DateTime.Now.Date;
204213 var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID);
205214 if (res != null)
206215 {
@@ -209,8 +218,6 @@ namespace Core.Servicers.Instances
209218
210219 // 分时段记录数据
211220
212删除: // 当前时段
213删除: var nowtime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0);
214221 var hourslog = db.HoursLog.SingleOrDefault(
215222 m =>
216223 m.DataTime == nowtime
改名Core/Servicers/Instances/DateObserver.cs → Core/Servicers/Instances/DateTimeObserver.cs+14 −18看文件
@@ -1,6 +1,8 @@
1删除:using Core.Servicers.Interfaces;
1新增:using Core.Event;
2新增:using Core.Servicers.Interfaces;
23using System;
34using System.Collections.Generic;
5新增:using System.Diagnostics;
46using System.Linq;
57using System.Text;
68using System.Threading.Tasks;
@@ -8,19 +10,11 @@ using System.Windows.Threading;
810
911namespace Core.Servicers.Instances
1012{
11删除: public class DateObserver : IDateObserver
13新增: public class DateTimeObserver : IDateTimeObserver
1214 {
13删除: public event EventHandler OnDateChanging;
14删除:
15删除:
16删除:
15新增: public event DateTimeObserverEventHandler OnDateTimeChanging;
1716 private DispatcherTimer timer;
1817
19删除: public DateObserver()
20删除: {
21删除: }
22删除:
23删除:
2418 public void Start()
2519 {
2620 SetTimer();
@@ -31,13 +25,13 @@ namespace Core.Servicers.Instances
3125 timer = new DispatcherTimer();
3226 timer.Tick += Timer_Tick;
3327 DateTime now = DateTime.Now;
34删除: DateTime tmorrow = new DateTime(now.Year, now.Month, now.Day, 23, 59, 30);
35删除: int diffseconds = (int)tmorrow.Subtract(now).TotalSeconds;
36删除: if (diffseconds < 0)
28新增: DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, 59, 59);
29新增: int diffMilliseconds = (int)updateTime.Subtract(now).TotalMilliseconds;
30新增: if (diffMilliseconds < 0)
3731 {
38删除: diffseconds = 0;
32新增: diffMilliseconds = 1;
3933 }
40删除: timer.Interval = new TimeSpan(0, 0, diffseconds);
34新增: timer.Interval = new TimeSpan(0, 0, 0, 0, diffMilliseconds);
4135 timer.Start();
4236 }
4337
@@ -45,11 +39,13 @@ namespace Core.Servicers.Instances
4539 {
4640 timer.Stop();
4741
48删除: OnDateChanging?.Invoke(this, EventArgs.Empty);
42新增: DateTime nowTime = DateTime.Now;
43新增:
44新增: OnDateTimeChanging?.Invoke(this, nowTime);
4945
5046 await Task.Run(async () =>
5147 {
52删除: await Task.Delay(60000);
48新增: await Task.Delay(1000);
5349 SetTimer();
5450 });
5551 }
修改Core/Servicers/Instances/Main.cs+18 −39看文件
@@ -23,7 +23,7 @@ namespace Core.Servicers.Instances
2323 private readonly IData data;
2424 private readonly ISleepdiscover sleepdiscover;
2525 private readonly IAppConfig appConfig;
26删除: private readonly IDateObserver dateObserver;
26新增: private readonly IDateTimeObserver dateTimeObserver;
2727 private readonly IAppData appData;
2828 private readonly ICategorys categories;
2929 // 忽略的进程
@@ -49,10 +49,6 @@ namespace Core.Servicers.Instances
4949 /// </summary>
5050 private DateTime activeStartTime = DateTime.Now;
5151
52删除: ///// <summary>
53删除: ///// 活动计时器
54删除: ///// </summary>
55删除: //private Timer activeTimer;
5652 /// <summary>
5753 /// 睡眠状态
5854 /// </summary>
@@ -64,46 +60,34 @@ namespace Core.Servicers.Instances
6460 private ConfigModel config;
6561
6662 public event EventHandler OnUpdateTime;
67删除: ///// <summary>
68删除: ///// 当前焦点使用时长(秒)
69删除: ///// </summary>
70删除: //private int activeSeconds = 0;
63新增:
7164 public Main(
7265 IObserver observer,
7366 IData data,
7467 ISleepdiscover sleepdiscover,
7568 IAppConfig appConfig,
76删除: IDateObserver dateObserver,
69新增: IDateTimeObserver dateTimeObserver,
7770 IAppData appData, ICategorys categories)
7871 {
7972 this.observer = observer;
8073 this.data = data;
8174 this.sleepdiscover = sleepdiscover;
8275 this.appConfig = appConfig;
83删除: this.dateObserver = dateObserver;
76新增: this.dateTimeObserver = dateTimeObserver;
8477 this.appData = appData;
8578 this.categories = categories;
8679
8780 observer.OnAppActive += Observer_OnAppActive;
8881 sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged;
89删除: //activeTimer = new Timer();
90删除: //activeTimer.Interval = 1000;
91删除: //activeTimer.Elapsed += ActiveTimer_Elapsed;
9282 appConfig.ConfigChanged += AppConfig_ConfigChanged;
93删除: dateObserver.OnDateChanging += DateObserver_OnDateChanging;
83新增: dateTimeObserver.OnDateTimeChanging += DateTimeObserver_OnDateTimeChanging;
9484 }
9585
96删除: //private void ActiveTimer_Elapsed(object sender, ElapsedEventArgs e)
97删除: //{
98删除: // activeSeconds++;
99删除: //}
100删除:
101删除: private void DateObserver_OnDateChanging(object sender, EventArgs e)
86新增: private void DateTimeObserver_OnDateTimeChanging(object sender, DateTime time)
10287 {
10388 if (sleepStatus == SleepStatus.Wake)
10489 {
105删除: Debug.WriteLine("日期变更前:" + DateTime.Now.ToString());
106删除: UpdateTime();
90新增: UpdateTime(time);
10791 }
10892 }
10993
@@ -144,7 +128,7 @@ namespace Core.Servicers.Instances
144128 config = appConfig.GetConfig();
145129
146130 // 日期变化观察
147删除: dateObserver.Start();
131新增: dateTimeObserver.Start();
148132
149133 // 启动进程观察
150134 observer.Start();
@@ -249,7 +233,7 @@ namespace Core.Servicers.Instances
249233 }
250234 }
251235
252删除: private void HandleLinks(string processName, int seconds)
236新增: private void HandleLinks(string processName, int seconds, DateTime? time = null)
253237 {
254238 try
255239 {
@@ -268,7 +252,7 @@ namespace Core.Servicers.Instances
268252 if (IsProcessRuning(linkProcess))
269253 {
270254 // 同步更新
271删除: data.Set(linkProcess, seconds);
255新增: data.Set(linkProcess, seconds, time);
272256 }
273257
274258 }
@@ -297,7 +281,7 @@ namespace Core.Servicers.Instances
297281 }
298282 #endregion
299283
300删除: private void UpdateTime()
284新增: private void UpdateTime(DateTime? time = null)
301285 {
302286 if (!string.IsNullOrEmpty(activeProcess))
303287 {
@@ -312,24 +296,19 @@ namespace Core.Servicers.Instances
312296 seconds -= 300;
313297 }
314298
315删除: if (seconds <= 0)
299新增: if (seconds > 0)
316300 {
317删除: return;
318删除: }
301新增: data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds, time);
319302
320删除:
321删除:
322删除: Logger.Info("【" + sleepStatus + "】进程:" + activeProcess + " 更新时间:" + seconds + ",开始时间:" + activeStartTime.ToString() + ",当前时间:" + DateTime.Now.ToString());
323删除:
324删除:
325删除: data.Set(activeProcess, activeProcessDescription, activeProcessFile, seconds);
326删除:
327删除: // 关联进程更新
328删除: HandleLinks(activeProcess, seconds);
303新增: // 关联进程更新
304新增: HandleLinks(activeProcess, seconds, time);
305新增: }
329306
330307 activeStartTime = DateTime.Now;
331308
332309 OnUpdateTime?.Invoke(this, null);
310新增:
311新增: Logger.Info("【" + sleepStatus + "】进程:" + activeProcess + " 更新时间:" + seconds + ",开始时间:" + activeStartTime.ToString() + ",当前时间:" + DateTime.Now.ToString());
333312 }
334313 }
335314
修改Core/Servicers/Interfaces/IData.cs+2 −2看文件
@@ -18,7 +18,7 @@ namespace Core.Servicers.Interfaces
1818 /// <param name="processDescription"></param>
1919 /// <param name="file"></param>
2020 /// <param name="seconds"></param>
21删除: void Set(string processName, string processDescription, string file, int seconds);
21新增: void Set(string processName, string processDescription, string file, int seconds, DateTime? time = null);
2222
2323 /// <summary>
2424 /// 获取今天的数据
@@ -48,7 +48,7 @@ namespace Core.Servicers.Interfaces
4848 /// </summary>
4949 /// <param name="processName"></param>
5050 /// <param name="seconds"></param>
51删除: void Set(string processName, int seconds);
51新增: void Set(string processName, int seconds, DateTime? time = null);
5252
5353 /// <summary>
5454 /// 获取指定进程某个月的数据
改名Core/Servicers/Interfaces/IDateObserver.cs → Core/Servicers/Interfaces/IDateTimeObserver.cs+5 −4看文件
@@ -1,4 +1,5 @@
1删除:using System;
1新增:using Core.Event;
2新增:using System;
23using System.Collections.Generic;
34using System.Linq;
45using System.Text;
@@ -9,15 +10,15 @@ namespace Core.Servicers.Interfaces
910 /// <summary>
1011 /// 日期变更观察(用于监听日期变化
1112 /// </summary>
12删除: public interface IDateObserver
13新增: public interface IDateTimeObserver
1314 {
1415 /// <summary>
1516 /// 启动
1617 /// </summary>
1718 void Start();
1819 /// <summary>
19删除: /// 日期即将变化时发生(前30秒)
20新增: /// 日期即将变化时发生(前1秒)
2021 /// </summary>
21删除: event EventHandler OnDateChanging;
22新增: event DateTimeObserverEventHandler OnDateTimeChanging;
2223 }
2324}
修改UI/App.xaml.cs+1 −1看文件
@@ -186,7 +186,7 @@ namespace UI
186186 services.AddSingleton<IData, Data>();
187187 services.AddSingleton<ISleepdiscover, Sleepdiscover>();
188188 services.AddSingleton<IAppConfig, AppConfig>();
189删除: services.AddSingleton<IDateObserver, DateObserver>();
189新增: services.AddSingleton<IDateTimeObserver, DateTimeObserver>();
190190 services.AddSingleton<IAppData, AppData>();
191191 services.AddSingleton<ICategorys, Categorys>();
192192