Skip to content

Portable Tool for an Ideal Windows Setup

monitoring of connected devices through events & re

Greedekscdb4dd61263b
diff --git a/.Source/GTweak/App.xaml.cs b/.Source/GTweak/App.xaml.cs
index 8c263e23..52e7dfde 100644
--- a/.Source/GTweak/App.xaml.cs
+++ b/.Source/GTweak/App.xaml.cs
@@ -13,9 +13,9 @@ namespace GTweak
{
internal static event EventHandler LanguageChanged;
internal static event EventHandler ThemeChanged;
- internal static event EventHandler ImportTweaksUpdate;
+ internal static event EventHandler TweaksImported;
- internal static void UpdateImport() => ImportTweaksUpdate?.Invoke(default, EventArgs.Empty);
+ internal static void UpdateImport() => TweaksImported?.Invoke(default, EventArgs.Empty);
public App()
{
@@ -54,7 +54,6 @@ namespace GTweak
Environment.Exit(0);
}
-
private static Uri GetResourceUri(string folder, bool isTheme = false) => isTheme ? new Uri($"Styles/Themes/{folder}/Colors.xaml", UriKind.Relative) : new Uri($"Languages/{folder}/Localize.xaml", UriKind.Relative);
internal static string Language
diff --git a/.Source/GTweak/Core/ViewModel/DataSystemVM.cs b/.Source/GTweak/Core/ViewModel/DataSystemVM.cs
index ee3f30b4..3feba400 100644
--- a/.Source/GTweak/Core/ViewModel/DataSystemVM.cs
+++ b/.Source/GTweak/Core/ViewModel/DataSystemVM.cs
@@ -66,7 +66,7 @@ namespace GTweak.Core.ViewModel
DisplayData = new ObservableCollection<DataSystemModel>
{
CreateModelCollection("Windows", SystemDiagnostics.HardwareData.OperatingSystem),
- CreateModelCollection("Processes", new MonitoringSystem().GetNumberRunningProcesses),
+ CreateModelCollection("Processes", new MonitoringService().GetNumberRunningProcesses),
CreateModelCollection("Bios", SystemDiagnostics.HardwareData.Bios, "no_device_information_systemInformatin"),
CreateModelCollection("Mode", SystemDiagnostics.HardwareData.BiosMode, "unknown_information_systemInformatin"),
CreateModelCollection("Motherboard", SystemDiagnostics.HardwareData.Motherboard, "no_device_information_systemInformatin"),
diff --git a/.Source/GTweak/Core/ViewModel/MainViewModel.cs b/.Source/GTweak/Core/ViewModel/MainViewModel.cs
index 5216e332..39d027e9 100644
--- a/.Source/GTweak/Core/ViewModel/MainViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/MainViewModel.cs
@@ -50,7 +50,7 @@ namespace GTweak.Core.ViewModel
CurrentView = new MoreVM();
- App.ImportTweaksUpdate += delegate { CurrentView = new MoreVM(); };
+ App.TweaksImported += delegate { CurrentView = new MoreVM(); };
}
}
}
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index c9fafd1a..b0fe3291 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -285,7 +285,7 @@
<Compile Include="Utilities\Helpers\TakingOwnership.cs" />
<Compile Include="Utilities\Tweaks\ClearingMemory.cs" />
<Compile Include="Utilities\Managers\INIManager.cs" />
- <Compile Include="Utilities\Configuration\MonitoringSystem.cs" />
+ <Compile Include="Utilities\Configuration\MonitoringService.cs" />
<Compile Include="Utilities\Configuration\SystemDiagnostics.cs" />
<Compile Include="Utilities\Managers\NotificationManager.cs" />
<Compile Include="Utilities\Helpers\TrustedInstaller.cs" />
diff --git a/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs b/.Source/GTweak/Utilities/Configuration/MonitoringService.cs
similarity index 59%
rename from .Source/GTweak/Utilities/Configuration/MonitoringSystem.cs
rename to .Source/GTweak/Utilities/Configuration/MonitoringService.cs
index 14cba663..6e3fe7c5 100644
--- a/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs
+++ b/.Source/GTweak/Utilities/Configuration/MonitoringService.cs
@@ -1,17 +1,31 @@
using GTweak.Utilities.Controls;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
+using System.Management;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace GTweak.Utilities.Configuration
{
- internal sealed class MonitoringSystem
+ internal class MonitoringService
{
+ internal event Action<DeviceType> HandleDevicesEvents;
+ private readonly List<ManagementEventWatcher> _eventWatchers = new List<ManagementEventWatcher>();
+
internal int GetMemoryUsage => GetPhysicalAvailableMemory();
internal string GetNumberRunningProcesses => Process.GetProcesses().Length.ToString();
internal static int GetProcessorUsage { get; private set; } = 1;
+ internal enum DeviceType
+ {
+ All,
+ Storage,
+ Audio,
+ Network
+ }
+
+
[StructLayout(LayoutKind.Sequential)]
private struct SystemTime
{
@@ -80,5 +94,50 @@ namespace GTweak.Utilities.Configuration
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
finally { if (!success) GetProcessorUsage = 1; }
}
+
+ internal void StartDeviceMonitoring()
+ {
+ Task.Run(() =>
+ {
+ foreach (var wmiClass in new[] { "Win32_DiskDrive", "MSFT_PhysicalDisk" })
+ {
+ SubscribeToDeviceEvents($"TargetInstance ISA '{wmiClass}'", DeviceType.Storage);
+ }
+ SubscribeToDeviceEvents("TargetInstance ISA 'Win32_SoundDevice'", DeviceType.Audio);
+ SubscribeToDeviceEvents("TargetInstance ISA 'Win32_NetworkAdapter' AND TargetInstance.NetConnectionStatus IS NOT NULL", DeviceType.Network);
+ }).ConfigureAwait(false);
+ }
+
+
+ private void SubscribeToDeviceEvents(string filter, DeviceType type)
+ {
+ try
+ {
+ WqlEventQuery query = new WqlEventQuery("__InstanceOperationEvent", TimeSpan.FromSeconds(1), filter);
+ ManagementEventWatcher managementEvent = new ManagementEventWatcher(query);
+ managementEvent.EventArrived += (s, e) => { HandleDevicesEvents?.Invoke(type); };
+ managementEvent.Start();
+ _eventWatchers.Add(managementEvent);
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ }
+
+ internal void StopDeviceMonitoring()
+ {
+ Task.Run(() =>
+ {
+ foreach (ManagementEventWatcher managementEvent in _eventWatchers)
+ {
+ try
+ {
+ managementEvent.Stop();
+ managementEvent.EventArrived -= null;
+ managementEvent.Dispose();
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ }
+ _eventWatchers.Clear();
+ }).ConfigureAwait(false);
+ }
}
}
diff --git a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
index ad5887a4..25601a4e 100644
--- a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
+++ b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
@@ -21,7 +21,7 @@ using System.Windows.Media.Imaging;
namespace GTweak.Utilities.Configuration
{
- internal sealed class SystemDiagnostics
+ internal sealed class SystemDiagnostics : MonitoringService
{
private sealed class GitMetadata
{
@@ -108,26 +108,42 @@ namespace GTweak.Utilities.Configuration
GetProcessorInfo,
GeVideoInfo,
GetMemoryInfo,
- UpdatingDevicesData,
- GetUserIpAddress
+ GetUserIpAddress,
+ () => { UpdatingDevicesData(); }
);
}
- internal void UpdatingDevicesData()
+ internal void UpdatingDevicesData(DeviceType deviceType = DeviceType.All)
{
- string storage = string.Empty;
- string audio = string.Empty;
- string netAdapter = string.Empty;
+ string storage = string.Empty, audio = string.Empty, netAdapter = string.Empty;
- Parallel.Invoke(
- () => storage = GetStorageDevices(),
- () => audio = GetAudioDevices(),
- () => netAdapter = GetNetworkAdapters()
- );
+ switch (deviceType)
+ {
+ case DeviceType.Storage:
+ Parallel.Invoke(() => storage = GetStorageDevices());
+ HardwareData.Storage = storage;
+ break;
+ case DeviceType.Audio:
+ Parallel.Invoke(() => audio = GetAudioDevices());
+ HardwareData.AudioDevice = audio;
+ break;
+ case DeviceType.Network:
+ Parallel.Invoke(() => netAdapter = GetNetworkAdapters());
+ HardwareData.NetworkAdapter = netAdapter;
+ break;
+ case DeviceType.All:
+ Parallel.Invoke
+ (
+ () => storage = GetStorageDevices(),
+ () => audio = GetAudioDevices(),
+ () => netAdapter = GetNetworkAdapters()
+ );
+ HardwareData.Storage = storage;
+ HardwareData.AudioDevice = audio;
+ HardwareData.NetworkAdapter = netAdapter;
+ break;
- HardwareData.Storage = storage;
- HardwareData.AudioDevice = audio;
- HardwareData.NetworkAdapter = netAdapter;
+ }
}
internal void GetOperatingSystemInfo()
diff --git a/.Source/GTweak/View/ConfidentialityView.xaml.cs b/.Source/GTweak/View/ConfidentialityView.xaml.cs
index b1aa4438..57ba790e 100644
--- a/.Source/GTweak/View/ConfidentialityView.xaml.cs
+++ b/.Source/GTweak/View/ConfidentialityView.xaml.cs
@@ -11,7 +11,7 @@ namespace GTweak.View
{
public partial class ConfidentialityView : UserControl
{
- private readonly ConfidentialityTweaks confTweaks = new ConfidentialityTweaks();
+ private readonly ConfidentialityTweaks _confTweaks = new ConfidentialityTweaks();
public ConfidentialityView()
{
@@ -41,10 +41,10 @@ namespace GTweak.View
if (NotificationManager.ConfActions.TryGetValue(toggleButton.Name, out string action))
new NotificationManager(300).Show(action);
- Parallel.Invoke(async delegate { await Task.Delay(1000); confTweaks.AnalyzeAndUpdate(this); });
+ Parallel.Invoke(async delegate { await Task.Delay(1000); _confTweaks.AnalyzeAndUpdate(this); });
}
- private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => confTweaks.AnalyzeAndUpdate(this));
+ private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => _confTweaks.AnalyzeAndUpdate(this));
}
}
diff --git a/.Source/GTweak/View/DataSystemView.xaml b/.Source/GTweak/View/DataSystemView.xaml
index 1380689b..a863acaf 100644
--- a/.Source/GTweak/View/DataSystemView.xaml
+++ b/.Source/GTweak/View/DataSystemView.xaml
@@ -53,7 +53,7 @@
<StackPanel Orientation="Horizontal" Height="91">
<TextBlock Style="{StaticResource Text}" FontSize="15pt" Width="Auto" Height="77">
<Run Foreground="{StaticResource Color_Accent}" Text="{DynamicResource title_win_systemInformation}"/>
- <Run Foreground="{StaticResource Color_Highlighted}" Text="{Binding [Windows].Data}" PreviewMouseDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <Run Foreground="{StaticResource Color_Highlighted}" Text="{Binding [Windows].Data}" PreviewMouseDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</TextBlock>
<Image x:Name="ImageWindows" Height="80" Width="80" HorizontalAlignment="Right" Margin="30,0,0,0">
<Image.Style>
@@ -113,9 +113,9 @@
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_bios_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
<TextBlock Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto">
- <Run Text="{Binding [Bios].Data}" PreviewMouseDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/><LineBreak/>
+ <Run Text="{Binding [Bios].Data}" PreviewMouseDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/><LineBreak/>
<Run Text="{DynamicResource title_mode_systemInformation}" Foreground="{StaticResource Color_Accent}"/>
- <Run Text="{Binding [Mode].Data}" PreviewMouseDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <Run Text="{Binding [Mode].Data}" PreviewMouseDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</TextBlock>
</StackPanel>
</Grid>
@@ -125,7 +125,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_motherbr_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Motherboard].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Motherboard].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -134,7 +134,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_cpu_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Processor].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Processor].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -143,7 +143,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_gpu_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Graphics].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Graphics].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -152,10 +152,10 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_ram_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Memory].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Memory].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
<TextBlock Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto">
<Run Text="{DynamicResource title_mtype_systemInformation}" Foreground="{StaticResource Color_Accent}"/>
- <Run Text="{Binding [Type].Data}" PreviewMouseDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <Run Text="{Binding [Type].Data}" PreviewMouseDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</TextBlock>
</StackPanel>
</Grid>
@@ -174,7 +174,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_disk_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Storage].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Storage].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -183,7 +183,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_sound_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Audio].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Audio].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -192,7 +192,7 @@
<Grid Width="543">
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_netadapter_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
- <TextBlock Text="{Binding [Network].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand"/>
+ <TextBlock Text="{Binding [Network].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand"/>
</StackPanel>
</Grid>
</Grid>
@@ -202,7 +202,7 @@
<StackPanel Orientation="Vertical" Margin="60,20,0,0">
<TextBlock Text="{DynamicResource title_ip_systemInformation}" Style="{StaticResource Text}" HorizontalAlignment="Left" Foreground="{StaticResource Color_Accent}" Height="Auto" Width="Auto"/>
<StackPanel Orientation="Horizontal">
- <TextBlock x:Name="IpAddress" Text="{Binding [IpAddress].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="TextComputerData_PreviewMouseDown" Cursor="Hand">
+ <TextBlock x:Name="IpAddress" Text="{Binding [IpAddress].Data}" Style="{StaticResource Text}" HorizontalAlignment="Left" Margin="1,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand">
<TextBlock.Effect>
<BlurEffect Radius="{Binding SetBlurValue}"/>
</TextBlock.Effect>
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index 4080bef8..9a59a16d 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -19,8 +19,8 @@ namespace GTweak.View
{
public partial class DataSystemView : UserControl
{
- private readonly MonitoringSystem monitoringSystem = new MonitoringSystem();
- private readonly SystemDiagnostics systemDiagnostics = new SystemDiagnostics();
+ private readonly MonitoringService _monitoringService = new MonitoringService();
+ private readonly SystemDiagnostics _systemDiagnostics = new SystemDiagnostics();
private readonly DispatcherTimer _timer = default;
private TimeSpan _time = TimeSpan.FromSeconds(0);
@@ -28,6 +28,12 @@ namespace GTweak.View
{
InitializeComponent();
+ _monitoringService.HandleDevicesEvents += OnHandleDevicesEvents;
+ _monitoringService.StartDeviceMonitoring();
+
+ RAMLoad.Value = _monitoringService.GetMemoryUsage;
+ CPULoad.Value = MonitoringService.GetProcessorUsage;
+
App.LanguageChanged += delegate
{
if (new Dictionary<SystemDiagnostics.ConnectionStatus, string>
@@ -44,17 +50,13 @@ namespace GTweak.View
if ((int)_time.TotalSeconds % 2 == 0)
{
BackgroundQueue backgroundQueue = new BackgroundQueue();
- await backgroundQueue.QueueTask(async delegate
- {
- systemDiagnostics.UpdatingDevicesData();
- await monitoringSystem.GetTotalProcessorUsage();
- });
+ await backgroundQueue.QueueTask(async delegate { await _monitoringService.GetTotalProcessorUsage(); });
AnimationProgressBars();
}
else if ((int)_time.TotalSeconds % 5 == 0)
{
BackgroundQueue backgroundQueue = new BackgroundQueue();
- await backgroundQueue.QueueTask(delegate { systemDiagnostics.GetUserIpAddress(); });
+ await backgroundQueue.QueueTask(delegate { _systemDiagnostics.GetUserIpAddress(); });
DataContext = new DataSystemVM();
}
@@ -69,9 +71,6 @@ namespace GTweak.View
_time = _time.Add(TimeSpan.FromSeconds(+1));
}, Application.Current.Dispatcher);
_timer.Start();
-
- RAMLoad.Value = monitoringSystem.GetMemoryUsage;
- CPULoad.Value = MonitoringSystem.GetProcessorUsage;
}
#region Animations
@@ -82,7 +81,7 @@ namespace GTweak.View
DoubleAnimation doubleAnim = new DoubleAnimation()
{
From = CPULoad.Value,
- To = MonitoringSystem.GetProcessorUsage,
+ To = MonitoringService.GetProcessorUsage,
EasingFunction = new QuadraticEase(),
Duration = TimeSpan.FromSeconds(0.2)
};
@@ -92,7 +91,7 @@ namespace GTweak.View
doubleAnim = new DoubleAnimation()
{
From = RAMLoad.Value,
- To = monitoringSystem.GetMemoryUsage,
+ To = _monitoringService.GetMemoryUsage,
EasingFunction = new QuadraticEase(),
Duration = TimeSpan.FromSeconds(0.2)
};
@@ -100,7 +99,6 @@ namespace GTweak.View
RAMLoad.BeginAnimation(ProgressBar.ValueProperty, doubleAnim);
});
}
-
private void AnimationPopup()
{
Dispatcher.Invoke(() =>
@@ -137,7 +135,13 @@ namespace GTweak.View
IpAddress.Effect.BeginAnimation(BlurEffect.RadiusProperty, doubleAnim);
}
- private void TextComputerData_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+ private async void OnHandleDevicesEvents(MonitoringService.DeviceType deviceType)
+ {
+ BackgroundQueue backgroundQueue = new BackgroundQueue();
+ await backgroundQueue.QueueTask(delegate { _systemDiagnostics.UpdatingDevicesData(deviceType); });
+ }
+
+ private void HandleCopyingData_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
@@ -178,6 +182,10 @@ namespace GTweak.View
}
}
- private void Page_Unloaded(object sender, RoutedEventArgs e) => _timer.Stop();
+ private void Page_Unloaded(object sender, RoutedEventArgs e)
+ {
+ _monitoringService.StopDeviceMonitoring();
+ _timer.Stop();
+ }
}
}
diff --git a/.Source/GTweak/View/InterfaceView.xaml.cs b/.Source/GTweak/View/InterfaceView.xaml.cs
index 996b2668..9e689196 100644
--- a/.Source/GTweak/View/InterfaceView.xaml.cs
+++ b/.Source/GTweak/View/InterfaceView.xaml.cs
@@ -15,7 +15,7 @@ namespace GTweak.View
{
public partial class InterfaceView : UserControl
{
- private readonly InterfaceTweaks intfTweaks = new InterfaceTweaks();
+ private readonly InterfaceTweaks _intfTweaks = new InterfaceTweaks();
public InterfaceView()
{
@@ -76,10 +76,10 @@ namespace GTweak.View
if (NotificationManager.IntfActions.TryGetValue(toggleButton.Name, out string action))
new NotificationManager(300).Show(action);
- Parallel.Invoke(async delegate { await Task.Delay(1000); intfTweaks.AnalyzeAndUpdate(this); });
+ Parallel.Invoke(async delegate { await Task.Delay(1000); _intfTweaks.AnalyzeAndUpdate(this); });
}
- private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => intfTweaks.AnalyzeAndUpdate(this));
+ private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => _intfTweaks.AnalyzeAndUpdate(this));
}
}
diff --git a/.Source/GTweak/View/ServicesView.xaml.cs b/.Source/GTweak/View/ServicesView.xaml.cs
index 4e67e1f8..76f5d2f8 100644
--- a/.Source/GTweak/View/ServicesView.xaml.cs
+++ b/.Source/GTweak/View/ServicesView.xaml.cs
@@ -10,7 +10,7 @@ namespace GTweak.View
{
public partial class ServicesView : UserControl
{
- private readonly ServicesTweaks svcTweaks = new ServicesTweaks();
+ private readonly ServicesTweaks _svcTweaks = new ServicesTweaks();
public ServicesView()
{
@@ -37,9 +37,9 @@ namespace GTweak.View
new NotificationManager(300).Show("restart");
- Parallel.Invoke(async delegate { await Task.Delay(((ToggleButton)sender).Name.Contains("15") ? 2000 : 1000); svcTweaks.AnalyzeAndUpdate(this); });
+ Parallel.Invoke(async delegate { await Task.Delay(((ToggleButton)sender).Name.Contains("15") ? 2000 : 1000); _svcTweaks.AnalyzeAndUpdate(this); });
}
- private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e) => Parallel.Invoke(() => svcTweaks.AnalyzeAndUpdate(this));
+ private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e) => Parallel.Invoke(() => _svcTweaks.AnalyzeAndUpdate(this));
}
}
diff --git a/.Source/GTweak/View/SystemView.xaml.cs b/.Source/GTweak/View/SystemView.xaml.cs
index 480b8e8d..142f7077 100644
--- a/.Source/GTweak/View/SystemView.xaml.cs
+++ b/.Source/GTweak/View/SystemView.xaml.cs
@@ -11,7 +11,7 @@ namespace GTweak.View
{
public partial class SystemView : UserControl
{
- private readonly SystemTweaks sysTweaks = new SystemTweaks();
+ private readonly SystemTweaks _sysTweaks = new SystemTweaks();
public SystemView()
{
@@ -52,12 +52,12 @@ namespace GTweak.View
if (NotificationManager.SysActions.TryGetValue(toggleButton.Name, out string action))
new NotificationManager(300).Show(action);
- Parallel.Invoke(async delegate { await Task.Delay(1000); sysTweaks.AnalyzeAndUpdate(this); });
+ Parallel.Invoke(async delegate { await Task.Delay(1000); _sysTweaks.AnalyzeAndUpdate(this); });
}
else
SystemTweaks.ApplyTweaks(toggleButton.Name, toggleButton.State);
}
- private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => sysTweaks.AnalyzeAndUpdate(this));
+ private void Page_Loaded(object sender, RoutedEventArgs e) => Parallel.Invoke(() => _sysTweaks.AnalyzeAndUpdate(this));
}
}
diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.cs
index dbe84d3e..0584e9fb 100644
--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs
+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs
@@ -17,8 +17,8 @@ namespace GTweak.Windows
public partial class ImportWindow : Window
{
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
- private readonly HashSet<string> requiredActions = new HashSet<string>();
- private bool isExpRestartNeed = false;
+ private readonly HashSet<string> _requiredActions = new HashSet<string>();
+ private bool _isExpRestartNeed = false;
public ImportWindow(in string importedFile)
{
@@ -43,12 +43,12 @@ namespace GTweak.Windows
{
if (valueProgress == 100)
{
- if (isExpRestartNeed)
+ if (_isExpRestartNeed)
ExplorerManager.Restart(new Process());
- if (requiredActions.Contains("restart"))
+ if (_requiredActions.Contains("restart"))
new NotificationManager().Show("restart");
- else if (requiredActions.Contains("logout"))
+ else if (_requiredActions.Contains("logout"))
new NotificationManager().Show("logout");
App.UpdateImport();
@@ -100,7 +100,7 @@ namespace GTweak.Windows
SystemTweaks.ApplyTweaksSlider(tweak, Convert.ToUInt32(value));
foreach (var act in NotificationManager.SysActions.Where(get => get.Key == tweak))
- requiredActions.Add(act.Value);
+ _requiredActions.Add(act.Value);
}
else
{
@@ -111,14 +111,14 @@ namespace GTweak.Windows
if (NotificationActions != null)
{
foreach (var act in NotificationActions.Where(get => get.Key == tweak))
- requiredActions.Add(act.Value);
+ _requiredActions.Add(act.Value);
}
if (ExplorerMapping != null && ExplorerMapping.Any(get => get.Key == tweak && get.Value == true))
- isExpRestartNeed = true;
+ _isExpRestartNeed = true;
if (section == INIManager.SectionSvc)
- requiredActions.Add("restart");
+ _requiredActions.Add("restart");
}
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index 05894aa7..9bc2f3c2 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -59,7 +59,7 @@ namespace GTweak.Windows
() => ExecuteWithLogging(new SystemTweaks().ViewConfigTick, nameof(SystemTweaks.ViewConfigTick))
);
- ExecuteWithLogging(() => new MonitoringSystem().GetTotalProcessorUsage().GetAwaiter().GetResult(), nameof(MonitoringSystem.GetTotalProcessorUsage));
+ ExecuteWithLogging(() => new MonitoringService().GetTotalProcessorUsage().GetAwaiter().GetResult(), nameof(MonitoringService.GetTotalProcessorUsage));
}
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 5b5958f4..b9e7fbf3 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -28,7 +28,7 @@ namespace GTweak
LanguageSelectionMenu.SelectedIndex = GetSelectedIndex(SettingsEngine.Language, "en", SettingsEngine.AvailableLangs);
ThemeSelectionMenu.SelectedIndex = GetSelectedIndex(SettingsEngine.Theme, "Dark", SettingsEngine.AvailableThemes);
- App.ImportTweaksUpdate += delegate { BtnMore.IsChecked = true; };
+ App.TweaksImported += delegate { BtnMore.IsChecked = true; };
App.ThemeChanged += delegate { Close(); new RebootWindow().ShowDialog(); };
}
@@ -41,7 +41,7 @@ namespace GTweak
#region Button Title/Animation Window
private void ButtonHelp_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) => Process.Start(new ProcessStartInfo("https://github.com/Greedeks/GTweak/issues/new/choose") { UseShellExecute = true });
- private void SettingsMenuAnimation()
+ private void AnimationSettingsMenu()
{
Dispatcher.Invoke(() =>
{
@@ -80,13 +80,13 @@ namespace GTweak
private void SettingsMenu_QueryCursor(object sender, QueryCursorEventArgs e)
{
if (SettingsMenu.Width == 400)
- SettingsMenuAnimation();
+ AnimationSettingsMenu();
}
private void ButtonSettings_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (SettingsMenu.Width == 0 || SettingsMenu.Width == 400)
- SettingsMenuAnimation();
+ AnimationSettingsMenu();
}
private void ButtonMinimized_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) => WindowState = WindowState.Minimized;
diff --git a/.Source/GTweak/Windows/MessageWindow.xaml.cs b/.Source/GTweak/Windows/MessageWindow.xaml.cs
index 9eabc57e..30666fb5 100644
--- a/.Source/GTweak/Windows/MessageWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MessageWindow.xaml.cs
@@ -11,8 +11,8 @@ namespace GTweak.Windows
{
public partial class MessageWindow
{
- private readonly DispatcherTimer timer;
- private TimeSpan time = TimeSpan.FromSeconds(4);
+ private readonly DispatcherTimer _timer;
+ private TimeSpan _time = TimeSpan.FromSeconds(4);
public MessageWindow(bool isViolationSystem = false)
{
@@ -20,16 +20,16 @@ namespace GTweak.Windows
try
{
- timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
+ _timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
- BtnAccept.Content = $"{new Regex("[(05)(04)(03)(02)]").Replace(BtnAccept.Content.ToString(), "")}({time:ss})";
- if (time == TimeSpan.Zero) { timer?.Stop(); Application.Current.Shutdown(); }
- time = time.Add(TimeSpan.FromSeconds(-1));
+ BtnAccept.Content = $"{new Regex("[(05)(04)(03)(02)]").Replace(BtnAccept.Content.ToString(), "")}({_time:ss})";
+ if (_time == TimeSpan.Zero) { _timer?.Stop(); Application.Current.Shutdown(); }
+ _time = _time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- timer?.Start();
+ _timer?.Start();
if (isViolationSystem)
{
diff --git a/.Source/GTweak/Windows/NotificationWindow.xaml.cs b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
index 39e7d499..62c7c721 100644
--- a/.Source/GTweak/Windows/NotificationWindow.xaml.cs
+++ b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
@@ -14,8 +14,8 @@ namespace GTweak.Windows
{
public partial class NotificationWindow
{
- private readonly DispatcherTimer timer;
- private TimeSpan time = TimeSpan.FromSeconds(3);
+ private readonly DispatcherTimer _timer;
+ private TimeSpan _time = TimeSpan.FromSeconds(3);
private string clickAction = string.Empty;
internal string TitleNotice { set => TitleSet.Text = value; get => TitleSet.Text; }
@@ -26,13 +26,13 @@ namespace GTweak.Windows
{
InitializeComponent();
- timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
+ _timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
- if (time == TimeSpan.Zero) { timer.Stop(); Close(); }
- time = time.Add(TimeSpan.FromSeconds(-1));
+ if (_time == TimeSpan.Zero) { _timer.Stop(); Close(); }
+ _time = _time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
- timer.Start();
+ _timer.Start();
}
private void BtnExit_PreviewMouseDown(object sender, MouseButtonEventArgs e)