Skip to content

Commit

Permalink
Merge pull request #38 from Planshit/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
noberumotto committed Apr 14, 2020
2 parents af8a1b1 + b61ebb9 commit b148a1d
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 183 deletions.
264 changes: 175 additions & 89 deletions src/Local/Project1.UI/Controls/Project1UIWindow.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Local/Project1.UI/Themes/Chart/Chart.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
Height="50"
VerticalAlignment="Bottom"
Visibility="{TemplateBinding AverageVisibility}"
Panel.ZIndex="3"
>
<TextBlock
x:Name="AverageLabel"
Expand Down
22 changes: 22 additions & 0 deletions src/Local/ProjectEye/Core/Models/Options/AnimationModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Project1.UI.Controls.Project1UIWindow;

namespace ProjectEye.Core.Models.Options
{
public class AnimationModel
{
public int ID { get; set; }
/// <summary>
/// 动画名
/// </summary>
public string DisplayName { get; set; }
/// <summary>
/// 动画类型
/// </summary>
public AnimationType AnimationType { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Local/ProjectEye/Core/Models/Options/GeneralModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class GeneralModel
/// <summary>
/// 是否启用一周数据分析
/// </summary>
public bool IsWeekDataAnalysis{ get; set; } = false;
public bool IsWeekDataAnalysis { get; set; } = false;

}
}
2 changes: 1 addition & 1 deletion src/Local/ProjectEye/Core/Models/Options/OptionsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ProjectEye.Core.Models.Options
{
[XmlRootAttribute("Options")]
public class OptionsModel
public class OptionsModel
{
/// <summary>
/// 通用设置
Expand Down
22 changes: 18 additions & 4 deletions src/Local/ProjectEye/Core/Models/Options/StyleModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using static Project1.UI.Controls.Project1UIWindow;

namespace ProjectEye.Core.Models.Options
{
Expand Down Expand Up @@ -31,10 +32,10 @@ public class StyleModel
/// 预提醒不操作时执行的动作
/// </summary>
public ComboxModel PreAlertAction { get; set; } = new ComboxModel() { DisplayName = "进入本次休息", Value = "1" };
/// <summary>
/// 是否启用预提醒自动操作
/// </summary>
public bool IsPreAlertAutoAction { get; set; } = true;
///// <summary>
///// 是否启用预提醒自动操作
///// </summary>
//public bool IsPreAlertAutoAction { get; set; } = true;
/// <summary>
/// 预提醒标题
/// </summary>
Expand Down Expand Up @@ -82,5 +83,18 @@ public class StyleModel
/// 动画效果
/// </summary>
public bool IsAnimation { get; set; } = false;
/// <summary>
/// 提示窗口动画类型
/// </summary>
public AnimationModel TipWindowAnimation { get; set; }
/// <summary>
/// 休息提示询问,如果开启可以使用预提醒功能以及在全屏提示窗口点击,关闭后则每到休息时间直接开始计时不询问,且支持鼠标穿透
/// </summary>
public bool IsTipAsk { get; set; } = true;
/// <summary>
/// 全屏提示窗口鼠标穿透
/// </summary>
public bool IsThruTipWindow { get; set; } = false;

}
}
58 changes: 33 additions & 25 deletions src/Local/ProjectEye/Core/Service/ConfigService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ProjectEye.Core.Models.Options;
using Newtonsoft.Json;
using ProjectEye.Core.Models.Options;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -21,6 +22,10 @@ public class ConfigService : IService
private readonly SystemResourcesService systemResources;
//存放文件夹
private readonly string dir = "Data";
/// <summary>
/// 未更改的配置
/// </summary>
private OptionsModel oldOptions_;
public OptionsModel options { get; set; }
/// <summary>
/// 配置文件被修改时发生
Expand All @@ -33,7 +38,7 @@ public ConfigService(SystemResourcesService systemResources)
dir,
"config.xml");
xmlExtensions = new XmlExtensions(configPath);
//Init();
oldOptions_ = new OptionsModel();
}
public void Init()
{
Expand All @@ -43,6 +48,7 @@ public void Init()
if (obj != null)
{
options = obj as OptionsModel;
SaveOldOptions();
}
else
{
Expand All @@ -61,12 +67,22 @@ public bool Save()
{
if (options != null)
{
Changed?.Invoke(options, null);

Changed?.Invoke(oldOptions_, null);
SaveOldOptions();
return xmlExtensions.Save(options);
}
return false;
}

/// <summary>
/// 保持旧选项数据
/// </summary>
private void SaveOldOptions()
{
string optionsStr = JsonConvert.SerializeObject(options);
oldOptions_ = JsonConvert.DeserializeObject<OptionsModel>(optionsStr);
}
/// <summary>
/// 创建默认配置文件
/// </summary>
Expand All @@ -84,49 +100,41 @@ private void CreateDefaultConfig()
options.Style = new StyleModel();
options.Style.Theme = systemResources.Themes[0];
options.Style.TipContent = "您已持续用眼{t}分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!";
options.Style.TipWindowAnimation = systemResources.Animations[0];

options.KeyboardShortcuts = new KeyboardShortcutModel();

options.Behavior = new BehaviorModel();

SaveOldOptions();

xmlExtensions.Save(options);
}
private void CheckOptions()
{
System.Reflection.PropertyInfo[] properties = options.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
CheckOptions(options);
CheckOptions(options.Style);
}
private void CheckOptions(object obj)
{
System.Reflection.PropertyInfo[] properties = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

foreach (System.Reflection.PropertyInfo item in properties)
{
string name = item.Name;
object value = item.GetValue(options, null);
object value = item.GetValue(obj, null);
if (value == null)
{
//配置项不存在时创建

//var constructorInfoObj = item.PropertyType.GetConstructors()[0];
//var constructorParameters = constructorInfoObj.GetParameters();
//int constructorParametersLength = constructorParameters.Length;
Type[] types = new Type[0];
object[] objs = new object[0];
//for (int i = 0; i < constructorParametersLength; i++)
//{
// string typeFullName = constructorParameters[i].ParameterType.FullName;
// Type t = Type.GetType(typeFullName);
// types[i] = t;
//}

ConstructorInfo ctor = item.PropertyType.GetConstructor(types);
object instance = ctor.Invoke(objs);
item.SetValue(options, instance);
item.SetValue(obj, instance);
}
Debug.WriteLine(string.Format("{0}:{1},", name, value));

//if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
//{
// tStr += string.Format("{0}:{1},", name, value);
//}
//else
//{
// getProperties(value);
//}
Debug.WriteLine(string.Format("{0}:{1},", name, value));
}
}

Expand Down
48 changes: 39 additions & 9 deletions src/Local/ProjectEye/Core/Service/MainService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Win32;
using Project1.UI.Controls;
using ProjectEye.Core.Models.Options;
using ProjectEye.ViewModels;
using ProjectEye.Views;
using System;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void Init()
//初始化用眼统计计时器
useeye_timer = new DispatcherTimer();
useeye_timer.Tick += new EventHandler(useeye_timer_Tick);
useeye_timer.Interval = new TimeSpan(0, 30, 0);
useeye_timer.Interval = new TimeSpan(0, 10, 0);
/****调试模式代码****/
#if DEBUG
//30秒提示休息
Expand All @@ -139,18 +140,25 @@ public void Init()
useeye_timer.Interval = new TimeSpan(0, 1, 0);
#endif

//在所有屏幕上创建全屏提示窗口
var tipWindow = WindowManager.GetCreateWindow("TipWindow", true);
CreateTipWindows();

foreach (var window in tipWindow)
{
window.IsVisibleChanged += new DependencyPropertyChangedEventHandler(isVisibleChanged);
}
//记录鼠标坐标
SaveCursorPos();

Start();

config.Changed += Config_Changed;
}

private void Config_Changed(object sender, EventArgs e)
{
var oldOptions = sender as OptionsModel;
if (oldOptions.Style.IsThruTipWindow != config.options.Style.IsThruTipWindow)
{
//鼠标穿透被打开
CreateTipWindows();
Debug.WriteLine("鼠标穿透更改,重新创建窗口");
}
}

#endregion
Expand Down Expand Up @@ -319,8 +327,12 @@ public bool SetWarnTime(int minutes)
{
Debug.WriteLine(timer.Interval.TotalMinutes + "," + minutes);
timer.Interval = new TimeSpan(0, minutes, 0);
ReStart();
return true;
if (!config.options.General.Noreset)
{
ReStart();
return true;
}
return false;
}
return false;
}
Expand Down Expand Up @@ -551,5 +563,23 @@ public void ReStartWorkTimerWatch()
workTimerStopwatch.Restart();
}
#endregion

#region 创建全屏提示窗口
/// <summary>
/// 创建全屏提示窗口
/// </summary>
public void CreateTipWindows()
{
//关闭
WindowManager.Close("TipWindow");
//在所有屏幕上创建全屏提示窗口
var tipWindow = WindowManager.GetCreateWindow("TipWindow", true);

foreach (var window in tipWindow)
{
window.IsVisibleChanged += new DependencyPropertyChangedEventHandler(isVisibleChanged);
}
}
#endregion
}
}
13 changes: 7 additions & 6 deletions src/Local/ProjectEye/Core/Service/StatisticService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,20 @@ public void Add(StatisticType type, double value)
#endregion

#region 查找日期数据,如果不存在则创建
public StatisticModel FindCreate()
{
return FindCreate(DateTime.Now.Date);
}
/// <summary>
/// 查找日期数据,如果不存在则创建
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public StatisticModel FindCreate(DateTime date = default)
public StatisticModel FindCreate(DateTime date)
{
if (date == default)
{
date = DateTime.Now;
}
if (date.Date == DateTime.Now.Date &&
todayStatistic != null)
todayStatistic != null &&
todayStatistic.Date == date.Date)
{
//当日
return todayStatistic;
Expand Down
23 changes: 22 additions & 1 deletion src/Local/ProjectEye/Core/Service/SystemResourcesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ public class SystemResourcesService : IService
{
public List<ThemeModel> Themes { get; set; }
public List<ComboxModel> PreAlertActions { get; set; }
public List<AnimationModel> Animations { get; set; }
public void Init()
{
Themes = new List<ThemeModel>();
PreAlertActions = new List<ComboxModel>();

Animations = new List<AnimationModel>();

Themes.Add(new ThemeModel()
{
Expand All @@ -40,6 +41,26 @@ public void Init()
DisplayName = "跳过本次休息",
Value = "2"
});
//预置动画
Animations.Add(new AnimationModel()
{
ID = 0,
AnimationType = Project1.UI.Controls.Project1UIWindow.AnimationType.None,
DisplayName = ""
});
Animations.Add(new AnimationModel()
{
ID = 1,
AnimationType = Project1.UI.Controls.Project1UIWindow.AnimationType.RightBottomScale,
DisplayName = "右下角缩放"
});
Animations.Add(new AnimationModel()
{
ID = 2,
AnimationType = Project1.UI.Controls.Project1UIWindow.AnimationType.Opacity,
DisplayName = "渐出渐隐"
});

}
}
}
1 change: 1 addition & 0 deletions src/Local/ProjectEye/Core/Service/TrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private void Theme_OnChangedTheme(string OldThemeName, string NewThemeName)

private void MainService_OnStart(object service, int msg)
{
config.options.General.Noreset = false;
if (!backgroundWorker.IsBusy)
{
UpdateIcon("sunglasses");
Expand Down
Loading

0 comments on commit b148a1d

Please sign in to comment.