Skip to content

Commit fe17da5

Browse files
authored
Merge pull request #13 from Planshit/dev
Dev
2 parents d8b759f + 24330d4 commit fe17da5

File tree

13 files changed

+359
-55
lines changed

13 files changed

+359
-55
lines changed

src/Project1.UI/Controls/Project1UIChart.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public string[] Labels
124124
public Project1UIChart()
125125
{
126126
DefaultStyleKey = typeof(Project1UIChart);
127-
128-
129127
}
130128

131129
public override void OnApplyTemplate()
@@ -200,11 +198,11 @@ public void DrawSnappedLinesBetweenPoints(DrawingContext dc,
200198
}
201199
dc.Pop();
202200
}
203-
private void Draw(DrawingContext dc, Point start, Point end, string color = "#dad9d9")
201+
private void Draw(DrawingContext dc, Point start, Point end, string color = "#dad9d9", double thickness = 1)
204202
{
205203
Pen _pen = new Pen();
206204
_pen.Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color));
207-
_pen.Thickness = 1;
205+
_pen.Thickness = thickness;
208206

209207
DrawSnappedLinesBetweenPoints(dc, _pen, 1, new[]
210208
{
@@ -522,7 +520,7 @@ private void DrawColorBlock()
522520
Color = (Color)ColorConverter.ConvertFromString(startcolor),
523521
Offset = 0
524522
});
525-
523+
526524
brush.GradientStops.Add(new GradientStop()
527525
{
528526
Color = (Color)ColorConverter.ConvertFromString(endcolor),
@@ -649,7 +647,7 @@ private void DrawDataPointLinkLine(DrawingContext dc)
649647
{
650648
var startPoint = DataPoints[i];
651649
var endPoint = DataPoints[i + 1];
652-
Draw(dc, startPoint, endPoint, UIDefaultSetting.DefaultThemeColor);
650+
Draw(dc, startPoint, endPoint, UIDefaultSetting.DefaultThemeColor,2);
653651
}
654652
}
655653
}

src/Project1.UI/Controls/Project1UIToast.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public Project1UIToast()
8080
Left = SystemParameters.PrimaryScreenWidth;
8181
Top = 0;
8282
SetIcon("pack://application:,,,/Project1.UI;component/Assets/Images/sunglasses.png");
83+
ShowActivated = false;
8384
}
8485

8586
/// <summary>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Xml.Serialization;
7+
8+
namespace ProjectEye.Core.Models.Options
9+
{
10+
/// <summary>
11+
/// 行为模型
12+
/// </summary>
13+
[XmlRootAttribute("Behavior")]
14+
public class BehaviorModel
15+
{
16+
/// <summary>
17+
/// 全屏时跳过休息
18+
/// </summary>
19+
public bool IsFullScreenBreak { get; set; } = false;
20+
/// <summary>
21+
/// 是否启用进程跳过功能
22+
/// </summary>
23+
public bool IsBreakProgressList { get; set; } = false;
24+
/// <summary>
25+
/// 跳过进程名单
26+
/// </summary>
27+
public ObservableCollection<string> BreakProgressList { get; set; } = new ObservableCollection<string>();
28+
}
29+
}

src/ProjectEye/Core/Models/Options/OptionsModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ public class OptionsModel
2121
/// 快捷键
2222
/// </summary>
2323
public KeyboardShortcutModel KeyboardShortcuts { get; set; }
24+
/// <summary>
25+
/// 行为
26+
/// </summary>
27+
public BehaviorModel Behavior { get; set; }
2428
}
2529
}

src/ProjectEye/Core/Service/ConfigService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ private void CreateDefaultConfig()
8686
options.Style.TipContent = "您已持续用眼{t}分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!";
8787

8888
options.KeyboardShortcuts = new KeyboardShortcutModel();
89+
90+
options.Behavior = new BehaviorModel();
8991
xmlExtensions.Save(options);
9092
}
9193
private void CheckOptions()

src/ProjectEye/Core/Service/MainService.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,18 @@ private void DoStop()
372372
/// </summary>
373373
private void ShowTipWindow()
374374
{
375-
Debug.WriteLine(preAlertAction);
376375
if (config.options.Style.IsPreAlert && preAlertAction == PreAlertAction.Break)
377376
{
378-
Debug.WriteLine("预提醒设置了跳过本次");
377+
//预提醒设置跳过
379378
statistic.Add(StatisticType.SkipCount, 1);
380379
}
381380
else
382381
{
383-
if (!config.options.General.Noreset)
382+
if (isBreakReset())
383+
{
384+
statistic.Add(StatisticType.SkipCount, 1);
385+
}
386+
else
384387
{
385388
busy_timer.Start();
386389
WindowManager.Show("TipWindow");
@@ -473,5 +476,50 @@ public void SetPreAlertAction(PreAlertAction preAlertAction)
473476
this.preAlertAction = preAlertAction;
474477
}
475478
#endregion
479+
480+
#region 是否跳过本次休息
481+
/// <summary>
482+
/// 是否跳过本次休息
483+
/// </summary>
484+
/// <returns>true跳过,false不跳过</returns>
485+
public bool isBreakReset()
486+
{
487+
if (!config.options.General.Noreset)
488+
{
489+
//0.全屏跳过判断
490+
if (config.options.Behavior.IsFullScreenBreak)
491+
{
492+
var info = Win32APIHelper.GetFocusWindowInfo();
493+
if (info.IsFullScreen)
494+
{
495+
return true;
496+
}
497+
}
498+
499+
//1.进程跳过判断
500+
if (config.options.Behavior.IsBreakProgressList)
501+
{
502+
Process[] processes = Process.GetProcesses();
503+
foreach (Process process in processes)
504+
{
505+
try
506+
{
507+
if (config.options.Behavior.BreakProgressList.Contains(process.ProcessName))
508+
{
509+
return true;
510+
}
511+
}
512+
catch
513+
{
514+
}
515+
}
516+
}
517+
518+
return false;
519+
}
520+
521+
return true;
522+
}
523+
#endregion
476524
}
477525
}

src/ProjectEye/Core/Service/PreAlertService.cs

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void Main_OnStart(object service, int msg)
126126
{
127127
InitPreAlert();
128128
}
129-
129+
130130
}
131131

132132
private void Main_OnPause(object service, int msg)
@@ -226,45 +226,56 @@ private void preAlertTimer_Tick(object sender, EventArgs e)
226226
{
227227
//到达预提醒时间弹出通知
228228
Debug.WriteLine(DateTime.Now.ToString());
229-
preAlertHasTime = config.options.Style.PreAlertTime - 1;
230-
231-
//通知数据模型
232-
var toastModel = new PreAlertModel();
233-
ParseModel(toastModel);
234229

235-
//通知弹窗
236-
var toast = new Project1UIToast();
237-
if (config.options.Style.PreAlertIcon != "")
230+
if (main.isBreakReset())
238231
{
239-
toast.SetIcon(config.options.Style.PreAlertIcon);
232+
//跳过本次
233+
SetPreAlertAction(PreAlertAction.Break);
240234
}
241-
toast.OnAutoHide += Toast_OnAutoHide;
242-
toast.OnButtonClick += Toast_OnButtonClick;
243-
toast.Alert(toastModel, config.options.Style.PreAlertTime,
244-
new string[] {
245-
"好的",
246-
"跳过本次"
247-
});
248-
249-
//播放通知提示音
250-
if (config.options.Style.IsPreAlertSound)
235+
else
251236
{
252-
sound.Play();
253-
}
237+
//预提醒弹出
254238

255-
//计时器
256-
var timer = new DispatcherTimer();
257-
timer.Interval = new TimeSpan(0, 0, 1);
258-
timer.Tick += (ee, cc) =>
259-
{
260-
preAlertHasTime--;
239+
preAlertHasTime = config.options.Style.PreAlertTime - 1;
240+
241+
//通知数据模型
242+
var toastModel = new PreAlertModel();
261243
ParseModel(toastModel);
262-
if (preAlertHasTime <= 0)
244+
245+
//通知弹窗
246+
var toast = new Project1UIToast();
247+
if (config.options.Style.PreAlertIcon != "")
248+
{
249+
toast.SetIcon(config.options.Style.PreAlertIcon);
250+
}
251+
toast.OnAutoHide += Toast_OnAutoHide;
252+
toast.OnButtonClick += Toast_OnButtonClick;
253+
toast.Alert(toastModel, config.options.Style.PreAlertTime,
254+
new string[] {
255+
"好的",
256+
"跳过本次"
257+
});
258+
259+
//播放通知提示音
260+
if (config.options.Style.IsPreAlertSound)
263261
{
264-
timer.Stop();
262+
sound.Play();
265263
}
266-
};
267-
timer.Start();
264+
265+
//计时器
266+
var timer = new DispatcherTimer();
267+
timer.Interval = new TimeSpan(0, 0, 1);
268+
timer.Tick += (ee, cc) =>
269+
{
270+
preAlertHasTime--;
271+
ParseModel(toastModel);
272+
if (preAlertHasTime <= 0)
273+
{
274+
timer.Stop();
275+
}
276+
};
277+
timer.Start();
278+
}
268279
}
269280

270281
/// <summary>

src/ProjectEye/Core/Win32APIHelper.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,104 @@ public class Win32APIHelper
1717
[DllImport("user32.dll", SetLastError = true)]
1818
[return: MarshalAs(UnmanagedType.Bool)]
1919
public static extern bool GetCursorPos(out Point lpPoint);
20+
21+
#region 窗口类
22+
/// <summary>
23+
/// 获取窗口标题
24+
/// </summary>
25+
/// <param name="hWnd"></param>
26+
/// <param name="lpString"></param>
27+
/// <param name="nMaxCount"></param>
28+
/// <returns></returns>
29+
[DllImport("user32", SetLastError = true)]
30+
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
31+
/// <summary>
32+
/// 获取窗口类名
33+
/// </summary>
34+
/// <param name="hWnd"></param>
35+
/// <param name="lpString"></param>
36+
/// <param name="nMaxCount"></param>
37+
/// <returns></returns>
38+
[DllImport("user32.dll")]
39+
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
40+
/// <summary>
41+
/// 获取当前焦点窗口句柄
42+
/// </summary>
43+
/// <returns></returns>
44+
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
45+
public static extern IntPtr GetForegroundWindow();
46+
47+
/// <summary>
48+
/// 获取窗口位置
49+
/// </summary>
50+
/// <param name="hWnd"></param>
51+
/// <param name="lpRect"></param>
52+
/// <returns></returns>
53+
[DllImport("user32.dll")]
54+
[return: MarshalAs(UnmanagedType.Bool)]
55+
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
56+
57+
[StructLayout(LayoutKind.Sequential)]
58+
public struct RECT
59+
{
60+
public int Left; //最左坐标
61+
public int Top; //最上坐标
62+
public int Right; //最右坐标
63+
public int Bottom; //最下坐标
64+
}
65+
/// <summary>
66+
/// 窗口信息结构
67+
/// </summary>
68+
public struct WindowInfo
69+
{
70+
/// <summary>
71+
/// 窗口宽度
72+
/// </summary>
73+
public int Width;
74+
/// <summary>
75+
/// 窗口高度
76+
/// </summary>
77+
public int Height;
78+
/// <summary>
79+
/// 窗口标题
80+
/// </summary>
81+
public string Title;
82+
/// <summary>
83+
/// 窗口类名
84+
/// </summary>
85+
public string ClassName;
86+
/// <summary>
87+
/// 是否全屏
88+
/// </summary>
89+
public bool IsFullScreen;
90+
}
91+
/// <summary>
92+
/// 获取当前焦点窗口信息
93+
/// </summary>
94+
/// <returns></returns>
95+
public static WindowInfo GetFocusWindowInfo()
96+
{
97+
var result = new WindowInfo();
98+
//获取当前焦点窗口句柄
99+
IntPtr intPtr = GetForegroundWindow();
100+
//获取窗口大小
101+
RECT rect = new RECT();
102+
GetWindowRect(intPtr, ref rect);
103+
result.Width = rect.Right - rect.Left;
104+
result.Height = rect.Bottom - rect.Top;
105+
//获取窗口标题
106+
StringBuilder title = new StringBuilder(256);
107+
GetWindowText(intPtr, title, title.Capacity);
108+
result.Title = title.ToString();
109+
//获取窗口类名
110+
StringBuilder className = new StringBuilder(256);
111+
GetClassName(intPtr, className, className.Capacity);
112+
result.ClassName = className.ToString();
113+
//判断全屏
114+
result.IsFullScreen = result.Width >= SystemParameters.PrimaryScreenWidth && result.Height >= SystemParameters.PrimaryScreenHeight;
115+
116+
return result;
117+
}
118+
#endregion
20119
}
21120
}

0 commit comments

Comments
 (0)