mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[Peek] Fix first preview stuck loading (#29183)
* fix first preview stuck loading * comment
This commit is contained in:
committed by
GitHub
parent
6a9d44fb4d
commit
8b92789f78
@@ -9,6 +9,7 @@ using Microsoft.UI.Xaml;
|
||||
using Peek.Common.Helpers;
|
||||
using Peek.Common.Models;
|
||||
using Peek.UI.Models;
|
||||
using Windows.Win32.Foundation;
|
||||
|
||||
namespace Peek.UI
|
||||
{
|
||||
@@ -40,11 +41,11 @@ namespace Peek.UI
|
||||
NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
public void Initialize(HWND foregroundWindowHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
Items = NeighboringItemsQuery.GetNeighboringItems();
|
||||
Items = NeighboringItemsQuery.GetNeighboringItems(foregroundWindowHandle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -85,20 +85,24 @@ namespace Peek.UI
|
||||
/// </summary>
|
||||
private void OnPeekHotkey()
|
||||
{
|
||||
// Need to read the foreground HWND before activating Peek to avoid focus stealing
|
||||
// Foreground HWND must always be Explorer or Desktop
|
||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
||||
|
||||
// First Peek activation
|
||||
if (!activated)
|
||||
{
|
||||
Activate();
|
||||
Initialize();
|
||||
Initialize(foregroundWindowHandle);
|
||||
activated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (AppWindow.IsVisible)
|
||||
{
|
||||
if (IsNewSingleSelectedItem())
|
||||
if (IsNewSingleSelectedItem(foregroundWindowHandle))
|
||||
{
|
||||
Initialize();
|
||||
Initialize(foregroundWindowHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,7 +111,7 @@ namespace Peek.UI
|
||||
}
|
||||
else
|
||||
{
|
||||
Initialize();
|
||||
Initialize(foregroundWindowHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +130,12 @@ namespace Peek.UI
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
private void Initialize(Windows.Win32.Foundation.HWND foregroundWindowHandle)
|
||||
{
|
||||
var bootTime = new System.Diagnostics.Stopwatch();
|
||||
bootTime.Start();
|
||||
|
||||
ViewModel.Initialize();
|
||||
ViewModel.Initialize(foregroundWindowHandle);
|
||||
ViewModel.ScalingFactor = this.GetMonitorScale();
|
||||
|
||||
bootTime.Stop();
|
||||
@@ -156,6 +160,7 @@ namespace Peek.UI
|
||||
private void FilePreviewer_PreviewSizeChanged(object sender, PreviewSizeChangedArgs e)
|
||||
{
|
||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
||||
|
||||
var monitorSize = foregroundWindowHandle.GetMonitorSize();
|
||||
var monitorScale = foregroundWindowHandle.GetMonitorScale();
|
||||
|
||||
@@ -210,12 +215,10 @@ namespace Peek.UI
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
private bool IsNewSingleSelectedItem()
|
||||
private bool IsNewSingleSelectedItem(Windows.Win32.Foundation.HWND foregroundWindowHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
||||
|
||||
var selectedItems = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle);
|
||||
var selectedItemsCount = selectedItems?.GetCount() ?? 0;
|
||||
if (selectedItems == null || selectedItemsCount == 0 || selectedItemsCount > 1)
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Peek.Common.Models;
|
||||
using Peek.UI.Extensions;
|
||||
using Peek.UI.Helpers;
|
||||
using Peek.UI.Models;
|
||||
|
||||
@@ -16,10 +13,8 @@ namespace Peek.UI
|
||||
[ObservableProperty]
|
||||
private bool isMultipleFilesActivation;
|
||||
|
||||
public NeighboringItems? GetNeighboringItems()
|
||||
public NeighboringItems? GetNeighboringItems(Windows.Win32.Foundation.HWND foregroundWindowHandle)
|
||||
{
|
||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
||||
|
||||
var selectedItemsShellArray = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle);
|
||||
var selectedItemsCount = selectedItemsShellArray?.GetCount() ?? 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user