Skip to content

Portable Tool for an Ideal Windows Setup

add common class for Opacity animation & re

Greedeks3dbee0261307
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index 7778d894..703880e4 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -271,6 +271,7 @@
</Compile>
<Compile Include="Utilities\Controls\BlockRunTweaker.cs" />
<Compile Include="Utilities\Controls\ErrorLogging.cs" />
+ <Compile Include="Utilities\Helpers\Animation\FadeAnimation.cs" />
<Compile Include="Utilities\Helpers\DisablingWinKeys.cs" />
<Compile Include="Utilities\Helpers\CommandExecutor.cs" />
<Compile Include="Utilities\Helpers\Managers\ExplorerManager.cs" />
diff --git a/.Source/GTweak/Utilities/Helpers/Animation/FadeAnimation.cs b/.Source/GTweak/Utilities/Helpers/Animation/FadeAnimation.cs
new file mode 100644
index 00000000..96b41ef6
--- /dev/null
+++ b/.Source/GTweak/Utilities/Helpers/Animation/FadeAnimation.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Windows;
+using System.Windows.Media.Animation;
+
+namespace GTweak.Utilities.Helpers.Animation
+{
+ internal static class FadeAnimation
+ {
+ internal static DoubleAnimation FadeIn(double toValue, double seconds, Action onCompleted = null, bool reverse = false)
+ {
+ DoubleAnimation doubleAnim = new DoubleAnimation()
+ {
+ From = 0,
+ To = toValue,
+ AutoReverse = reverse,
+ Duration = TimeSpan.FromSeconds(seconds),
+ EasingFunction = new QuadraticEase()
+ };
+
+ if (onCompleted != null)
+ doubleAnim.Completed += (s, e) => onCompleted();
+
+ Timeline.SetDesiredFrameRate(doubleAnim, 240);
+ return doubleAnim;
+ }
+
+ internal static DoubleAnimation FadeTo(double seconds, Action onCompleted = null)
+ {
+ DoubleAnimation doubleAnim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(seconds));
+
+ if (onCompleted != null)
+ doubleAnim.Completed += (s, e) => onCompleted();
+
+ Timeline.SetDesiredFrameRate(doubleAnim, 240);
+ return doubleAnim;
+ }
+ }
+}
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index 0708b8d5..211dfca9 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -2,6 +2,7 @@
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using System;
using System.Collections.Generic;
using System.Windows;
@@ -104,19 +105,7 @@ namespace GTweak.View
Dispatcher.Invoke(() =>
{
PopupCopy.IsOpen = true;
-
- DoubleAnimation opacityAnim = new DoubleAnimation()
- {
- From = 0,
- To = 0.9,
- SpeedRatio = 9,
- AutoReverse = true,
- EasingFunction = new QuadraticEase(),
- Duration = TimeSpan.FromSeconds(3)
- };
- opacityAnim.Completed += delegate { PopupCopy.IsOpen = false; };
- Timeline.SetDesiredFrameRate(opacityAnim, 240);
- CopyTextToastBody.BeginAnimation(ContextMenu.OpacityProperty, opacityAnim);
+ CopyTextToastBody.BeginAnimation(ContextMenu.OpacityProperty, FadeAnimation.FadeIn(0.9, 0.27, () => { PopupCopy.IsOpen = false; }, true));
DoubleAnimation offsetAnim = new DoubleAnimation()
{
diff --git a/.Source/GTweak/View/MoreView.xaml.cs b/.Source/GTweak/View/MoreView.xaml.cs
index b289b6d1..4d5d81d2 100644
--- a/.Source/GTweak/View/MoreView.xaml.cs
+++ b/.Source/GTweak/View/MoreView.xaml.cs
@@ -1,6 +1,7 @@
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using GTweak.Utilities.Tweaks;
using GTweak.Windows;
using Ookii.Dialogs.Wpf;
@@ -8,7 +9,6 @@ using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
-using System.Windows.Media.Animation;
namespace GTweak.View
{
@@ -22,20 +22,6 @@ namespace GTweak.View
InitializeComponent();
}
- private void OverlayAnimation(double from, double to, double duration, EventHandler onComplete = null)
- {
- DoubleAnimation doubleAnim = new DoubleAnimation
- {
- From = from,
- To = to,
- Duration = TimeSpan.FromSeconds(duration),
- EasingFunction = new QuadraticEase()
- };
- if (onComplete != null) { doubleAnim.Completed += onComplete; }
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- Overlay.BeginAnimation(OpacityProperty, doubleAnim);
- }
-
private async void BtnLicenseWindows_ClickButton(object sender, EventArgs e)
{
if (WindowsLicense.IsWindowsActivated)
@@ -67,7 +53,7 @@ namespace GTweak.View
{
Overlay.Visibility = Visibility.Visible;
- OverlayAnimation(0, 1, 0.3);
+ Overlay.BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.3));
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
@@ -92,7 +78,7 @@ namespace GTweak.View
try { _isWinOldRemoval = await tcs.Task; }
catch (TaskCanceledException) { _isWinOldRemoval = false; }
- OverlayAnimation(1, 0, 0.25, (s, e) => Overlay.Visibility = Visibility.Collapsed);
+ Overlay.BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.25, () => { Overlay.Visibility = Visibility.Collapsed; }));
}
BackgroundQueue backgroundQueue = new BackgroundQueue();
diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.cs
index 3964c831..05c66f8b 100644
--- a/.Source/GTweak/View/PakagesView.xaml.cs
+++ b/.Source/GTweak/View/PakagesView.xaml.cs
@@ -1,5 +1,6 @@
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using GTweak.Utilities.Helpers.Managers;
using GTweak.Utilities.Tweaks;
using System;
@@ -13,7 +14,6 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
-using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace GTweak.View
@@ -44,20 +44,6 @@ namespace GTweak.View
_timer.Start();
}
- private void OverlayAnimation(double from, double to, double duration, EventHandler onComplete = null)
- {
- DoubleAnimation doubleAnim = new DoubleAnimation
- {
- From = from,
- To = to,
- Duration = TimeSpan.FromSeconds(duration),
- EasingFunction = new QuadraticEase()
- };
- if (onComplete != null) { doubleAnim.Completed += onComplete; }
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- Overlay.BeginAnimation(OpacityProperty, doubleAnim);
- }
-
private void Apps_MouseEnter(object sender, MouseEventArgs e)
{
string descriptionApp = (string)FindResource(((Image)sender).Name + "_applications");
@@ -87,7 +73,7 @@ namespace GTweak.View
{
Overlay.Visibility = Visibility.Visible;
- OverlayAnimation(0, 1, 0.3);
+ Overlay.BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.3));
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
@@ -111,7 +97,7 @@ namespace GTweak.View
try { _isWebViewRemoval = await tcs.Task; }
catch (TaskCanceledException) { _isWebViewRemoval = false; }
- OverlayAnimation(1, 0, 0.25, (s, e) => Overlay.Visibility = Visibility.Collapsed);
+ Overlay.BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.25, () => { Overlay.Visibility = Visibility.Collapsed; }));
}
BackgroundQueue backgroundQueue = new BackgroundQueue();
diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.cs
index 7d1cede2..52378798 100644
--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs
+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs
@@ -1,5 +1,6 @@
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using GTweak.Utilities.Helpers.Managers;
using GTweak.Utilities.Helpers.Storage;
using GTweak.Utilities.Tweaks;
@@ -34,6 +35,7 @@ namespace GTweak.Windows
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.2));
Progress<byte> progress = new Progress<byte>(ReportProgress);
try { await SortByPageDate(_cancellationTokenSource.Token, progress); } catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
@@ -50,7 +52,7 @@ namespace GTweak.Windows
else if (!isRestartNeed && isLogoutNeed)
new ViewNotification().Show("logout");
App.UpdateImport();
- Close();
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
}
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml b/.Source/GTweak/Windows/LoadingWindow.xaml
index 1fd863a6..e882e7c1 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml
@@ -10,7 +10,7 @@
Title="GTweak" WindowStyle="None"
Height="260" Width="260" Background="Transparent" AllowsTransparency="True" WindowStartupLocation="CenterScreen"
ResizeMode="CanMinimize" SnapsToDevicePixels="True" UseLayoutRounding="True"
- IsTabStop="False" Opacity="0.98" ContentRendered="Window_ContentRendered" Closing="Window_Closing">
+ IsTabStop="False" Opacity="0.98" ContentRendered="Window_ContentRendered" Closing="Window_Closing" Loaded="Window_Loaded">
<Window.DataContext>
<vm:MainViewModel/>
</Window.DataContext>
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index a319e965..aca23e48 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -7,7 +7,6 @@ using System;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
-using System.Windows.Media.Animation;
namespace GTweak.Windows
{
@@ -78,9 +77,9 @@ namespace GTweak.Windows
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnim = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));
- doubleAnim.Completed += delegate { Close(); };
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
+
+ private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) => BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.1));
}
}
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index d0291a2d..21f4c4b3 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -103,31 +103,21 @@ namespace GTweak
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.1));
- doubleAnim.Completed += delegate { Close(); };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
- DoubleAnimation doubleAnim = new DoubleAnimation()
- {
- From = 0,
- To = 1,
- Duration = TimeSpan.FromSeconds(0.3),
- EasingFunction = new QuadraticEase()
- };
- doubleAnim.Completed += async delegate
- {
- if (SystemDiagnostics.IsNeedUpdate && SettingsRepository.IsUpdateCheckRequired)
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.3,
+ async () =>
{
- await Task.Delay(500);
- new UpdateWindow().ShowDialog();
- }
- };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+
+ if (SystemDiagnostics.IsNeedUpdate && SettingsRepository.IsUpdateCheckRequired)
+ {
+ await Task.Delay(500);
+ new UpdateWindow().ShowDialog();
+ }
+ }));
new TypewriterAnimation(UtilityTitle.Text, UtilityTitle, TimeSpan.FromSeconds(0.4));
}
#endregion
diff --git a/.Source/GTweak/Windows/MessageWindow.xaml.cs b/.Source/GTweak/Windows/MessageWindow.xaml.cs
index 16f48a14..5ef3f0aa 100644
--- a/.Source/GTweak/Windows/MessageWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MessageWindow.xaml.cs
@@ -1,10 +1,10 @@
using GTweak.Utilities.Controls;
+using GTweak.Utilities.Helpers.Animation;
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
-using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace GTweak.Windows
@@ -54,22 +54,9 @@ namespace GTweak.Windows
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnim = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));
- doubleAnim.Completed += delegate { timer.Stop(); Application.Current.Shutdown(); };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- DoubleAnimation doublAnim = new DoubleAnimation()
- {
- From = 0,
- To = 1,
- Duration = TimeSpan.FromSeconds(0.2)
- };
- Timeline.SetDesiredFrameRate(doublAnim, 240);
- BeginAnimation(OpacityProperty, doublAnim);
- }
+ private void Window_Loaded(object sender, RoutedEventArgs e) => BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.2));
}
}
diff --git a/.Source/GTweak/Windows/NotificationWindow.xaml.cs b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
index ae59ea0e..42ab205e 100644
--- a/.Source/GTweak/Windows/NotificationWindow.xaml.cs
+++ b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
@@ -1,5 +1,6 @@
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using System;
using System.ComponentModel;
using System.Media;
@@ -102,19 +103,12 @@ namespace GTweak.Windows
doubleAnimKeyFrames.KeyFrames.Add(fromFrame);
doubleAnimKeyFrames.KeyFrames.Add(toFrame);
- DoubleAnimation doubleAnim = new DoubleAnimation()
- {
- From = 0,
- To = 1,
- EasingFunction = new QuadraticEase(),
- Duration = TimeSpan.FromSeconds(0.25)
- };
-
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
Timeline.SetDesiredFrameRate(doubleAnimKeyFrames, 240);
BeginAnimation(Canvas.LeftProperty, doubleAnimKeyFrames);
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.25));
+
+
});
}
@@ -122,10 +116,7 @@ namespace GTweak.Windows
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnimation = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));
- doubleAnimation.Completed += delegate { Close(); };
- Timeline.SetDesiredFrameRate(doubleAnimation, 240);
- BeginAnimation(OpacityProperty, doubleAnimation);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
}
}
diff --git a/.Source/GTweak/Windows/RebootWindow.xaml.cs b/.Source/GTweak/Windows/RebootWindow.xaml.cs
index abb7e8c9..7f14ced4 100644
--- a/.Source/GTweak/Windows/RebootWindow.xaml.cs
+++ b/.Source/GTweak/Windows/RebootWindow.xaml.cs
@@ -1,8 +1,7 @@
using GTweak.Utilities.Controls;
-using System;
+using GTweak.Utilities.Helpers.Animation;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Media.Animation;
namespace GTweak.Windows
{
@@ -13,18 +12,6 @@ namespace GTweak.Windows
InitializeComponent();
}
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- DoubleAnimation doubleAnim = new DoubleAnimation()
- {
- From = 0,
- To = 100,
- EasingFunction = new QuadraticEase(),
- Duration = TimeSpan.FromSeconds(1.5)
- };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- doubleAnim.Completed += delegate { SettingsRepository.SelfReboot(); };
- RestartProgress.BeginAnimation(ProgressBar.ValueProperty, doubleAnim);
- }
+ private void Window_Loaded(object sender, RoutedEventArgs e) => RestartProgress.BeginAnimation(ProgressBar.ValueProperty, FadeAnimation.FadeIn(1, 1.5, () => { SettingsRepository.SelfReboot(); }));
}
}
diff --git a/.Source/GTweak/Windows/UpdateWindow.xaml.cs b/.Source/GTweak/Windows/UpdateWindow.xaml.cs
index 4a3e7627..3847edfe 100644
--- a/.Source/GTweak/Windows/UpdateWindow.xaml.cs
+++ b/.Source/GTweak/Windows/UpdateWindow.xaml.cs
@@ -1,13 +1,13 @@
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
using GTweak.Utilities.Helpers;
+using GTweak.Utilities.Helpers.Animation;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Input;
-using System.Windows.Media.Animation;
namespace GTweak.Windows
{
@@ -25,27 +25,13 @@ namespace GTweak.Windows
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
-
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- DoubleAnimation doubleAnim = new DoubleAnimation()
- {
- From = 0,
- To = 1,
- Duration = TimeSpan.FromSeconds(0.3),
- EasingFunction = new QuadraticEase()
- };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- }
+ private void Window_Loaded(object sender, RoutedEventArgs e) => BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.3));
private void Window_Closing(object sender, CancelEventArgs e)
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.1));
- doubleAnim.Completed += delegate { Close(); };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.1, () => { Close(); }));
}
private void BtnExit_PreviewMouseDown(object sender, MouseButtonEventArgs e)
diff --git a/.Source/GTweak/Windows/WaitingWindow.xaml.cs b/.Source/GTweak/Windows/WaitingWindow.xaml.cs
index 1ed64877..91a952a4 100644
--- a/.Source/GTweak/Windows/WaitingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/WaitingWindow.xaml.cs
@@ -1,9 +1,8 @@
using GTweak.Utilities.Helpers;
-using System;
+using GTweak.Utilities.Helpers.Animation;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
-using System.Windows.Media.Animation;
namespace GTweak.Windows
{
@@ -23,16 +22,13 @@ namespace GTweak.Windows
{
Closing -= Window_Closing;
e.Cancel = true;
- DoubleAnimation doubleAnim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.15));
- doubleAnim.Completed += delegate
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeTo(0.15, () =>
{
ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;
disablingWinKeys.objKeyboardProcess = new DisablingWinKeys.LowLevelKeyboardProc(disablingWinKeys.CaptureKey);
disablingWinKeys.ptrHook = DisablingWinKeys.SetWindowsHookEx(13, disablingWinKeys.objKeyboardProcess, DisablingWinKeys.GetModuleHandle(objCurrentModule.ModuleName), 1);
Close();
- };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+ }));
}
private void Window_Loaded(object sender, RoutedEventArgs e)
@@ -40,17 +36,7 @@ namespace GTweak.Windows
ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;
disablingWinKeys.objKeyboardProcess = new DisablingWinKeys.LowLevelKeyboardProc(disablingWinKeys.CaptureKey);
disablingWinKeys.ptrHook = DisablingWinKeys.SetWindowsHookEx(13, disablingWinKeys.objKeyboardProcess, DisablingWinKeys.GetModuleHandle(objCurrentModule.ModuleName), 0);
-
- DoubleAnimation doubleAnim = new DoubleAnimation()
- {
- From = 0,
- To = 0.5,
- SpeedRatio = 2,
- EasingFunction = new PowerEase(),
- Duration = TimeSpan.FromSeconds(0.3)
- };
- Timeline.SetDesiredFrameRate(doubleAnim, 240);
- BeginAnimation(OpacityProperty, doubleAnim);
+ BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(0.5, 0.3));
}
}
}