Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,6 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
.vscode/settings.json

# JetBrains Rider files
.idea/
20 changes: 14 additions & 6 deletions Core/Librarys/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public static string ToHoursString(double seconds)
return "0";
}
}
public static string ToString(int seconds)

public static object[] ToString(int seconds)
{
if (seconds < 60)
{
return seconds + "秒";
return new Object[]{"time.seconds", seconds};
}
else
{
Expand All @@ -36,10 +37,13 @@ public static string ToString(int seconds)
{
double pointNumber = minutes - (int)minutes;
int seconds_ = (int)(pointNumber * 60);
return (int)minutes + "分钟" + (seconds_ > 0 ? seconds_ + "秒" : "");
if (seconds_ > 0)
{
return new Object[]{"time.minutesWithSeconds", (int) minutes, seconds_};
}
}

return minutes + "分钟";
return new Object[]{"time.minutes", (int) minutes};
}
else
{
Expand All @@ -48,9 +52,13 @@ public static string ToString(int seconds)
{
double pointNumber = hours - (int)hours;
int minutes_ = (int)(pointNumber * 60);
return (int)hours + "小时" + (minutes_ > 0 ? minutes_ + "分" : "");
if (minutes_ > 0)
{
return new Object[]{"time.hoursWithMinutes", (int) hours, minutes_};
}
}
return hours + "小时";

return new Object[]{"time.hours", (int) hours};
}
}
}
Expand Down
37 changes: 30 additions & 7 deletions Core/Models/Config/BehaviorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,55 @@ namespace Core.Models.Config
/// </summary>
public class BehaviorModel
{
[Config(Name = "睡眠监测", Description = "离开电脑时自动停止统计,重启软件生效。(一般情况不建议关闭)", Group = "偏好")]
/// <summary>
/// 睡眠监测
/// </summary>
[Config(
Name = "config.behaviorModel.isSleepWatch.name",
Description = "config.behaviorModel.isSleepWatch.description",
Group = "config.behaviorModel.group.isSleepWatch")]
public bool IsSleepWatch { get; set; } = true;
[Config(IsCanImportExport = true, Name = "忽略应用", Description = "可以通过进程名称或者正则表达式进行匹配。当使用正则表达式时可以匹配程序路径", Group = "忽略应用", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")]

/// <summary>
/// 忽略的进程列表
/// </summary>
[Config(
IsCanImportExport = true,
Name = "config.behaviorModel.ignoreProcessList.name",
Description = "config.behaviorModel.ignoreProcessList.description",
Group = "config.behaviorModel.group.ignoreProcess",
Placeholder = "config.behaviorModel.ignoreProcessList.placeholder")]
public List<string> IgnoreProcessList { get; set; } = new List<string>();

[Config(IsCanImportExport = true, Name = "忽略URL", Description = "过滤不需要统计的网站或链接", Group = "忽略URL", Placeholder = "URL 支持正则表达式")]
/// <summary>
/// 忽略的进程列表
/// 忽略的 URL 列表
/// </summary>
[Config(
IsCanImportExport = true,
Name = "config.behaviorModel.ignoreURLList.name",
Description = "config.behaviorModel.ignoreURLList.description",
Group = "config.behaviorModel.group.ignoreURL",
Placeholder = "config.behaviorModel.ignoreURLList.placeholder")]
public List<string> IgnoreURLList { get; set; } = new List<string>();

[Config(Name = "应用白名单", Description = "仅统计白名单内的应用", Group = "应用白名单")]
/// <summary>
/// 睡眠监测
/// </summary>
[Config(
Name = "config.behaviorModel.isWhiteList.name",
Description = "config.behaviorModel.isWhiteList.description",
Group = "config.behaviorModel.group.whiteList")]
public bool IsWhiteList { get; set; } = false;
[Config(IsCanImportExport = true, Name = "应用白名单", Description = "可以通过进程名称或者正则表达式进行匹配,当使用正则表达式时可以匹配程序路径", Group = "应用白名单", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")]

/// <summary>
/// 应用白名单
/// </summary>
[Config(
IsCanImportExport = true,
Name = "config.behaviorModel.processWhiteList.name",
Description = "config.behaviorModel.processWhiteList.description",
Group = "config.behaviorModel.group.whiteList",
Placeholder = "config.behaviorModel.processWhiteList.placeholder")]
public List<string> ProcessWhiteList { get; set; } = new List<string>();
}
}
}
56 changes: 47 additions & 9 deletions Core/Models/Config/GeneralModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,48 @@ namespace Core.Models.Config
/// </summary>
public class GeneralModel
{
[Config(Name = "开机自启动", Description = "在电脑启动时自动运行 Tai", Group = "基础")]
/// <summary>
/// 是否启用开机自启动
/// </summary>
[Config(
Name = "config.general.isStartAtBoot.name",
Description = "config.general.isStartAtBoot.description",
Group = "config.general.group.basic")]
public bool IsStartatboot { get; set; }

/// <summary>
/// 主题模式
/// </summary>
[Config(Options = "浅色|深色", Name = "主题模式", Description = "设置以浅色或深色模式显示", Group = "外观")]
[Config(
Options = "config.general.theme.options",
Name = "config.general.theme.name",
Description = "config.general.theme.description",
Group = "config.general.group.appearance")]
public int Theme { get; set; } = 0;

/// <summary>
/// 主题颜色
/// </summary>
[Config(Name = "主题颜色", Description = "", Group = "外观")]
[Config(
Name = "config.general.themeColor.name",
Description = "config.general.themeColor.description",
Group = "config.general.group.appearance")]
public string ThemeColor { get; set; } = "#2b20d9";

/// <summary>
/// 是否保留界面大小
/// </summary>
[Config(Name = "保留窗口大小", Description = "保留当前的窗口大小,而非使用系统默认尺寸", Group = "外观")]
[Config(
Name = "config.general.isSaveWindowSize.name",
Description = "config.general.isSaveWindowSize.description",
Group = "config.general.group.appearance")]
public bool IsSaveWindowSize { get; set; } = false;

/// <summary>
/// 窗口宽度
/// </summary>
public double WindowWidth { get; set; } = 815;

/// <summary>
/// 窗口高度
/// </summary>
Expand All @@ -44,28 +61,49 @@ public class GeneralModel
/// <summary>
/// 启动页选择
/// </summary>
[Config(Options = "概览|统计|详细|分类", Name = "启动页", Description = "设置打开主界面时显示的页面", Group = "基础")]
[Config(
Options = "config.general.startPage.options",
Name = "config.general.startPage.name",
Description = "config.general.startPage.description",
Group = "config.general.group.basic")]
public int StartPage { get; set; } = 0;
[Config(Name = "启动软件时显示主界面", Description = "在开机自启动时此选项无效", Group = "基础")]

/// <summary>
/// 启动软件时显示主界面
/// </summary>
[Config(
Name = "config.general.isStartupShowMainWindow.name",
Description = "config.general.isStartupShowMainWindow.description",
Group = "config.general.group.basic")]
public bool IsStartupShowMainWindow { get; set; } = true;

/// <summary>
/// 概览页最为频繁显示条数
/// </summary>
[Config(Options = "1|2|3|4|5|6|7|8|9|10", Name = "最为频繁显示条数", Description = "", Group = "概览页")]
[Config(
Options = "config.general.indexPageFrequentUseNum.options",
Name = "config.general.indexPageFrequentUseNum.name",
Description = "config.general.indexPageFrequentUseNum.description",
Group = "config.general.group.overview")]
public int IndexPageFrequentUseNum { get; set; } = 2;

/// <summary>
/// 概览页最为频繁显示条数
/// </summary>
[Config(Options = "1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20", Name = "更多显示条数", Description = "", Group = "概览页")]
[Config(
Options = "config.general.indexPageMoreNum.options",
Name = "config.general.indexPageMoreNum.name",
Description = "config.general.indexPageMoreNum.description",
Group = "config.general.group.overview")]
public int IndexPageMoreNum { get; set; } = 11;

/// <summary>
/// 是否启用网站记录功能
/// </summary>
[Config(Name = "网站浏览统计", Description = "统计浏览器的网站访问数据,支持:Google Chrome、MSEdge或任何能够安装Chrome拓展的浏览器。请点击 “关于 > 浏览器统计插件” 了解如何安装和使用此功能。", Group = "功能")]
[Config(
Name = "config.general.isWebEnabled.name",
Description = "config.general.isWebEnabled.description",
Group = "config.general.group.feature")]
public bool IsWebEnabled { get; set; } = false;
}
}
4 changes: 2 additions & 2 deletions Core/Models/Config/Link/LinkModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class LinkModel
/// <summary>
/// 关联名称
/// </summary>
[Config(Name = "名称", Description = "设置一个名称用于识别该关联", IsName = true, IsCanRepeat = false)]
[Config(Name = "config.linkMode.name.name", Description = "config.linkMode.name.description", IsName = true, IsCanRepeat = false)]
public string Name { get; set; } = "新的关联";
/// <summary>
/// 关联进程列表
/// </summary>
[Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此,至少两个。", IsCanRepeat = false)]
[Config(Name = "config.linkMode.processList.name", Description = "config.linkMode.processList.description", IsCanRepeat = false)]
public List<string> ProcessList { get; set; } = new List<string>();
}
}
1 change: 1 addition & 0 deletions UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private void ConfigureServices(IServiceCollection services)
services.AddSingleton<IWebFilter, WebFilter>();

// UI服务
services.AddSingleton<ILocalizationServicer, LocalizationServicer>();
services.AddSingleton<IUIServicer, UIServicer>();
services.AddSingleton<IAppContextMenuServicer, AppContextMenuServicer>();
services.AddSingleton<IThemeServicer, ThemeServicer>();
Expand Down
4 changes: 3 additions & 1 deletion UI/Controls/Charts/Charts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using UI.Controls.Charts.Model;
using UI.Controls.Input;
using UI.Extensions;
using UI.Models;
using UI.Servicers;

namespace UI.Controls.Charts
{
Expand Down Expand Up @@ -1470,7 +1472,7 @@ private string Covervalue(double value)
{
if (DataValueType == ChartDataValueType.Seconds)
{
return Time.ToString((int)value);
return LocalizationServicer.Instance.Translated(Time.ToString((int)value));
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion UI/Controls/Charts/ChartsItemTypeRadar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using UI.Controls.Charts.Model;
using UI.Servicers;

namespace UI.Controls.Charts
{
Expand Down Expand Up @@ -176,7 +177,7 @@ private void Render()
font.Text = Data[i].Name.Length > 4 ? Data[i].Name.Substring(0, 4) : Data[i].Name;
font.Foreground = UI.Base.Color.Colors.GetFromString("#7f7f7f");
font.FontSize = 12;
font.ToolTip = $"{Data[i].Name} {Time.ToString((int)Data[i].Values.Sum())}";
font.ToolTip = $"{Data[i].Name} {LocalizationServicer.Instance.Translated(Time.ToString((int)Data[i].Values.Sum()))}";

var textSize = MeasureString(font);
Debug.WriteLine(font.Text + " -> " + angle * i);
Expand Down
9 changes: 5 additions & 4 deletions UI/Controls/SettingPanel/SettingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using UI.Controls.Input;
using UI.Controls.List;
using UI.Controls.Select;
using UI.Servicers;

namespace UI.Controls.SettingPanel
{
Expand Down Expand Up @@ -299,7 +300,7 @@ private StackPanel GetCreateGroupContainer(UIElement item, string groupName = nu
if (groupName != null)
{
var groupNameControl = new TextBlock();
groupNameControl.Text = groupName;
groupNameControl.Text = LocalizationServicer.Instance.Translated(groupName);
groupNameControl.FontSize = 14;
groupNameControl.Margin = new Thickness(0, 0, 0, 10);
container.Children.Add(groupNameControl);
Expand Down Expand Up @@ -377,7 +378,7 @@ private UIElement RenderColorConfigControl(ConfigAttribute configAttribute, Prop
private UIElement RenderOptionsConfigControl(ConfigAttribute configAttribute, PropertyInfo pi)
{
var control = new Select.Select();
var optionsArr = configAttribute.Options.Split('|');
var optionsArr = LocalizationServicer.Instance.Translated(configAttribute.Options).Split('|');

var options = new List<SelectItemModel>();
for (int i = 0; i < optionsArr.Length; i++)
Expand Down Expand Up @@ -493,7 +494,7 @@ private UIElement RenderListStringConfigControl(ConfigAttribute configAttribute,

// 添加输入框
var addInputBox = new InputBox();
addInputBox.Placeholder = configAttribute.Placeholder;
addInputBox.Placeholder = LocalizationServicer.Instance.Translated(configAttribute.Placeholder);
addInputBox.Margin = new Thickness(0, 0, 10, 0);


Expand Down Expand Up @@ -635,7 +636,7 @@ private UIElement RenderListStringConfigControl(ConfigAttribute configAttribute,
// 标题和说明

var description = new TextBlock();
description.Text = configAttribute.Description;
description.Text = LocalizationServicer.Instance.Translated(configAttribute.Description);
description.Margin = new Thickness(10, 10, 10, 0);
description.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#989CA1"));
var container = new StackPanel();
Expand Down
9 changes: 7 additions & 2 deletions UI/Controls/SettingPanel/SettingPanelItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using UI.Servicers;

namespace UI.Controls.SettingPanel
{
Expand All @@ -29,15 +30,19 @@ public class SettingPanelItem : Control
public bool IsBeta { get { return (bool)GetValue(IsBetaProperty); } set { SetValue(IsBetaProperty, value); } }
public static readonly DependencyProperty IsBetaProperty = DependencyProperty.Register("IsBeta", typeof(bool), typeof(SettingPanelItem));

public string DisplayName { get { return (string)GetValue(DisplayNameProperty); } set { SetValue(DisplayNameProperty, value); } }
public static readonly DependencyProperty DisplayNameProperty = DependencyProperty.Register("DisplayName", typeof(string), typeof(SettingPanelItem));

public SettingPanelItem()
{
DefaultStyleKey = typeof(SettingPanelItem);
}

public void Init(ConfigAttribute configAttribute_, object content_)
{
Name = configAttribute_.Name;
Description = configAttribute_.Description;
Name = configAttribute_.Name.Replace(".", "_");
DisplayName = LocalizationServicer.Instance.Translated(configAttribute_.Name);
Description = LocalizationServicer.Instance.Translated(configAttribute_.Description);
IsBeta = configAttribute_.IsBeta;
Content = content_;
}
Expand Down
9 changes: 5 additions & 4 deletions UI/Controls/SettingPanel/SettingPanelMultiItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using UI.Controls.Button;
using UI.Controls.Input;
using UI.Controls.List;
using UI.Servicers;

namespace UI.Controls.SettingPanel
{
Expand Down Expand Up @@ -117,8 +118,8 @@ private void Render()
private void RenderStringList(ConfigAttribute attribute, PropertyInfo pi)
{
var title = new SettingPanelItem();
title.Name = attribute.Name;
title.Description = attribute.Description;
title.Name = LocalizationServicer.Instance.Translated(attribute.Name);
title.Description = LocalizationServicer.Instance.Translated(attribute.Description);

Container.Children.Add(title);

Expand Down Expand Up @@ -319,8 +320,8 @@ private void RenderTextBox(ConfigAttribute attribute, PropertyInfo pi)

};
var item = new SettingPanelItem();
item.Name = attribute.Name;
item.Description = attribute.Description;
item.Name = LocalizationServicer.Instance.Translated(attribute.Name);
item.Description = LocalizationServicer.Instance.Translated(attribute.Description);
item.Content = textBox;
pi.SetValue(configData, textBox.Text);
if (attribute.IsName)
Expand Down
Loading