Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix invalid handle crash on app removal & overlaydialog has been moved to a separate class
Greedeksb31f317a19be
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csprojindex 9b9b78c0..1ac75a6f 100644--- a/.Source/GTweak/GTweak.csproj+++ b/.Source/GTweak/GTweak.csproj@@ -276,6 +276,7 @@<Compile Include="Utilities\Helpers\DisablingWinKeys.cs" /><Compile Include="Utilities\Helpers\CommandExecutor.cs" /><Compile Include="Utilities\Managers\ExplorerManager.cs" />+ <Compile Include="Utilities\Managers\OverlayDialogManager.cs" /><Compile Include="Utilities\Managers\TimerControlManager.cs" /><Compile Include="Utilities\Storage\WinKeyStorage.cs" /><Compile Include="Utilities\Managers\TaskSchedulerManager.cs" />diff --git a/.Source/GTweak/Utilities/Managers/OverlayDialogManager.cs b/.Source/GTweak/Utilities/Managers/OverlayDialogManager.csnew file mode 100644index 00000000..054abef0--- /dev/null+++ b/.Source/GTweak/Utilities/Managers/OverlayDialogManager.cs@@ -0,0 +1,66 @@+using GTweak.Utilities.Animation;+using System;+using System.Threading.Tasks;+using System.Windows;+using System.Windows.Controls;++namespace GTweak.Utilities.Managers+{+ internal sealed class OverlayDialogManager+ {+ private readonly FrameworkElement _overlay;+ private readonly DependencyProperty _opacityProperty;+ private readonly Button _btnPrimary;+ private readonly Button _btnSecondary;+ private readonly Action _onPrimary;+ private readonly Action _onSecondary;++ internal OverlayDialogManager(FrameworkElement overlay, DependencyProperty opacityProperty, Button btnPrimary, Button btnSecondary, Action onPrimary = null, Action onSecondary = null)+ {+ _overlay = overlay;+ _opacityProperty = opacityProperty;+ _btnPrimary = btnPrimary;+ _btnSecondary = btnSecondary;+ _onPrimary = onPrimary;+ _onSecondary = onSecondary;+ }++ internal async Task<bool> Show()+ {+ TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();++ void PrimaryHandler(object s, RoutedEventArgs e)+ {+ tcs.TrySetResult(true);+ _onPrimary?.Invoke();+ Detach();+ }+ void SecondaryHandler(object s, RoutedEventArgs e)+ {+ tcs.TrySetResult(false);+ _onSecondary?.Invoke();+ Detach();+ }++ void Detach()+ {+ _btnPrimary.PreviewMouseLeftButtonDown -= PrimaryHandler;+ _btnSecondary.PreviewMouseLeftButtonDown -= SecondaryHandler;+ }++ _overlay.Visibility = Visibility.Visible;+ _overlay.BeginAnimation(_opacityProperty, FactoryAnimation.CreateIn(0, 1, 0.3));++ _btnPrimary.PreviewMouseLeftButtonDown += PrimaryHandler;+ _btnSecondary.PreviewMouseLeftButtonDown += SecondaryHandler;++ bool result;+ try { result = await tcs.Task; }+ catch (TaskCanceledException) { result = false; }++ _overlay.BeginAnimation(_opacityProperty, FactoryAnimation.CreateTo(0.25, () => { _overlay.Visibility = Visibility.Collapsed; }));++ return result;+ }+ }+}diff --git a/.Source/GTweak/View/MoreView.xaml.cs b/.Source/GTweak/View/MoreView.xaml.csindex 7db17fd5..2d8e6380 100644--- a/.Source/GTweak/View/MoreView.xaml.cs+++ b/.Source/GTweak/View/MoreView.xaml.cs@@ -1,5 +1,4 @@-using GTweak.Utilities.Animation;-using GTweak.Utilities.Configuration;+using GTweak.Utilities.Configuration;using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers;using GTweak.Utilities.Managers;@@ -8,8 +7,6 @@ using GTweak.Windows;using Ookii.Dialogs.Wpf;using System;using System.IO;-using System.Threading.Tasks;-using System.Windows;namespace GTweak.View{@@ -52,34 +49,8 @@ namespace GTweak.View{if (ClearingMemory.IsWinOldExists && !_hasDeclined){- Overlay.Visibility = Visibility.Visible;-- Overlay.BeginAnimation(OpacityProperty, FactoryAnimation.CreateIn(0, 1, 0.3));-- TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();-- void AgreeHandler(object sender, RoutedEventArgs args)- {- tcs.TrySetResult(true);- BtnAgree.PreviewMouseLeftButtonDown -= AgreeHandler;- BtnDecline.PreviewMouseLeftButtonDown -= DeclineHandler;- }-- void DeclineHandler(object sender, RoutedEventArgs args)- {- tcs.TrySetResult(false);- BtnAgree.PreviewMouseLeftButtonDown -= AgreeHandler;- BtnDecline.PreviewMouseLeftButtonDown -= DeclineHandler;- _hasDeclined = true;- }-- BtnAgree.PreviewMouseLeftButtonDown += AgreeHandler;- BtnDecline.PreviewMouseLeftButtonDown += DeclineHandler;-- try { _isWinOldRemoval = await tcs.Task; }- catch (TaskCanceledException) { _isWinOldRemoval = false; }-- Overlay.BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.25, () => { Overlay.Visibility = Visibility.Collapsed; }));+ OverlayDialogManager overlayDialog = new OverlayDialogManager(Overlay, OpacityProperty, BtnAgree, BtnDecline, onSecondary: () => _hasDeclined = true);+ _isWinOldRemoval = await overlayDialog.Show();}BackgroundQueue backgroundQueue = new BackgroundQueue();diff --git a/.Source/GTweak/View/PakagesView.xaml b/.Source/GTweak/View/PakagesView.xamlindex d7838b2d..e76d2e32 100644--- a/.Source/GTweak/View/PakagesView.xaml+++ b/.Source/GTweak/View/PakagesView.xaml@@ -6,7 +6,7 @@xmlns:uc="clr-namespace:GTweak.Assets.UserControl"xmlns:local="clr-namespace:GTweak.View"mc:Ignorable="d" d:DesignHeight="550" d:DesignWidth="1100"- Style="{StaticResource LaunchPage}" Loaded="Page_Loaded" Unloaded="Page_Unloaded">+ Style="{StaticResource LaunchPage}" Loaded="Page_Loaded"><Grid><Grid x:Name="Overlay" Panel.ZIndex="1" Visibility="Collapsed"><Grid Background="{StaticResource Color_Background_Dark}" Opacity="0.9"/>diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.csindex c2e2169a..8cfe357e 100644--- a/.Source/GTweak/View/PakagesView.xaml.cs+++ b/.Source/GTweak/View/PakagesView.xaml.cs@@ -1,5 +1,4 @@-using GTweak.Utilities.Animation;-using GTweak.Utilities.Controls;+using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers;using GTweak.Utilities.Managers;using GTweak.Utilities.Tweaks;@@ -20,7 +19,9 @@ namespace GTweak.View{public partial class PakagesView : UserControl{+ private readonly BackgroundQueue backgroundQueue = new BackgroundQueue();private readonly TimerControlManager timer = default;+private bool _isWebViewRemoval = false;public PakagesView()@@ -33,7 +34,7 @@ namespace GTweak.View{BackgroundWorker backgroundWorker = new BackgroundWorker();backgroundWorker.DoWork += delegate { new UninstallingPakages().LoadInstalledPackages(); };- backgroundWorker.RunWorkerCompleted += delegate { UpdateViewStatePakages(); };+ backgroundWorker.RunWorkerCompleted += delegate { Dispatcher.Invoke(() => { UpdateViewStatePakages(); }); };backgroundWorker.RunWorkerAsync();}});@@ -67,36 +68,10 @@ namespace GTweak.View{if (packageName.Equals("Edge")){- Overlay.Visibility = Visibility.Visible;-- Overlay.BeginAnimation(OpacityProperty, FactoryAnimation.CreateIn(0, 1, 0.3));-- TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();-- void DeleteHandler(object sender, RoutedEventArgs args)- {- tcs.TrySetResult(true);- BtnDelete.PreviewMouseLeftButtonDown -= DeleteHandler;- BtnCancel.PreviewMouseLeftButtonDown -= CancelHandler;- }-- void CancelHandler(object sender, RoutedEventArgs args)- {- tcs.TrySetResult(false);- BtnDelete.PreviewMouseLeftButtonDown -= DeleteHandler;- BtnCancel.PreviewMouseLeftButtonDown -= CancelHandler;- }-- BtnDelete.PreviewMouseLeftButtonDown += DeleteHandler;- BtnCancel.PreviewMouseLeftButtonDown += CancelHandler;-- try { _isWebViewRemoval = await tcs.Task; }- catch (TaskCanceledException) { _isWebViewRemoval = false; }-- Overlay.BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.25, () => { Overlay.Visibility = Visibility.Collapsed; }));+ OverlayDialogManager overlayDialog = new OverlayDialogManager(Overlay, OpacityProperty, BtnDelete, BtnCancel);+ _isWebViewRemoval = await overlayDialog.Show();}- BackgroundQueue backgroundQueue = new BackgroundQueue();await backgroundQueue.QueueTask(async () =>{Dispatcher.Invoke(() =>@@ -113,11 +88,13 @@ namespace GTweak.View{UninstallingPakages.HandleAvailabilityStatus(packageName, false);UpdateViewStatePakages();+ });+ await Dispatcher.BeginInvoke(new Action(() =>+ {if (ExplorerManager.PackageMapping.TryGetValue(packageName, out bool needRestart))ExplorerManager.Restart(new Process());- });-+ }), DispatcherPriority.ApplicationIdle);});break;}@@ -130,7 +107,6 @@ namespace GTweak.View{new NotificationManager().Show("", "info", "success_onedrive_notification");- BackgroundQueue backgroundQueue = new BackgroundQueue();await backgroundQueue.QueueTask(async () =>{@@ -160,8 +136,6 @@ namespace GTweak.Viewprivate void Page_Loaded(object sender, RoutedEventArgs e) => UpdateViewStatePakages();- private void Page_Unloaded(object sender, RoutedEventArgs e) => timer.Stop();-private ImageSource AvailabilityInstalledPackage(string packageName, bool isOneDrive = false){if (!UninstallingPakages.PackagesDetails.TryGetValue(packageName, out var details) || details.Scripts == null)