mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[Peek]Add setting to close after losing focus (#26364)
* [Peek] WindowActivationState checks are added for focus and close after losing focus. * Add setting to activate the behavior --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -6,6 +6,7 @@ using System;
|
||||
using interop;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Peek.Common.Constants;
|
||||
using Peek.FilePreviewer.Models;
|
||||
@@ -28,6 +29,7 @@ namespace Peek.UI
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Activated += PeekWindow_Activated;
|
||||
|
||||
ViewModel = App.GetService<MainWindowViewModel>();
|
||||
|
||||
@@ -38,6 +40,23 @@ namespace Peek.UI
|
||||
AppWindow.Closing += AppWindow_Closing;
|
||||
}
|
||||
|
||||
private void PeekWindow_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
|
||||
{
|
||||
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.CodeActivated)
|
||||
{
|
||||
this.BringToForeground();
|
||||
}
|
||||
|
||||
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.Deactivated)
|
||||
{
|
||||
var userSettings = App.GetService<IUserSettings>();
|
||||
if (userSettings.CloseAfterLosingFocus)
|
||||
{
|
||||
Uninitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle Peek hotkey, by toggling the window visibility and querying files when necessary.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user