提交记录修改Core/Servicers/Instances/Main.cs+22 −14看文件
修改Core/Servicers/Interfaces/IMain.cs+4 −0看文件
| @@ -43,7 +43,7 @@ namespace Core.Servicers.Instances | ||
| 43 | 43 | /// <summary> |
| 44 | 44 | /// 当前聚焦进程 |
| 45 | 45 | /// </summary> |
| 46 | 删除: private string activeProcess, activeProcessDescription, activeProcessFile = null; | |
| 46 | 新增: private string activeProcess = null; | |
| 47 | 47 | |
| 48 | 48 | /// <summary> |
| 49 | 49 | /// 焦点开始时间 |
| @@ -61,6 +61,7 @@ namespace Core.Servicers.Instances | ||
| 61 | 61 | private ConfigModel config; |
| 62 | 62 | |
| 63 | 63 | public event EventHandler OnUpdateTime; |
| 64 | 新增: public event EventHandler OnStarted; | |
| 64 | 65 | |
| 65 | 66 | /// <summary> |
| 66 | 67 | /// 忽略进程缓存列表 |
| @@ -104,8 +105,14 @@ namespace Core.Servicers.Instances | ||
| 104 | 105 | private void DateTimeObserver_OnDateTimeChanging(object sender, DateTime time) |
| 105 | 106 | { |
| 106 | 107 | 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 | 新增: } | |
| 109 | 116 | } |
| 110 | 117 | |
| 111 | 118 | private void AppConfig_ConfigChanged(ConfigModel oldConfig, ConfigModel newConfig) |
| @@ -157,6 +164,7 @@ namespace Core.Servicers.Instances | ||
| 157 | 164 | // 启动睡眠监测 |
| 158 | 165 | sleepdiscover.Start(); |
| 159 | 166 | |
| 167 | 新增: OnStarted?.Invoke(this, EventArgs.Empty); | |
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | public void Exit() |
| @@ -188,14 +196,11 @@ namespace Core.Servicers.Instances | ||
| 188 | 196 | { |
| 189 | 197 | this.sleepStatus = sleepStatus; |
| 190 | 198 | |
| 191 | 删除: Debug.WriteLine("睡眠状态:" + sleepStatus); | |
| 192 | 删除: Logger.Info("【" + sleepStatus + "】当前进程:" + activeProcess); | |
| 199 | 新增: Logger.Info($"[{sleepStatus}] process:{activeProcess},start:{activeStartTime}"); | |
| 193 | 200 | if (sleepStatus == SleepStatus.Sleep) |
| 194 | 201 | { |
| 195 | 202 | // 更新时间 |
| 196 | 203 | UpdateTime(); |
| 197 | 删除: | |
| 198 | 删除: activeProcess = null; | |
| 199 | 204 | } |
| 200 | 205 | else if (sleepStatus == SleepStatus.Wake) |
| 201 | 206 | { |
| @@ -258,22 +263,25 @@ namespace Core.Servicers.Instances | ||
| 258 | 263 | |
| 259 | 264 | private void Observer_OnAppActive(string processName, string description, string file) |
| 260 | 265 | { |
| 266 | 新增: if (sleepStatus == SleepStatus.Sleep) | |
| 267 | 新增: { | |
| 268 | 新增: return; | |
| 269 | 新增: } | |
| 270 | 新增: | |
| 261 | 271 | bool isCheck = IsCheckApp(processName, description, file); |
| 262 | 272 | |
| 263 | 删除: if (activeProcess != processName && activeProcessFile != file) | |
| 273 | 新增: if (activeProcess != processName) | |
| 264 | 274 | { |
| 265 | 275 | UpdateTime(); |
| 266 | 276 | } |
| 267 | 277 | |
| 268 | 删除: if (isCheck && sleepStatus != SleepStatus.Sleep) | |
| 278 | 新增: if (isCheck) | |
| 269 | 279 | { |
| 270 | 280 | if (activeProcess == null) |
| 271 | 281 | { |
| 272 | 282 | activeStartTime = DateTime.Now; |
| 273 | 283 | } |
| 274 | 284 | activeProcess = processName; |
| 275 | 删除: activeProcessDescription = description; | |
| 276 | 删除: activeProcessFile = file; | |
| 277 | 285 | } |
| 278 | 286 | else |
| 279 | 287 | { |
| @@ -329,10 +337,12 @@ namespace Core.Servicers.Instances | ||
| 329 | 337 | } |
| 330 | 338 | #endregion |
| 331 | 339 | |
| 332 | 删除: private void UpdateTime(DateTime? time = null) | |
| 340 | 新增: private void UpdateTime() | |
| 333 | 341 | { |
| 334 | 342 | if (!string.IsNullOrEmpty(activeProcess)) |
| 335 | 343 | { |
| 344 | 新增: var time = activeStartTime; | |
| 345 | 新增: | |
| 336 | 346 | // 更新计时 |
| 337 | 347 | TimeSpan timeSpan = DateTime.Now - activeStartTime; |
| 338 | 348 | |
| @@ -357,8 +367,6 @@ namespace Core.Servicers.Instances | ||
| 357 | 367 | activeStartTime = DateTime.Now; |
| 358 | 368 | |
| 359 | 369 | OnUpdateTime?.Invoke(this, null); |
| 360 | 删除: | |
| 361 | 删除: | |
| 362 | 370 | } |
| 363 | 371 | } |
| 364 | 372 | |
| @@ -24,5 +24,9 @@ namespace Core.Servicers.Interfaces | ||
| 24 | 24 | /// 更新某个进程时间时发生 |
| 25 | 25 | /// </summary> |
| 26 | 26 | event EventHandler OnUpdateTime; |
| 27 | 新增: /// <summary> | |
| 28 | 新增: /// 初始化完成时发生 | |
| 29 | 新增: /// </summary> | |
| 30 | 新增: event EventHandler OnStarted; | |
| 27 | 31 | } |
| 28 | 32 | } |

