mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
[PT Run] Closing PT Run and new settings app when PowerToys is not running (#3853)
Closing PowerLauncher, FZ Editor and new settings app when PowerToys is not running
This commit is contained in:
committed by
GitHub
parent
38350a1ae4
commit
6fdfd3b9e7
@@ -2,6 +2,9 @@
|
||||
// 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;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using FancyZonesEditor.Models;
|
||||
|
||||
@@ -21,6 +24,8 @@ namespace FancyZonesEditor
|
||||
|
||||
private void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
WaitForPowerToysRunner();
|
||||
|
||||
LayoutModel foundModel = null;
|
||||
|
||||
foreach (LayoutModel model in ZoneSettings.DefaultModels)
|
||||
@@ -57,5 +62,27 @@ namespace FancyZonesEditor
|
||||
overlay.Show();
|
||||
overlay.DataContext = foundModel;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
|
||||
|
||||
private void WaitForPowerToysRunner()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
const uint INFINITE = 0xFFFFFFFF;
|
||||
const uint WAIT_OBJECT_0 = 0x00000000;
|
||||
const uint SYNCHRONIZE = 0x00100000;
|
||||
|
||||
IntPtr powerToysProcHandle = OpenProcess(SYNCHRONIZE, false, Settings.PowerToysPID);
|
||||
if (WaitForSingleObject(powerToysProcHandle, INFINITE) == WAIT_OBJECT_0)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user