aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Program.cs3
-rw-r--r--src/GetWindows.cs2
-rw-r--r--src/WatchLog.cs30
-rw-r--r--watcher.csproj3
4 files changed, 25 insertions, 13 deletions
diff --git a/Program.cs b/Program.cs
index ef19467..31fe70e 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,10 +1,9 @@
using hyprwatch.Logger;
-class Program
+class Program
{
static void Main(string[] args)
{
WatchLog.LogCreation();
}
-
}
diff --git a/src/GetWindows.cs b/src/GetWindows.cs
index d2bba9f..90f28c6 100644
--- a/src/GetWindows.cs
+++ b/src/GetWindows.cs
@@ -40,7 +40,7 @@ namespace hyprwatch.Window
Console.WriteLine(ex.Message);
}
- return activeWindow;
+ return activeWindow ?? string.Empty;
}
}
diff --git a/src/WatchLog.cs b/src/WatchLog.cs
index f24e5a6..b153804 100644
--- a/src/WatchLog.cs
+++ b/src/WatchLog.cs
@@ -40,7 +40,7 @@ namespace hyprwatch.Logger
Console.WriteLine(ex.Message);
}
- return t;
+ return t ?? string.Empty;
}
public static string GetDate()
@@ -73,16 +73,24 @@ namespace hyprwatch.Logger
Console.WriteLine(ex.Message);
}
- return d;
+ return d ?? string.Empty;
}
static void UpdateCSV(string date, Dictionary<string, string> data)
{
- string homeDir = Environment.GetEnvironmentVariable("HOME");
- string dataDir = Path.Combine(homeDir, ".cache", "hyprwatch", "daily_data");
+ string homeDir = Environment.GetEnvironmentVariable("HOME") ?? throw new InvalidOperationException("HOME environment variable is not set.");
string filePath = Path.Combine(homeDir, ".cache", "hyprwatch", "daily_data", $"{date}.csv");
- Directory.CreateDirectory(Path.GetDirectoryName(dataDir));
+
+ string? dirPath = Path.GetDirectoryName(filePath);
+ if(dirPath is not null)
+ {
+ Directory.CreateDirectory(dirPath);
+ }
+ else
+ {
+ throw new InvalidOperationException("Invalid file path.");
+ }
var overwriteData = new List<string[]>();
foreach(var kvp in data)
@@ -133,12 +141,14 @@ namespace hyprwatch.Logger
{
// The using block ensures the file is created and closed properly
}
+ }
bool isAfk = false;
- int afkTimeout = 1;
+ //int afkTimeout = 1;
var data = ImportData(filename);
-
+ data ??= new Dictionary<string, string>();
+
while(true)
{
string date = GetDate();
@@ -148,13 +158,13 @@ namespace hyprwatch.Logger
if(!isAfk)
{
string activeWindow = GetWindows.ActiveWindow();
- string usage = data.TryGetValue(activeWindow, out string value) ? value : null;
+ string usage = data.TryGetValue(activeWindow, out string? value) ? value : null;
if(usage == null)
{
usage = "00:00:00";
}
- Thread.Sleep(1);
+ Thread.Sleep(1000);
usage = TimeOperations.TimeAddition("00:00:01", usage);
data[$"{activeWindow}"] = usage;
@@ -174,7 +184,7 @@ namespace hyprwatch.Logger
data.Clear();
}
}
- }
+
}
}
}
diff --git a/watcher.csproj b/watcher.csproj
index 2150e37..e230d2b 100644
--- a/watcher.csproj
+++ b/watcher.csproj
@@ -5,6 +5,9 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
+ <PublishSingleFile>true</PublishSingleFile>
+ <SelfContained>true</SelfContained>
+ <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>