Skip to content

Commit

Permalink
增加睡眠监测功能开关;启动时显示主窗口开关
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Oct 24, 2023
1 parent 2561773 commit 3352dc4
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 56 deletions.
5 changes: 5 additions & 0 deletions Core/Models/Config/BehaviorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace Core.Models.Config
/// </summary>
public class BehaviorModel
{
[Config(Name = "睡眠监测", Description = "离开电脑时自动停止统计,重启软件生效。(一般情况不建议关闭)", Group = "偏好")]
/// <summary>
/// 睡眠监测
/// </summary>
public bool IsSleepWatch { get; set; } = true;
[Config(IsCanImportExport = true, Name = "忽略应用", Description = "可以通过进程名称或者正则表达式进行匹配。当使用正则表达式时可以匹配程序路径", Group = "忽略应用", Placeholder = "进程名称,不需要输入.exe。支持正则表达式")]
/// <summary>
/// 忽略的进程列表
Expand Down
5 changes: 5 additions & 0 deletions Core/Models/Config/GeneralModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class GeneralModel
/// </summary>
[Config(Options = "概览|统计|详细|分类", Name = "启动页", Description = "设置打开主界面时显示的页面", Group = "基础")]
public int StartPage { get; set; } = 0;
[Config(Name = "启动软件时显示主界面", Description = "在开机自启动时此选项无效", Group = "基础")]
/// <summary>
/// 启动软件时显示主界面
/// </summary>
public bool IsStartupShowMainWindow { get; set; } = true;
/// <summary>
/// 概览页最为频繁显示条数
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.1")]
[assembly: AssemblyFileVersion("1.1.0.1")]
[assembly: AssemblyVersion("1.1.0.2")]
[assembly: AssemblyFileVersion("1.1.0.2")]
10 changes: 5 additions & 5 deletions Core/Servicers/Instances/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ await Task.Run(() =>
config = appConfig.GetConfig();
UpdateConfigIgnoreProcess();



// 启动睡眠监测
sleepdiscover.Start();

// 初始化过滤器
_webFilter.Init();

Expand All @@ -180,6 +175,11 @@ public void Start()
{
_webServer.Start();
}
if (config.Behavior.IsSleepWatch)
{
// 启动睡眠监测
sleepdiscover.Start();
}
}
public void Stop()
{
Expand Down
5 changes: 5 additions & 0 deletions Core/Servicers/Instances/Sleepdiscover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public void Start()
Win32API.SetKeyboardHook(keyboardProc);
}

public void Stop()
{
StopTimer();
}

private void StartTimer()
{
StopTimer();
Expand Down
4 changes: 4 additions & 0 deletions Core/Servicers/Interfaces/ISleepdiscover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public interface ISleepdiscover
/// 启动
/// </summary>
void Start();
/// <summary>
/// 停止
/// </summary>
void Stop();

/// <summary>
/// 休眠状态发生更改
Expand Down
4 changes: 2 additions & 2 deletions UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.0.1")]
[assembly: AssemblyFileVersion("1.5.0.1")]
[assembly: AssemblyVersion("1.5.0.2")]
[assembly: AssemblyFileVersion("1.5.0.2")]
7 changes: 5 additions & 2 deletions UI/Servicers/MainServicer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ public class MainServicer : IMainServicer
private readonly IAppContextMenuServicer appContextMenuServicer;
private readonly IWebSiteContextMenuServicer _webSiteContext;
private readonly IStatusBarIconServicer _statusBarIconServicer;
private readonly IAppConfig _config;
private bool isSelfStart = false;
public MainServicer(
IMain main,
IThemeServicer themeServicer,
IInputServicer inputServicer,
IAppContextMenuServicer appContextMenuServicer,
IWebSiteContextMenuServicer webSiteContext_,
IStatusBarIconServicer statusBarIconServicer_)
IStatusBarIconServicer statusBarIconServicer_,
IAppConfig config_)
{
this.main = main;
this.themeServicer = themeServicer;
this.inputServicer = inputServicer;
this.appContextMenuServicer = appContextMenuServicer;
_webSiteContext = webSiteContext_;
_statusBarIconServicer = statusBarIconServicer_;
_config = config_;
}
public void Start(bool isSelfStart)
{
Expand All @@ -47,7 +50,7 @@ private void Main_OnStarted(object sender, EventArgs e)
appContextMenuServicer.Init();
_webSiteContext.Init();

if(!isSelfStart)
if (!isSelfStart && _config.GetConfig().General.IsStartupShowMainWindow)
{
_statusBarIconServicer.ShowMainWindow();
}
Expand Down
103 changes: 58 additions & 45 deletions UI/ViewModels/DataPageVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,32 +204,39 @@ await Task.Run(() =>
private List<ChartsDataModel> MapToChartsData(IEnumerable<Core.Models.DailyLogModel> list)
{
var resData = new List<ChartsDataModel>();
var config = appConfig.GetConfig();

foreach (var item in list)
try
{
var bindModel = new ChartsDataModel();
bindModel.Data = item;
bindModel.Name = string.IsNullOrEmpty(item.AppModel?.Description) ? item.AppModel.Name : item.AppModel.Description;
bindModel.Value = item.Time;
bindModel.Tag = Time.ToString(item.Time);
bindModel.PopupText = item.AppModel?.File;
bindModel.Icon = item.AppModel?.IconFile;
bindModel.BadgeList = new List<ChartBadgeModel>();
if (item.AppModel.Category != null)
var config = appConfig.GetConfig();

foreach (var item in list)
{
bindModel.BadgeList.Add(new ChartBadgeModel()
var bindModel = new ChartsDataModel();
bindModel.Data = item;
bindModel.Name = string.IsNullOrEmpty(item.AppModel?.Description) ? item.AppModel.Name : item.AppModel.Description;
bindModel.Value = item.Time;
bindModel.Tag = Time.ToString(item.Time);
bindModel.PopupText = item.AppModel?.File;
bindModel.Icon = item.AppModel?.IconFile;
bindModel.BadgeList = new List<ChartBadgeModel>();
if (item.AppModel.Category != null)
{
Name = item.AppModel.Category.Name,
Color = item.AppModel.Category.Color,
Type = ChartBadgeType.Category
});
}
if (config.Behavior.IgnoreProcessList.Contains(item.AppModel.Name))
{
bindModel.BadgeList.Add(ChartBadgeModel.IgnoreBadge);
bindModel.BadgeList.Add(new ChartBadgeModel()
{
Name = item.AppModel.Category.Name,
Color = item.AppModel.Category.Color,
Type = ChartBadgeType.Category
});
}
if (config.Behavior.IgnoreProcessList.Contains(item.AppModel.Name))
{
bindModel.BadgeList.Add(ChartBadgeModel.IgnoreBadge);
}
resData.Add(bindModel);
}
resData.Add(bindModel);
}
catch (Exception e)
{
Logger.Error(e.ToString());
}

return resData;
Expand All @@ -238,34 +245,40 @@ private List<ChartsDataModel> MapToChartsData(IEnumerable<Core.Models.DailyLogMo
private List<ChartsDataModel> MapToChartsWebData(IEnumerable<Core.Models.Db.WebSiteModel> list)
{
var resData = new List<ChartsDataModel>();
var config = appConfig.GetConfig();

foreach (var item in list)
try
{
var bindModel = new ChartsDataModel();
bindModel.Data = item;
bindModel.Name = item.Title;
bindModel.Value = item.Duration;
bindModel.Tag = Time.ToString(item.Duration);
bindModel.PopupText = item.Domain;
bindModel.Icon = item.IconFile;
bindModel.BadgeList = new List<ChartBadgeModel>();
if (item.Category != null)
var config = appConfig.GetConfig();

foreach (var item in list)
{
bindModel.BadgeList.Add(new ChartBadgeModel()
var bindModel = new ChartsDataModel();
bindModel.Data = item;
bindModel.Name = item.Title;
bindModel.Value = item.Duration;
bindModel.Tag = Time.ToString(item.Duration);
bindModel.PopupText = item.Domain;
bindModel.Icon = item.IconFile;
bindModel.BadgeList = new List<ChartBadgeModel>();
if (item.Category != null)
{
Name = item.Category.Name,
Color = item.Category.Color,
Type = ChartBadgeType.Category
});
}
if (config.Behavior.IgnoreURLList.Contains(item.Domain))
{
bindModel.BadgeList.Add(ChartBadgeModel.IgnoreBadge);
bindModel.BadgeList.Add(new ChartBadgeModel()
{
Name = item.Category.Name,
Color = item.Category.Color,
Type = ChartBadgeType.Category
});
}
if (config.Behavior.IgnoreURLList.Contains(item.Domain))
{
bindModel.BadgeList.Add(ChartBadgeModel.IgnoreBadge);
}
resData.Add(bindModel);
}
resData.Add(bindModel);
}

catch (Exception e)
{
Logger.Error(e.ToString());
}
return resData;
}
#endregion
Expand Down

0 comments on commit 3352dc4

Please sign in to comment.