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

differentiate between break and pause. Add cycle count to notifyIcon

parent 78b052cb
No related branches found
No related tags found
1 merge request!32differentiate between break and pause
...@@ -11,7 +11,8 @@ namespace InnoLabProjektDektopApp ...@@ -11,7 +11,8 @@ namespace InnoLabProjektDektopApp
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private readonly NotifyIconManager _notifyIcon = new(); private readonly NotifyIconManager _notifyIconManager = new();
private static ProcessMonitor _processMonitor = new(); private static ProcessMonitor _processMonitor = new();
internal static ProcessMonitor GetProcessMonitor() internal static ProcessMonitor GetProcessMonitor()
...@@ -27,13 +28,13 @@ namespace InnoLabProjektDektopApp ...@@ -27,13 +28,13 @@ namespace InnoLabProjektDektopApp
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
_notifyIcon.Initialize(); _notifyIconManager.Initialize();
base.OnStartup(e); base.OnStartup(e);
} }
protected override void OnExit(ExitEventArgs e) protected override void OnExit(ExitEventArgs e)
{ {
_notifyIcon.Dispose(); _notifyIconManager.Dispose();
base.OnExit(e); base.OnExit(e);
} }
......
...@@ -31,17 +31,20 @@ namespace InnoLabProjektDektopApp.Services ...@@ -31,17 +31,20 @@ namespace InnoLabProjektDektopApp.Services
private readonly List<BreakInfo> breakInfoList = []; private readonly List<BreakInfo> breakInfoList = [];
public bool IsBreak { get; private set;} public bool IsBreak { get; private set;}
public bool IsPause { get; private set; }
private DateTime breakStartTime; private DateTime breakStartTime;
public int currentCycle = 1;
public ProcessMonitor() public ProcessMonitor()
{ {
IsBreak = false; IsBreak = false;
IsPause = false;
blockedProcesses = LoadBlockedProcesses(); blockedProcesses = LoadBlockedProcesses();
} }
public async void StartMonitoring() public async void StartMonitoring()
{ {
if (isMonitoring || IsBreak) if (isMonitoring || IsBreak || IsPause)
{ {
return; return;
} }
...@@ -55,6 +58,8 @@ namespace InnoLabProjektDektopApp.Services ...@@ -55,6 +58,8 @@ namespace InnoLabProjektDektopApp.Services
// check if any distracting processes are already running // check if any distracting processes are already running
var processes = GetRunningProcessList(); var processes = GetRunningProcessList();
await Task.Run(() =>
{
foreach (var process in processes) foreach (var process in processes)
{ {
if (IsProcessOnBlockedList(process.Key)) if (IsProcessOnBlockedList(process.Key))
...@@ -75,6 +80,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -75,6 +80,7 @@ namespace InnoLabProjektDektopApp.Services
} }
} }
} }
});
await Task.Run(() => await Task.Run(() =>
{ {
...@@ -122,6 +128,29 @@ namespace InnoLabProjektDektopApp.Services ...@@ -122,6 +128,29 @@ namespace InnoLabProjektDektopApp.Services
breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now)); breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now));
IsBreak = false; IsBreak = false;
StartMonitoring(); StartMonitoring();
currentCycle++;
}
public void StartPause()
{
if (IsPause)
{
return;
}
IsPause = true;
breakStartTime = DateTime.Now;
StopMonitoring();
}
public void EndPause()
{
if (!IsPause)
{
return;
}
breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now));
IsPause = false;
StartMonitoring();
} }
public void FinishSession() public void FinishSession()
...@@ -142,7 +171,7 @@ namespace InnoLabProjektDektopApp.Services ...@@ -142,7 +171,7 @@ namespace InnoLabProjektDektopApp.Services
processInfoList.Clear(); processInfoList.Clear();
breakInfoList.Clear(); breakInfoList.Clear();
processStartTimes.Clear(); processStartTimes.Clear();
currentCycle = 1;
} }
public int CalculateCurrentDistractionStage(DateTime endTime) public int CalculateCurrentDistractionStage(DateTime endTime)
......
...@@ -60,30 +60,44 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -60,30 +60,44 @@ namespace InnoLabProjektDektopApp.Utils
_notifyIcon.ContextMenuStrip.Items.Clear(); _notifyIcon.ContextMenuStrip.Items.Clear();
LoadSettings(); LoadSettings();
if (_processMonitor.isMonitoring || _processMonitor.IsBreak) if (_processMonitor.isMonitoring || _processMonitor.IsBreak || _processMonitor.IsPause)
{ {
_notifyIcon.ContextMenuStrip.Items.Add(new Forms.ToolStripLabel($"Focussession 1/{_settings.cycles}", null, false)); _notifyIcon.ContextMenuStrip.Items.Add(new Forms.ToolStripLabel($"Focussession {_processMonitor.currentCycle}/{_settings.cycles}", null, false));
// Add the countdown label (initialize it if it doesn't exist) // Add the countdown label (initialize it if it doesn't exist)
_countdownLabel = new Forms.ToolStripLabel($"Countdown: {_countdownTime:mm\\:ss}"); string label_text = (_processMonitor.IsBreak ? "Break: " : "Focus: ") + $"{_countdownTime:mm\\:ss}" + (_processMonitor.IsPause ? " (Paused)" : "");
_countdownLabel = new Forms.ToolStripLabel(label_text);
_notifyIcon.ContextMenuStrip.Items.Add(_countdownLabel); _notifyIcon.ContextMenuStrip.Items.Add(_countdownLabel);
if (!_processMonitor.IsBreak) if (!_processMonitor.IsBreak && !_processMonitor.IsPause)
{ {
_notifyIcon.ContextMenuStrip.Items.Add("Take a Break", Drawing.Image.FromFile("Assets/pause.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("Pause", Drawing.Image.FromFile("Assets/pause.png"), (sender, args) =>
{ {
_countdownTimer.Stop(); _countdownTimer.Stop();
_processMonitor.StartBreak(); _processMonitor.StartPause();
RerenderContextMenu(true); RerenderContextMenu(true);
}); });
} }
if (_processMonitor.IsPause)
{
_notifyIcon.ContextMenuStrip.Items.Add("Continue", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) =>
{
_countdownTimer.Start();
_processMonitor.EndPause();
RerenderContextMenu(true);
});
}
if (_processMonitor.IsBreak) if (_processMonitor.IsBreak)
{ {
_notifyIcon.ContextMenuStrip.Items.Add("Skip Break", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("Skip Break", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) =>
{ {
_countdownTimer.Start();
_processMonitor.EndBreak(); _processMonitor.EndBreak();
_countdownTimer.Stop();
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
RerenderContextMenu(true); RerenderContextMenu(true);
}); });
} }
_notifyIcon.ContextMenuStrip.Items.Add("End Session", Drawing.Image.FromFile("Assets/end.png"), (sender, args) => _notifyIcon.ContextMenuStrip.Items.Add("End Session", Drawing.Image.FromFile("Assets/end.png"), (sender, args) =>
{ {
_processMonitor.StopMonitoring(); _processMonitor.StopMonitoring();
...@@ -162,7 +176,18 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -162,7 +176,18 @@ namespace InnoLabProjektDektopApp.Utils
} }
else else
{ {
_countdownTimer.Stop(); if (_processMonitor.IsBreak)
{
_processMonitor.EndBreak();
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
RerenderContextMenu();
}
else
{
_processMonitor.StartBreak();
StartCountdown(TimeSpan.FromMinutes(_settings.breakPeriod));
RerenderContextMenu();
}
} }
} }
...@@ -170,7 +195,7 @@ namespace InnoLabProjektDektopApp.Utils ...@@ -170,7 +195,7 @@ namespace InnoLabProjektDektopApp.Utils
{ {
if (_countdownLabel != null) if (_countdownLabel != null)
{ {
_countdownLabel.Text = $"Countdown: {_countdownTime:mm\\:ss}"; _countdownLabel.Text = (_processMonitor.IsBreak ? "Break: " : "Focus: ") + $"{_countdownTime:mm\\:ss}" + (_processMonitor.IsPause ? " (Paused)" : "");
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment