From dacfac59f1cf60df7fc80a21cb7f3d63843aa591 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Sun, 19 Apr 2026 23:04:46 +0530 Subject: chore: made sure the binary is static --- src/GetWindows.cs | 91 +++++++++++++++++++--------------------------- src/WatchLog.cs | 106 +++++++++++++++++++----------------------------------- 2 files changed, 73 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/GetWindows.cs b/src/GetWindows.cs index 0508a88..44e7109 100644 --- a/src/GetWindows.cs +++ b/src/GetWindows.cs @@ -5,7 +5,6 @@ namespace hyprwatch.Window using System.Runtime.InteropServices; using System.Diagnostics; using System.Text.RegularExpressions; - using Newtonsoft.Json; public partial class GetWindows { @@ -14,75 +13,59 @@ namespace hyprwatch.Window string desktopEnv = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP"); string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string? activeWindow = null; - string? os = null; string configFile = Path.Combine(homeDir, ".config", "hypr-wellbeing", "config.json"); - if(File.Exists(configFile)) - { - string content = File.ReadAllText(configFile); - var config = JsonConvert.DeserializeObject>(content); - - os = config["os"]; - } - else - { - os = "Linux"; - } - - if(os == "Linux") - { - try { - Process process = new Process(); - process.StartInfo = new ProcessStartInfo(); - - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; + try { + Process process = new Process(); + process.StartInfo = new ProcessStartInfo(); + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; - if(desktopEnv == "Hyprland") - { - process.StartInfo.FileName = "hyprctl"; - process.StartInfo.Arguments = "activewindow"; - } - else if(desktopEnv == "niri") - { - process.StartInfo.FileName = "niri"; - process.StartInfo.Arguments = "msg focused-window"; - } - - process.Start(); - - string output = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); + if(desktopEnv == "Hyprland") + { + process.StartInfo.FileName = "hyprctl"; + process.StartInfo.Arguments = "activewindow"; + } + else if(desktopEnv == "niri") + { + process.StartInfo.FileName = "niri"; + process.StartInfo.Arguments = "msg focused-window"; + } - var classMatch = ClassRegex().Match(output); + process.Start(); - if(desktopEnv == "niri") - { - var match = Regex.Match(output, "App ID:\\s+\"([^\"]+)\""); - if(match.Success) - { - activeWindow = match.Groups[1].Value.Trim(); - } - } + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + var classMatch = ClassRegex().Match(output); - if(desktopEnv == "Hyprland") + if(desktopEnv == "niri") { - if(classMatch.Success) + var match = Regex.Match(output, "App ID:\\s+\"([^\"]+)\""); + if(match.Success) { - activeWindow = classMatch.Groups[1].Value.Trim(); + activeWindow = match.Groups[1].Value.Trim(); } - } + } - } - catch(Exception ex) + if(desktopEnv == "Hyprland") { - Console.WriteLine(ex.Message); + if(classMatch.Success) + { + activeWindow = classMatch.Groups[1].Value.Trim(); + } } + + + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); } if(activeWindow == null) diff --git a/src/WatchLog.cs b/src/WatchLog.cs index 9340822..99137db 100644 --- a/src/WatchLog.cs +++ b/src/WatchLog.cs @@ -5,7 +5,6 @@ namespace hyprwatch.Logger using System.Threading; using System.Diagnostics; using System.Collections.Generic; - using Newtonsoft.Json; using hyprwatch.Window; using hyprwatch.Time; @@ -14,50 +13,33 @@ namespace hyprwatch.Logger public static string GetTime() { string? t = 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>(content); - - os = config["os"]; - } - else + try { - os = "Linux"; - } - - if(os == "Linux") - { - try + Process process = new Process { - Process process = new Process + StartInfo = new ProcessStartInfo { - StartInfo = new ProcessStartInfo - { - FileName = "date", - Arguments = "+%T", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + 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); - } - catch(Exception ex) - { - Console.WriteLine(ex.Message); - } + t = output.Substring(0, output.Length - 1); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); } return t ?? string.Empty; @@ -66,50 +48,34 @@ 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)) + try { - string content = File.ReadAllText(configFile); - var config = JsonConvert.DeserializeObject>(content); - - os = config["os"]; - } - else - { - os = "Linux"; - } - - if(os == "Linux") - { - try + Process process = new Process { - Process process = new Process + StartInfo = new ProcessStartInfo { - StartInfo = new ProcessStartInfo - { - FileName = "date", - Arguments = "+%d-%m-%Y", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; + 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); - } - catch(Exception ex) - { - Console.WriteLine(ex.Message); - } + d = output.Substring(0, output.Length - 1); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); } return d ?? string.Empty; -- cgit v1.1