Skip to content

Commit

Permalink
Play sound notification when timer finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccidral committed May 19, 2017
1 parent 78cc19f commit d1d4e8b
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tomighty.Core/IMutableUserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IMutableUserPreferences : IUserPreferences
{
void SetIntervalDuration(IntervalType intervalType, Duration duration);
new bool ShowToastNotifications { get; set; }
new bool PlaySoundNotifications { get; set; }
new int MaxPomodoroCount { get; set; }
}
}
1 change: 1 addition & 0 deletions Tomighty.Core/IUserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IUserPreferences
Duration GetIntervalDuration(IntervalType intervalType);
int MaxPomodoroCount { get; }
bool ShowToastNotifications { get; }
bool PlaySoundNotifications { get; }

void Update(Action<IMutableUserPreferences> action);
}
Expand Down
25 changes: 25 additions & 0 deletions Tomighty.Windows/Notifications/SoundNotificationPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Media;
using Tomighty.Events;

namespace Tomighty.Windows.Notifications
{
public class SoundNotificationPlayer
{
private readonly IUserPreferences userPreferences;
private readonly SoundPlayer intervalCompletedNotification = new SoundPlayer(Properties.Resources.audio_deskbell);

public SoundNotificationPlayer(IUserPreferences userPreferences, IEventHub eventHub)
{
this.userPreferences = userPreferences;
eventHub.Subscribe<TimerStopped>(OnTimerStopped);
}

private void OnTimerStopped(TimerStopped @event)
{
if (@event.IsIntervalCompleted && userPreferences.PlaySoundNotifications)
{
intervalCompletedNotification.Play();
}
}
}
}
10 changes: 9 additions & 1 deletion Tomighty.Windows/Preferences/UserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ private static Values GetDefaultValues()
ShortBreakDuration = Duration.InMinutes(5).Seconds,
LongBreakDuration = Duration.InMinutes(15).Seconds,
MaxPomodoroCount = 4,
ShowToastNotifications = true
ShowToastNotifications = true,
PlaySoundNotifications = true
};
}

Expand Down Expand Up @@ -80,6 +81,12 @@ public bool ShowToastNotifications
set { values.ShowToastNotifications = value; }
}

public bool PlaySoundNotifications
{
get { return values.PlaySoundNotifications; }
set { values.PlaySoundNotifications = value; }
}

public void Update(Action<IMutableUserPreferences> action)
{
action(this);
Expand All @@ -94,6 +101,7 @@ private class Values
public int LongBreakDuration { get; set; }
public int MaxPomodoroCount { get; set; }
public bool ShowToastNotifications { get; set; }
public bool PlaySoundNotifications { get; set; }
}
}
}
13 changes: 13 additions & 0 deletions Tomighty.Windows/Preferences/UserPreferencesForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Tomighty.Windows/Preferences/UserPreferencesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public UserPreferencesForm(IUserPreferences userPreferences)
longBreakDurationTextBox.Value = userPreferences.GetIntervalDuration(IntervalType.LongBreak).Minutes;
maxPomodoroCountTextBox.Value = userPreferences.MaxPomodoroCount;
toastNotification.Checked = userPreferences.ShowToastNotifications;
soundNotifications.Checked = userPreferences.PlaySoundNotifications;
}

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

Close();
Expand Down
9 changes: 9 additions & 0 deletions Tomighty.Windows/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tomighty.Windows/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@
<data name="toast_template_interval_completed" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Toasts\interval-completed.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="audio_deskbell" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Audio\deskbell.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file added Tomighty.Windows/Resources/Audio/deskbell.wav
Binary file not shown.
2 changes: 2 additions & 0 deletions Tomighty.Windows/Tomighty.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</Compile>
<Compile Include="About\AboutWindowPresenter.cs" />
<Compile Include="IntervalTypeExtensions.cs" />
<Compile Include="Notifications\SoundNotificationPlayer.cs" />
<Compile Include="Preferences\UserPreferencesPresenter.cs" />
<Compile Include="Tray\ITrayMenu.cs" />
<Compile Include="Tray\ITrayMenuMutator.cs" />
Expand Down Expand Up @@ -153,6 +154,7 @@
<None Include="Resources\icon_tomato_green.ico" />
<None Include="Resources\icon_tomato_red.ico" />
<None Include="Resources\icon_tomato_white.ico" />
<Content Include="Resources\Audio\deskbell.wav" />
<Content Include="Resources\image_clock.tiff" />
<Content Include="Resources\image_tomato_black.tiff" />
<Content Include="Resources\image_tomato_blue.tiff" />
Expand Down
1 change: 1 addition & 0 deletions Tomighty.Windows/TomightyApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public TomightyApplication()
new TrayIconController(trayIcon, timerWindowPresenter, eventHub);
new TrayMenuController(trayMenu, this, pomodoroEngine, eventHub);
new NotificationsPresenter(pomodoroEngine, userPreferences, eventHub);
new SoundNotificationPlayer(userPreferences, eventHub);

var aboutWindowPresenter = new AboutWindowPresenter();
var userPreferencesPresenter = new UserPreferencesPresenter(userPreferences);
Expand Down

0 comments on commit d1d4e8b

Please sign in to comment.