aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Program.cs1
-rw-r--r--hypr-wellbeing.csproj10
-rw-r--r--src/GetWindows.cs91
-rw-r--r--src/WatchLog.cs106
4 files changed, 77 insertions, 131 deletions
diff --git a/Program.cs b/Program.cs
index f58dc99..fe392f9 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,6 +1,5 @@
using System.IO;
using System.Runtime.InteropServices;
-using Newtonsoft.Json;
using hyprwatch.Logger;
using hyprwatch.Report.Weekly;
diff --git a/hypr-wellbeing.csproj b/hypr-wellbeing.csproj
index 9aef20e..d5a2493 100644
--- a/hypr-wellbeing.csproj
+++ b/hypr-wellbeing.csproj
@@ -6,12 +6,10 @@
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<IsAotCompatible>true</IsAotCompatible>
- <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier> <!-- musl for static -->
- <StaticExecutable>true</StaticExecutable>
+ <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
<StripSymbols>true</StripSymbols>
- <InvariantGlobalization>true</InvariantGlobalization> <!-- removes ICU dep -->
+ <InvariantGlobalization>true</InvariantGlobalization>
+ <StaticExecutable>true</StaticExecutable>
+ <CppCompilerAndLinker>clang-wrapper</CppCompilerAndLinker>
</PropertyGroup>
- <ItemGroup>
- <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
- </ItemGroup>
</Project>
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)
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<Dictionary<string, string>>(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<Dictionary<string, string>>(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;