diff options
| author | DemonKingSwarn <rockingswarn@gmail.com> | 2025-01-25 19:14:51 +0530 |
|---|---|---|
| committer | DemonKingSwarn <rockingswarn@gmail.com> | 2025-01-25 19:14:51 +0530 |
| commit | 2ca5774c6b2f965553825ddb10088b206d2bf75a (patch) | |
| tree | cf63cf4a877fb87036a1b45d4eb34d28911fb0d8 /src | |
| parent | e9a36d9a3cc50105ade148e0f8a286f89ac0c4df (diff) | |
| download | hypr-wellbeing-2ca5774c6b2f965553825ddb10088b206d2bf75a.zip hypr-wellbeing-2ca5774c6b2f965553825ddb10088b206d2bf75a.tar.gz | |
chore: minor bug fix
Diffstat (limited to 'src')
| -rw-r--r-- | src/GetWindows.cs | 2 | ||||
| -rw-r--r-- | src/WatchLog.cs | 30 |
2 files changed, 21 insertions, 11 deletions
diff --git a/src/GetWindows.cs b/src/GetWindows.cs index d2bba9f..90f28c6 100644 --- a/src/GetWindows.cs +++ b/src/GetWindows.cs @@ -40,7 +40,7 @@ namespace hyprwatch.Window Console.WriteLine(ex.Message); } - return activeWindow; + return activeWindow ?? string.Empty; } } diff --git a/src/WatchLog.cs b/src/WatchLog.cs index f24e5a6..b153804 100644 --- a/src/WatchLog.cs +++ b/src/WatchLog.cs @@ -40,7 +40,7 @@ namespace hyprwatch.Logger Console.WriteLine(ex.Message); } - return t; + return t ?? string.Empty; } public static string GetDate() @@ -73,16 +73,24 @@ namespace hyprwatch.Logger Console.WriteLine(ex.Message); } - return d; + return d ?? string.Empty; } static void UpdateCSV(string date, Dictionary<string, string> data) { - string homeDir = Environment.GetEnvironmentVariable("HOME"); - string dataDir = Path.Combine(homeDir, ".cache", "hyprwatch", "daily_data"); + string homeDir = Environment.GetEnvironmentVariable("HOME") ?? throw new InvalidOperationException("HOME environment variable is not set."); string filePath = Path.Combine(homeDir, ".cache", "hyprwatch", "daily_data", $"{date}.csv"); - Directory.CreateDirectory(Path.GetDirectoryName(dataDir)); + + string? dirPath = Path.GetDirectoryName(filePath); + if(dirPath is not null) + { + Directory.CreateDirectory(dirPath); + } + else + { + throw new InvalidOperationException("Invalid file path."); + } var overwriteData = new List<string[]>(); foreach(var kvp in data) @@ -133,12 +141,14 @@ namespace hyprwatch.Logger { // The using block ensures the file is created and closed properly } + } bool isAfk = false; - int afkTimeout = 1; + //int afkTimeout = 1; var data = ImportData(filename); - + data ??= new Dictionary<string, string>(); + while(true) { string date = GetDate(); @@ -148,13 +158,13 @@ namespace hyprwatch.Logger if(!isAfk) { string activeWindow = GetWindows.ActiveWindow(); - string usage = data.TryGetValue(activeWindow, out string value) ? value : null; + string usage = data.TryGetValue(activeWindow, out string? value) ? value : null; if(usage == null) { usage = "00:00:00"; } - Thread.Sleep(1); + Thread.Sleep(1000); usage = TimeOperations.TimeAddition("00:00:01", usage); data[$"{activeWindow}"] = usage; @@ -174,7 +184,7 @@ namespace hyprwatch.Logger data.Clear(); } } - } + } } } |
