Skip to content

Commit

Permalink
一些更新
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Apr 30, 2019
1 parent 1913884 commit d030b0a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/ProjectEye/Core/Models/Options/GeneralModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ public class GeneralModel
/// 离开监听
/// </summary>
public bool leavelistener { get; set; }
/// <summary>
/// 提醒间隔时间(单位:分钟)
/// </summary>
public int warntime { get; set; }
}
}
1 change: 1 addition & 0 deletions src/ProjectEye/Core/Service/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private void CreateDefaultConfig()
options.general.sound = true;
options.general.startup = false;
options.general.leavelistener = false;
options.general.warntime = 20;

xmlExtensions.Save(options);
}
Expand Down
55 changes: 41 additions & 14 deletions src/ProjectEye/Core/Service/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,49 @@ public class MainService : IService
/// </summary>
private readonly DispatcherTimer back_timer;

private readonly ScreenService screenService;
private readonly ScreenService screen;
private readonly ConfigService config;
private readonly CacheService cache;
public MainService(App app,
ScreenService screenService,
ConfigService configService,
ScreenService screen,
ConfigService config,
CacheService cache)
{
this.screenService = screenService;
this.config = configService;
this.screen = screen;
this.config = config;
this.cache = cache;

//初始化用眼计时器
timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 20, 0);
#if DEBUG
timer.Interval = new TimeSpan(0, 0, 20);
#endif

timer.Interval = new TimeSpan(0, config.options.general.warntime, 0);
//初始化离开检测计时器
leave_timer = new DispatcherTimer();
leave_timer.Tick += new EventHandler(leave_timer_Tick);
leave_timer.Interval = new TimeSpan(0, 5, 0);

//初始化回来检测计时器
back_timer = new DispatcherTimer();
back_timer.Tick += new EventHandler(back_timer_Tick);
back_timer.Interval = new TimeSpan(0, 1, 0);


/****调试模式代码****/
#if DEBUG
//60秒提示休息
timer.Interval = new TimeSpan(0, 1, 0);
//20秒表示离开
leave_timer.Interval = new TimeSpan(0, 0, 20);
//每10秒检测回来
back_timer.Interval = new TimeSpan(0, 0, 10);
#endif
app.Exit += new ExitEventHandler(app_Exit);
}

private void back_timer_Tick(object sender, EventArgs e)
{
if (IsCursorPosChanged())
{
//Debug.WriteLine("用户回来了");
Debug.WriteLine("用户回来了");
//鼠标变化,停止计时器
back_timer.Stop();
leave_timer.Start();
Expand All @@ -79,7 +84,7 @@ private void leave_timer_Tick(object sender, EventArgs e)
{
if (IsUserLeave())
{
//Debug.WriteLine("用户离开了");
Debug.WriteLine("用户离开了");
//用户可能是离开电脑了
leave_timer.Stop();
//启动back timer监听鼠标状态
Expand Down Expand Up @@ -112,7 +117,7 @@ public void Init()
/// </summary>
public void Exit()
{
screenService.Dispose();
screen.Dispose();
DoStop();
WindowManager.Close("TipWindow");
}
Expand Down Expand Up @@ -149,6 +154,28 @@ public void CloseLeaveListener()
timer.Start();
}
}
/// <summary>
/// 设置提醒间隔时间并重新启动休息计时
/// </summary>
/// <param name="minutes"></param>
public void SetWarnTime(int minutes)
{
if (timer.Interval.TotalMinutes != minutes)
{
Debug.WriteLine(timer.Interval.TotalMinutes + "," + minutes);
timer.Interval = new TimeSpan(0, minutes, 0);
ReStart();
}
}
/// <summary>
/// 重新启动休息计时
/// </summary>
private void ReStart()
{
Debug.WriteLine("重新启动休息计时");
DoStop();
DoStart();
}
private void DoStart()
{
//休息提醒
Expand Down
13 changes: 13 additions & 0 deletions src/ProjectEye/Models/TipModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ namespace ProjectEye.Models
{
public class TipModel : UINotifyPropertyChanged
{
private int WarnTime_ = 20;
/// <summary>
/// 提醒间隔时间
/// </summary>
public int WarnTime
{
get { return WarnTime_; }
set
{
WarnTime_ = value;
OnPropertyChanged("WarnTime");
}
}
private int CountDown_ = 20;
/// <summary>
/// 倒计时
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectEye/ViewModels/OptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private void applyCommand_action(object obj)
{
mainService.CloseLeaveListener();
}
//处理休息间隔调整
mainService.SetWarnTime(config.options.general.warntime);
}
MessageBox.Show(msg, "提示");
}
Expand Down
15 changes: 14 additions & 1 deletion src/ProjectEye/ViewModels/TipViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TipViewModel : TipModel
private readonly SoundService sound;
private readonly ConfigService config;

public TipViewModel(ResetService reset,
public TipViewModel(ResetService reset,
SoundService sound,
ConfigService config)
{
Expand All @@ -31,10 +31,23 @@ public TipViewModel(ResetService reset,

this.sound = sound;
this.config = config;
this.config.Changed += config_Changed;
resetCommand = new Command(new Action<object>(resetCommand_action));
busyCommand = new Command(new Action<object>(busyCommand_action));

LoadConfig();
}
//加载配置
private void LoadConfig()
{
WarnTime = config.options.general.warntime;
}

//配置文件被修改时
private void config_Changed(object sender, EventArgs e)
{
//更新提醒时间
WarnTime = config.options.general.warntime;
}

private void resetCompleted(object sender, int timed)
Expand Down
20 changes: 18 additions & 2 deletions src/ProjectEye/Views/OptionsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@
<CheckBox Content="休息结束提示音" IsChecked="{Binding Model.data.general.sound}" Margin="0,10,0,0"/>
<CheckBox Content="离开监听" IsChecked="{Binding Model.data.general.leavelistener}" Margin="0,10,0,0"/>
<!--<CheckBox Content="数据统计(并不会联网上传)" IsChecked="{Binding Model.data.general.data}" Margin="0,10,0,0"/>-->

<Grid Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Margin="0,0,10,0">提醒间隔</TextBlock>
<Slider Grid.Column="1" Maximum="420" Minimum="1" SmallChange="1" Value="{Binding Model.data.general.warntime}" ToolTip="滑动后可用键盘方向键微调"/>
<TextBlock Text="{Binding Model.data.general.warntime}"
Grid.Column="2"
HorizontalAlignment="Right"/>
<TextBlock Text="分钟"
Grid.Column="3"
HorizontalAlignment="Left"/>
</Grid>
</StackPanel>
</TabItem>
<!--<TabItem Header="提醒规则">
<Grid Background="#FFE5E5E5"/>
</TabItem>-->
<TabItem Header="关于">
<StackPanel Margin="5">
<Image Source="/ProjectEye;component/Resources/sunglasses.ico" Height="30"/>
<Image Source="/ProjectEye;component/Resources/sunglasses.ico" Height="30" HorizontalAlignment="Left"/>
<TextBlock TextWrapping="Wrap" Text="Project Eye"
Margin="0,5,0,0"/>
<TextBlock TextWrapping="Wrap" Text="版本号:1.0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectEye/Views/TipWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
HorizontalAlignment="Center"
Margin="0,10"
TextWrapping="Wrap"
Foreground="#45435b">您已持续用眼20分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!</TextBlock>
Foreground="#45435b">您已持续用眼<Run Text="{Binding WarnTime}"/>分钟,休息一会吧!请将注意力集中在至少6米远的地方20秒!</TextBlock>
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
Expand Down

0 comments on commit d030b0a

Please sign in to comment.