Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (89 loc) · 2.71 KB
/
Copy pathProgram.cs
File metadata and controls
101 lines (89 loc) · 2.71 KB
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
98
99
100
101
using System.Text.Json;
using Terminal.Gui;
using DashboardTui.Models;
using DashboardTui.Services;
using DashboardTui.Views;
// Load configuration
var configJson = File.ReadAllText("appsettings.json");
var config = JsonSerializer.Deserialize<AppConfig>(configJson) ?? throw new InvalidOperationException("Failed to load configuration");
// Initialize services
var httpClient = new HttpClient();
var weatherService = new WeatherApiService(httpClient, config.Weather.ApiKey);
var notificationService = new WindowsNotificationService();
// Initialize Terminal.Gui with NetDriver for better emoji support
Application.Init(driverName: "NetDriver");
try
{
// Window navigation state
var windows = new Func<Window>[]
{
() => new MainWindow(weatherService, notificationService, config),
() => new NewsWindow(config),
() => new PullRequestsWindow(config)
};
var currentWindowIndex = 0;
var shouldContinue = true;
Window? currentWindow = null;
// Function to switch windows
void SwitchToWindow(int index)
{
if (index < 0 || index >= windows.Length)
return;
currentWindowIndex = index;
// Stop current window if running
if (currentWindow != null)
{
Application.RequestStop();
}
}
// Function to quit application
void QuitApplication()
{
shouldContinue = false;
Application.RequestStop();
}
// Main window loop
while (shouldContinue)
{
// Create current window
currentWindow = windows[currentWindowIndex]();
// Add global key handler for window navigation
currentWindow.KeyDown += (sender, e) =>
{
// Plus (+) - Next window
if (e == (Key)'+')
{
var nextIndex = (currentWindowIndex + 1) % windows.Length;
SwitchToWindow(nextIndex);
e.Handled = true;
}
// Minus (-) - Previous window
else if (e == (Key)'-')
{
var prevIndex = (currentWindowIndex - 1 + windows.Length) % windows.Length;
SwitchToWindow(prevIndex);
e.Handled = true;
}
// Ctrl+Q - Quit application
else if (e == Key.Q.WithCtrl)
{
QuitApplication();
e.Handled = true;
}
// Esc - Quit application
else if (e == Key.Esc)
{
QuitApplication();
e.Handled = true;
}
};
Application.Run(currentWindow);
currentWindow.Dispose();
}
}
finally
{
// Cleanup
httpClient.Dispose();
Application.Shutdown();
}