Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
ref. move DataSystemView logic to ViewModel
Greedeks872d11a2d902
diff --git a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.csindex 83cecb69..18246fba 100644--- a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs+++ b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs@@ -50,13 +50,18 @@ namespace GTweak.Assets.UserControlsLoaded += delegate{+ App.LanguageChanged += OnLanguageChanged;if (FunctionDescription != null){TypewriterAnimation.Create(DefaultText, FunctionDescription, TimeSpan.FromMilliseconds(300));}};- Unloaded += delegate { _scrollCts?.Cancel(); };+ Unloaded += delegate+ {+ App.LanguageChanged -= OnLanguageChanged;+ _scrollCts?.Cancel();+ };App.LanguageChanged += delegate{@@ -68,6 +73,14 @@ namespace GTweak.Assets.UserControls};}+ private void OnLanguageChanged(object sender, EventArgs e)+ {+ _scrollCts?.Cancel();+ if (FunctionDescription != null)+ {+ TypewriterAnimation.Create(DefaultText, FunctionDescription, TimeSpan.Zero);+ }+ }private async Task StartAutoScrollAsync(string text, CancellationToken token){diff --git a/.Source/GTweak/Core/Model/DataSystemModel.cs b/.Source/GTweak/Core/Model/DataSystemModel.csindex 04c67166..2ac635c6 100644--- a/.Source/GTweak/Core/Model/DataSystemModel.cs+++ b/.Source/GTweak/Core/Model/DataSystemModel.cs@@ -1,12 +1,29 @@-using System.Windows;+using System.Windows;+using GTweak.Core.Base;-namespace GTweak.Core.Model+internal sealed class DataSystemModel : ViewModelBase{- internal sealed class DataSystemModel+ private string _data;+ private int _blurValue;+ private Visibility _ipVisibility;++ public string Name { get; set; }++ public string Data+ {+ get => _data;+ set { _data = value; OnPropertyChanged(); }+ }++ public int BlurValue+ {+ get => _blurValue;+ set { _blurValue = value; OnPropertyChanged(); }+ }++ public Visibility IpVisibility{- public string Name { get; set; }- public string Data { get; set; }- internal int BlurValue { get; set; }- internal Visibility IpVisibility { get; set; }+ get => _ipVisibility;+ set { _ipVisibility = value; OnPropertyChanged(); }}-}+}\ No newline at end of filediff --git a/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs b/.Source/GTweak/Core/ViewModel/DataSystemViewModel.csindex 3c0da45a..1a2b1bfa 100644--- a/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs+++ b/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs@@ -3,7 +3,6 @@ using System.Linq;using System.Windows;using System.Windows.Media;using GTweak.Core.Base;-using GTweak.Core.Model;using GTweak.Utilities.Configuration;using GTweak.Utilities.Controls;@@ -59,6 +58,7 @@ namespace GTweak.Core.ViewModel{SettingsEngine.IsHiddenIpAddress = value;OnPropertyChanged();+ RefreshStates();}}}@@ -86,8 +86,44 @@ namespace GTweak.Core.ViewModelCreateModelCollection("IpAddress", HardwareData.UserIPAddress, "connection_lose_sysinfo")};- SetBlurValue = (NetworkProvider.isIPAddressFormatValid && SettingsEngine.IsHiddenIpAddress) ? 20 : 0;- SetVisibility = NetworkProvider.isIPAddressFormatValid ? Visibility.Visible : Visibility.Hidden;+ RefreshStates();+ }++ public void Update()+ {+ UpdateModelData("Storage", HardwareData.Storage, "no_device_information_sysinfo");+ UpdateModelData("Audio", HardwareData.AudioDevice, "driver_not_installed_sysinfo");+ UpdateModelData("Network", HardwareData.NetworkAdapter, "driver_not_installed_sysinfo");+ UpdateModelData("IpAddress", HardwareData.UserIPAddress, "connection_lose_sysinfo");++ RefreshStates();+ }++ private void RefreshStates()+ {+ DataSystemModel ipModel = this["IpAddress"];+ if (ipModel != null)+ {+ if (NetworkProvider.isIPAddressFormatValid || ipModel.Data.Any(char.IsDigit))+ {+ SetBlurValue = SettingsEngine.IsHiddenIpAddress ? 20 : 0;+ SetVisibility = Visibility.Visible;+ }+ else+ {+ SetBlurValue = 0;+ SetVisibility = Visibility.Hidden;+ }+ }+ }++ private void UpdateModelData(string name, string newData, string fallbackResourceKey)+ {+ DataSystemModel model = this[name];+ if (model != null)+ {+ model.Data = !string.IsNullOrEmpty(newData) ? newData : (string)Application.Current.Resources[fallbackResourceKey];+ }}private DataSystemModel CreateModelCollection(string name, object data, string fallbackResourceKey = null)diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csprojindex e5f3ec3d..27705c34 100644--- a/.Source/GTweak/GTweak.csproj+++ b/.Source/GTweak/GTweak.csproj@@ -159,6 +159,7 @@<Compile Include="Core\ViewModel\PackagesViewModel.cs" /><Compile Include="Core\ViewModel\ServicesViewModel.cs" /><Compile Include="Core\ViewModel\SystemViewModel.cs" />+ <Compile Include="Utilities\Animation\BlurAnimation.cs" /><Compile Include="Utilities\Configuration\NetworkProvider.cs" /><Compile Include="Utilities\Configuration\StorageTypeIdentifier.cs" /><Compile Include="Utilities\Configuration\HardwareData.cs" />diff --git a/.Source/GTweak/Utilities/Animation/BlurAnimation.cs b/.Source/GTweak/Utilities/Animation/BlurAnimation.csnew file mode 100644index 00000000..35f7200f--- /dev/null+++ b/.Source/GTweak/Utilities/Animation/BlurAnimation.cs@@ -0,0 +1,31 @@+using System.Windows;+using System.Windows.Media.Effects;++namespace GTweak.Utilities.Animation+{+ internal class BlurAnimation+ {+ internal static readonly DependencyProperty TargetRadiusProperty =+ DependencyProperty.RegisterAttached("TargetRadius", typeof(double), typeof(BlurAnimation), new PropertyMetadata(0.0, OnTargetRadiusChanged));++ internal static double GetTargetRadius(DependencyObject obj) => (double)obj.GetValue(TargetRadiusProperty);+ internal static void SetTargetRadius(DependencyObject obj, double value) => obj.SetValue(TargetRadiusProperty, value);++ private static void OnTargetRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)+ {+ if (d is UIElement element)+ {+ if (!(element.Effect is BlurEffect blurEffect))+ {+ blurEffect = new BlurEffect { Radius = (double)e.OldValue };+ element.Effect = blurEffect;+ }++ double fromValue = (double)e.OldValue;+ double toValue = (double)e.NewValue;++ blurEffect.BeginAnimation(BlurEffect.RadiusProperty, FactoryAnimation.CreateIn(fromValue, toValue, 0.2));+ }+ }+ }+}diff --git a/.Source/GTweak/View/DataSystemView.xaml b/.Source/GTweak/View/DataSystemView.xamlindex 47466878..a4603cc9 100644--- a/.Source/GTweak/View/DataSystemView.xaml+++ b/.Source/GTweak/View/DataSystemView.xaml@@ -333,12 +333,12 @@</Grid></Border><StackPanel Orientation="Horizontal" Margin="5,1,0,0">- <TextBlock x:Name="IpAddress" Text="{Binding [IpAddress].Data}" Style="{StaticResource TextDefault}" HorizontalAlignment="Left" Foreground="{StaticResource Brush_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand">+ <TextBlock x:Name="IpAddress" Text="{Binding [IpAddress].Data}" Style="{StaticResource TextDefault}" HorizontalAlignment="Left" Foreground="{StaticResource Brush_Highlighted}" Height="Auto" Width="Auto" PreviewMouseLeftButtonDown="HandleCopyingData_PreviewMouseDown" Cursor="Hand" anim:BlurAnimation.TargetRadius="{Binding SetBlurValue}"><TextBlock.Effect><BlurEffect Radius="{Binding SetBlurValue}"/></TextBlock.Effect></TextBlock>- <ToggleButton x:Name="BtnVision" Margin="10,0,0,0" Width="24" Height="24" Visibility="{Binding SetVisibility}" VerticalAlignment="Center" Style="{StaticResource TglVision}" IsChecked="{Binding StateButtonVision}" PreviewMouseLeftButtonUp="BtnVision_PreviewMouseLeftButtonUp" PreviewKeyDown="BtnVision_PreviewKeyDown"/>+ <ToggleButton x:Name="BtnVision" Margin="10,0,0,0" Width="24" Height="24" Visibility="{Binding SetVisibility}" VerticalAlignment="Center" Style="{StaticResource TglVision}" IsChecked="{Binding StateButtonVision, Mode=TwoWay}"/></StackPanel></StackPanel>diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.csindex f5743eb4..18243b0c 100644--- a/.Source/GTweak/View/DataSystemView.xaml.cs+++ b/.Source/GTweak/View/DataSystemView.xaml.cs@@ -7,12 +7,10 @@ using System.Windows.Controls.Primitives;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;-using System.Windows.Media.Effects;using GTweak.Core.Base;using GTweak.Core.ViewModel;using GTweak.Utilities.Animation;using GTweak.Utilities.Configuration;-using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers;using GTweak.Utilities.Managers;@@ -28,29 +26,34 @@ namespace GTweak.View{InitializeComponent();- App.LanguageChanged += delegate- {- Dispatcher.BeginInvoke(new Action(() =>- {- if (new Dictionary<HardwareData.ConnectionStatus, string>- {- { HardwareData.ConnectionStatus.Lose, "connection_lose_sysinfo" },- { HardwareData.ConnectionStatus.Block, "connection_block_sysinfo" },- { HardwareData.ConnectionStatus.Limited, "connection_limited_sysinfo" }- }.TryGetValue(HardwareData.CurrentConnection, out string resourceKey))- {- HardwareData.UserIPAddress = (string)FindResource(resourceKey);- DataContext = new DataSystemViewModel();- }- }));- };-- Unloaded += delegate { _timer.Stop(); };Loaded += delegate{+ App.LanguageChanged += OnLanguageChanged;StartMonitoringData();_timer.Start();};+ Unloaded += delegate+ {+ App.LanguageChanged -= OnLanguageChanged;+ _timer.Stop();+ };+ }++ private void OnLanguageChanged(object sender, EventArgs e)+ {+ Dispatcher.BeginInvoke(new Action(() =>+ {+ if (new Dictionary<HardwareData.ConnectionStatus, string>+ {+ { HardwareData.ConnectionStatus.Lose, "connection_lose_sysinfo" },+ { HardwareData.ConnectionStatus.Block, "connection_block_sysinfo" },+ { HardwareData.ConnectionStatus.Limited, "connection_limited_sysinfo" }+ }.TryGetValue(HardwareData.CurrentConnection, out string resourceKey))+ {+ HardwareData.UserIPAddress = (string)FindResource(resourceKey);+ UpdateDataContext();+ }+ }));}private void StartMonitoringData()@@ -62,68 +65,48 @@ namespace GTweak.View{if ((int)time.TotalSeconds % 2 == 0){+ await backgroundQueue.QueueTask(async () =>+ {+ await _hardwareProvider.GetTotalProcessorUsage();+ await _hardwareProvider.GetPhysicalAvailableMemory();+ });++ HardwareData.RunningProcessesCount = await Task.Run(() => _hardwareProvider.GetProcessCount());+ HardwareData.RunningServicesCount = await Task.Run(() => _hardwareProvider.GetServicesCount());- await backgroundQueue.QueueTask(async delegate { await _hardwareProvider.GetTotalProcessorUsage(); });- await backgroundQueue.QueueTask(async delegate { await _hardwareProvider.GetPhysicalAvailableMemory(); });_ = Dispatcher.BeginInvoke(new Action(() =>{AnimateArcProgress(CPULoad, HardwareData.Processor.Usage);AnimateArcProgress(RAMLoad, HardwareData.Memory.Usage);- }));- _ = Dispatcher.BeginInvoke(new Action(async () =>- {- HardwareData.RunningProcessesCount = await Task.Run(() => _hardwareProvider.GetProcessCount());- HardwareData.RunningServicesCount = await Task.Run(() => _hardwareProvider.GetServicesCount());+ UpdateDataContext();}));}- else if ((int)time.TotalSeconds % 5 == 0)+ if ((int)time.TotalSeconds % 5 == 0){await backgroundQueue.QueueTask(async delegate { await _hardwareProvider.GetUserIpAddress(); });- _ = Dispatcher.BeginInvoke(new Action(() => { DataContext = new DataSystemViewModel(); }));}- _ = Dispatcher.BeginInvoke(new Action(() =>- {- if (BtnVision.IsChecked.Value & BtnVision.Visibility == Visibility.Hidden & !NetworkProvider.isIPAddressFormatValid)- {- IpAddress.Effect.BeginAnimation(BlurEffect.RadiusProperty, FactoryAnimation.CreateTo(0.18, () => { SettingsEngine.IsHiddenIpAddress = false; }));- }- }));});}- private void AnimateArcProgress(Wpf.Ui.Controls.Arc arc, double percent) => arc.BeginAnimation(Wpf.Ui.Controls.Arc.EndAngleProperty, FactoryAnimation.CreateIn(arc.EndAngle, percent * 3.6, 0.2, useCubicEase: true));-- private void AnimationPopup()+ private void UpdateDataContext(){- PopupCopy.IsOpen = true;- CopyTextToastBody.BeginAnimation(OpacityProperty, FactoryAnimation.CreateIn(0, 0.9, 0.27, () => { PopupCopy.IsOpen = false; }, true));- PopupCopy.BeginAnimation(Popup.VerticalOffsetProperty, FactoryAnimation.CreateIn(-20, -50, 0.35, useCubicEase: true));- }-- private void BtnVision_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)- {- SettingsEngine.IsHiddenIpAddress = !BtnVision.IsChecked.Value;- IpAddress.Effect.BeginAnimation(BlurEffect.RadiusProperty, BtnVision.IsChecked.Value ? FactoryAnimation.CreateTo(0.2) : FactoryAnimation.CreateIn(0, 20, 0.2));- }-- private void BtnVision_PreviewKeyDown(object sender, KeyEventArgs e)- {- if (e?.Key == Key.Space || e?.Key == Key.Enter)+ if (DataContext as DataSystemViewModel is var vm && vm != null){- e.Handled = true;+ vm.Update();}}+ private void AnimateArcProgress(Wpf.Ui.Controls.Arc arc, double percent) => arc.BeginAnimation(Wpf.Ui.Controls.Arc.EndAngleProperty, FactoryAnimation.CreateIn(arc.EndAngle, percent * 3.6, 0.2, useCubicEase: true));+private void HandleCopyingData_PreviewMouseDown(object sender, MouseButtonEventArgs e){if (e?.LeftButton == MouseButtonState.Pressed){Clipboard.Clear();- switch (sender.GetType().Name)+ switch (sender){- case "TextBlock":+ case TextBlock textBlock:{- TextBlock textBlock = (TextBlock)sender;double cumulativeHeight = 0;string SelectedLine = string.Empty;@@ -142,9 +125,8 @@ namespace GTweak.ViewClipboard.SetData(DataFormats.UnicodeText, SelectedLine);break;}- case "Run":+ case Run runtext:{- Run runtext = (Run)sender;Clipboard.SetData(DataFormats.UnicodeText, runtext.Text.Replace('\n', ' '));break;}@@ -154,7 +136,9 @@ namespace GTweak.Viewif (!PopupCopy.IsOpen){- AnimationPopup();+ PopupCopy.IsOpen = true;+ CopyTextToastBody.BeginAnimation(OpacityProperty, FactoryAnimation.CreateIn(0, 0.9, 0.27, () => { PopupCopy.IsOpen = false; }, true));+ PopupCopy.BeginAnimation(Popup.VerticalOffsetProperty, FactoryAnimation.CreateIn(-20, -50, 0.35, useCubicEase: true));}}}diff --git a/.Source/GTweak/View/PackagesView.xaml.cs b/.Source/GTweak/View/PackagesView.xaml.csindex a7e7b89c..f7300072 100644--- a/.Source/GTweak/View/PackagesView.xaml.cs+++ b/.Source/GTweak/View/PackagesView.xaml.cs@@ -24,11 +24,6 @@ namespace GTweak.View{InitializeComponent();- Unloaded += delegate- {- _timer.Stop();- OverlayDialogManager.Close();- };Loaded += delegate{backgroundWorker.DoWork += delegate { _uninstalling.GetInstalledPackages(); };@@ -47,6 +42,11 @@ namespace GTweak.View_timer.Start();};+ Unloaded += delegate+ {+ _timer.Stop();+ OverlayDialogManager.Close();+ };}private void Package_MouseEnter(object sender, MouseEventArgs e)diff --git a/.Source/GTweak/Windows/MessageWindow.xaml.cs b/.Source/GTweak/Windows/MessageWindow.xaml.csindex 2972115a..afc57457 100644--- a/.Source/GTweak/Windows/MessageWindow.xaml.cs+++ b/.Source/GTweak/Windows/MessageWindow.xaml.cs@@ -22,7 +22,6 @@ namespace GTweak.WindowsInitializeComponent();InitializeMessageContent(type);- Unloaded += delegate { _timer.Stop(); };Loaded += delegate{_timer = new TimerControlManager(TimeSpan.FromSeconds(4), TimerControlManager.TimerMode.CountDown, time =>@@ -31,6 +30,7 @@ namespace GTweak.Windows}, () => Application.Current.Shutdown());_timer.Start();};+ Unloaded += delegate { _timer.Stop(); };}private void InitializeMessageContent(MessageWindowType type)