mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
check if FZ is running
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// 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.
|
||||||
|
|
||||||
@@ -13,6 +13,9 @@ namespace Microsoft.FancyZones.UnitTests.Utils
|
|||||||
public class FancyZonesSession : IDisposable
|
public class FancyZonesSession : IDisposable
|
||||||
{
|
{
|
||||||
private const string FancyZonesPath = @"\..\..\..\PowerToys.FancyZones.exe";
|
private const string FancyZonesPath = @"\..\..\..\PowerToys.FancyZones.exe";
|
||||||
|
private const string FancyZonesProcessName = "PowerToys.FancyZones";
|
||||||
|
|
||||||
|
private bool stopFancyZones = true;
|
||||||
|
|
||||||
public Process? FancyZonesProcess { get; }
|
public Process? FancyZonesProcess { get; }
|
||||||
|
|
||||||
@@ -20,12 +23,22 @@ namespace Microsoft.FancyZones.UnitTests.Utils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Launch FancyZones
|
// Check if FancyZones is already running
|
||||||
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
Process[] runningFZ = Process.GetProcessesByName(FancyZonesProcessName);
|
||||||
path += FancyZonesPath;
|
if (runningFZ.Length > 0)
|
||||||
|
{
|
||||||
|
FancyZonesProcess = runningFZ[0];
|
||||||
|
stopFancyZones = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Launch FancyZones
|
||||||
|
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
path += FancyZonesPath;
|
||||||
|
|
||||||
ProcessStartInfo info = new ProcessStartInfo(path);
|
ProcessStartInfo info = new ProcessStartInfo(path);
|
||||||
FancyZonesProcess = Process.Start(info);
|
FancyZonesProcess = Process.Start(info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -40,7 +53,11 @@ namespace Microsoft.FancyZones.UnitTests.Utils
|
|||||||
// Close the application
|
// Close the application
|
||||||
if (FancyZonesProcess != null)
|
if (FancyZonesProcess != null)
|
||||||
{
|
{
|
||||||
FancyZonesProcess.Kill();
|
if (stopFancyZones)
|
||||||
|
{
|
||||||
|
FancyZonesProcess.Kill();
|
||||||
|
}
|
||||||
|
|
||||||
FancyZonesProcess.Close();
|
FancyZonesProcess.Close();
|
||||||
FancyZonesProcess.Dispose();
|
FancyZonesProcess.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user