Skip to content

Commit

Permalink
Add sound notifications for work/rest transitions and make design enh…
Browse files Browse the repository at this point in the history
…ancements.
  • Loading branch information
dotpep committed Dec 21, 2023
1 parent 9bce378 commit 18320ca
Show file tree
Hide file tree
Showing 36 changed files with 4,639 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.suo
*.user
*.suo
*.user
*.vscode/
.vs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PomodoroTimerApp/.vs/PomodoroTimerApp/v17/.futdcache.v2
Binary file not shown.
Binary file modified PomodoroTimerApp/.vs/PomodoroTimerApp/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 21 additions & 10 deletions PomodoroTimerApp/Form1.Designer.cs

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

101 changes: 75 additions & 26 deletions PomodoroTimerApp/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.IO;
using System.Media;
using System.Windows.Forms;

namespace PomodoroTimerApp
{
public partial class Form1 : Form
public partial class PomoInitD : Form
{
private int workMinutes = 25;
private int restMinutes = 5;
private const int WorkMinutes = 25;
private const int RestMinutes = 5;

private int currentMinutes;
private int currentSeconds;
Expand All @@ -16,45 +18,99 @@ public partial class Form1 : Form
private bool isWorking = true;
private bool isPaused = false;

public Form1()
private readonly SoundPlayer notifySoundPlayer;

public PomoInitD()
{
InitializeComponent();
timerPomodoro.Interval = 1000; // 1-second interval
timerPomodoro.Interval = 1000; // 1-second
timerPomodoro.Tick += TimerPomodoro_Tick;

// sound path: PomodoroTimerApp\bin\Debug\net6.0-windows\sound.wav
string soundFileName = "sound.wav";
notifySoundPlayer = InitializeSoundPlayer(soundFileName);

UpdateTimerDisplay();
}

private void ShowErrorMessage(string message, string filePath)
{
MessageBox.Show($"{message}\n\nExpected path: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private SoundPlayer InitializeSoundPlayer(string soundFileName)
{
try
{
if (File.Exists(soundFileName))
{
return new SoundPlayer(soundFileName);
}

ShowErrorMessage("Sound file not found.", soundFileName);
return null;
}
catch (Exception ex)
{
ShowErrorMessage($"Error initializing sound player: {ex.Message}", soundFileName);
return null;
}
}


private void TimerPomodoro_Tick(object sender, EventArgs e)
{
if (currentMinutes == 0 && currentSeconds == 0)
{
isWorking = !isWorking;
iterationCount++;
currentMinutes = isWorking ? workMinutes : restMinutes;
currentMinutes = isWorking ? WorkMinutes : RestMinutes;
currentSeconds = 0;

PlayNotificationSound();
}
else
{
if (!isPaused)
{
if (currentSeconds == 0)
{
currentMinutes--;
currentSeconds = 59;
}
else
{
currentSeconds--;
}
UpdateTimeRemaining();
}
}

UpdateTimerDisplay();
}

private void UpdateTimeRemaining()
{
if (currentSeconds == 0)
{
currentMinutes--;
currentSeconds = 59;
}
else
{
currentSeconds--;
}
}

private void PlayNotificationSound()
{
if (notifySoundPlayer != null)
{
try
{
notifySoundPlayer.Play();
}
catch (Exception ex)
{
MessageBox.Show($"Error playing sound: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

private void StartNewSession()
{
currentMinutes = workMinutes;
currentMinutes = WorkMinutes;
currentSeconds = 0;
iterationCount = 0;
isWorking = true;
Expand All @@ -66,23 +122,15 @@ private void SkipToNextPomodoro()
{
iterationCount++;
isWorking = !isWorking;
currentMinutes = isWorking ? workMinutes : restMinutes;
currentMinutes = isWorking ? WorkMinutes : RestMinutes;
currentSeconds = 0;
}

private void UpdateTimerDisplay()
{
labelTimer.Text = $"{currentMinutes:D2}:{currentSeconds:D2}";

if (isWorking)
{
textBoxStatus.Text = "Time to Focus!";
}
else
{
textBoxStatus.Text = "Time for a Break!";
}

textBoxStatus.Text = isWorking ? "Time to Focus!" : "Time for a Break!";
textBoxIterations.Text = $"Iteration: {iterationCount}";
}

Expand All @@ -99,6 +147,7 @@ private void btnStartPause_Click(object sender, EventArgs e)
private void btnSkip_Click(object sender, EventArgs e)
{
SkipToNextPomodoro();
PlayNotificationSound();
UpdateTimerDisplay();
}

Expand Down
Loading

0 comments on commit 18320ca

Please sign in to comment.