From 792b9df7112ec8cedc52f8deba6468380a68d723 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Mon, 27 Jan 2025 10:01:38 +0530 Subject: chore: readme updated --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d23679..62ef9b8 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,16 @@ ## Usage -### Monitor Mode +> [!NOTE] +> make sure you ran this command before running the program ```sh mkdir -p $HOME/.cache/hyprwatch/daily_data +``` + +### Monitor Mode + +```sh hyprwatch -d &> /dev/null & ``` -- cgit v1.1 From 3ec798d2e3c3985de185107f47b2de7632ab6c50 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Tue, 28 Jan 2025 17:36:48 +0530 Subject: chore: working on hyprland ipc communication --- src/GetWindowsv2.cs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/GetWindowsv2.cs diff --git a/src/GetWindowsv2.cs b/src/GetWindowsv2.cs new file mode 100644 index 0000000..7185776 --- /dev/null +++ b/src/GetWindowsv2.cs @@ -0,0 +1,62 @@ +namespace hyprwatch.Window +{ + using System; + using System.Net.Sockets; + using System.Text; + using System.IO; + using System.Text.RegularExpressions; + + public partial class GetWindowsv2 + { + public static string ActiveWindow() + { + string xdgRuntimeDir = Environment.GetEnvironmentVariable("XDG_RUNTIME_DIR"); + string hyprlandInstanceSig = Environment.GetEnvironmentVariable("HYPRLAND_INSTANCE_SIGNATURE"); + + string socketPath = Path.Combine(xdgRuntimeDir, "hypr", hyprlandInstanceSig, ".socket2.sock"); + + string activeWindow = "Home-Screen"; + + var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); + + try + { + socket.Connect(new UnixDomainSocketEndPoint(socketPath)); + + using (var stream = new NetworkStream(socket)) + using (var reader = new StreamReader(stream)) + { + while (true) + { + string line = reader.ReadLine(); + + if (line == null) + { + break; + } + + var classMatch = ClassRegex().Match(line); + if(classMatch.Success) + { + activeWindow = classMatch.Groups[1].Value.Trim(); + break; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + socket.Close(); + } + + return activeWindow; + } + + [GeneratedRegex(@"activewindow>>([^,]+)")] + public static partial Regex ClassRegex(); + } +} -- cgit v1.1 From ac70491939ab9dce5cce45c8c3403cd332736d98 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Mon, 3 Feb 2025 17:54:58 +0530 Subject: chore: project rename `hyprwatch` -> `hypr-wellbeing` --- README.md | 2 +- src/GetWindowsv2.cs | 21 ++++++++------------- src/WatchLog.cs | 3 ++- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 62ef9b8..40c1d78 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hyprwatch +# hypr-wellbeing ![](./.assets/show.png) diff --git a/src/GetWindowsv2.cs b/src/GetWindowsv2.cs index 7185776..ea61cb7 100644 --- a/src/GetWindowsv2.cs +++ b/src/GetWindowsv2.cs @@ -15,7 +15,7 @@ namespace hyprwatch.Window string socketPath = Path.Combine(xdgRuntimeDir, "hypr", hyprlandInstanceSig, ".socket2.sock"); - string activeWindow = "Home-Screen"; + string? activeWindow = null; var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); @@ -26,22 +26,17 @@ namespace hyprwatch.Window using (var stream = new NetworkStream(socket)) using (var reader = new StreamReader(stream)) { - while (true) - { string line = reader.ReadLine(); - if (line == null) + if (line != null) { - break; - } - var classMatch = ClassRegex().Match(line); - if(classMatch.Success) - { - activeWindow = classMatch.Groups[1].Value.Trim(); - break; + var classMatch = ClassRegex().Match(line); + if(classMatch.Success) + { + activeWindow = classMatch.Groups[1].Value.Trim(); + } } - } } } catch (Exception ex) @@ -53,7 +48,7 @@ namespace hyprwatch.Window socket.Close(); } - return activeWindow; + return activeWindow ?? "Home-Screen"; } [GeneratedRegex(@"activewindow>>([^,]+)")] diff --git a/src/WatchLog.cs b/src/WatchLog.cs index 9191aa0..cb2aa7a 100644 --- a/src/WatchLog.cs +++ b/src/WatchLog.cs @@ -165,9 +165,10 @@ namespace hyprwatch.Logger } } - Console.WriteLine(data); + //Console.WriteLine(data); string activeWindow = GetWindows.ActiveWindow(); + Console.WriteLine(activeWindow); string usage = data.TryGetValue(activeWindow, out string? value) ? value : "00:00:00"; Thread.Sleep(1000); -- cgit v1.1 From 9fbd42f43eef6fea31dfa2dbf442ac1ab40a9e67 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Mon, 3 Feb 2025 17:59:45 +0530 Subject: chore: directory creation if doesnt exist --- Program.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Program.cs b/Program.cs index d230875..15011ed 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,11 @@ class Program { static void Main(string[] args) { + string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + string hyprwatchDirectory = Path.Combine(homeDirectory, ".cache", "hyprwatch"); + string dailyDataDirectory = Path.Combine(hyprwatchDirectory, "daily_data"); + Directory.CreateDirectory(dailyDataDirectory); + if (args.Length == 0 || args[0] != "-d" && args[0] != "--show") { Console.WriteLine("Usage: -d || --show"); -- cgit v1.1 From b0a98c204ece65644c7376c514f98f90b77c6ca0 Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Mon, 3 Feb 2025 18:00:07 +0530 Subject: chore: README update --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 40c1d78..8c38630 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,6 @@ ## Usage -> [!NOTE] -> make sure you ran this command before running the program - -```sh -mkdir -p $HOME/.cache/hyprwatch/daily_data -``` - ### Monitor Mode ```sh -- cgit v1.1 From 86a24f435f46c866a068a294214bd955b36a3d9a Mon Sep 17 00:00:00 2001 From: DemonKingSwarn Date: Mon, 3 Feb 2025 18:29:24 +0530 Subject: chore: install instructions added --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 8c38630..580d477 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,18 @@ ![](./.assets/show.png) +## Installation + +### AUR + +```sh +paru -S hypr-wellbeing-bin +``` + +### Github Releases + +You can download it from [Releases](https://github.com/DemonKingSwarn/hypr-wellbeing/releases) + ## Usage ### Monitor Mode -- cgit v1.1