Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PackageManager.UI/PackageManager.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<AssemblyName>PackageManager.UI</AssemblyName>
<TargetFramework>net461</TargetFramework>
<ApplicationIcon>Views\Assets\box-search-result.ico</ApplicationIcon>
<StartupObject>PackageManager.Program</StartupObject>
</PropertyGroup>

<ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions src/PackageManager.UI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Threading;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;

namespace PackageManager
{
public static class Program
{
private const string ApplicationKey = "5CFB158B-8346-4588-926D-99006A5195B6";
private const int RestoreWindowCommandCode = 0x09;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll")]
private static extern IntPtr SetForegroundWindow(IntPtr hWnd);

[STAThread]
public static void Main()
{
using var mutex = new Mutex(false, ApplicationKey, out bool createdNew);

if (createdNew)
{
var application = new App();

application.InitializeComponent();
application.Run();
}
else
{
var currentProcess = Process.GetCurrentProcess();
var mainProcess = Process.GetProcesses()
.Where(x => x.Id != currentProcess.Id)
.FirstOrDefault(x => x.ProcessName == currentProcess.ProcessName);

if (mainProcess != null)
{
ShowWindow(mainProcess.MainWindowHandle, RestoreWindowCommandCode);
SetForegroundWindow(mainProcess.MainWindowHandle);
}
}
}
}
}