提交记录修改Core/Servicers/Instances/Main.cs+32 −7看文件
| @@ -11,6 +11,8 @@ using System.Diagnostics; | ||
| 11 | 11 | using System.Linq; |
| 12 | 12 | using System.Text; |
| 13 | 13 | using System.Threading.Tasks; |
| 14 | 新增:using System.Timers; | |
| 15 | 新增:using System.Windows.Threading; | |
| 14 | 16 | |
| 15 | 17 | namespace Core.Servicers.Instances |
| 16 | 18 | { |
| @@ -42,7 +44,7 @@ namespace Core.Servicers.Instances | ||
| 42 | 44 | /// <summary> |
| 43 | 45 | /// 活动计时器 |
| 44 | 46 | /// </summary> |
| 45 | 删除: private Stopwatch activeWatcher; | |
| 47 | 新增: private Timer activeTimer; | |
| 46 | 48 | /// <summary> |
| 47 | 49 | /// 睡眠状态 |
| 48 | 50 | /// </summary> |
| @@ -54,7 +56,10 @@ namespace Core.Servicers.Instances | ||
| 54 | 56 | private ConfigModel config; |
| 55 | 57 | |
| 56 | 58 | public event EventHandler OnUpdateTime; |
| 57 | 删除: | |
| 59 | 新增: /// <summary> | |
| 60 | 新增: /// 当前焦点使用时长(秒) | |
| 61 | 新增: /// </summary> | |
| 62 | 新增: private int activeSeconds = 0; | |
| 58 | 63 | public Main( |
| 59 | 64 | IObserver observer, |
| 60 | 65 | IData data, |
| @@ -69,12 +74,26 @@ namespace Core.Servicers.Instances | ||
| 69 | 74 | |
| 70 | 75 | observer.OnAppActive += Observer_OnAppActive; |
| 71 | 76 | 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; | |
| 73 | 81 | appConfig.ConfigChanged += AppConfig_ConfigChanged; |
| 74 | 82 | dateObserver.OnDateChanging += DateObserver_OnDateChanging; |
| 75 | 83 | |
| 76 | 84 | } |
| 77 | 85 | |
| 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 | 新增: | |
| 78 | 97 | private void DateObserver_OnDateChanging(object sender, EventArgs e) |
| 79 | 98 | { |
| 80 | 99 | Debug.WriteLine("日期变更前:" + DateTime.Now.ToString()); |
| @@ -126,7 +145,7 @@ namespace Core.Servicers.Instances | ||
| 126 | 145 | |
| 127 | 146 | activeProcess = null; |
| 128 | 147 | |
| 129 | 删除: activeWatcher.Stop(); | |
| 148 | 新增: activeTimer.Stop(); | |
| 130 | 149 | } |
| 131 | 150 | } |
| 132 | 151 | |
| @@ -148,7 +167,12 @@ namespace Core.Servicers.Instances | ||
| 148 | 167 | activeProcessFile = file; |
| 149 | 168 | |
| 150 | 169 | //activeStartTime = DateTime.Now; |
| 151 | 删除: activeWatcher.Restart(); | |
| 170 | 新增: | |
| 171 | 新增: activeSeconds = 0; | |
| 172 | 新增: if (!activeTimer.Enabled) | |
| 173 | 新增: { | |
| 174 | 新增: activeTimer.Start(); | |
| 175 | 新增: } | |
| 152 | 176 | |
| 153 | 177 | // 提取icon |
| 154 | 178 | Iconer.ExtractFromFile(file, processName, description); |
| @@ -156,7 +180,8 @@ namespace Core.Servicers.Instances | ||
| 156 | 180 | else |
| 157 | 181 | { |
| 158 | 182 | activeProcess = null; |
| 159 | 删除: activeWatcher.Stop(); | |
| 183 | 新增: activeSeconds = 0; | |
| 184 | 新增: activeTimer.Stop(); | |
| 160 | 185 | } |
| 161 | 186 | } |
| 162 | 187 | |
| @@ -214,7 +239,7 @@ namespace Core.Servicers.Instances | ||
| 214 | 239 | { |
| 215 | 240 | // 更新计时 |
| 216 | 241 | |
| 217 | 删除: int seconds = (int)activeWatcher.Elapsed.TotalSeconds; | |
| 242 | 新增: int seconds = activeSeconds; | |
| 218 | 243 | |
| 219 | 244 | Debug.WriteLine(sleepStatus + " 进程:" + activeProcess + " 更新时间:" + seconds); |
| 220 | 245 | if (seconds <= 0) |

