Repository navigation
Expand file tree
/
Copy pathMainWindow.Net.cs
More file actions
96 lines (84 loc) · 3.48 KB
/
Copy pathMainWindow.Net.cs
File metadata and controls
96 lines (84 loc) · 3.48 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
using System.Windows;
using System.Windows.Threading;
namespace ResetExplode;
/// <summary>Páginas Energia (bateria e fonte) e Rede (diagnóstico de lag).</summary>
public partial class MainWindow
{
// ================= Energia =================
private bool _energyBusy;
private async void RefreshEnergy()
{
if (_energyBusy) return;
_energyBusy = true;
BtnEnergyRefresh.IsEnabled = false;
EnergyStatus.Text = "Lendo bateria e energia…";
try
{
var sensors = _monitor.Rows.ToList();
var cards = await Task.Run(() => BatteryInfo.Read(sensors));
EnergyCards.ItemsSource = cards;
bool hasBattery = cards.Count > 1;
EnergyStatus.Text = (hasBattery ? "Bateria detectada" : "Nenhuma bateria (PC de mesa)") + $" · lido às {DateTime.Now:HH:mm:ss}";
}
catch (Exception ex) { EnergyStatus.Text = "Falhou: " + ex.Message; }
finally
{
_energyBusy = false;
BtnEnergyRefresh.IsEnabled = true;
}
}
private void BtnEnergyRefresh_Click(object sender, RoutedEventArgs e) => RefreshEnergy();
// ================= Rede =================
private CancellationTokenSource? _netCts;
private bool _netRunning;
private List<DiskHealthCard>? _lastNet;
private async void BtnNetTest_Click(object sender, RoutedEventArgs e)
{
if (_netRunning) { _netCts?.Cancel(); return; }
if (AnyBenchRunning || TestRunning) { NetStatus.Text = "Termine o outro teste antes."; return; }
_netRunning = true;
_netCts = new CancellationTokenSource();
var ct = _netCts.Token;
BtnNetTest.Content = "CANCELAR";
NetCards.ItemsSource = null;
NetProgress.ScaleX = 0;
try
{
var cards = await NetworkTest.Run((text, frac) => Dispatcher.BeginInvoke(new Action(() =>
{
NetStatus.Text = text;
NetProgress.ScaleX = Math.Clamp(frac, 0, 1);
})), ct);
_lastNet = cards;
NetCards.ItemsSource = cards;
NetStatus.Text = $"Concluído às {DateTime.Now:HH:mm:ss}. O resultado entra no relatório exportado.";
NetProgress.ScaleX = 1;
}
catch (OperationCanceledException) { NetStatus.Text = "Teste cancelado."; NetProgress.ScaleX = 0; }
catch (Exception ex) { NetStatus.Text = "Falhou: " + ex.Message; NetProgress.ScaleX = 0; }
finally
{
_netRunning = false;
_netCts?.Dispose();
_netCts = null;
BtnNetTest.Content = "TESTAR";
}
}
// ================= Tema (escuro / claro) =================
private void Theme_Click(object sender, RoutedEventArgs e)
{
ThemeManager.Apply(!ThemeManager.IsLight);
_settings.LightTheme = ThemeManager.IsLight;
try { _settings.Save(); } catch { }
UpdateThemeButton();
}
/// <summary>Mostra o ícone do modo para onde o clique leva (sol = ir para o claro, lua = ir para o escuro) e troca o logo.</summary>
private void UpdateThemeButton()
{
bool light = ThemeManager.IsLight;
BtnTheme.Content = light ? "\uE708" : "\uE706";
BtnTheme.ToolTip = light ? "Modo escuro" : "Modo claro";
TitleLogo.Source = new System.Windows.Media.Imaging.BitmapImage(
new Uri(light ? "pack://application:,,,/Assets/logo-dark.png" : "pack://application:,,,/Assets/logo.png"));
}
}