跳到主要内容

github/tai

公开

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

提交记录
修改Core/Models/Config/BehaviorModel.cs+5 −0看文件
@@ -27,5 +27,10 @@ namespace Core.Models.Config
2727 /// 忽略的进程列表
2828 /// </summary>
2929 public List<string> IgnoreURLList { get; set; } = new List<string>();
30新增: [Config(IsCanImportExport = true, Name = "应用白名单", Description = "仅统计白名单中的应用\r\n可以通过进程名称或者正则表达式进行匹配\r\n当使用正则表达式时可以匹配程序路径", Group = "应用白名单", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")]
31新增: /// <summary>
32新增: /// 应用白名单
33新增: /// </summary>
34新增: public List<string> ProcessWhiteList { get; set; } = new List<string>();
3035 }
3136}
修改Core/Servicers/Instances/Main.cs+46 −0看文件
@@ -82,6 +82,7 @@ namespace Core.Servicers.Instances
8282 private DateTime updadteAppDateTime_ = DateTime.Now.Date;
8383 // 已经更新过的应用列表
8484 private List<string> updatedAppList = new List<string>();
85新增: private List<string> _configProcessNameWhiteList, _configProcessRegexWhiteList;
8586 public Main(
8687 IAppObserver appObserver,
8788 IData data,
@@ -108,6 +109,8 @@ namespace Core.Servicers.Instances
108109 IgnoreProcessCacheList = new List<string>();
109110 ConfigIgnoreProcessRegxList = new List<string>();
110111 ConfigIgnoreProcessList = new List<string>();
112新增: _configProcessNameWhiteList = new List<string>();
113新增: _configProcessRegexWhiteList = new List<string>();
111114
112115 sleepdiscover.SleepStatusChanged += Sleepdiscover_SleepStatusChanged;
113116 appConfig.ConfigChanged += AppConfig_ConfigChanged;
@@ -125,6 +128,9 @@ namespace Core.Servicers.Instances
125128 // 更新忽略规则
126129 UpdateConfigIgnoreProcess();
127130
131新增: // 更新白名单
132新增: UpdateConfigProcessWhiteList();
133新增:
128134 // 处理web记录功能启停
129135 HandleWebServiceConfig();
130136 }
@@ -157,6 +163,7 @@ namespace Core.Servicers.Instances
157163 appConfig.Load();
158164 config = appConfig.GetConfig();
159165 UpdateConfigIgnoreProcess();
166新增: UpdateConfigProcessWhiteList();
160167
161168 // 初始化过滤器
162169 _webFilter.Init();
@@ -215,6 +222,19 @@ namespace Core.Servicers.Instances
215222 ConfigIgnoreProcessRegxList = config.Behavior.IgnoreProcessList.Where(m => IsRegex(m)).ToList();
216223 }
217224
225新增: private void UpdateConfigProcessWhiteList()
226新增: {
227新增: if (config == null)
228新增: {
229新增: return;
230新增: }
231新增: _configProcessNameWhiteList.Clear();
232新增: _configProcessRegexWhiteList.Clear();
233新增:
234新增: _configProcessNameWhiteList = config.Behavior.ProcessWhiteList.Where(m => !IsRegex(m)).ToList();
235新增: _configProcessRegexWhiteList = config.Behavior.ProcessWhiteList.Where(m => IsRegex(m)).ToList();
236新增: }
237新增:
218238 private bool IsRegex(string str)
219239 {
220240 return Regex.IsMatch(str, @"[\.|\*|\?|\{|\\|\[|\^|\|]");
@@ -279,6 +299,32 @@ namespace Core.Servicers.Instances
279299 }
280300 }
281301
302新增: // 应用白名单过滤
303新增: if (config.Behavior.ProcessWhiteList.Count > 0)
304新增: {
305新增: bool isWhite = false;
306新增: // 通过进程名称判断
307新增: if (_configProcessNameWhiteList.Contains(processName))
308新增: {
309新增: isWhite = true;
310新增: }
311新增: else
312新增: {
313新增: // 进程名称中匹配不到时尝试正则表达式
314新增: foreach (string reg in _configProcessRegexWhiteList)
315新增: {
316新增: if (RegexHelper.IsMatch(processName, reg) || RegexHelper.IsMatch(file, reg))
317新增: {
318新增: isWhite = true;
319新增: break;
320新增: }
321新增: }
322新增: }
323新增: // 白名单中找不到时不统计
324新增: Debug.WriteLine("白名单过滤结果:" + processName + " -> " + isWhite);
325新增: if (!isWhite) return false;
326新增: }
327新增:
282328 AppModel app = appData.GetApp(processName);
283329 if (app == null)
284330 {
修改UI/Servicers/AppContextMenuServicer.cs+36 −1看文件
@@ -26,6 +26,7 @@ namespace UI.Servicers
2626 private MenuItem setCategory;
2727 private MenuItem setLink;
2828 MenuItem block = new MenuItem();
29新增: MenuItem _whiteList = new MenuItem();
2930
3031
3132 public AppContextMenuServicer(MainViewModel main, ICategorys categorys, IAppData appData, IAppConfig appConfig, IThemeServicer theme)
@@ -70,6 +71,9 @@ namespace UI.Servicers
7071 block.Header = "忽略此应用";
7172 block.Click += Block_Click;
7273
74新增: _whiteList.Header = "添加到白名单";
75新增: _whiteList.Click += _whiteList_Click;
76新增:
7377 menu.Items.Add(run);
7478 menu.Items.Add(new Separator());
7579 menu.Items.Add(setCategory);
@@ -78,11 +82,33 @@ namespace UI.Servicers
7882
7983 menu.Items.Add(openDir);
8084 menu.Items.Add(block);
85新增: menu.Items.Add(_whiteList);
8186
8287 menu.ContextMenuOpening += SetCategory_ContextMenuOpening;
8388 }
8489
85删除:
90新增: private void _whiteList_Click(object sender, System.Windows.RoutedEventArgs e)
91新增: {
92新增: var data = menu.Tag as ChartsDataModel;
93新增: var log = data.Data as DailyLogModel;
94新增: var app = log != null ? log.AppModel : null;
95新增:
96新增: if (log == null)
97新增: {
98新增: app = (data.Data as HoursLogModel).AppModel;
99新增: }
100新增: var config = appConfig.GetConfig();
101新增: if (config.Behavior.ProcessWhiteList.Contains(app.Name))
102新增: {
103新增: config.Behavior.ProcessWhiteList.Remove(app.Name);
104新增: main.Toast($"已从白名单移除此应用 {app.Description}", Controls.Window.ToastType.Success);
105新增: }
106新增: else
107新增: {
108新增: config.Behavior.ProcessWhiteList.Add(app.Name);
109新增: main.Toast($"已添加至白名单 {app.Description}", Controls.Window.ToastType.Success);
110新增: }
111新增: }
86112
87113 private void Theme_OnThemeChanged(object sender, EventArgs e)
88114 {
@@ -148,6 +174,15 @@ namespace UI.Servicers
148174 block.Header = "忽略此应用";
149175 }
150176
177新增: if (config.Behavior.ProcessWhiteList.Contains(app.Name))
178新增: {
179新增: _whiteList.Header = "从白名单移除";
180新增: }
181新增: else
182新增: {
183新增: _whiteList.Header = "添加到白名单";
184新增: }
185新增:
151186 UpdateCategory();
152187
153188 setLink.IsEnabled = config.Links.Count > 0;
修改UI/ViewModels/DetailPageVM.cs+30 −1看文件
@@ -35,6 +35,7 @@ namespace UI.ViewModels
3535 public Command ClearSelectMonthDataCommand { get; set; }
3636 public Command RefreshCommand { get; set; }
3737 private MenuItem _setCategoryMenuItem;
38新增: private MenuItem _whiteListMenuItem;
3839 public DetailPageVM(
3940 IData data,
4041 MainViewModel main,
@@ -169,6 +170,20 @@ namespace UI.ViewModels
169170 _setCategoryMenuItem = new MenuItem();
170171 _setCategoryMenuItem.Header = "设置分类";
171172
173新增: _whiteListMenuItem = new MenuItem();
174新增: _whiteListMenuItem.Click += (e, c) =>
175新增: {
176新增: if (config.Behavior.ProcessWhiteList.Contains(App.Name))
177新增: {
178新增: config.Behavior.ProcessWhiteList.Remove(App.Name);
179新增: main.Toast($"已从白名单移除此应用 {App.Description}", Controls.Window.ToastType.Success);
180新增: }
181新增: else
182新增: {
183新增: config.Behavior.ProcessWhiteList.Add(App.Name);
184新增: main.Toast($"已添加至白名单 {App.Description}", Controls.Window.ToastType.Success);
185新增: }
186新增: };
172187
173188 AppContextMenu.Items.Add(open);
174189 AppContextMenu.Items.Add(new Separator());
@@ -181,6 +196,7 @@ namespace UI.ViewModels
181196 AppContextMenu.Items.Add(openDir);
182197 AppContextMenu.Items.Add(new Separator());
183198 AppContextMenu.Items.Add(clear);
199新增: AppContextMenu.Items.Add(_whiteListMenuItem);
184200 }
185201
186202 private async void ClearAppData_Click(object sender, RoutedEventArgs e)
@@ -210,6 +226,15 @@ namespace UI.ViewModels
210226 };
211227 _setCategoryMenuItem.Items.Add(categoryMenu);
212228 }
229新增:
230新增: if (config.Behavior.ProcessWhiteList.Contains(App.Name))
231新增: {
232新增: _whiteListMenuItem.Header = "从白名单移除";
233新增: }
234新增: else
235新增: {
236新增: _whiteListMenuItem.Header = "添加到白名单";
237新增: }
213238 }
214239
215240 /// <summary>
@@ -300,7 +325,11 @@ namespace UI.ViewModels
300325
301326 private async void OnClearSelectMonthDataCommand(object obj)
302327 {
303删除: await Clear();
328新增: bool isConfirm = await _uIServicer.ShowConfirmDialogAsync("清空确认", $"是否确定清空此应用 {Date.Year}年{Date.Month}月 的数据?");
329新增: if (isConfirm)
330新增: {
331新增: await Clear();
332新增: }
304333 }
305334
306335 private void OnBlockActionCommand(object obj)
修改UI/Views/DetailPage.xaml+1 −1看文件
@@ -177,7 +177,7 @@
177177 <Grid>
178178 <DatePickerBar:DatePickerBar ShowType="Month" HorizontalAlignment="Left" SelectedDate="{Binding Date,Mode=TwoWay}"/>
179179
180删除: <btn:Button ToolTip="清空此应用在该月的统计数据" HorizontalAlignment="Right" VerticalAlignment="Top" Background="#f51837" Foreground="White" Width="120" Margin="0" Icon="Delete" Command="{Binding ClearSelectMonthDataCommand}">清空统计</btn:Button>
180新增: <btn:Button ToolTip="清空此应用在该月的统计数据" HorizontalAlignment="Right" VerticalAlignment="Top" Background="#f51837" Foreground="White" Width="120" Margin="0" Icon="Delete" Command="{Binding ClearSelectMonthDataCommand}">清空该月统计</btn:Button>
181181
182182 </Grid>
183183 <Grid Margin="0,20,0,0">