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
/// </summary>
public partial class App : Application
{
private readonly NotifyIconManager _notifyIcon = new();
private readonly NotifyIconManager _notifyIconManager = new();
private static ProcessMonitor _processMonitor = new();
internal static ProcessMonitor GetProcessMonitor()
......@@ -27,13 +28,13 @@ namespace InnoLabProjektDektopApp
protected override void OnStartup(StartupEventArgs e)
{
_notifyIcon.Initialize();
_notifyIconManager.Initialize();
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
_notifyIcon.Dispose();
_notifyIconManager.Dispose();
base.OnExit(e);
}
......
......@@ -31,17 +31,20 @@ namespace InnoLabProjektDektopApp.Services
private readonly List<BreakInfo> breakInfoList = [];
public bool IsBreak { get; private set;}
public bool IsPause { get; private set; }
private DateTime breakStartTime;
public int currentCycle = 1;
public ProcessMonitor()
{
IsBreak = false;
IsPause = false;
blockedProcesses = LoadBlockedProcesses();
}
public async void StartMonitoring()
{
if (isMonitoring || IsBreak)
if (isMonitoring || IsBreak || IsPause)
{
return;
}
......@@ -55,27 +58,30 @@ namespace InnoLabProjektDektopApp.Services
// check if any distracting processes are already running
var processes = GetRunningProcessList();
foreach (var process in processes)
await Task.Run(() =>
{
if (IsProcessOnBlockedList(process.Key))
foreach (var process in processes)
{
var result = MessageBox.Show($"Are you sure you want to get distracted by {process.Key}?", "Distracting Process Detected",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.No,
MessageBoxOptions.DefaultDesktopOnly
);
if (result == MessageBoxResult.No)
if (IsProcessOnBlockedList(process.Key))
{
KillProcessesByName(process.Key);
}
else
{
TrackProcess(process.Key, DateTime.Now);
var result = MessageBox.Show($"Are you sure you want to get distracted by {process.Key}?", "Distracting Process Detected",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.No,
MessageBoxOptions.DefaultDesktopOnly
);
if (result == MessageBoxResult.No)
{
KillProcessesByName(process.Key);
}
else
{
TrackProcess(process.Key, DateTime.Now);
}
}
}
}
});
await Task.Run(() =>
{
while (isMonitoring)
......@@ -122,6 +128,29 @@ namespace InnoLabProjektDektopApp.Services
breakInfoList.Add(new BreakInfo(breakStartTime, DateTime.Now));
IsBreak = false;
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()
......@@ -142,7 +171,7 @@ namespace InnoLabProjektDektopApp.Services
processInfoList.Clear();
breakInfoList.Clear();
processStartTimes.Clear();
currentCycle = 1;
}
public int CalculateCurrentDistractionStage(DateTime endTime)
......
......@@ -60,30 +60,44 @@ namespace InnoLabProjektDektopApp.Utils
_notifyIcon.ContextMenuStrip.Items.Clear();
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)
_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);
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();
_processMonitor.StartBreak();
_processMonitor.StartPause();
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)
{
_notifyIcon.ContextMenuStrip.Items.Add("Skip Break", Drawing.Image.FromFile("Assets/skip.png"), (sender, args) =>
{
_countdownTimer.Start();
_processMonitor.EndBreak();
_countdownTimer.Stop();
StartCountdown(TimeSpan.FromMinutes(_settings.focusPeriod));
RerenderContextMenu(true);
});
}
_notifyIcon.ContextMenuStrip.Items.Add("End Session", Drawing.Image.FromFile("Assets/end.png"), (sender, args) =>
{
_processMonitor.StopMonitoring();
......@@ -107,12 +121,12 @@ namespace InnoLabProjektDektopApp.Utils
Window mainWindow = Application.Current.MainWindow;
NavigationService mainNavigation = ((System.Windows.Navigation.NavigationWindow)mainWindow).NavigationService;
mainNavigation.Navigate(
new Session(_settings.focusPeriod,
_settings.breakPeriod,
_settings.cycles,
_settings.distractionMode,
_settings.mascotVisible,
_settings.wordsOfAffirmation,
new Session(_settings.focusPeriod,
_settings.breakPeriod,
_settings.cycles,
_settings.distractionMode,
_settings.mascotVisible,
_settings.wordsOfAffirmation,
_settings.insultingWords));
});
}
......@@ -162,7 +176,18 @@ namespace InnoLabProjektDektopApp.Utils
}
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
{
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.
Finish editing this message first!
Please register or to comment