mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +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.Helpers;
|
||||||
using Peek.Common.Models;
|
using Peek.Common.Models;
|
||||||
using Peek.UI.Models;
|
using Peek.UI.Models;
|
||||||
|
using Windows.Win32.Foundation;
|
||||||
|
|
||||||
namespace Peek.UI
|
namespace Peek.UI
|
||||||
{
|
{
|
||||||
@@ -40,11 +41,11 @@ namespace Peek.UI
|
|||||||
NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs);
|
NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize(HWND foregroundWindowHandle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Items = NeighboringItemsQuery.GetNeighboringItems();
|
Items = NeighboringItemsQuery.GetNeighboringItems(foregroundWindowHandle);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,20 +85,24 @@ namespace Peek.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnPeekHotkey()
|
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
|
// First Peek activation
|
||||||
if (!activated)
|
if (!activated)
|
||||||
{
|
{
|
||||||
Activate();
|
Activate();
|
||||||
Initialize();
|
Initialize(foregroundWindowHandle);
|
||||||
activated = true;
|
activated = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AppWindow.IsVisible)
|
if (AppWindow.IsVisible)
|
||||||
{
|
{
|
||||||
if (IsNewSingleSelectedItem())
|
if (IsNewSingleSelectedItem(foregroundWindowHandle))
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize(foregroundWindowHandle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -107,7 +111,7 @@ namespace Peek.UI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize(foregroundWindowHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,12 +130,12 @@ namespace Peek.UI
|
|||||||
Uninitialize();
|
Uninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize(Windows.Win32.Foundation.HWND foregroundWindowHandle)
|
||||||
{
|
{
|
||||||
var bootTime = new System.Diagnostics.Stopwatch();
|
var bootTime = new System.Diagnostics.Stopwatch();
|
||||||
bootTime.Start();
|
bootTime.Start();
|
||||||
|
|
||||||
ViewModel.Initialize();
|
ViewModel.Initialize(foregroundWindowHandle);
|
||||||
ViewModel.ScalingFactor = this.GetMonitorScale();
|
ViewModel.ScalingFactor = this.GetMonitorScale();
|
||||||
|
|
||||||
bootTime.Stop();
|
bootTime.Stop();
|
||||||
@@ -156,6 +160,7 @@ namespace Peek.UI
|
|||||||
private void FilePreviewer_PreviewSizeChanged(object sender, PreviewSizeChangedArgs e)
|
private void FilePreviewer_PreviewSizeChanged(object sender, PreviewSizeChangedArgs e)
|
||||||
{
|
{
|
||||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
||||||
|
|
||||||
var monitorSize = foregroundWindowHandle.GetMonitorSize();
|
var monitorSize = foregroundWindowHandle.GetMonitorSize();
|
||||||
var monitorScale = foregroundWindowHandle.GetMonitorScale();
|
var monitorScale = foregroundWindowHandle.GetMonitorScale();
|
||||||
|
|
||||||
@@ -210,12 +215,10 @@ namespace Peek.UI
|
|||||||
Uninitialize();
|
Uninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsNewSingleSelectedItem()
|
private bool IsNewSingleSelectedItem(Windows.Win32.Foundation.HWND foregroundWindowHandle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow();
|
|
||||||
|
|
||||||
var selectedItems = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle);
|
var selectedItems = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle);
|
||||||
var selectedItemsCount = selectedItems?.GetCount() ?? 0;
|
var selectedItemsCount = selectedItems?.GetCount() ?? 0;
|
||||||
if (selectedItems == null || selectedItemsCount == 0 || selectedItemsCount > 1)
|
if (selectedItems == null || selectedItemsCount == 0 || selectedItemsCount > 1)
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Diagnostics;
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Peek.Common.Models;
|
|
||||||
using Peek.UI.Extensions;
|
|
||||||
using Peek.UI.Helpers;
|
using Peek.UI.Helpers;
|
||||||
using Peek.UI.Models;
|
using Peek.UI.Models;
|
||||||
|
|
||||||
@@ -16,10 +13,8 @@ namespace Peek.UI
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isMultipleFilesActivation;
|
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 selectedItemsShellArray = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle);
|
||||||
var selectedItemsCount = selectedItemsShellArray?.GetCount() ?? 0;
|
var selectedItemsCount = selectedItemsShellArray?.GetCount() ?? 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user