-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
181 lines (156 loc) · 4.96 KB
/
MainWindow.xaml.cs
File metadata and controls
181 lines (156 loc) · 4.96 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using TweakHub.Services;
using TweakHub.Views;
namespace TweakHub;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly ThemeService _themeService;
private Button? _activeButton = null;
public MainWindow()
{
InitializeComponent();
_themeService = ThemeService.Instance;
Loaded += MainWindow_Loaded;
Closing += MainWindow_Closing;
UpdateThemeButton();
}
private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{
// Stop all monitoring services to ensure clean shutdown
try
{
HardwareMonitoringService.Instance.StopMonitoring();
SystemMonitoringService.Instance.Stop();
}
catch
{
// Ignore errors during shutdown
}
// Force shutdown of the entire application
Application.Current.Shutdown();
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Navigate to Registry Tweaks by default
NavigateToRegistryTweaks();
}
private void RegistryTweaksButton_Click(object sender, RoutedEventArgs e)
{
NavigateToRegistryTweaks();
}
private void ExternalToolsButton_Click(object sender, RoutedEventArgs e)
{
NavigateToExternalTools();
}
private void AutomatedScriptsButton_Click(object sender, RoutedEventArgs e)
{
NavigateToAutomatedScripts();
}
private void QuickAccessButton_Click(object sender, RoutedEventArgs e)
{
NavigateToQuickAccess();
}
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
NavigateToAbout();
}
private void ThemeToggleButton_Click(object sender, RoutedEventArgs e)
{
_themeService.CurrentTheme = _themeService.CurrentTheme == Services.AppTheme.Dark
? Services.AppTheme.Light
: Services.AppTheme.Dark;
UpdateThemeButton();
}
private void UpdateThemeButton()
{
var isDark = _themeService.CurrentTheme == Services.AppTheme.Dark ||
(_themeService.CurrentTheme == Services.AppTheme.System && IsSystemDarkTheme());
ThemeIcon.Text = isDark ? "☀️" : "🌙";
ThemeText.Text = isDark ? "Light Theme" : "Dark Theme";
}
private bool IsSystemDarkTheme()
{
try
{
using var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
var value = key?.GetValue("AppsUseLightTheme");
return value is int intValue && intValue == 0;
}
catch
{
return false;
}
}
private void NavigateToRegistryTweaks()
{
MainFrame.Navigate(new RegistryTweaksPage());
UpdateActiveSidebarButton(RegistryTweaksButton);
UpdateRegistryTweaksBadge();
}
private void NavigateToExternalTools()
{
MainFrame.Navigate(new ExternalToolsPage());
UpdateActiveSidebarButton(ExternalToolsButton);
}
private void NavigateToAutomatedScripts()
{
MainFrame.Navigate(new AutomatedScriptsPage());
UpdateActiveSidebarButton(AutomatedScriptsButton);
}
private void NavigateToQuickAccess()
{
MainFrame.Navigate(new QuickAccessPage());
UpdateActiveSidebarButton(QuickAccessButton);
}
private void NavigateToAbout()
{
MainFrame.Navigate(new Views.AboutPage());
UpdateActiveSidebarButton(AboutButton);
}
private void UpdateActiveSidebarButton(Button activeButton)
{
// Reset previous active button to normal style
if (_activeButton != null)
{
_activeButton.Style = (Style)FindResource("SidebarButtonStyle");
}
// Set new active button to active style
_activeButton = activeButton;
if (_activeButton != null)
{
_activeButton.Style = (Style)FindResource("ActiveSidebarButtonStyle");
}
}
public void UpdateRegistryTweaksBadge()
{
try
{
var tweakService = TweakHub.Services.TweakService.Instance;
var activeCount = tweakService.TweakCategories
.SelectMany(c => c.Tweaks)
.Count(t => t.IsEnabled);
if (this.FindName("RegistryTweaksBadge") is Border badge &&
this.FindName("RegistryTweaksBadgeText") is TextBlock text)
{
if (activeCount > 0)
{
badge.Visibility = Visibility.Visible;
text.Text = activeCount.ToString();
}
else
{
badge.Visibility = Visibility.Collapsed;
}
}
}
catch
{
// Ignore errors in badge update
}
}
}