[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:
Yevhenii Holovachov
2020-06-10 20:58:34 +03:00
committed by GitHub
parent 38350a1ae4
commit 6fdfd3b9e7
7 changed files with 111 additions and 6 deletions

View File

@@ -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);
}
});
}
}
}

View File

@@ -25,6 +25,7 @@ namespace FancyZonesEditor
ActiveZoneSetTmpFile,
AppliedZoneSetTmpFile,
CustomZoneSetsTmpFile,
PowerToysPID,
}
private static CanvasLayoutModel _blankCustomModel;
@@ -242,6 +243,13 @@ namespace FancyZonesEditor
private static string _customZoneSetsTmpFile;
public static int PowerToysPID
{
get { return _powerToysPID; }
}
private static int _powerToysPID;
// UpdateLayoutModels
// Update the five default layouts based on the new ZoneCount
private void UpdateLayoutModels()
@@ -410,7 +418,7 @@ namespace FancyZonesEditor
WorkArea = SystemParameters.WorkArea;
string[] args = Environment.GetCommandLineArgs();
if (args.Length == 5)
if (args.Length == 6)
{
var parsedLocation = args[(int)CmdArgs.X_Y_Width_Height].Split('_');
var x = int.Parse(parsedLocation[0]);
@@ -424,6 +432,8 @@ namespace FancyZonesEditor
_appliedZoneSetTmpFile = args[(int)CmdArgs.AppliedZoneSetTmpFile];
_customZoneSetsTmpFile = args[(int)CmdArgs.CustomZoneSetsTmpFile];
int.TryParse(args[(int)CmdArgs.PowerToysPID], out _powerToysPID);
ParseDeviceInfoData();
}
}