diff options
| author | DemonKingSwarn <rockingswarn@gmail.com> | 2025-01-26 16:45:40 +0530 |
|---|---|---|
| committer | DemonKingSwarn <rockingswarn@gmail.com> | 2025-01-26 16:45:40 +0530 |
| commit | 1672804f18823a428efc0be8af1655d8f261744f (patch) | |
| tree | 5a53250d7c418ac1314427084fc313bb32238648 /src | |
| parent | cf45c0829fedefbe1ed9c38337507c987d5b21aa (diff) | |
| download | hypr-wellbeing-1672804f18823a428efc0be8af1655d8f261744f.zip hypr-wellbeing-1672804f18823a428efc0be8af1655d8f261744f.tar.gz | |
chore: update when day changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/WatchLog.cs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/WatchLog.cs b/src/WatchLog.cs index 83001c1..9191aa0 100644 --- a/src/WatchLog.cs +++ b/src/WatchLog.cs @@ -130,7 +130,8 @@ namespace hyprwatch.Logger public static void LogCreation() { string homeDir = Environment.GetEnvironmentVariable("HOME"); - string filename = Path.Combine($"{homeDir}", ".cache", "hyprwatch", "daily_data", $"{GetDate()}.csv"); + string currentDate = GetDate(); + string filename = Path.Combine($"{homeDir}", ".cache", "hyprwatch", "daily_data", $"{currentDate}.csv"); if(!File.Exists(filename)) { string directoryPath = Path.Combine($"{homeDir}", ".cache", "Watcher", "daily_data"); @@ -151,23 +152,30 @@ namespace hyprwatch.Logger while(true) { - string date = GetDate(); - filename = Path.Combine($"{homeDir}", ".cache", "hyprwatch", "daily_data", $"{date}.csv"); + string newDate = GetDate(); + if(newDate != currentDate) + { + currentDate = newDate; + filename = Path.Combine($"{homeDir}", ".cache", "hyprwatch", "daily_data", $"{currentDate}.csv"); + data.Clear(); + + using (var fp = File.Create(filename)) + { + // The using block ensures the file is created and closed properly + } + } + Console.WriteLine(data); string activeWindow = GetWindows.ActiveWindow(); - string usage = data.TryGetValue(activeWindow, out string? value) ? value : null; - if(usage == null) - { - usage = "00:00:00"; - } + string usage = data.TryGetValue(activeWindow, out string? value) ? value : "00:00:00"; Thread.Sleep(1000); usage = TimeOperations.TimeAddition("00:00:01", usage); - data[$"{activeWindow}"] = usage; + data[activeWindow] = usage; - if(File.Exists(filename)) + /*if(File.Exists(filename)) { UpdateCSV(GetDate(), data); } @@ -180,7 +188,11 @@ namespace hyprwatch.Logger } data.Clear(); - } + + + }*/ + + UpdateCSV(currentDate, data); } } } |
