diff options
Diffstat (limited to 'src/GetWindows.cs')
| -rw-r--r-- | src/GetWindows.cs | 91 |
1 files changed, 37 insertions, 54 deletions
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<Dictionary<string, string>>(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) |
