From 55afa8c2a4cc0454e79af0759e4f1f6480b61182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Troja=C5=84ski?= <80624809+enviGit@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:28:42 +0100 Subject: [PATCH] Start function for resuming timer fixed --- PomodoroTimer/MainWindow.xaml | 2 +- PomodoroTimer/MainWindow.xaml.cs | 2 ++ PomodoroTimer/Models/Timer.cs | 30 +++++++++++++++++++--------- PomodoroTimer/PomodoroTimer.csproj | 7 +++---- PomodoroTimer/Resources/appIcon.ico | Bin 0 -> 16958 bytes 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 PomodoroTimer/Resources/appIcon.ico diff --git a/PomodoroTimer/MainWindow.xaml b/PomodoroTimer/MainWindow.xaml index 6913b88..450f023 100644 --- a/PomodoroTimer/MainWindow.xaml +++ b/PomodoroTimer/MainWindow.xaml @@ -10,7 +10,7 @@ - + diff --git a/PomodoroTimer/MainWindow.xaml.cs b/PomodoroTimer/MainWindow.xaml.cs index d030c24..96914e0 100644 --- a/PomodoroTimer/MainWindow.xaml.cs +++ b/PomodoroTimer/MainWindow.xaml.cs @@ -2,6 +2,8 @@ using System; using System.Windows; +#nullable disable + namespace PomodoroTimer { public partial class MainWindow : Window diff --git a/PomodoroTimer/Models/Timer.cs b/PomodoroTimer/Models/Timer.cs index 3744689..fcdc276 100644 --- a/PomodoroTimer/Models/Timer.cs +++ b/PomodoroTimer/Models/Timer.cs @@ -57,17 +57,28 @@ public void Start() return; IsRunning = true; - IsPaused = false; - if (_timer == null) + if (_timer != null) { - _timer = new System.Timers.Timer(1000); - _timer.Elapsed += OnTimerElapsed; + _timer.Stop(); + _timer.Dispose(); } - if (IsPaused) + _timer = new System.Timers.Timer(1000); + _timer.Elapsed += OnTimerElapsed; + + if (!IsPaused) + { + TimeRemaining = Duration; + } + else if (IsPaused) { - _timeRemaining = _remainingTimeOnPause; + if (_remainingTimeOnPause.TotalMilliseconds > 0) + TimeRemaining = _remainingTimeOnPause; + else + TimeRemaining = Duration; + + _remainingTimeOnPause = TimeSpan.Zero; } _timer.Start(); @@ -78,11 +89,12 @@ public void Pause() return; IsPaused = true; + _remainingTimeOnPause = TimeRemaining; if (_timer != null) _timer.Stop(); - _remainingTimeOnPause = TimeRemaining; + IsRunning = false; } public void Reset() { @@ -105,7 +117,7 @@ private void OnTimerElapsed(object sender, ElapsedEventArgs e) IsPaused = false; } - Tick?.Invoke(this, EventArgs.Empty); + OnTick(); } private void OnTick() { @@ -113,4 +125,4 @@ private void OnTick() Tick(this, EventArgs.Empty); } } -} +} \ No newline at end of file diff --git a/PomodoroTimer/PomodoroTimer.csproj b/PomodoroTimer/PomodoroTimer.csproj index 173d2cb..bbca90e 100644 --- a/PomodoroTimer/PomodoroTimer.csproj +++ b/PomodoroTimer/PomodoroTimer.csproj @@ -5,6 +5,7 @@ net6.0-windows enable true + Resources\appIcon.ico @@ -17,13 +18,11 @@ - + - - C:\Users\Envi\.nuget\packages\lighty.controls\1.0.3\lib\net45\Lighty.Controls.dll - + diff --git a/PomodoroTimer/Resources/appIcon.ico b/PomodoroTimer/Resources/appIcon.ico new file mode 100644 index 0000000000000000000000000000000000000000..bb76bc309d6141a9ea6f0c8a2fa83b849155979b GIT binary patch literal 16958 zcmeHMdr*^C7XMs#Wu0{&y0gx{x^_C-Z2<)zpsZj)#lkphs|Z-~CV`NU7a;+0?Z(b_ zYyWWTI7RKw)@i$H-NEU~BMPJ`^Nv6vu;H<6(uVjnVmZh3?d#4mqhHS2-<**yXG z1l$vFPry9^=S?8`jWe&tcxE$VyfP0X)6l#!wKUJnz8KG}QEZmASJtf<&&+(9XI8o; z*HgX3d5WBm%<#(o1I;V@uQA?P*J<9_FeCHIuBCZpy&vs;<`w5FriOv(o8?Vkrv49o zY0en(V6~iH+R~g%y0==vSemn$wk-FJm}TmP@vEwSgblCpnKhiM?H${B*P~s4EJa+Bd$U9;Rx$%jD;~7KI$>L zulgv<_slQs#dBsp!zVY4zC5>`u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