Skip to content

Commit d1d4e8b

Browse files
committed
Play sound notification when timer finishes
1 parent 78cc19f commit d1d4e8b

11 files changed

Lines changed: 66 additions & 1 deletion

File tree

Tomighty.Core/IMutableUserPreferences.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface IMutableUserPreferences : IUserPreferences
1111
{
1212
void SetIntervalDuration(IntervalType intervalType, Duration duration);
1313
new bool ShowToastNotifications { get; set; }
14+
new bool PlaySoundNotifications { get; set; }
1415
new int MaxPomodoroCount { get; set; }
1516
}
1617
}

Tomighty.Core/IUserPreferences.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface IUserPreferences
1414
Duration GetIntervalDuration(IntervalType intervalType);
1515
int MaxPomodoroCount { get; }
1616
bool ShowToastNotifications { get; }
17+
bool PlaySoundNotifications { get; }
1718

1819
void Update(Action<IMutableUserPreferences> action);
1920
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Media;
2+
using Tomighty.Events;
3+
4+
namespace Tomighty.Windows.Notifications
5+
{
6+
public class SoundNotificationPlayer
7+
{
8+
private readonly IUserPreferences userPreferences;
9+
private readonly SoundPlayer intervalCompletedNotification = new SoundPlayer(Properties.Resources.audio_deskbell);
10+
11+
public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub)
12+
{
13+
this.userPreferences = userPreferences;
14+
eventHub.Subscribe<TimerStopped>(OnTimerStopped);
15+
}
16+
17+
private void OnTimerStopped(TimerStopped @event)
18+
{
19+
if (@event.IsIntervalCompleted && userPreferences.PlaySoundNotifications)
20+
{
21+
intervalCompletedNotification.Play();
22+
}
23+
}
24+
}
25+
}

Tomighty.Windows/Preferences/UserPreferences.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ private static Values GetDefaultValues()
4040
ShortBreakDuration = Duration.InMinutes(5).Seconds,
4141
LongBreakDuration = Duration.InMinutes(15).Seconds,
4242
MaxPomodoroCount = 4,
43-
ShowToastNotifications = true
43+
ShowToastNotifications = true,
44+
PlaySoundNotifications = true
4445
};
4546
}
4647

@@ -80,6 +81,12 @@ public bool ShowToastNotifications
8081
set { values.ShowToastNotifications = value; }
8182
}
8283

84+
public bool PlaySoundNotifications
85+
{
86+
get { return values.PlaySoundNotifications; }
87+
set { values.PlaySoundNotifications = value; }
88+
}
89+
8390
public void Update(Action<IMutableUserPreferences> action)
8491
{
8592
action(this);
@@ -94,6 +101,7 @@ private class Values
94101
public int LongBreakDuration { get; set; }
95102
public int MaxPomodoroCount { get; set; }
96103
public bool ShowToastNotifications { get; set; }
104+
public bool PlaySoundNotifications { get; set; }
97105
}
98106
}
99107
}

Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tomighty.Windows/Preferences/UserPreferencesForm.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public UserPreferencesForm(IUserPreferences userPreferences)
2424
longBreakDurationTextBox.Value = userPreferences.GetIntervalDuration(IntervalType.LongBreak).Minutes;
2525
maxPomodoroCountTextBox.Value = userPreferences.MaxPomodoroCount;
2626
toastNotification.Checked = userPreferences.ShowToastNotifications;
27+
soundNotifications.Checked = userPreferences.PlaySoundNotifications;
2728
}
2829

2930
private void OnCancelButtonClick(object sender, System.EventArgs e)
@@ -40,6 +41,7 @@ private void OnOkButtonClick(object sender, System.EventArgs e)
4041
newPreferences.SetIntervalDuration(IntervalType.LongBreak, Duration.InMinutes((int)longBreakDurationTextBox.Value));
4142
newPreferences.MaxPomodoroCount = (int)maxPomodoroCountTextBox.Value;
4243
newPreferences.ShowToastNotifications = toastNotification.Checked;
44+
newPreferences.PlaySoundNotifications = soundNotifications.Checked;
4345
});
4446

4547
Close();

Tomighty.Windows/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tomighty.Windows/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@
172172
<data name="toast_template_interval_completed" type="System.Resources.ResXFileRef, System.Windows.Forms">
173173
<value>..\Resources\Toasts\interval-completed.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
174174
</data>
175+
<data name="audio_deskbell" type="System.Resources.ResXFileRef, System.Windows.Forms">
176+
<value>..\Resources\Audio\deskbell.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
177+
</data>
175178
</root>
54.8 KB
Binary file not shown.

Tomighty.Windows/Tomighty.Windows.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
</Compile>
8989
<Compile Include="About\AboutWindowPresenter.cs" />
9090
<Compile Include="IntervalTypeExtensions.cs" />
91+
<Compile Include="Notifications\SoundNotificationPlayer.cs" />
9192
<Compile Include="Preferences\UserPreferencesPresenter.cs" />
9293
<Compile Include="Tray\ITrayMenu.cs" />
9394
<Compile Include="Tray\ITrayMenuMutator.cs" />
@@ -153,6 +154,7 @@
153154
<None Include="Resources\icon_tomato_green.ico" />
154155
<None Include="Resources\icon_tomato_red.ico" />
155156
<None Include="Resources\icon_tomato_white.ico" />
157+
<Content Include="Resources\Audio\deskbell.wav" />
156158
<Content Include="Resources\image_clock.tiff" />
157159
<Content Include="Resources\image_tomato_black.tiff" />
158160
<Content Include="Resources\image_tomato_blue.tiff" />

0 commit comments

Comments
 (0)