diff options
| author | DemonKingSwarn <rockingswarn@gmail.com> | 2025-11-10 15:30:15 +0530 |
|---|---|---|
| committer | DemonKingSwarn <rockingswarn@gmail.com> | 2025-11-10 15:30:15 +0530 |
| commit | 80ba776bfae57f2622caa0ecf8a5eb3821ab08b0 (patch) | |
| tree | d769b644d47c4e19126c4b1b26dd7d14fed90987 /src/WatchLog.cs | |
| parent | a98522b15e3819a5172a8a97b2057cb7c0c1196f (diff) | |
| download | hypr-wellbeing-80ba776bfae57f2622caa0ecf8a5eb3821ab08b0.zip hypr-wellbeing-80ba776bfae57f2622caa0ecf8a5eb3821ab08b0.tar.gz | |
chore: widnows support added
Diffstat (limited to 'src/WatchLog.cs')
| -rw-r--r-- | src/WatchLog.cs | 141 |
1 files changed, 107 insertions, 34 deletions
diff --git a/src/WatchLog.cs b/src/WatchLog.cs index cb2aa7a..4a029d9 100644 --- a/src/WatchLog.cs +++ b/src/WatchLog.cs @@ -5,6 +5,7 @@ namespace hyprwatch.Logger using System.Threading; using System.Diagnostics; using System.Collections.Generic; + using Newtonsoft.Json; using hyprwatch.Window; using hyprwatch.Time; @@ -13,31 +14,55 @@ namespace hyprwatch.Logger public static string GetTime() { string? t = null; + string? os = null; - try + string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + string configFile = Path.Combine(homeDir, ".config", "hypr-wellbeing", "config.json"); + + if(File.Exists(configFile)) + { + string content = File.ReadAllText(configFile); + var config = JsonConvert.DeserializeObject<Dictionary<string, string>>(content); + + os = config["os"]; + } + else + { + os = "Linux"; + } + + if(os == "Linux") { - Process process = new Process + try { - StartInfo = new ProcessStartInfo + Process process = new Process { - FileName = "date", - Arguments = "+%T", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + StartInfo = new ProcessStartInfo + { + FileName = "date", + Arguments = "+%T", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; - process.Start(); + process.Start(); - string output = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); - t = output.Substring(0, output.Length - 1); + t = output.Substring(0, output.Length - 1); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); + } } - catch(Exception ex) + + else if(os == "Windows") { - Console.WriteLine(ex.Message); + t = DateTime.Now.ToString("HH:mm:ss"); } return t ?? string.Empty; @@ -46,31 +71,79 @@ namespace hyprwatch.Logger public static string GetDate() { string? d = null; + string? os = null; + + string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + string configFile = Path.Combine(homeDir, ".config", "hypr-wellbeing", "config.json"); + + if(File.Exists(configFile)) + { + string content = File.ReadAllText(configFile); + var config = JsonConvert.DeserializeObject<Dictionary<string, string>>(content); + + os = config["os"]; + } + else + { + os = "Linux"; + } - try + if(os == "Linux") { - Process process = new Process + try { - StartInfo = new ProcessStartInfo + Process process = new Process { - FileName = "date", - Arguments = "+%d-%m-%Y", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + StartInfo = new ProcessStartInfo + { + FileName = "date", + Arguments = "+%d-%m-%Y", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; - process.Start(); + process.Start(); - string output = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); - d = output.Substring(0, output.Length - 1); + d = output.Substring(0, output.Length - 1); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); + } } - catch(Exception ex) + + else if(os == "Windows") { - Console.WriteLine(ex.Message); + try + { + Process process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "powershell", + Arguments = "-Command \"Get-Date -Format dd-MM-yyyy\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + d = output.Substring(0, output.Length - 1); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); + } } return d ?? string.Empty; @@ -78,7 +151,7 @@ namespace hyprwatch.Logger static void UpdateCSV(string date, Dictionary<string, string> data) { - string homeDir = Environment.GetEnvironmentVariable("HOME") ?? throw new InvalidOperationException("HOME environment variable is not set."); + string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string filePath = Path.Combine(homeDir, ".cache", "hyprwatch", "daily_data", $"{date}.csv"); @@ -129,7 +202,7 @@ namespace hyprwatch.Logger public static void LogCreation() { - string homeDir = Environment.GetEnvironmentVariable("HOME"); + string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string currentDate = GetDate(); string filename = Path.Combine($"{homeDir}", ".cache", "hyprwatch", "daily_data", $"{currentDate}.csv"); if(!File.Exists(filename)) |
