[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:
gokcekantarci
2023-05-30 11:44:58 +03:00
committed by GitHub
parent 9786d08695
commit 0c69e3422c
9 changed files with 162 additions and 0 deletions

View File

@@ -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>