跳到主要内容

github/tai

公开

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

提交记录
修改Core/Models/Config/ConfigAttribute.cs+3 −0看文件
@@ -21,10 +21,13 @@ namespace Core.Models.Config
2121 public string Group;
2222 public int Index;
2323 public bool IsName;
24新增: public string Placeholder;
25新增: public bool IsCanRepeat;
2426 public ConfigAttribute()
2527 {
2628 ToggleTrueText = "开";
2729 ToggleFalseText = "关";
30新增: IsCanRepeat = true;
2831 Index = 0;
2932 IsName = false;
3033 }
修改Core/Models/Config/Link/LinkModel.cs+2 −2看文件
@@ -11,12 +11,12 @@ namespace Core.Models.Config.Link
1111 /// <summary>
1212 /// 关联名称
1313 /// </summary>
14删除: [Config(Name = "关联名称", Description = "设置一个名称用于识别该关联的目的", IsName = true)]
14新增: [Config(Name = "关联名称", Description = "设置一个名称用于识别该关联的目的", IsName = true, IsCanRepeat = false)]
1515 public string Name { get; set; } = "新的关联";
1616 /// <summary>
1717 /// 关联进程列表
1818 /// </summary>
19删除: [Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此")]
19新增: [Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此", IsCanRepeat = false)]
2020 public List<string> ProcessList { get; set; } = new List<string>();
2121 }
2222}
修改Core/Servicers/Instances/AppConfig.cs+33 −0看文件
@@ -5,8 +5,10 @@ using Core.Servicers.Interfaces;
55using Newtonsoft.Json;
66using System;
77using System.Collections.Generic;
8新增:using System.Diagnostics;
89using System.IO;
910using System.Linq;
11新增:using System.Reflection;
1012using System.Text;
1113using System.Threading.Tasks;
1214
@@ -45,6 +47,8 @@ namespace Core.Servicers.Instances
4547 }
4648
4749 CopyToOldConfig();
50新增:
51新增: CheckOption(config);
4852 }
4953 catch (JsonSerializationException ex)
5054 {
@@ -82,6 +86,9 @@ namespace Core.Servicers.Instances
8286
8387 config.General = new GeneralModel();
8488 config.General.IsStartatboot = false;
89新增:
90新增: config.Behavior = new BehaviorModel();
91新增: config.Behavior.IgnoreProcessList.Add("Test");
8592 }
8693
8794 public ConfigModel GetConfig()
@@ -111,5 +118,31 @@ namespace Core.Servicers.Instances
111118 Logger.Error(ex.Message);
112119 }
113120 }
121新增:
122新增: private void CheckOption(object obj)
123新增: {
124新增: System.Reflection.PropertyInfo[] properties = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
125新增:
126新增: foreach (System.Reflection.PropertyInfo item in properties)
127新增: {
128新增: string name = item.Name;
129新增: object value = item.GetValue(obj, null);
130新增: if (value == null)
131新增: {
132新增: //配置项不存在时创建
133新增: Type[] types = new Type[0];
134新增: object[] objs = new object[0];
135新增:
136新增: ConstructorInfo ctor = item.PropertyType.GetConstructor(types);
137新增: if (ctor != null)
138新增: {
139新增: object instance = ctor.Invoke(objs);
140新增: item.SetValue(obj, instance);
141新增: }
142新增: }
143新增:
144新增: Debug.WriteLine(string.Format("{0}:{1},", name, value));
145新增: }
146新增: }
114147 }
115148}
修改UI/Controls/SettingPanel/SettingPanel.cs+111 −0看文件
@@ -11,6 +11,8 @@ using System.Threading.Tasks;
1111using System.Windows;
1212using System.Windows.Controls;
1313using System.Windows.Media;
14新增:using UI.Controls.Input;
15新增:using UI.Controls.List;
1416
1517namespace UI.Controls.SettingPanel
1618{
@@ -39,9 +41,11 @@ namespace UI.Controls.SettingPanel
3941 private object configData;
4042 private readonly string nosetGroupKey = "noset_group";
4143 private Dictionary<string, List<Config>> configList;
44新增: public Dictionary<string, List<string>> SettingData { get; set; }
4245 public SettingPanel()
4346 {
4447 DefaultStyleKey = typeof(SettingPanel);
48新增: SettingData = new Dictionary<string, List<string>>();
4549 }
4650 public override void OnApplyTemplate()
4751 {
@@ -141,6 +145,7 @@ namespace UI.Controls.SettingPanel
141145 var panel = new SettingPanelMultiItem();
142146 panel.Data = data;
143147 panel.Tag = id;
148新增: panel.SettingData = SettingData;
144149 panel.DataChanged += (e, c) =>
145150 {
146151 int pid = (int)panel.Tag;
@@ -299,6 +304,10 @@ namespace UI.Controls.SettingPanel
299304 {
300305 uIElement = RenderBooleanConfigControl(attribute, pi);
301306 }
307新增: else if (pi.PropertyType == typeof(List<string>))
308新增: {
309新增: uIElement = RenderListStringConfigControl(attribute, pi);
310新增: }
302311
303312 return uIElement;
304313 }
@@ -322,5 +331,107 @@ namespace UI.Controls.SettingPanel
322331
323332 return item;
324333 }
334新增:
335新增: private UIElement RenderListStringConfigControl(ConfigAttribute configAttribute, PropertyInfo pi)
336新增: {
337新增: var list = pi.GetValue(Data) as List<string>;
338新增:
339新增: var listControl = new BaseList();
340新增: listControl.MaxHeight = 200;
341新增: listControl.Loaded += (sender, args) =>
342新增: {
343新增: listControl.Items.CollectionChanged += (o, e) =>
344新增: {
345新增: var newData = new List<string>();
346新增: foreach (var item in listControl.Items)
347新增: {
348新增: newData.Add(item.ToString());
349新增: }
350新增: pi.SetValue(configData, newData);
351新增: Data = configData;
352新增: };
353新增: };
354新增: listControl.Margin = new Thickness(15, 0, 15, 10);
355新增:
356新增: if (list != null)
357新增: {
358新增: foreach (string item in list)
359新增: {
360新增: listControl.Items.Add(item);
361新增: }
362新增: }
363新增: else
364新增: {
365新增: list = new List<string>();
366新增: }
367新增: var contextMenu = new ContextMenu();
368新增:
369新增: var contextMenuItemDel = new MenuItem();
370新增: contextMenuItemDel.Header = "移除";
371新增: contextMenuItemDel.Click += (e, c) =>
372新增: {
373新增: listControl.Items.Remove(listControl.SelectedItem);
374新增: };
375新增: contextMenu.Items.Add(contextMenuItemDel);
376新增: listControl.ContextMenu = contextMenu;
377新增:
378新增:
379新增: // 添加输入框
380新增: var addInputBox = new InputBox();
381新增: addInputBox.Placeholder = configAttribute.Placeholder;
382新增: addInputBox.Margin = new Thickness(0, 0, 10, 0);
383新增:
384新增: var addBtn = new Button.Button();
385新增: //addBtn.Margin = new Thickness(15, 0, 15, 10);
386新增: addBtn.Content = "添加";
387新增:
388新增: addBtn.Click += (e, c) =>
389新增: {
390新增: if (addInputBox.Text == String.Empty || list.Contains(addInputBox.Text))
391新增: {
392新增: addInputBox.Error = configAttribute.Name + (addInputBox.Text == String.Empty ? "不能为空" : "已存在");
393新增: addInputBox.ShowError();
394新增: return;
395新增: }
396新增: //list.Add(addInputBox.Text);
397新增: listControl.Items.Add(addInputBox.Text);
398新增: addInputBox.Text = String.Empty;
399新增:
400新增:
401新增:
402新增: };
403新增: pi.SetValue(configData, list);
404新增:
405新增: var inputPanel = new Grid();
406新增: inputPanel.ColumnDefinitions.Add(
407新增: new ColumnDefinition()
408新增: {
409新增: Width = new GridLength(10, GridUnitType.Star)
410新增: });
411新增: inputPanel.ColumnDefinitions.Add(
412新增: new ColumnDefinition()
413新增: {
414新增: Width = new GridLength(2, GridUnitType.Star)
415新增: });
416新增: inputPanel.Margin = new Thickness(15, 10, 15, 10);
417新增: Grid.SetColumn(addInputBox, 0);
418新增: Grid.SetColumn(addBtn, 1);
419新增: inputPanel.Children.Add(addInputBox);
420新增: inputPanel.Children.Add(addBtn);
421新增:
422新增:
423新增: // 标题和说明
424新增:
425新增: var description = new TextBlock();
426新增: description.Text = configAttribute.Description;
427新增: description.Margin = new Thickness(10, 10, 10, 0);
428新增: description.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#989CA1"));
429新增: var container = new StackPanel();
430新增:
431新增: container.Children.Add(description);
432新增: container.Children.Add(inputPanel);
433新增: container.Children.Add(listControl);
434新增: return container;
435新增: }
325436 }
326437}
修改UI/Controls/SettingPanel/SettingPanelMultiItem.cs+33 −1看文件
@@ -8,6 +8,7 @@ using System.Diagnostics;
88using System.Linq;
99using System.Reflection;
1010using System.Text;
11新增:using System.Text.RegularExpressions;
1112using System.Threading.Tasks;
1213using System.Windows;
1314using System.Windows.Controls;
@@ -19,6 +20,11 @@ namespace UI.Controls.SettingPanel
1920{
2021 public class SettingPanelMultiItem : Control
2122 {
23新增: /// <summary>
24新增: /// 所有设置数据
25新增: /// </summary>
26新增: public Dictionary<string, List<string>> SettingData { get { return (Dictionary<string, List<string>>)GetValue(SettingDataProperty); } set { SetValue(SettingDataProperty, value); } }
27新增: public static readonly DependencyProperty SettingDataProperty = DependencyProperty.Register("SettingData", typeof(Dictionary<string, List<string>>), typeof(SettingPanelMultiItem));
2228 public bool Fold { get { return (bool)GetValue(FoldProperty); } set { SetValue(FoldProperty, value); } }
2329 public static readonly DependencyProperty FoldProperty = DependencyProperty.Register("Fold", typeof(bool), typeof(SettingPanelMultiItem), new PropertyMetadata(false));
2430
@@ -39,6 +45,11 @@ namespace UI.Controls.SettingPanel
3945 public SettingPanelMultiItem()
4046 {
4147 DefaultStyleKey = typeof(SettingPanelMultiItem);
48新增:
49新增: if (SettingData == null)
50新增: {
51新增: SettingData = new Dictionary<string, List<string>>();
52新增: }
4253 }
4354 public override void OnApplyTemplate()
4455 {
@@ -113,6 +124,15 @@ namespace UI.Controls.SettingPanel
113124
114125 var list = pi.GetValue(Data) as List<string>;
115126
127新增: if (SettingData.ContainsKey(pi.Name))
128新增: {
129新增: SettingData[pi.Name] = SettingData[pi.Name].Concat(list).ToList();
130新增: }
131新增: else
132新增: {
133新增: SettingData.Add(pi.Name, list);
134新增: }
135新增:
116136 var listControl = new BaseList();
117137
118138 listControl.Loaded += (sender, args) =>
@@ -175,10 +195,21 @@ namespace UI.Controls.SettingPanel
175195
176196 addBtn.Click += (e, c) =>
177197 {
198新增: addInputBox.Error = attribute.Name + (addInputBox.Text == String.Empty ? "不能为空" : "已存在");
199新增:
178200 if (addInputBox.Text == String.Empty || list.Contains(addInputBox.Text))
179201 {
202新增: addInputBox.ShowError();
180203 return;
181204 }
205新增:
206新增: // 判断重复
207新增: if (!attribute.IsCanRepeat && SettingData[pi.Name].Contains(addInputBox.Text))
208新增: {
209新增: addInputBox.ShowError();
210新增: return;
211新增: }
212新增:
182213 //list.Add(addInputBox.Text);
183214 listControl.Items.Add(addInputBox.Text);
184215 addInputBox.Text = String.Empty;
@@ -211,9 +242,10 @@ namespace UI.Controls.SettingPanel
211242 }
212243 private void RenderTextBox(ConfigAttribute attribute, PropertyInfo pi)
213244 {
245新增: string value = (string)pi.GetValue(Data);
214246
215247 var textBox = new InputBox();
216删除: textBox.Text = (string)pi.GetValue(Data);
248新增: textBox.Text = value;
217249 textBox.Placeholder = attribute.Name;
218250 textBox.Width = 125;
219251 textBox.LostFocus += (e, c) =>