From 89e03d695a56cef83e1da95d9777b8c114c3ae52 Mon Sep 17 00:00:00 2001 From: DB p Date: Wed, 26 Mar 2025 13:58:01 +0900 Subject: [PATCH 1/3] Remove Cachemode --- Flow.Launcher/MainWindow.xaml.cs | 3 ++- Flow.Launcher/SettingWindow.xaml.cs | 6 ++--- Flow.Launcher/ViewModel/MainViewModel.cs | 34 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 136440a6547..026eda4adf5 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -96,7 +96,7 @@ private void OnSourceInitialized(object sender, EventArgs e) Win32Helper.HideFromAltTab(this); Win32Helper.DisableControlBox(this); } - + private async void OnLoaded(object sender, RoutedEventArgs _) { // Check first launch @@ -236,6 +236,7 @@ private async void OnLoaded(object sender, RoutedEventArgs _) DependencyPropertyDescriptor .FromProperty(VisibilityProperty, typeof(StackPanel)) // History는 StackPanel이라고 가정 .AddValueChanged(History, (s, e) => UpdateClockPanelVisibility()); + _viewModel.ClearAllCacheModes(this); } private async void OnClosing(object sender, CancelEventArgs e) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 28140f0245c..75d770a5be0 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -36,9 +36,9 @@ private void OnLoaded(object sender, RoutedEventArgs e) RefreshMaximizeRestoreButton(); // Fix (workaround) for the window freezes after lock screen (Win+L) or sleep // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf - HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; - HwndTarget hwndTarget = hwndSource.CompositionTarget; - hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here + //HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; + //HwndTarget hwndTarget = hwndSource.CompositionTarget; + //hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here InitializePosition(); } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 258ba3abf57..ced2f1910dd 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics; using System.Globalization; using System.Windows.Input; using System.Linq; @@ -1428,7 +1429,36 @@ public bool ShouldIgnoreHotkeys() #endregion #region Public Methods + public void ClearAllCacheModes(DependencyObject element) + { + if (element == null) + return; + // 현재 요소의 CacheMode를 확인하고 제거 + if (element is UIElement uiElement && uiElement.CacheMode != null) + { + string elementName = GetElementName(uiElement); + Debug.WriteLine($"CacheMode 제거: {elementName} - CacheMode 타입: {uiElement.CacheMode.GetType().Name}"); + uiElement.CacheMode = null; + } + + // 모든 자식 요소에 대해 재귀적으로 CacheMode 제거 + int childCount = VisualTreeHelper.GetChildrenCount(element); + for (int i = 0; i < childCount; i++) + { + DependencyObject child = VisualTreeHelper.GetChild(element, i); + ClearAllCacheModes(child); + } + } + private string GetElementName(UIElement element) + { + // 요소의 이름 가져오기 시도 + if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name)) + return fe.Name; + + // 이름이 없으면 타입 반환 + return element.GetType().Name; + } public void Show() { Application.Current.Dispatcher.Invoke(() => @@ -1442,6 +1472,7 @@ public void Show() mainWindow.ClockPanel.Visibility = Visibility.Visible; //mainWindow.SearchIcon.Visibility = Visibility.Visible; SearchIconVisibility = Visibility.Visible; + ClearAllCacheModes(mainWindow); } // Update WPF properties @@ -1454,8 +1485,11 @@ public void Show() { Win32Helper.SwitchToEnglishKeyboardLayout(true); } + }); } + + #pragma warning disable VSTHRD100 // Avoid async void methods From ef9f946a12f13161ad81e7478cc448ec0868aaed Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 1 Apr 2025 15:46:13 +0800 Subject: [PATCH 2/3] Code quality --- Flow.Launcher.Infrastructure/Win32Helper.cs | 52 +++++++++++++++++++++ Flow.Launcher/MainWindow.xaml.cs | 1 - Flow.Launcher/SettingWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 36 -------------- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 7a3a0c36e26..e120f165055 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Runtime.InteropServices; @@ -488,5 +489,56 @@ or PInvoke.LOCALE_TRANSIENT_KEYBOARD3 } #endregion + + #region Window Freeze + + public static Dictionary ClearAllCacheModes(DependencyObject parent) + { + Dictionary cacheModes = new(); + + foreach (var element in FindVisualChildren(parent)) + { + if (element.CacheMode is null) continue; + + System.Diagnostics.Debug.WriteLine($"CacheMode Changed: {GetElementName(element)}{element.CacheMode.GetType().Name}"); + + // Store the previous CacheMode value + cacheModes[element] = element.CacheMode.Clone(); + + // Set the CacheMode to null + element.CacheMode = null; + } + + return cacheModes; + } + + private static string GetElementName(UIElement element) + { + if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name)) return fe.Name; + return element.GetType().Name; + } + + private static IEnumerable FindVisualChildren(DependencyObject parent) where T : DependencyObject + { + if (parent != null) + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) + { + var child = VisualTreeHelper.GetChild(parent, i); + + if (child is T t) + { + yield return t; + } + + foreach (var childOfChild in FindVisualChildren(child)) + { + yield return childOfChild; + } + } + } + } + + #endregion } } diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 058b845e37a..5fbe3748961 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -275,7 +275,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _) DependencyPropertyDescriptor .FromProperty(VisibilityProperty, typeof(StackPanel)) .AddValueChanged(History, (s, e) => UpdateClockPanelVisibility()); - _viewModel.ClearAllCacheModes(this); } private async void OnClosing(object sender, CancelEventArgs e) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 75d770a5be0..b5a6a117f34 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -2,7 +2,6 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; -using System.Windows.Interop; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; @@ -34,6 +33,7 @@ public SettingWindow() private void OnLoaded(object sender, RoutedEventArgs e) { RefreshMaximizeRestoreButton(); + // Fix (workaround) for the window freezes after lock screen (Win+L) or sleep // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf //HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index be71a7709e3..12c65771b81 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; @@ -1479,38 +1478,6 @@ public bool ShouldIgnoreHotkeys() #region Public Methods - public void ClearAllCacheModes(DependencyObject element) - { - if (element == null) - return; - - // 현재 요소의 CacheMode를 확인하고 제거 - if (element is UIElement uiElement && uiElement.CacheMode != null) - { - string elementName = GetElementName(uiElement); - Debug.WriteLine($"CacheMode 제거: {elementName} - CacheMode 타입: {uiElement.CacheMode.GetType().Name}"); - uiElement.CacheMode = null; - } - - // 모든 자식 요소에 대해 재귀적으로 CacheMode 제거 - int childCount = VisualTreeHelper.GetChildrenCount(element); - for (int i = 0; i < childCount; i++) - { - DependencyObject child = VisualTreeHelper.GetChild(element, i); - ClearAllCacheModes(child); - } - } - - private string GetElementName(UIElement element) - { - // 요소의 이름 가져오기 시도 - if (element is FrameworkElement fe && !string.IsNullOrEmpty(fe.Name)) - return fe.Name; - - // 이름이 없으면 타입 반환 - return element.GetType().Name; - } - #pragma warning disable VSTHRD100 // Avoid async void methods public void Show() @@ -1539,9 +1506,6 @@ public void Show() { SearchIconVisibility = Visibility.Visible; } - - // Clear all cache modes - ClearAllCacheModes(mainWindow); } }, DispatcherPriority.Render); From 1816e3aa312e4d0de311a8351515dabf2166024c Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 7 Apr 2025 21:48:55 +0800 Subject: [PATCH 3/3] Fix build issue --- Flow.Launcher.Infrastructure/Win32Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 516214c839a..32c0c70fe2e 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -566,8 +566,8 @@ private static IEnumerable FindVisualChildren(DependencyObject parent) whe } } } + } #endregion - } }