Skip to content
Snippets Groups Projects
Commit d62de6de authored by Philipp Müller's avatar Philipp Müller
Browse files

Sync tray icon with session screen (timers are not perfectly synced but close enuff)

parent b69b1e0a
No related branches found
No related tags found
1 merge request!50Fix process monitor integration and tray icon sync
...@@ -40,6 +40,11 @@ namespace InnoLabProjektDektopApp.Services ...@@ -40,6 +40,11 @@ namespace InnoLabProjektDektopApp.Services
private DateTime breakStartTime; private DateTime breakStartTime;
public int currentCycle = 1; public int currentCycle = 1;
public event EventHandler MonitorCycleStarted;
public event EventHandler MonitorPaused;
public event EventHandler MonitorResumed;
public event EventHandler MonitorBreakStarted;
public ProcessMonitor() public ProcessMonitor()
{ {
IsBreak = false; IsBreak = false;
...@@ -55,6 +60,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -55,6 +60,7 @@ namespace InnoLabProjektDektopApp.Services
} }
if (cycleStartTimeList.Count == 0) if (cycleStartTimeList.Count == 0)
{ {
MonitorCycleStarted?.Invoke(this, EventArgs.Empty);
cycleStartTimeList[1] = DateTime.Now; cycleStartTimeList[1] = DateTime.Now;
} }
Debug.WriteLine("Started Process Monitoring"); Debug.WriteLine("Started Process Monitoring");
...@@ -116,6 +122,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -116,6 +122,7 @@ namespace InnoLabProjektDektopApp.Services
IsBreak = true; IsBreak = true;
breakStartTime = DateTime.Now; breakStartTime = DateTime.Now;
StopMonitoring(); StopMonitoring();
MonitorBreakStarted?.Invoke(this, EventArgs.Empty);
} }
public void EndBreak() public void EndBreak()
...@@ -129,6 +136,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -129,6 +136,7 @@ namespace InnoLabProjektDektopApp.Services
StartMonitoring(); StartMonitoring();
currentCycle++; currentCycle++;
cycleStartTimeList[currentCycle] = DateTime.Now; cycleStartTimeList[currentCycle] = DateTime.Now;
MonitorCycleStarted?.Invoke(this, EventArgs.Empty);
} }
public void StartPause() public void StartPause()
...@@ -140,6 +148,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -140,6 +148,7 @@ namespace InnoLabProjektDektopApp.Services
IsPause = true; IsPause = true;
breakStartTime = DateTime.Now; breakStartTime = DateTime.Now;
StopMonitoring(); StopMonitoring();
MonitorPaused?.Invoke(this, EventArgs.Empty);
} }
public void EndPause() public void EndPause()
...@@ -151,6 +160,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -151,6 +160,7 @@ namespace InnoLabProjektDektopApp.Services
breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now, IsBreak, currentCycle)); breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now, IsBreak, currentCycle));
IsPause = false; IsPause = false;
StartMonitoring(); StartMonitoring();
MonitorResumed?.Invoke(this, EventArgs.Empty);
} }
public string FinishSession() public string FinishSession()
......
...@@ -45,6 +45,12 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -45,6 +45,12 @@ namespace InnoLabProjektDektopApp.Utils
_countdownTimer.Interval = TimeSpan.FromSeconds(1); _countdownTimer.Interval = TimeSpan.FromSeconds(1);
_countdownTimer.Tick += CountdownTimer_Tick; _countdownTimer.Tick += CountdownTimer_Tick;
// Subscribe to the events of the process monitor
_processMonitor.MonitorCycleStarted += HandleMonitorCycleStarted;
_processMonitor.MonitorPaused += HandleMonitorPaused;
_processMonitor.MonitorResumed += HandleMonitorResumed;
_processMonitor.MonitorBreakStarted += HandleMonitorBreakStarted;
RerenderContextMenu(); RerenderContextMenu();
} }
...@@ -71,7 +77,6 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -71,7 +77,6 @@ namespace InnoLabProjektDektopApp.Utils
{ {
_notifyIcon.ContextMenuStrip.Items.Add("Pause", Drawing.Image.FromFile("Assets/pause.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("Pause", Drawing.Image.FromFile("Assets/pause.png"), (sender, args) =>
{ {
_countdownTimer.Stop();
_processMonitor.StartPause(); _processMonitor.StartPause();
RerenderContextMenu(true); RerenderContextMenu(true);
}); });
...@@ -80,7 +85,6 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -80,7 +85,6 @@ namespace InnoLabProjektDektopApp.Utils
{ {
_notifyIcon.ContextMenuStrip.Items.Add("Continue", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("Continue", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) =>
{ {
_countdownTimer.Start();
_processMonitor.EndPause(); _processMonitor.EndPause();
RerenderContextMenu(true); RerenderContextMenu(true);
}); });
...@@ -114,8 +118,6 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -114,8 +118,6 @@ namespace InnoLabProjektDektopApp.Utils
$"Focus Duration: {_settings.focusPeriod} min | Break Duration: {_settings.breakPeriod} min | Cycles: {_settings.cycles}", null, false)); $"Focus Duration: {_settings.focusPeriod} min | Break Duration: {_settings.breakPeriod} min | Cycles: {_settings.cycles}", null, false));
_notifyIcon.ContextMenuStrip.Items.Add("Start Session", Drawing.Image.FromFile("Assets/start.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("Start Session", Drawing.Image.FromFile("Assets/start.png"), (sender, args) =>
{ {
_processMonitor.StartMonitoring();
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
RerenderContextMenu(true); RerenderContextMenu(true);
Window mainWindow = Application.Current.MainWindow; Window mainWindow = Application.Current.MainWindow;
NavigationService mainNavigation = ((System.Windows.Navigation.NavigationWindow)mainWindow).NavigationService; NavigationService mainNavigation = ((System.Windows.Navigation.NavigationWindow)mainWindow).NavigationService;
...@@ -139,6 +141,26 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -139,6 +141,26 @@ namespace InnoLabProjektDektopApp.Utils
} }
} }
private void HandleMonitorCycleStarted(object sender, EventArgs e)
{
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
}
private void HandleMonitorPaused(object sender, EventArgs e)
{
_countdownTimer.Stop();
}
private void HandleMonitorResumed(object sender, EventArgs e)
{
_countdownTimer.Start();
}
private void HandleMonitorBreakStarted(object sender, EventArgs e)
{
StartCountdown(TimeSpan.FromMinutes(_settings.breakPeriod));
}
private void NotifyIcon_MouseClick(object sender, Forms.MouseEventArgs e) private void NotifyIcon_MouseClick(object sender, Forms.MouseEventArgs e)
{ {
if (e.Button == Forms.MouseButtons.Left) if (e.Button == Forms.MouseButtons.Left)
...@@ -183,7 +205,6 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -183,7 +205,6 @@ namespace InnoLabProjektDektopApp.Utils
if (_processMonitor.IsBreak) if (_processMonitor.IsBreak)
{ {
_processMonitor.EndBreak(); _processMonitor.EndBreak();
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
RerenderContextMenu(); RerenderContextMenu();
} }
else else
...@@ -191,7 +212,6 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -191,7 +212,6 @@ namespace InnoLabProjektDektopApp.Utils
if (_processMonitor.currentCycle < _settings.cycles) if (_processMonitor.currentCycle < _settings.cycles)
{ {
_processMonitor.StartBreak(); _processMonitor.StartBreak();
StartCountdown(TimeSpan.FromMinutes(_settings.breakPeriod));
RerenderContextMenu(); RerenderContextMenu();
} }
else else
...@@ -234,6 +254,5 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -234,6 +254,5 @@ namespace InnoLabProjektDektopApp.Utils
} }
} }
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment