Skip to content

Commit ef9f946

Browse files
committed
Code quality
1 parent 1191656 commit ef9f946

File tree

4 files changed

+53
-38
lines changed

4 files changed

+53
-38
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Globalization;
45
using System.Runtime.InteropServices;
@@ -488,5 +489,56 @@ or PInvoke.LOCALE_TRANSIENT_KEYBOARD3
488489
}
489490

490491
#endregion
492+
493+
#region Window Freeze
494+
495+
public static Dictionary<UIElement, CacheMode> ClearAllCacheModes(DependencyObject parent)
496+
{
497+
Dictionary<UIElement, CacheMode> cacheModes = new();
498+
499+
foreach (var element in FindVisualChildren<UIElement>(parent))
500+
{
501+
if (element.CacheMode is null) continue;
502+
503+
System.Diagnostics.Debug.WriteLine($"CacheMode Changed: {GetElementName(element)}{element.CacheMode.GetType().Name}");
504+
505+
// Store the previous CacheMode value
506+
cacheModes[element] = element.CacheMode.Clone();
507+
508+
// Set the CacheMode to null
509+
element.CacheMode = null;
510+
}
511+
512+
return cacheModes;
513+
}
514+
515+
private static string GetElementName(UIElement element)
516+
{
517+
if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name)) return fe.Name;
518+
return element.GetType().Name;
519+
}
520+
521+
private static IEnumerable<T> FindVisualChildren<T>(DependencyObject parent) where T : DependencyObject
522+
{
523+
if (parent != null)
524+
{
525+
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
526+
{
527+
var child = VisualTreeHelper.GetChild(parent, i);
528+
529+
if (child is T t)
530+
{
531+
yield return t;
532+
}
533+
534+
foreach (var childOfChild in FindVisualChildren<T>(child))
535+
{
536+
yield return childOfChild;
537+
}
538+
}
539+
}
540+
}
541+
542+
#endregion
491543
}
492544
}

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
275275
DependencyPropertyDescriptor
276276
.FromProperty(VisibilityProperty, typeof(StackPanel))
277277
.AddValueChanged(History, (s, e) => UpdateClockPanelVisibility());
278-
_viewModel.ClearAllCacheModes(this);
279278
}
280279

281280
private async void OnClosing(object sender, CancelEventArgs e)

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Windows;
33
using System.Windows.Forms;
44
using System.Windows.Input;
5-
using System.Windows.Interop;
65
using CommunityToolkit.Mvvm.DependencyInjection;
76
using Flow.Launcher.Infrastructure;
87
using Flow.Launcher.Infrastructure.UserSettings;
@@ -34,6 +33,7 @@ public SettingWindow()
3433
private void OnLoaded(object sender, RoutedEventArgs e)
3534
{
3635
RefreshMaximizeRestoreButton();
36+
3737
// Fix (workaround) for the window freezes after lock screen (Win+L) or sleep
3838
// https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
3939
//HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using System.Diagnostics;
54
using System.Globalization;
65
using System.Linq;
76
using System.Text;
@@ -1479,38 +1478,6 @@ public bool ShouldIgnoreHotkeys()
14791478

14801479
#region Public Methods
14811480

1482-
public void ClearAllCacheModes(DependencyObject element)
1483-
{
1484-
if (element == null)
1485-
return;
1486-
1487-
// 현재 요소의 CacheMode를 확인하고 제거
1488-
if (element is UIElement uiElement && uiElement.CacheMode != null)
1489-
{
1490-
string elementName = GetElementName(uiElement);
1491-
Debug.WriteLine($"CacheMode 제거: {elementName} - CacheMode 타입: {uiElement.CacheMode.GetType().Name}");
1492-
uiElement.CacheMode = null;
1493-
}
1494-
1495-
// 모든 자식 요소에 대해 재귀적으로 CacheMode 제거
1496-
int childCount = VisualTreeHelper.GetChildrenCount(element);
1497-
for (int i = 0; i < childCount; i++)
1498-
{
1499-
DependencyObject child = VisualTreeHelper.GetChild(element, i);
1500-
ClearAllCacheModes(child);
1501-
}
1502-
}
1503-
1504-
private string GetElementName(UIElement element)
1505-
{
1506-
// 요소의 이름 가져오기 시도
1507-
if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name))
1508-
return fe.Name;
1509-
1510-
// 이름이 없으면 타입 반환
1511-
return element.GetType().Name;
1512-
}
1513-
15141481
#pragma warning disable VSTHRD100 // Avoid async void methods
15151482

15161483
public void Show()
@@ -1539,9 +1506,6 @@ public void Show()
15391506
{
15401507
SearchIconVisibility = Visibility.Visible;
15411508
}
1542-
1543-
// Clear all cache modes
1544-
ClearAllCacheModes(mainWindow);
15451509
}
15461510
}, DispatcherPriority.Render);
15471511

0 commit comments

Comments
 (0)