aboutsummaryrefslogtreecommitdiff
path: root/Program.cs
blob: 14e36300db5a3279922d3d7af15454fd56b0e53e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.IO;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using hyprwatch.Logger;
using hyprwatch.Report.Weekly;

class Program
{
  static void Main(string[] args)
  {
    string os;

    string version = "0.0.8";
    string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
    string configDir = Path.Combine(homeDirectory, ".config", "hypr-wellbeing");
    string configFile = Path.Combine(configDir, "config.json");
    string hyprwatchDirectory = Path.Combine(homeDirectory, ".cache", "hyprwatch");
    string dailyDataDirectory = Path.Combine(hyprwatchDirectory, "daily_data");
    Directory.CreateDirectory(dailyDataDirectory);
    Directory.CreateDirectory(configDir);

    if (args.Length == 0 || args[0] != "-d" && args[0] != "--show" && args[0] != "--weekly" && args[0] != "-v")
    {
      Console.WriteLine("Usage: -d || -v || --show || --weekly");
      return;
    }

    if(args[0] == "-v")
    {
      Console.WriteLine($"hypr-wellbeing v{version}");
    }

    if(args[0] == "-d")
    {
        while(true)
        {
          WatchLog.LogCreation();
          System.Threading.Thread.Sleep(5000);
        }
    }

    if(args[0] == "--show")
    {
      string green = "\x1b[0;32m";
      string yellow = "\x1b[1;33m";
      string red = "\x1b[0;31m";
      string blue = "\x1b[0;34m";
      string reset = "\x1b[0m";

      Dictionary<string, string> data = new Dictionary<string, string>();

      var date = WatchLog.GetDate(); 
      string filePath = Environment.GetEnvironmentVariable("HOME") + $"/.cache/hyprwatch/daily_data/{date}.csv";

      var rawData = File.ReadAllLines(filePath);

      foreach(var line in rawData)
      {
        var parts = line.Split('\t');
        if(parts.Length >= 2)
        {
          string key = parts[1].TrimEnd();
          string value = parts[0];
          data[key] = value;
        }
      }
      
      TimeSpan totalTime = TimeSpan.Zero;

      foreach (var entry in data)
      {
        if (TimeSpan.TryParse(entry.Value, out TimeSpan time))
        {
          totalTime += time;
        }
      }
      
      Console.WriteLine(" ");
      Console.WriteLine($"Today's Screen Usage\t{totalTime}");
      Console.WriteLine($"{red}{new string('-', 60)}{reset}");
      Console.WriteLine($"{yellow}{"App",-30}{"Time",30}{reset}");
      Console.WriteLine($"{red}{new string('-', 60)}{reset}");
      
      foreach (var entry in data)
      {
        string key = entry.Key.Length > 30 ? entry.Key.Substring(0, 27) + "..." : entry.Key;
        Console.WriteLine($"{blue}{key,-30}{reset}{green}{entry.Value,30}{reset}");
      }
      
    }
    if(args[0] == "--weekly")
    {
      WeeklyReport.DisplayWeeklyReport();
    }
  }

}