Skip to content

Commit

Permalink
优化番茄时钟的交互体验
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Aug 3, 2021
1 parent a98b289 commit 0587fb9
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/Local/ProjectEye/Core/Models/Options/TomatoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class TomatoModel
/// 工作结束提示音路径
/// </summary>
public string WorkEndSoundPath { get; set; } = "";

/// <summary>
/// 是否开启交互模式
/// </summary>
public bool IsEnabledInteractiveModel { get; set; } = false;
}
}
77 changes: 69 additions & 8 deletions src/Local/ProjectEye/Core/Service/TomatoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class TomatoService : IService

private DispatcherTimer workTimer;
private DispatcherTimer restTimer;
private DispatcherTimer icorefreshTimer;

private Models.Statistic.TomatoModel tomatoDataToday;
private int workCount = 0;
private int restartCount = -1;
private int refreshTick = 1;

private Project1UIToast worktoast;
private Stopwatch timerWatcher;
Expand Down Expand Up @@ -67,6 +69,9 @@ public void Init()
restTimer.Tick += RestTimer_Tick; ;
restTimer.Interval = new TimeSpan(0, config.options.Tomato.ShortRestMinutes, 0);

icorefreshTimer = new DispatcherTimer();
icorefreshTimer.Tick += icorefreshTimer_Tick; ;

/****调试模式代码****/
#if DEBUG
workTimer.Interval = new TimeSpan(0, 0, 25);
Expand All @@ -80,6 +85,8 @@ public void Init()





#endregion

#region event
Expand Down Expand Up @@ -153,7 +160,21 @@ private void WorkTimer_Tick(object sender, EventArgs e)
//进入休息时间
restTimer.Start();
timerWatcher.Restart();
Dialog($"{Application.Current.Resources["Lang_TomatoTimer"]}", tip, subtitle);

// 启动图标更新
tray.UpdateIcon("green-tomato-1");
icorefreshTimer.Interval = new TimeSpan(0, 0, (int)restTimer.Interval.TotalMinutes * 60 / 10);
icorefreshTimer.Start();


if (config.options.Tomato.IsEnabledInteractiveModel)
{
Dialog($"{Application.Current.Resources["Lang_TomatoTimer"]}", tip, subtitle);
}
else
{
tray.BalloonTipIcon($"Tomato:{workCount}/4", tip);
}
}
private void RestTimer_Tick(object sender, EventArgs e)
{
Expand All @@ -179,14 +200,51 @@ private void Tray_MouseMoveTrayIcon(object sender, System.Windows.Forms.MouseEve
}
}

private void icorefreshTimer_Tick(object sender, EventArgs e)
{
refreshTick++;
if (refreshTick >= 10)
{
icorefreshTimer.Stop();
refreshTick = 1;
}
else
{
// 更新图标
tray.UpdateIcon((restTimer.IsEnabled ? "green-tomato-" + refreshTick : "red-tomato-" + (10 - refreshTick)));
}

}

#endregion

#region function

#region 启动番茄时钟
public void Start()
{
WorkDialog();
workTimer.Interval = new TimeSpan(0, config.options.Tomato.WorkMinutes, 0);
restTimer.Interval = new TimeSpan(0, config.options.Tomato.ShortRestMinutes, 0);

//播放提示音
if (config.options.Tomato.IsWorkStartSound)
{
sound.Play(Enums.SoundType.TomatoWorkStartSound);
}

// 交互模式
if (config.options.Tomato.IsEnabledInteractiveModel)
{
WorkDialog();
}
else
{
workTimer.Start();
timerWatcher.Restart();
tray.UpdateIcon("red-tomato-10");
icorefreshTimer.Interval = new TimeSpan(0, 0, config.options.Tomato.WorkMinutes * 60 / 10);
icorefreshTimer.Start();
}
}
#endregion

Expand All @@ -195,8 +253,10 @@ public void Close()
{
workCount = 0;
restartCount++;
refreshTick = 1;
workTimer.Stop();
restTimer.Stop();
icorefreshTimer.Stop();
config.SaveOldOptions();
config.options.General.IsTomatoMode = false;
config.OnChanged();
Expand Down Expand Up @@ -227,7 +287,7 @@ public void RestDone()
}

//继续
WorkDialog();
Start();
}
}
#endregion
Expand Down Expand Up @@ -366,11 +426,7 @@ public void SaveData()
//工作提醒
private void WorkDialog()
{
//播放提示音
if (config.options.Tomato.IsWorkStartSound)
{
sound.Play(Enums.SoundType.TomatoWorkStartSound);
}

//通知弹窗
worktoast = new Project1UIToast();
worktoast.SetIcon("pack://application:,,,/ProjectEye;component/Resources/tomato.ico");
Expand All @@ -395,6 +451,9 @@ private void Worktoast_OnButtonClick(string name, Project1UIToast sender)
{
workTimer.Start();
timerWatcher.Restart();
tray.UpdateIcon("red-tomato-10");
icorefreshTimer.Interval = new TimeSpan(0, 0, config.options.Tomato.WorkMinutes * 60 / 10);
icorefreshTimer.Start();
}
else
{
Expand Down Expand Up @@ -430,6 +489,8 @@ private void Toast_OnButtonClick(string name, Project1UIToast sender)
}

#endregion


#endregion
}
}
20 changes: 13 additions & 7 deletions src/Local/ProjectEye/Core/Service/TrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,8 @@ public void Init()
notifyIcon.MouseMove += NotifyIcon_MouseMove;
notifyIcon.MouseClick += notifyIcon_MouseClick;
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
//在win10中将显示通知
//notifyIcon.BalloonTipTitle = "test";
//notifyIcon.BalloonTipText = "content";
//notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
//notifyIcon.ShowBalloonTip(3000);
noresetTimer = new DispatcherTimer();

noresetTimer = new DispatcherTimer();

}
#endregion
Expand Down Expand Up @@ -361,7 +356,7 @@ public void Remove()
{
notifyIcon.Visible = false;
}
private void UpdateIcon(string name = "", bool save = true)
public void UpdateIcon(string name = "", bool save = true)
{
name = name == "" ? lastIcon : name;
if (name == "")
Expand Down Expand Up @@ -442,6 +437,17 @@ public void SetText(string text)
{
notifyIcon.Text = text.Length > 63 ? text.Substring(0, 63) : text;
}

/// <summary>
/// 显示气泡或通知(在windows7上是任务栏气泡,win10上是系统通知)
/// </summary>
public void BalloonTipIcon(string title, string content, System.Windows.Forms.ToolTipIcon icon = System.Windows.Forms.ToolTipIcon.None)
{
notifyIcon.BalloonTipTitle = title;
notifyIcon.BalloonTipText = content;
notifyIcon.BalloonTipIcon = icon;
notifyIcon.ShowBalloonTip(5000);
}
#endregion
}
}
24 changes: 24 additions & 0 deletions src/Local/ProjectEye/ProjectEye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,29 @@
<ItemGroup>
<Resource Include="Resources\conference_presentation__monochromatic.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\red-tomato-1.ico" />
<Resource Include="Resources\red-tomato-10.ico" />
<Resource Include="Resources\red-tomato-2.ico" />
<Resource Include="Resources\red-tomato-3.ico" />
<Resource Include="Resources\red-tomato-4.ico" />
<Resource Include="Resources\red-tomato-5.ico" />
<Resource Include="Resources\red-tomato-6.ico" />
<Resource Include="Resources\red-tomato-7.ico" />
<Resource Include="Resources\red-tomato-8.ico" />
<Resource Include="Resources\red-tomato-9.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\green-tomato-1.ico" />
<Resource Include="Resources\green-tomato-10.ico" />
<Resource Include="Resources\green-tomato-2.ico" />
<Resource Include="Resources\green-tomato-3.ico" />
<Resource Include="Resources\green-tomato-4.ico" />
<Resource Include="Resources\green-tomato-5.ico" />
<Resource Include="Resources\green-tomato-6.ico" />
<Resource Include="Resources\green-tomato-7.ico" />
<Resource Include="Resources\green-tomato-8.ico" />
<Resource Include="Resources\green-tomato-9.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions src/Local/ProjectEye/Resources/Language/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,6 @@
<sys:String x:Key="Lang_TomatoWorkfinishTip3">Ready go,focus on your job,i will remind you at the end,are you ready?</sys:String>
<sys:String x:Key="Lang_Remainingtime">Remaining time</sys:String>
<sys:String x:Key="Lang_Tomatodescription2">The Pomodoro Technique is a time management method developed by Francesco Cirillo in the late 1980s.The technique uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. Each interval is known as a pomodoro, from the Italian word for 'tomato', after the tomato-shaped kitchen timer that Cirillo used as a university student.</sys:String>
<sys:String x:Key="Lang_Tomato_IsEnabledInteractiveModel">Enabled interactive model</sys:String>

</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Local/ProjectEye/Resources/Language/zh.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<sys:String x:Key="Lang_TomatoWorkfinishTip3">准备开始,请保持专注工作,我会在结束时提醒你,准备好了吗?</sys:String>
<sys:String x:Key="Lang_Remainingtime">剩余时间</sys:String>
<sys:String x:Key="Lang_Tomatodescription2">番茄工作法(Pomodoro Technique)是一种时间管理法,在1980年代由Francesco Cirillo创立。该方法使用一个定时器来分割出一个一般为25分钟的工作时间和5分钟的休息时间,而那些时间段被称为pomodoros,为意大利语单词 pomodoro(中文:番茄)之复数。</sys:String>
<sys:String x:Key="Lang_Tomato_IsEnabledInteractiveModel">启用交互模式</sys:String>


</ResourceDictionary>
Binary file added src/Local/ProjectEye/Resources/green-tomato-1.ico
Binary file not shown.
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-2.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-3.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-4.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-5.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-6.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-7.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-8.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/green-tomato-9.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-1.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-10.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-2.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-3.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-4.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-5.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-6.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-7.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-8.ico
Binary file not shown.
Binary file added src/Local/ProjectEye/Resources/red-tomato-9.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Local/ProjectEye/Views/OptionsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
</TextBlock>
</Grid>
<!--是否启用交互模式-->
<CheckBox Content="{DynamicResource Lang_Soundforworksstart}" IsChecked="{Binding Model.Data.Tomato.IsWorkStartSound}" Margin="0,10,0,0" Cursor="Hand"/>
<CheckBox Content="{DynamicResource Lang_Tomato_IsEnabledInteractiveModel}" IsChecked="{Binding Model.Data.Tomato.IsEnabledInteractiveModel}" Margin="0,10,0,0" Cursor="Hand"/>

<!--提示音-->
<CheckBox Content="{DynamicResource Lang_Soundforworksstart}" IsChecked="{Binding Model.Data.Tomato.IsWorkStartSound}" Margin="0,10,0,0" Cursor="Hand"/>
Expand Down

0 comments on commit 0587fb9

Please sign in to comment.